Commit 09cd21c0 by BellCodeEditor

auto save

parent eb56baaf
Showing with 16 additions and 8 deletions
import pygame
from pygame import locals
import random
pygame.init() # 初始化
class Block(pygame.sprite.Sprite):
def __init__(self,image1,image2,image3):
super().__init__()
......@@ -16,7 +16,6 @@ class player(pygame.sprite.Sprite):
self.rect = self.image.get_rect()
self.rect.x = 150
self.rect.y = 400
pygame.init() # 初始化
# 创建一个窗口
screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
......@@ -51,13 +50,15 @@ while True:
jumpState = "up"
if jumpState == "up": # 起跳状态
if t > 0:
y-= t
y -= t
wukong.rect.y = y
t -= 2
else:
jumpState = "down"
if jumpState == "down": # 降落状态
if t <= 30:
y += t
wukong.rect.y = y
t += 2
else:
jumpState = "runing"
......@@ -79,14 +80,20 @@ while True:
lu_x=0
screen.blit(road, (lu_x, 500)) # 路
screen.blit(wukong.image, (150, y)) # 悟空
if obstacle.rect.x <= 0-obstacle.rect.width: # 障碍物消失
# 创建障碍物对象
time += 1
if time >= 60:
time = 0
num = ramdon.randint(0,50)
if num >20:
obstacle=Block(bush,cacti,stone)
block_list.add(obstacle)
for sprit in block_list:
obstacle.rect.x -= 8
screen.blit(obstacle.image, (obstacle.rect.x, obstacle.rect.y))
if obstacle.rect.x <= 0-obstacle.rect.width:
sprite.kill() # 障碍物消失
if pygame.sprite.collide_rect(wukong,sprite):
# 刷新画面
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