Commit e4993009 by BellCodeEditor

auto save

parent 26ab0738
Showing with 48 additions and 3 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import random
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
pygame.init() # 初始化 pygame.init() # 初始化
# 创建一个窗口 # 创建一个窗口
...@@ -24,6 +33,13 @@ a = 0 #悟空造型变量 ...@@ -24,6 +33,13 @@ a = 0 #悟空造型变量
kingy = 400 kingy = 400
jump = "running" jump = "running"
name_list = pygame.sprite.Group()
rode_x = 0
background_x = 0
time = 0
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
...@@ -37,7 +53,7 @@ while True: ...@@ -37,7 +53,7 @@ while True:
if event.key == locals.K_SPACE: if event.key == locals.K_SPACE:
jump = "up" jump = "up"
if jump == "up": if jump == "up":
if high >= 0: if high > 0:
kingy -= high kingy -= high
high -= 2 high -= 2
...@@ -55,9 +71,38 @@ while True: ...@@ -55,9 +71,38 @@ while True:
screen.blit(background, (0, 0)) screen.blit(background, (background_x, 0))
screen.blit(road, (0, 500)) screen.blit(road, (rode_x, 500))
screen.blit(hero[a], (150, kingy)) screen.blit(hero[a], (150, kingy))
time += 1
if time >= 60:
time = 0
num = random.randint(0,50)
if num > 20:
face = Block(stone,cacti,apple)
name_list.add(face)
for sprite in name_list:
sprite.rect.x -= 8
screen.blit(sprite.image,(sprite.rect.x,sprite.rect.y))
if sprite.rect.x <= 0 - sprite.rect.width:
sprite.kill()
# screen.blit(face.image,(face.rect.x,face.rect.y))
# if face.rect.x <= 0 - face.rect.width:
# face = Block(stone,cacti,apple)
# else:
# face.rect.x -= 8
if rode_x<=-1000:
rode_x = 0
else:
rode_x-= 8
if background_x <= -1000:
background_x = 0
else:
background_x -= 2
if a <=3: if a <=3:
a+=1 a+=1
else: else:
......
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