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

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

save project

parent 936f2083
Hide whitespace changes
Inline Side-by-side
Showing with 19 additions and 14 deletions
  • my_game.py
my_game.py
View file @ 6598252a
......@@ -14,6 +14,7 @@ class Block(pygame.sprite.Sprite):
# 障碍物绘制坐标
self.rect.x = 1000
self.rect.y = 500 - self.rect.height
self.score=1
class Player(pygame.sprite.Sprite):
def __init__(self,image):
......@@ -38,11 +39,14 @@ hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero3.png'),
pygame.image.load('hero4.png'),
pygame.image.load('hero5.png')]
my_font=pygame.font.Font("STKAITI.TTF",25)
index = 0
y = 400
jumpState = "runing"
t = 30
t = 34
score=0
bg_x = 0
road_x = 0
time = 0
......@@ -77,13 +81,13 @@ while True:
else:
jumpState = "down"
if jumpState == "down": # 降落状态
if t <= 30:
if t <= 34:
y += t
wukong.rect.y=y
t += 2
else:
jumpState = "runing"
t =30
t =34
# 将背景图画上去
......@@ -97,17 +101,10 @@ while True:
screen.blit(road, (road_x, 500))
screen.blit(wukong.image, (150, y)) # 悟空
# 绘制障碍物
# if obstacle.rect.x <= 0-obstacle.rect.width:
# obstacle = Block(bush,cacti,stone)
# obstacle.rect.x -= 8
# obstacle.draw()
# +++++++++++++++++++++++++++++++++++++++
# 创建障碍物对象
time += 1
if time >= 60:
r = random.randint(0, 100)
if r > 40:
r = random.randint(0, 50)
if r > 20:
obstacle = Block(bush,cacti,stone)
block_list.add(obstacle)
time = 0
......@@ -121,7 +118,14 @@ while True:
gameover=pygame.image.load('gameover.png')
screen.blit(gameover,(400,200))
gamestate=False
# print(len(block_list))
else:
if sprite.rect.x<wukong.rect.x-sprite.rect.width:
score+=sprite.score
sprite.score=0
info="Score "+ str(score)
text=my_font.render(info,True,(0,0,0))
screen.blit(text,(850,70))
# 刷新画面
pygame.display.update()
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