Apr-26-2025, 04:15 PM
whenever I press 'W' it crashed without a error
whenever I turn, the tank moves massively
whenever I turn, the tank moves massively
import pygame import math window = pygame.display.set_mode((800, 600)) keys = pygame.key.get_pressed() class Tank: def __init__(self): self.instance = pygame.image.load('green-tank.png') self.rect = self.instance.get_rect(center=(400, 300)) self.direction = 0 def frame(self): if keys[pygame.K_w] or keys[pygame.K_SPACE]: self.rect.x += 3 * sin(self.direction) self.rect.y += 3 * cos(self.direction) if keys[pygame.K_a] or keys[pygame.K_LEFT]: self.direction -= 3 self.instance = pygame.transform.rotate(self.instance, -3) if keys[pygame.K_d] or keys[pygame.K_RIGHT]: self.direction += 3 self.instance = pygame.transform.rotate(self.instance, 3) window.blit(self.instance, self.rect) tank = Tank() while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() exit() window.fill('black') keys = pygame.key.get_pressed() tank.frame() pygame.display.flip() pygame.time.Clock().tick(120)