Commit 1c78ed4a by BellCodeEditor

save project

parent 404b1b35
Showing with 19 additions and 14 deletions
import pygame
from pygame import locals
import random
pygame.init() # 初始化
class a(pygame.sprite.Sprite):
def __init__(self,a1,a2,a3):
super().__init__()
self.image=random.choice([a1,a2,a3])
self.rect=self.image.get_rect()
self.rect.x=1000
self.rect.y=500-self.rect.height
self.score=1
# 创建一个窗口
screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
......@@ -11,7 +21,7 @@ background = pygame.image.load('bg.png') # 背景
road = pygame.image.load('road.png') # 路
stone = pygame.image.load('stone.png') # 石头
cacti = pygame.image.load('cacti.png') # 仙人掌
apple = pygame.image.load('bush.png') # 灌木丛
bush = pygame.image.load('bush.png') # 灌木丛
hero =[pygame.image.load('hero1.png'),
pygame.image.load('hero2.png'),
pygame.image.load('hero3.png'),
......@@ -21,9 +31,7 @@ index = 0
a="running"
y=400
t=30
road_x=0
bg_x=0
aa=a(bush,cacti,stone)
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -53,17 +61,14 @@ while True:
if index>len(hero)-1:
index=0
# 将背景图画上去
bg_x-=50
if bg_x<-1000:
bg_x=0
screen.blit(background, (bg_x, 0))
road_x-=50
if road_x<-1000:
road_x=0
screen.blit(road, (road_x, 500))
screen.blit(background, (0, 0))
screen.blit(road, (0, 500))
screen.blit(wukong, (150, y))
if aa.rect.x <=0-aa.rect.width:
aa=a(bush,cacti,stone)
screen.blit(aa.image,(aa.rect.x,aa.rect.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