好的,跟进我的上一个问题后,我取得了一些进展。游戏现在拥有左右移动和简单跳跃脚本,进化哦 :D
我最新加入的是一个空闲动画,现在这个角色无法向左移动 :D 我希望这不会太愚蠢,我检查了所有东西,但找不出问题 >.> ..
无论如何,这里是代码,请提前致谢,非常感激!(原始代码太糟糕了,抱歉 >.<):
import pygame
pygame.init()
path = "C:/Users/user/Documents/Le game/"
win = pygame.display.set_mode((800, 700))
pygame.display.set_caption("Potato ultra")
bg = pygame.image.load(path + "BG.jpg")
walk_right = [pygame.image.load("C:/Users/user/Documents/Le game/R2.png"), pygame.image.load("C:/Users/user/Documents/Le game/R3.png"), pygame.image.load("C:/Users/user/Documents/Le game/R4.png"), pygame.image.load("C:/Users/user/Documents/Le game/R5.png"), pygame.image.load("C:/Users/user/Documents/Le game/R6.png"), pygame.image.load("C:/Users/user/Documents/Le game/R7.png"), pygame.image.load("C:/Users/user/Documents/Le game/R8.png"), pygame.image.load("C:/Users/user/Documents/Le game/R9.png")]
walk_left = [pygame.image.load("C:/Users/user/Documents/Le game/L2.png"), pygame.image.load("C:/Users/user/Documents/Le game/L3.png"), pygame.image.load("C:/Users/user/Documents/Le game/L4.png"), pygame.image.load("C:/Users/user/Documents/Le game/L5.png"), pygame.image.load("C:/Users/user/Documents/Le game/L6.png"), pygame.image.load("C:/Users/user/Documents/Le game/L7.png"), pygame.image.load("C:/Users/user/Documents/Le game/L8.png"), pygame.image.load("C:/Users/user/Documents/Le game/L9.png")]
Static = pygame.image.load("C:/Users/user/Documents/Le game/Idle.png")
SW = 800
SH = 700
x = 0
y = 480
width = 64
height = 64
vel = 20
isJump = False
MoveLeft = False
MoveRight = False
Idle = False
JumpCount = 10
walkCount = 0
def redrawGameWindow():
win.blit(bg, (0,0))
global walkCount
if not Idle:
if MoveRight:
if walkCount <= 7:
win.blit(walk_right[walkCount], (x, y))
elif walkCount > 7:
walkCount = 0
win.blit(walk_right[walkCount], (x, y))
if MoveLeft:
if walkCount <= 7:
win.blit(walk_left[walkCount], (x, y))
elif walkCount > 7:
walkCount = 0
win.blit(walk_left[walkCount], (x, y))
else:
win.blit(Static, (x, y))
pygame.display.update()
run = True
while run:
pygame.time.delay(50)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and x > 0:
Idle = False
MoveRight = False
MoveLeft = True
x -= vel
walkCount += 1
if keys[pygame.K_RIGHT] and x < SW - width:
Idle = False
MoveRight = True
MoveLeft = False
x += vel
walkCount += 1
else:
Idle = True
if not isJump:
if keys[pygame.K_UP] and y > 0:
y -= vel
if y < 0:
y = 0
if keys[pygame.K_DOWN] and y < SH - height:
y += vel
if y > 636:
y = 636
if keys[pygame.K_SPACE]:
isJump = True
else:
if JumpCount >= -10:
y -= (JumpCount * 4)
if y < 0:
y = 0
JumpCount -= 2
else:
isJump = False
JumpCount = 10
redrawGameWindow()
pygame.quit()