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

Administrator / pygame_lesson7_diy4

  • 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 b0c1e74b authored 3 years ago by BellCodeEditor's avatar BellCodeEditor
Browse files
Options
  • Browse Files
  • Download
  • Email Patches
  • Plain Diff

save project

parent f5d37d85
Show whitespace changes
Inline Side-by-side
Showing with 27 additions and 13 deletions
  • my_game.py
my_game.py
View file @ b0c1e74b
...@@ -3,6 +3,14 @@ from pygame import locals ...@@ -3,6 +3,14 @@ from pygame import locals
import random import random
pygame.init() # 初始化 pygame.init() # 初始化
class Block(pygame.sprite.Sprite):
def __init__(self,image1,image2,image3):
super().__init__()
self.image=random.choice([image1,image2,image3])
self.rect=self.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))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
...@@ -23,10 +31,10 @@ index = 0 ...@@ -23,10 +31,10 @@ index = 0
y=400 y=400
jumpSatate="running" jumpSatate="running"
t=30 t=30
obstacle=random.choice([bush,stone,cacti]) rode_x=0
rect = obstacle.get_rect() background_x=0
rect.x=1000 block_list=pygame.sprite.Group()
rect.y=500-rect.height
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
...@@ -56,16 +64,21 @@ while True: ...@@ -56,16 +64,21 @@ while True:
if index==5: if index==5:
index=0 index=0
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) if rode_x<=-1000:
screen.blit(road, (0, 500)) rode_x=0
if background_x<=-1000:
background_x=0
background_x-=0.5
screen.blit(background, (background_x, 0))
rode_x-=8
screen.blit(road, (rode_x, 500))
screen.blit(wukong, (150, y)) screen.blit(wukong, (150, y))
# 刷新画面 # 刷新画面
if rect.x <= 0-rect.width: obstacle=Block(bush,cacti,stone)
obstacle = choice([bush,stone,cacti]) block_list.add(obstacle)
rect=obstacle.get_rect() for sprite in block_list:
rect.x=1000 sprite.rect.x-=8
rect.y=500-rect.height screen.blit(sprite.image,(sprite.rect.x,sprite.rect.y))
rect.x-=8 screen.blit(obstacle.image,(obstacle.rect.x,obstacle.rect.y))
screen.blit(obstacle,(rect.x,rect.y))
pygame.display.update() pygame.display.update()
FPS.tick(60) FPS.tick(60)
\ No newline at end of file
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