Commit 5ceaca80 by BellCodeEditor

save project

parent a2eb5993
Showing with 31 additions and 4 deletions
import pygame
from pygame import locals
import random
pygame.init() # 初始化
# 创建一个窗口
screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
pygame.display.set_caption("悟空酷跑")
# 载入图片
class Block(pygame.sprite.Sprite):
def _init_(self,image1,image2,image3):
super()._init_()
self.image=random.choice([image1,image2,image3])
self.rect=self.image.get_rect()
self.rect.x=1000
self.rect.y=500-self.rect.height
background = pygame.image.load('bg.png') # 背景
road = pygame.image.load('road.png') # 路
stone = pygame.image.load('stone.png') # 石头
......@@ -17,6 +27,11 @@ index = 0
y=400
jumpstart="running"
t=30
road_x=0
background_x=0
object=Block(stone,cacti,apple)
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -44,11 +59,22 @@ while True:
index+=1
if index>4:
index=0
if road_x<-1000:
road_x=0
road_x-=8
if background_x<-1000:
background_x=0
background_x-=3
if object.rect.x<0-object.rect.width:
object=Block(stone,cacti,apple)
object.rect.x-=8
# 将背景图画上去
screen.blit(background, (0, 0))
screen.blit(road, (0, 500))
screen.blit(background, (background_x, 0))
screen.blit(road, (road_x, 500))
screen.blit(wukong, (150, y))
screen.blit(object.image,(object.rect.x,object.rect.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