forked from JarvistheJellyFish/AICivGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameEntity.py
51 lines (36 loc) · 1.44 KB
/
GameEntity.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
42
43
44
45
46
47
48
49
50
51
from World import *
from StateMachine import *
from vector2 import *
import pygame
from pygame.locals import *
class GameEntity(object):
def __init__(self, world, name, image):
self.world = world
self.name = name
self.image = image
try:
self.image.set_colorkey((255,0,255))
except AttributeError:
pass
self.location = Vector2(0, 0)
self.world_location = Vector2(0, 0)
self.destination = Vector2(0, 0)
self.speed = 0.
self.brain = StateMachine()
self.id = 0
self.tp = 1.0
def render(self, surface):
x, y = self.world_location
w, h = self.image.get_size()
pos = (x-w/2, y-h/2)
surface.blit(self.image, pos)
def process(self, time_passed):
self.brain.think()
self.tp = time_passed
self.world_location=self.location+self.world.background_pos
if self.speed > 0. and self.location != self.destination:
vec_to_destination = self.destination - self.location
distance_to_destination = vec_to_destination.get_length()
heading = vec_to_destination.get_normalized()
travel_distance = min(distance_to_destination, time_passed * self.speed)
self.location += travel_distance * heading *time_passed * self.speed