Python Forum
How to move the player upwards and downwards?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to move the player upwards and downwards?
#1
Hello everybody.

I am making a little game and somehow I can't figure out how to move my player sprite upwards or downwards without needing to rotate the player image.

So here is my code:

vec = pg.math.Vector2
class Player(pg.sprite.Sprite):
    def get_keys(self):
        self.rot_speed = 0
        self.vel = vec(0, 0)
        keys = pg.key.get_pressed()
        if keys[pg.K_LEFT] or keys[pg.K_a]:
            self.vel = vec(-PLAYER_SPEED / 2, 0).rotate(-self.rot)
        if keys[pg.K_RIGHT] or keys[pg.K_d]:
            self.vel = vec(PLAYER_SPEED, 0).rotate(-self.rot)
        if keys[pg.K_UP] or keys[pg.K_w]:
            pass
        if keys[pg.K_DOWN] or keys[pg.K_s]:
            pass

   
Can anybody tell me how to do this? Thanks, would be nice. Smile
Piethon
Reply


Messages In This Thread
How to move the player upwards and downwards? - by Piethon - Feb-17-2020, 04:29 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020