Mercurial > touhou
annotate pytouhou/utils/interpolator.py @ 50:811cefefb5c8
Fix a few bugs and add support for a few instructions
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Mon, 22 Aug 2011 21:16:47 +0200 |
parents | 6ebf9539c077 |
children | ab826bc29aa2 |
rev | line source |
---|---|
13 | 1 class Interpolator(object): |
2 def __init__(self, values=()): | |
3 self.values = tuple(values) | |
4 self.start_values = tuple(values) | |
5 self.end_values = tuple(values) | |
6 self.start_frame = 0 | |
7 self.end_frame = 0 | |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
8 self._frame = 0 |
13 | 9 |
10 | |
11 def set_interpolation_start(self, frame, values): | |
12 self.start_values = tuple(values) | |
13 self.start_frame = frame | |
14 | |
15 | |
16 def set_interpolation_end(self, frame, values): | |
17 self.end_values = tuple(values) | |
18 self.end_frame = frame | |
19 | |
20 | |
21 def set_interpolation_end_frame(self, end_frame): | |
22 self.end_frame = end_frame | |
23 | |
24 | |
25 def set_interpolation_end_values(self, values): | |
26 self.end_values = tuple(values) | |
27 | |
28 | |
29 def update(self, frame): | |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
30 self._frame = frame |
13 | 31 if frame >= self.end_frame: |
32 self.values = tuple(self.end_values) | |
33 self.start_values = tuple(self.end_values) | |
34 self.start_frame = frame | |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
35 return frame == self.end_frame |
13 | 36 else: |
37 truc = float(frame - self.start_frame) / float(self.end_frame - self.start_frame) | |
38 self.values = tuple(start_value + truc * (end_value - start_value) | |
39 for (start_value, end_value) in zip(self.start_values, self.end_values)) | |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
40 return True |
20
6ebf9539c077
Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents:
13
diff
changeset
|
41 |