Commit f5eb1184 by BellCodeEditor

auto save

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