Commit c1e6ca51 by BellCodeEditor

auto save

parent 67e0708d
Showing with 25 additions and 7 deletions
import pygame
from pygame import locals
import random
pygame.init() # 初始化
class Block(pygame.sprite.Sprite):
def __init__(self,img1,img2,img3):
super().__init__()
self.zaw=random.choice([cacti,stone,apple])
self.rect=self.zaw.get_rect()
self.rect.x=1000
self.rect.y=500-self.rect.height
# 创建一个窗口
screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
......@@ -22,6 +29,9 @@ y=400
state='running'
wukong=hero[0]
t=30
block=Block(cacti,stone,apple)
road_x=0
bg_x=0
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -46,13 +56,22 @@ while True:
t=30
wukong=hero[index%5]
if state=='running':
index+=1 】‘
index+=1
if block.rect.x<0-block.rect.width:
block=Block(cacti,stone,apple)
block.rect.x-=8
# 将背景图画上去
screen.blit(background, (0, 0))
screen.blit(road, (0, 500))
bg_x-=1
if bg_x<-1000:
bg_x=0
screen.blit(background, (bg_x, 0))
road_x-=8
if road_x<-1000:
road_x=0
screen.blit(road, (road_x, 500))
screen.blit(wukong, (150, y))
screen.blit(block.zaw, (block.rect.x,block.rect.y))
# 刷新画面
pygame.display.update()
FPS.tick(60)
\ No newline at end of file
FPS.tick(60)
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