comparison skaapsteker/physics.py @ 623:65881746dc20

More Sprite hierarchy work.
author Jeremy Thurgood <firxen@gmail.com>
date Sat, 07 May 2011 13:59:00 +0200
parents da331c80ec08
children 83569a6b3ad8
comparison
equal deleted inserted replaced
622:da331c80ec08 623:65881746dc20
31 collision_layer = None # never collides with anything 31 collision_layer = None # never collides with anything
32 collides_with = set() # nothing collides with this 32 collides_with = set() # nothing collides with this
33 33
34 # set to True to have .update() called once per tick (and have .collision_group set) 34 # set to True to have .update() called once per tick (and have .collision_group set)
35 wants_updates = False 35 wants_updates = False
36
37 debug_color = (240, 0, 0)
38 36
39 floor = False # We special case collisions with ground objects 37 floor = False # We special case collisions with ground objects
40 block = False 38 block = False
41 39
42 def __init__(self, *args, **kwargs): 40 def __init__(self, *args, **kwargs):
51 self.collision_group = None 49 self.collision_group = None
52 self._mask_cache = {} # image id -> collision bit mask 50 self._mask_cache = {} # image id -> collision bit mask
53 51
54 def init_pos(self): 52 def init_pos(self):
55 self._float_pos = self.rect.center 53 self._float_pos = self.rect.center
56
57 def get_debug_color(self):
58 return self.debug_color
59
60 def draw_debug(self, surface):
61 pygame.draw.rect(surface, self.get_debug_color(), self.collide_rect, 1)
62 54
63 55
64 def deltav(self, dv): 56 def deltav(self, dv):
65 velocity = cadd(self.velocity, dv) 57 velocity = cadd(self.velocity, dv)
66 self.velocity = cclamp(velocity, self.terminal_velocity) 58 self.velocity = cclamp(velocity, self.terminal_velocity)