/
entityConfig.py
41 lines (31 loc) · 1.21 KB
/
entityConfig.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
35
36
37
38
39
40
41
__author__ = 'Peter'
import pygame
from vector import Vector
# base class to build game pygame creatures on. sets up the pygame surface, with a vector.
# bounds defines the game area to keep the sprite within, checked within the update methods
# the inheriting class should draw to the
class Entity(pygame.sprite.Sprite):
def __init__(self, bounds=[0,600,0,800], size=(4,4)):
pygame.sprite.Sprite.__init__(self)
self.__update_surface_size(size) #creates scope variable "image", which is a pygame surface
self.alive = True
self.bounds = bounds
self.vector = Vector()
def die(self):
self.alive = False
self.vector.dx = 0
self.vector.dy = 0
def update(self, timestep = 1):
self.update_position(timestep)
def __update_position(self, timestep = 1):
self.vector.update(timestep)
def __update_surface_size(self, size=(1,1)):
self.image = pygame.Surface(size)
def set_size(self, size=(1,1)):
self.update_surface_size(size)
@property
def orientation(self):
return self.vector.orientation()
@property
def rect(self):
return self.image.get_rect(topleft=(self.vector.x,self.vector.y))