Commit 279d4e51 by BellCodeEditor

save project

parent 846a210d
Showing with 46 additions and 36 deletions
import pygame import pygame
from pygame import locals from pygame import locals
pygame.init() # 初始化 pygame.init() # 初始化
score = 0 # 创建一个窗口
grid_size = 20 # 格子大小 screen = pygame.display.set_mode((1000, 600))
grid_num_width = 15 # 横向格子数量 FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
grid_num_height = 25 # 纵向格子数量 # 载入图片
FPS = 30 background = pygame.image.load('bg.png') # 背景
center=[2,7] road = pygame.image.load('road.png') # 路
# 创建窗口 stone = pygame.image.load('stone.png') # 石头
screen = pygame.display.set_mode((460, 500)) cacti = pygame.image.load('cacti.png') # 仙人掌
pygame.display.set_caption("俄罗斯方块") apple = pygame.image.load('bush.png') # 灌木丛
clock = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) hero = [pygame.image.load('hero1.png'),pygame.image.load('hero2.png'),pygame.image.load('hero3.png'),pygame.image.load('hero4.png'),pygame.image.load('hero5.png')]
# 载入素材 index = 0
background = pygame.image.load('bg.png') pygame.display.set_caption("悟空跑酷")
font = pygame.font.Font('STKAITI.TTF', 40) # 字体 y=400
j="run"
t=30
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:
# 接收到退出事件后退出程序
exit() exit()
if event.type==locals.KEYDOWN: if event.type == locals.KEYDOWN:
if event.key==locals.K_RIGHT: if j=="run":
if center[1]<15: if event.key == locals.K_SPACE:
center[1]+=1 j="up"
if j=="up":
elif event.key==locals.K_LEFT: if t>0:
if center[1]>1: y-=t
center[1]-=1 t-=2
elif event.key==locals.K_DOWN: else:
if center[0]<25: j="down"
center[0]+=1 if j=="down":
if t<=30:
y+=t
t+=2
else:
j="run"
t=30
wukong=hero[index]
if j =="run":
index+=1
if index==5:
index=0
# 将背景图画上去 # 将背景图画上去
screen.blit(background,(0,0)) screen.blit(background, (0, 0))
pygame.draw.rect(screen,(255,255,255),(center[1]*20-20,center[0]*20-20,20,20),0) screen.blit(road, (0, 500))
pygame.draw.rect(screen,(0,0,0),(center[1]*20-20,center[0]*20-20,20,20),1) screen.blit(wukong, (150, y))
# 得分
score1 = font.render(str(score),True,(255,255,255))
screen.blit(score1,(350,70))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
clock.tick(FPS) FPS.tick(30)
\ No newline at end of file \ 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