From 706afd224be173da65ff354450585a97c97c3214 Mon Sep 17 00:00:00 2001
From: BellCodeEditor <bellcode_dev@bell.ai>
Date: Sun, 12 Mar 2023 11:54:27 +0800
Subject: [PATCH] save project

---
 my_game.py | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/my_game.py b/my_game.py
index 28a8564..c3789a0 100644
--- a/my_game.py
+++ b/my_game.py
@@ -18,17 +18,31 @@ hero = [pygame.image.load('hero1.png'),
         pygame.image.load('hero4.png'),
         pygame.image.load('hero5.png')]
 index = 0 
+y=400
+jumpState='running'
 
 while True:
     for event in pygame.event.get():
         if event.type == locals.QUIT:
             # 接收到退出事件后退出程序
             exit()
-    
+        if event.type == locals.KEYDOWN:
+            if event.key == locals.K_SPACE:
+                jumpState = 'up'
+    if jumpState=='up':
+        if y>150:
+            y-=5
+        else:
+            jumpState = 'down'
+    if jumpState=='down':
+        if y<400:
+            y+=5
+        else:
+            jumpState = 'running'
     # 将背景图画上去
     screen.blit(background, (0, 0))
     screen.blit(road, (0, 500))
-    screen.blit(hero[index], (150, 400))
+    screen.blit(hero[index], (150, y))
     index+=1
     if index>4:
         index=0
--
libgit2 0.25.0