-
Notifications
You must be signed in to change notification settings - Fork 1
/
Player.py
34 lines (24 loc) · 1 KB
/
Player.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Two objects: Enemy and Player
# Connect keys for movement, inherited from Parent to Child class
import pygame
import random
from Object import Object
PL_V = 3 # player velocity, had to include this here
class Player(Object):
def __init__(self, name, width, height, x, y, image_path):
super(Player, self).__init__(name, width, height, x,y, image_path)
self.in_middle = False
def update(self):
key = pygame.key.get_pressed()
if key[pygame.K_LEFT]:
if self.rect.centerx > 0:
self.move_x(-PL_V)
self.in_middle = False
elif key[pygame.K_RIGHT]:
if self.rect.centerx > 380:
self.in_middle = True
elif self.in_middle == False:
self.move_x(PL_V)
self.rect.centerx = self.x
self.rect.centery = self.y
# jumping can be added here, but for now, this will be for movements left and right.