Changeset 334:a3f1b2f0e3fb for nagslang/protagonist.py
 Timestamp:
 09/06/13 09:39:48 (9 years ago)
 Branch:
 default
 Phase:
 public
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

nagslang/protagonist.py
r333 r334 1 1 import pymunk 2 2 import pymunk.pygame_util 3 from pymunk.vec2d import Vec2d4 3 5 4 from nagslang import render … … 13 12 from nagslang.resources import resources 14 13 from nagslang.events import ScreenChange 14 from nagslang.utils import vec_from_angle, vec_with_length 15 15 16 16 … … 171 171 172 172 def get_facing_direction(self): 173 # It's easier to work with a vector than an angle here. 174 vec = Vec2d.unit() 175 vec.angle = self.angle 176 # We probably don't have exactly 1, 0, or 1 here. 173 # Our angle is quantised to 45 degree intervals, so possible values for 174 # x and y in a unit vector are +/(0, sqrt(2)/2, 1) with some floating 175 # point imprecision. Rounding will normalise these to (1.0, 0.0, 1.0) 176 # which we can safely turn into integers and use as dict keys. 177 vec = vec_from_angle(self.angle) 177 178 x = int(round(vec.x)) 178 179 y = int(round(vec.y)) … … 204 205 return 205 206 self.is_moving = True 206 self.angle = pymunk.Vec2d((dx, dy)).angle207 self. physicser.apply_impulse(208 (dx * self.impulse_factor, dy * self.impulse_factor))207 vec = vec_with_length((dx, dy), self.impulse_factor) 208 self.angle = vec.angle 209 self.physicser.apply_impulse(vec) 209 210 210 211 def set_position(self, position): … … 259 260 if not self.has_item('gun'): 260 261 return 261 vec = Vec2d.unit() 262 vec.angle = self.angle 263 vec.length = 1000 262 vec = vec_from_angle(self.angle, 1000) 264 263 FireEvent.post( 265 264 self.physicser.position, vec, BULLET_DAMAGE, COLLISION_TYPE_PLAYER) 266 265 267 266 def claw(self): 268 vec = Vec2d.unit() 269 vec.angle = self.angle 270 vec.length = 30 267 vec = vec_from_angle(self.angle, 30) 271 268 ClawEvent.post(self.physicser.position, vec, CLAW_DAMAGE) 272 269
Note:
See TracChangeset
for help on using the changeset viewer.