forked from bdilly/lastcity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_entity.py
executable file
·37 lines (31 loc) · 1.24 KB
/
game_entity.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#----------------------------------------------------------------------
# Author:
# Bruno Dilly <[email protected]>
#
# Copyright (C) 2008 Bruno Dilly
#
# Released under GNU GPL, read the file 'COPYING' for more information
# ----------------------------------------------------------------------
class GameEntity(object):
def __init__(self, world, kind, image, location, speed = 0):
self.world = world
self.kind = kind
self.image = image
self.location = location
self.speed = speed
self.destination = location
def render(self, surface):
x, y = self.location
w, h = self.image.get_size()
surface.blit(self.image, (x-w/2, y-h/2))
def act(self, time_passed):
if self.speed > 0 and self.location != self.destination:
path_to_destination = self.destination - self.location
distance_to_destination = path_to_destination.get_magnitude()
path_to_destination.normalize()
travel_distance = min(distance_to_destination, time_passed * self.speed)
self.location += path_to_destination * travel_distance
def destroy(self):
self.world.remove_entity(self)