step relative; turn sprite

This commit is contained in:
Frank DeMarco 2017-12-14 03:47:26 -05:00
parent b5f7057506
commit 446388ef9a
4 changed files with 21 additions and 7 deletions

7
README
View File

@ -49,8 +49,7 @@ Todo
- Debug levels
Contact
-------
Credit
------
frank dot s dot demarco at gmail
http://A-O.in
Frank DeMarco <if.self.end@a-o.in>

View File

@ -8,7 +8,6 @@ class Animation(GameChild):
self.default_method = method or self.build_frame
self.accounts = {}
self.register(self.default_method, interval=interval)
self.current_elapsed = 0
self.last_update = 0
def build_frame(self):
@ -57,7 +56,7 @@ class Animation(GameChild):
def is_account_playing(self, account, include_delay):
return account.playing and (not include_delay or not account.delay)
def reset_timer(self, method):
def reset_timer(self, method=None):
if not method:
for account in self.accounts.values():
account.reset_timer()

View File

@ -5,7 +5,7 @@ from glob import glob
from pygame import Color, Rect, Surface, PixelArray
from pygame.image import load
from pygame.transform import flip
from pygame.transform import flip, rotate
from pygame.locals import *
from Animation import Animation
@ -14,6 +14,8 @@ from extension import get_hue_shifted_surface, get_step
class Sprite(Animation):
N, W, S, E = range(4)
def __init__(self, parent, framerate=None, neighbors=[], mass=None):
Animation.__init__(self, parent, self.shift_frame, framerate)
self.frames = []
@ -29,6 +31,7 @@ class Sprite(Animation):
self.locations.append(Location(self))
self.motion_overflow = Vector()
self.display_surface = self.get_display_surface()
self.rotation = self.N
def __getattr__(self, name):
if name in ("location", "rect"):
@ -135,6 +138,16 @@ class Sprite(Animation):
frames[ii] = flip(frame, True, False)
self.mirrored = not self.mirrored
def point(self, heading):
center = self.location.center
for ii, frame in enumerate(self.frames):
self.frames[ii] = rotate(frame, abs(heading - self.rotation) * 90)
for frameset in self.framesets:
frameset.measure_rect()
self.update_location_size()
self.rotation = heading
self.location.center = center
def clear_frames(self):
self.frames = []
for frameset in self.framesets:

View File

@ -11,6 +11,9 @@ def get_step(start, end, speed):
angle = atan2(x1 - x0, y1 - y0)
return speed * sin(angle), speed * cos(angle)
def get_step_relative(start, end, step):
return get_step(start, end, get_distance(start, end) * step)
def get_angle(start, end, transpose=False):
angle = atan2(end[1] - start[1], end[0] - start[0])
if transpose: