Mercurial > touhou
annotate pytouhou/utils/interpolator.py @ 56:299de3a9b69f
Filter out off-screen enemies (the same way the official game does)
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Tue, 23 Aug 2011 00:15:22 +0200 |
parents | ab826bc29aa2 |
children | 694f25881d0f |
rev | line source |
---|---|
52
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
1 # -*- encoding: utf-8 -*- |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
2 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com> |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
4 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
5 ## This program is free software; you can redistribute it and/or modify |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
6 ## it under the terms of the GNU General Public License as published |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
7 ## by the Free Software Foundation; version 3 only. |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
8 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
9 ## This program is distributed in the hope that it will be useful, |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
12 ## GNU General Public License for more details. |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
13 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
14 |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
15 |
13 | 16 class Interpolator(object): |
17 def __init__(self, values=()): | |
18 self.values = tuple(values) | |
19 self.start_values = tuple(values) | |
20 self.end_values = tuple(values) | |
21 self.start_frame = 0 | |
22 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
|
23 self._frame = 0 |
13 | 24 |
25 | |
26 def set_interpolation_start(self, frame, values): | |
27 self.start_values = tuple(values) | |
28 self.start_frame = frame | |
29 | |
30 | |
31 def set_interpolation_end(self, frame, values): | |
32 self.end_values = tuple(values) | |
33 self.end_frame = frame | |
34 | |
35 | |
36 def set_interpolation_end_frame(self, end_frame): | |
37 self.end_frame = end_frame | |
38 | |
39 | |
40 def set_interpolation_end_values(self, values): | |
41 self.end_values = tuple(values) | |
42 | |
43 | |
44 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
|
45 self._frame = frame |
13 | 46 if frame >= self.end_frame: |
47 self.values = tuple(self.end_values) | |
48 self.start_values = tuple(self.end_values) | |
49 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
|
50 return frame == self.end_frame |
13 | 51 else: |
52 truc = float(frame - self.start_frame) / float(self.end_frame - self.start_frame) | |
53 self.values = tuple(start_value + truc * (end_value - start_value) | |
54 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
|
55 return True |
20
6ebf9539c077
Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents:
13
diff
changeset
|
56 |