Commit f5eb1184 by BellCodeEditor

auto save

parent b3b23e6c
Showing with 24 additions and 11 deletions
import pygame
from pygame import locals
import random
pygame.init() # 初始化
# 创建一个窗口
......@@ -22,6 +23,11 @@ index = 0
a = [hero,hero2,hero3,hero4,hero5]
y = 400
jump = "run"
b= random.choice([stone,stone,cacti])
rect = b.get_rect()
rect.x = 1000
rect.y = 400
t=30
......@@ -31,38 +37,45 @@ while True:
# 接收到退出事件后退出程序
exit()
if event.type == locals.KEYDOWN:
if jump=="run":
if event.key == locals.K_SPACE:
jump = "up"
if jump == "up":
if y >= 150:
y -= 5
if t >=0:
y -= t
t-=2
else:
jump = "down"
t=0
if jump == "down":
if y <= 400:
y += 5
if t <=30:
y += t
t+=2
else:
jump = "run"
t=30
if rect.x <= 0-rect.width:
b = random.choice([stone,stone,cacti])
rect = b.get_rect()
rect.x = 1000
rect.y = 400
rect.x -= 8
rect = cacti.get_rect()
print(rect)
print(rect.x)
print(rect.y)
print(rect.width)
print(rect.height)
if jump=="run":
index += 1
if index >= 5:
index = 0
# 将背景图画上去
screen.blit(background, (0, 0))
screen.blit(road, (0, 500))
screen.blit(b, (rect.x,rect.y))
screen.blit(a[index], (150, y))
# 刷新画面
pygame.display.update()
......
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