Sep-13-2021, 11:59 AM
Here I have some code:
import pygame import pymunk import sys pygame.init() screen = pygame.display.set_mode((1280,720)) clock = pygame.time.Clock() space = pymunk.Space() class Player(): def __init__(self, x, y, w, h): self.x = x self.y = y self.w = w self.h = h self.body = pymunk.Body(body_type = pymunk.Body.KINEMATIC) self.body.position = x, y self.shape = pymunk.Poly.create_box(self.body, (w, h)) self.shape.elasticity = 1 space.add(self.body, self.shape) def draw(self): pygame.draw.rect(screen, (100,200,255), (self.x, self.y, self.w, self.h),0, 10) def moveUP(self, up_down): if up_down: self.body.velocity = 0, -600 if not up_down: self.body.velocity = 0, 600 def moveDOWN(self, left_right): if left_right: self.body.velocity = -600, 0 if not left_right: self.body.velocity = 600, 0 def stop(self): self.body.velocity = 0, 0 player = Player(100,200,50,50) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() player.draw() k = pygame.key.get_pressed() if k[pygame.K_w]: player.moveUP(True) elif k[pygame.K_s]: player.moveUP(False) else: player.stop() pygame.display.flip() screen.fill((0,0,0)) clock.tick(60) space.step(1/60)After setting the velocity to -600 in the moveUP function at Player Class, shouldn't the player move? Am I doing something wrong??