My friend wrote this and sent it to me to debug but I can not figure out what's wrong? Why does this subtract, but not add? I have tried many workarounds like subtraction by negative number etc, but it doesn't work. Granted I am new to python and don't know much about the pygame module, so please advise.
import pygame
pygame.init
WIN = pygame.display.set_mode((1000, 600))
pygame.display.set_caption ("Space Cats")
icon = pygame.image.load('007-cat-2.png')
pygame.display.set_icon(icon)
pla_img = pygame.image.load("002-grinning.png")
def draw_window(plaHB):
WIN.fill((0, 100, 75))
WIN.blit(pla_img, (plaHB.x, plaHB.y))
pygame.display.update()
def MAIN():
run = True
plaX, plaY = 450, 500
plaSpeed = 0.7
plaHB = pygame.Rect(plaX, plaY, 32, 32)
#FPS = 60
#clock = pygame.time.Clock
while run == True:
#clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
key_pre = pygame.key.get_pressed()
if key_pre[pygame.K_RIGHT] and plaHB.x < 1000:
plaHB.x = plaHB.x + plaSpeed
if key_pre[pygame.K_LEFT] and plaHB.x > 0:
plaHB.x -= plaSpeed
if key_pre[pygame.K_UP]:
plaHB.y -= plaSpeed
if key_pre[pygame.K_DOWN]:
plaHB.y += plaSpeed
draw_window(plaHB)
pygame.QUIT
if __name__ == "__main__":
MAIN()