From db336d5b31dca462cd184f69518b167934d99334 Mon Sep 17 00:00:00 2001 From: BellCodeEditor <bellcode_dev@bell.ai> Date: Sun, 11 Jun 2023 08:59:20 +0800 Subject: [PATCH] save project --- 1.PY | 8 ++++++++ my_game.py | 22 +++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 1.PY diff --git a/1.PY b/1.PY new file mode 100644 index 0000000..f2120f6 --- /dev/null +++ b/1.PY @@ -0,0 +1,8 @@ +import pygame +cacti=pygame.image.load('cacti.png') +rect=cacti.get_rect() +print(rect) +print(rect.x) +print(rect.y) +print(rect.width) +print(rect.height) \ No newline at end of file diff --git a/my_game.py b/my_game.py index df73b22..ca630e6 100644 --- a/my_game.py +++ b/my_game.py @@ -1,6 +1,6 @@ import pygame from pygame import locals - +import random pygame.init() # 初始化 # 创建一个窗口 screen = pygame.display.set_mode((1000, 600)) @@ -15,7 +15,12 @@ apple = 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')] index = 0 jumpState='running' +ob=random.choice([bush,stone,cacti]) +rect=ob.get_rect() +rect.x + y=400 +t=30 while True: for event in pygame.event.get(): if event.type == locals.QUIT: @@ -34,8 +39,19 @@ while True: y+=5 else: jumpState='running' - - + if jumpState=='up': + if t>0: + y-=t + t-=2 + else: + jumpState='down' + if jumpState=='down': + if t<=30: + y+=t + t+=2 + else: + jumpState='runing' + y=400 wukong=hero[index] index+=1 if index==5: -- libgit2 0.25.0