Commit 6c86f0cb by BellCodeEditor

auto save

parent 14580aa7
Showing with 60 additions and 3 deletions
import pygame
cacti = pygame.image.load("cacti.png")
rect = cacti.get_rect()
print(rect)
print(type(rect))
print(rect.x)
print(rect.y)
print(rect.width)
print(rect.height)
\ No newline at end of file
import pygame
from pygame import locals
import random
pygame.init() # 初始化
# 创建一个窗口
......@@ -16,22 +17,67 @@ hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero3.png'),
pygame.image.load('hero4.png'),
pygame.image.load('hero5.png')]
index = 0
wukong_number = 0
jumpstate = "running"
y = 400
t = 30
zhangaiwu = random.choice([stone,cacti,apple])
rect = zhangaiwu.get_rect()
rect.x = 1000
rect.y = 500 - rect.height
zhangaiwu2 = random.choice([stone,cacti,apple])
rect2 = zhangaiwu2.get_rect()
rect2.x = 1000
rect2.y = 500 - rect2.height
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
if event.type == locals.KEYDOWN:
if event.key == locals.K_SPACE:
if jumpstate == "running":
jumpstate = "up"
if jumpstate == "up" :
if t > 0 and y > 150:
y -= t
t -= 2
else:
jumpstate = "down"
if jumpstate == "down":
if t <= 30 and y < 400 :
y += t
t += 2
else:
jumpstate = "running"
t = 30
wukong = hero[wukong_number]
if jumpstate == "running":
wukong_number +=1
if wukong_number == len(hero) - 1 :
wukong_number = 0
# 将背景图画上去
screen.blit(background, (0, 0))
screen.blit(road, (0, 500))
screen.blit(wukong, (150, 400))
screen.blit(wukong, (150, y))
rect.x -= 8
if rect.x < 0 - rect.width:
zhangaiwu = random.choice([stone,apple,cacti])
rect = zhangaiwu.get_rect()
rect.x = 1000
rect.y = 500 - rect.height
if rect.x < 500 :
while not rect2.x < 0 - rect2.width:
rect2.x -= 8
if rect2.x < 0 - rect2.width:
zhangaiwu2 = random.choice([stone,apple,cacti])
rect2 = zhangaiwu2.get_rect()
rect2.x = 1000
rect2.y = 500 - rect.height
print(rect.x)
print(rect2.x)
screen.blit(zhangaiwu,(rect.x,rect.y))
screen.blit(zhangaiwu2,(rect2.x,rect2.y))
# 刷新画面
pygame.display.update()
FPS.tick(60)
\ No newline at end of file
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