Commit cd2d6fd9 by BellCodeEditor

save project

parent 2e73ee62
Showing with 67 additions and 6 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import random
from random import *
pygame.init() # 初始化 pygame.init() # 初始化
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((1000, 600)) screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
# 载入图片 # 载入图片
background = pygame.image.load('bg.png') # 背景 bg = pygame.image.load('bg.png') # 背景
road = pygame.image.load('road.png') # 路 road = pygame.image.load('road.png') # 路
stone = pygame.image.load('stone.png') # 石头 stone = pygame.image.load('stone.png') # 石头
cacti = pygame.image.load('cacti.png') # 仙人掌 cacti = pygame.image.load('cacti.png') # 仙人掌
...@@ -20,10 +22,38 @@ index = 0 ...@@ -20,10 +22,38 @@ index = 0
G=5 G=5
y=400 y=400
IM='running' IM='running'
I_M=0
rond_x=0
bg_x=0
ind=0
dw,s=150,0
time=0
PS=60
class Rsc(pygame.sprite.Sprite):
def __init__(self,im1,im2,im3):
super().__init__()
self.image=choice([im1,im2,im3])
self.rect=self.image.get_rect()
self.rect.x=1000
self.rect.y=500-self.rect.height
obg=Rsc(stone,cacti,apple)
blist=pygame.sprite.Group()
while True: while True:
print(G)
time+=1
if time>=60:
a=randint(1,60)
if a>=20:
obg=Rsc(stone,cacti,apple)
blist.add(obg)
time=0
if IM=='running': if IM=='running':
index+=1 ind+=1
if ind>=5:
index+=1
ind=0
if index==5: if index==5:
index=0 index=0
for event in pygame.event.get(): for event in pygame.event.get():
...@@ -32,14 +62,33 @@ while True: ...@@ -32,14 +62,33 @@ while True:
exit() exit()
if event.type == locals.KEYDOWN: if event.type == locals.KEYDOWN:
if event.key == locals.K_SPACE: if event.key == locals.K_SPACE:
if IM=='running':
I_M=0
if IM!='up'and IM!='down': if IM!='up'and IM!='down':
IM='up' IM='up'
I_M=1
if IM!='running' and I_M>=1:
if event.key == locals.K_w:
IM='dup'
I_M=0
G+=2
if index<=4:
index+=1
if index==5:
index=1
dws=150,y
if IM=='up': if IM=='up':
if y>150: if y>150:
y-=2*G y-=2*G
G-=0.1 G-=0.1
else: else:
IM='down' IM='down'
if IM=='dup':
if G>=0:
y-=G
G-=0.15
else:
IM='down'
if IM=='down': if IM=='down':
if y<=400: if y<=400:
y+=2*G y+=2*G
...@@ -53,9 +102,21 @@ while True: ...@@ -53,9 +102,21 @@ while True:
herorun=hero[index] herorun=hero[index]
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) bg_x-=1
screen.blit(road, (0, 500)) if bg_x<=-1000:
bg_x=0
screen.blit(bg, (bg_x, 0))
rond_x-=8
if rond_x<= -1000:
rond_x=0
screen.blit(road, (rond_x, 500))
screen.blit(herorun, (150, y)) screen.blit(herorun, (150, y))
# if obg.rect.x<0-obg.rect.height:
# obg=Rsc(stone,cacti,apple)
for pop in blist:
pop.rect.x-=8
screen.blit(pop.image,(pop.rect.x,pop.rect.y))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPS.tick(60) PS+=1
\ No newline at end of file FPS.tick(PS)
\ 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