Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

Administrator / pygame_lesson7_diy1

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Commit 6f9f7676 authored 3 years ago by BellCodeEditor's avatar BellCodeEditor
Browse files
Options
  • Browse Files
  • Download
  • Email Patches
  • Plain Diff

save project

parent 46e93d09
Hide whitespace changes
Inline Side-by-side
Showing with 15 additions and 8 deletions
  • my_game.py
my_game.py
View file @ 6f9f7676
...@@ -4,6 +4,16 @@ import random ...@@ -4,6 +4,16 @@ import random
from pygame import locals from pygame import locals
pygame.init() # 初始化 pygame.init() # 初始化
class Block(pygame.sprite.Sprite):
def _init_ (self,image1,image2,image3):
surper()._init_()
self.image = random.choice([image1,image2,image3])
self.rect = image.get_rect()
self.rect.x = 1000
self.rect.y = 500-self.rect.height
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((1000, 600)) screen = pygame.display.set_mode((1000, 600))
pygame.display.set_caption('wukongkupao') pygame.display.set_caption('wukongkupao')
...@@ -31,7 +41,7 @@ hero = [pygame.image.load('hero1.png'), ...@@ -31,7 +41,7 @@ hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero5.png')] pygame.image.load('hero5.png')]
zhang_ai = random.choice([stone,cacti,bush]) zhang_ai = Block(stone,cacti,bush)
rect = zhang_ai.get_rect() rect = zhang_ai.get_rect()
rect.x=1000 rect.x=1000
rect.y = 500-rect.height rect.y = 500-rect.height
...@@ -84,13 +94,10 @@ while True: ...@@ -84,13 +94,10 @@ while True:
#障碍:随机,移动 #障碍:随机,移动
if rect.x <= 0-rect.width: if zhang_ai.rect.x <= 0-zhang_ai.rect.width:
zhang_ai = random.choice([stone,cacti,bush]) zhang_ai = Block([stone,cacti,bush])
rect = zhang_ai.get_rect() zhang_ai.rect.x -=8
rect.x = 1000 screen.blit(zhang_ai,(zhang_ai.image,zhang_ai.rect.x,zhang_ai.rect.y))
rect.y = 500-rect.height
rect.x -=8
screen.blit(zhang_ai,(rect.x,rect.y))
pygame.display.update()#保存 pygame.display.update()#保存
......
This diff is collapsed. Click to expand it.
  • Write
  • Preview
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment