-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyPlayer.py
28 lines (23 loc) · 838 Bytes
/
MyPlayer.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
import pygame
import colors
#Player class
class player(pygame.sprite.Sprite):
def __init__(self, name, color, lifes,score=0):
super().__init__()
self.name = name
self.color = color
self.lifes = lifes
self.speed = 21
self.width = self.height = 25
self.score = score
self.image = pygame.Surface([self.width, self.height])
self.image.fill(colors.WHITE)
self.image.set_colorkey(colors.WHITE)
pygame.draw.rect(self.image, color, [0, 0, 21, 21])
self.rect = pygame.rect.Rect((0, 0, 21, 21))
def move(self,direction, pixels = 21):
#Up -> 1, Right -> 2, Down -> -1, Left -> -2
if direction == 1 or direction == -1:
self.rect.y += pixels*-direction
else:
self.rect.x += pixels*(direction/2)