Commit 419bac80 by BellCodeEditor

save project

parent fbbe75c0
Showing with 49 additions and 16 deletions
import pygame
from pygame import locals
import random
from random import *
#----------------------------------
#----------------------------------
pygame.init() # 初始化
class Spr(pygame.sprite.Sprite):
def __init__(self,i1,i2,i3):
super().__init__()
self.i = choice([i1,i2,i3])
self.rect = self.i.get_rect()
self.rect.x = 1000
self.rect.y = 500 - self.rect.height
#----------------------------------
# 创建一个窗口
screen = pygame.display.set_mode((1145, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
#----------------------------------
pygame.display.set_caption("Braised Intestines in Brown Sauce")#-"感人故事:我保留了一部分寒假作业"-
#----------------------------------
# 载入图片
background = pygame.image.load('bg.png') # 背景
road = pygame.image.load('road.png')# 路
#----------------------------------
stone = pygame.image.load('stone.png') # 石头
cacti = pygame.image.load('cacti.png') # 仙人掌
bush = pygame.image.load('bush.png') # 灌木丛
#----------------------------------
hero = [pygame.image.load('hero1.png'),pygame.image.load('hero2.png'),pygame.image.load('hero3.png'),pygame.image.load('hero4.png'),pygame.image.load('hero5.png'),]
stone_x = 1000
obstacle = random.choice([bush,stone,cacti])
rest = obstacle.get_rect()
rest.x = 1000
rest.y = 500 - rest.height
#----------------------------------
#---------------------
obs = Spr(bush,cacti,stone)
road_x = 0
bg_x = 0
index = 0
#---------------------
y = 400
......@@ -42,19 +59,24 @@ while True:
exit()
if event.type == locals.KEYDOWN and jump_ == "run":
if event.key == locals.K_SPACE:
pygame.display.set_caption("我保留了一部分九转大肠")
pygame.display.set_caption(choice(["俞涛保留了一部分九转大肠的鲜味","感人故事:我保留了一部分寒假作业","压缩毛巾","任何答辩终将原地爆炸","YATM又TM的死机了","极速地球2","假酒害人","逃离物锂卷","距离唱跳还有2.5年",choice(["船新升级中.","船新升级中..","船新升级中..."])]))
jump_ = "up"
#----------------------------------
if jump_ == "up":
if speed_y>0:
#----------------------------------
if speed_y > 0:
y-=speed_y
speed_y-=2
speed_y -= 1.5
#----------------------------------
else:
jump_ = "down"
#----------------------------------
else:
#----------------------------------
if speed_y <= 30:
y+=speed_y
speed_y+=2
speed_y += 1.5
#----------------------------------
else:
y=400
speed_y = 30
......@@ -65,8 +87,14 @@ while True:
# 将背景图画上去
#-------------------------------
screen.blit(background, (0, 0))
screen.blit(road, (0, 500))
bg_x -= 2
if bg_x <= -1000:
bg_x=0
screen.blit(background, (bg_x, 0))
road_x -= 10
if road_x <= -1000:
road_x=0
screen.blit(road, (road_x, 500))
#-------------------------------跑步
if jump_ == "run":
screen.blit(hero[index], (150, 400))
......@@ -74,8 +102,13 @@ while True:
else:
screen.blit(hero[index], (150, y))
#-------------------------------
rest.x -= 15
screen.blit(obstacle, (rest.x,rest.y))
#-------------------------------
if obs.rect.x <= 0-obs.rect.height:
obs.rect.x=1000
obs = Spr(bush,cacti,stone)
obs.rect.x -= 10
screen.blit(obs.i, (obs.rect.x,obs.rect.y))
# 刷新画面
pygame.display.update()
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