Mercurial > touhou
annotate pytouhou/vm/anmrunner.py @ 73:e4af16a019d3
Do not remove enemies as soon as they lose their animation (Daiyousei...)
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Sun, 28 Aug 2011 11:20:16 +0200 |
parents | 6a08f44fa01b |
children | f5f9b5eb69a3 |
rev | line source |
---|---|
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
1 # -*- encoding: utf-8 -*- |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
2 ## |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com> |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
4 ## |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
5 ## This program is free software; you can redistribute it and/or modify |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
6 ## it under the terms of the GNU General Public License as published |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
7 ## by the Free Software Foundation; version 3 only. |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
8 ## |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
9 ## This program is distributed in the hope that it will be useful, |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
12 ## GNU General Public License for more details. |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
13 ## |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
14 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
15 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
16 from random import randrange |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
17 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
18 from pytouhou.utils.helpers import get_logger |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
19 from pytouhou.vm.common import MetaRegistry, instruction |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
20 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
21 logger = get_logger(__name__) |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
22 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
23 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
24 class ANMRunner(object): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
25 __metaclass__ = MetaRegistry |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
26 __slots__ = ('_anm_wrapper', '_sprite', '_running', |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
27 'script', 'instruction_pointer', 'frame') |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
28 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
29 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
30 def __init__(self, anm_wrapper, script_id, sprite): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
31 self._anm_wrapper = anm_wrapper |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
32 self._sprite = sprite |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
33 self._running = True |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
34 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
35 anm, self.script = anm_wrapper.get_script(script_id) |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
36 self.frame = 0 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
37 self.instruction_pointer = 0 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
38 pass |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
39 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
40 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
41 def run_frame(self): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
42 if self._sprite._removed: |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
43 return False |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
44 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
45 while self._running: |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
46 try: |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
47 frame, instr_type, args = self.script[self.instruction_pointer] |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
48 except IndexError: |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
49 return False |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
50 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
51 if frame > self.frame: |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
52 break |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
53 else: |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
54 self.instruction_pointer += 1 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
55 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
56 if frame == self.frame: |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
57 try: |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
58 callback = self._handlers[instr_type] |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
59 except KeyError: |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
60 logger.warn('unhandled opcode %d (args: %r)', instr_type, args) |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
61 else: |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
62 callback(self, *args) |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
63 self._sprite._changed = True |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
64 self.frame += 1 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
65 return self._running |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
66 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
67 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
68 @instruction(0) |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
69 def remove(self): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
70 self._sprite._removed = True |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
71 self._running = True |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
72 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
73 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
74 @instruction(1) |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
75 def load_sprite(self, sprite_index): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
76 self._sprite.anm, self._sprite.texcoords = self._anm_wrapper.get_sprite(sprite_index) |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
77 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
78 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
79 @instruction(2) |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
80 def set_scale(self, sx, sy): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
81 self._sprite.rescale = sx, sy |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
82 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
83 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
84 @instruction(3) |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
85 def set_alpha(self, alpha): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
86 self._sprite.alpha = alpha % 256 #TODO |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
87 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
88 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
89 @instruction(4) |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
90 def set_color(self, b, g, r): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
91 self._sprite.color = (r, g, b) |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
92 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
93 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
94 @instruction(5) |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
95 def jump(self, instruction_pointer): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
96 #TODO: is that really how it works? |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
97 self.instruction_pointer = instruction_pointer |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
98 self.frame = self.script[self.instruction_pointer][0] |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
99 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
100 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
101 @instruction(7) |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
102 def toggle_mirrored(self): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
103 self._sprite.mirrored = not self._sprite.mirrored |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
104 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
105 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
106 @instruction(9) |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
107 def set_rotations_3d(self, rx, ry, rz): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
108 self._sprite.rotations_3d = rx, ry, rz |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
109 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
110 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
111 @instruction(10) |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
112 def set_rotations_speed_3d(self, srx, sry, srz): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
113 self._sprite.rotations_speed_3d = srx, sry, srz |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
114 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
115 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
116 @instruction(11) |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
117 def set_scale_speed(self, ssx, ssy): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
118 self._sprite.scale_speed = ssx, ssy |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
119 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
120 |
71
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
121 @instruction(12) |
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
122 def fade(self, new_alpha, duration): |
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
123 self._sprite.fade(duration, new_alpha, lambda x: x) #TODO: formula |
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
124 |
72
6a08f44fa01b
Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents:
71
diff
changeset
|
125 |
6a08f44fa01b
Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents:
71
diff
changeset
|
126 @instruction(13) |
6a08f44fa01b
Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents:
71
diff
changeset
|
127 def set_blendfunc_alphablend(self): |
6a08f44fa01b
Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents:
71
diff
changeset
|
128 self._sprite.blendfunc = 1 |
6a08f44fa01b
Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents:
71
diff
changeset
|
129 |
6a08f44fa01b
Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents:
71
diff
changeset
|
130 |
6a08f44fa01b
Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents:
71
diff
changeset
|
131 @instruction(14) |
6a08f44fa01b
Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents:
71
diff
changeset
|
132 def set_blendfunc_add(self): |
6a08f44fa01b
Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents:
71
diff
changeset
|
133 self._sprite.blendfunc = 0 #TODO |
6a08f44fa01b
Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents:
71
diff
changeset
|
134 |
6a08f44fa01b
Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents:
71
diff
changeset
|
135 |
71
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
136 @instruction(15) |
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
137 @instruction(21) #TODO |
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
138 def keep_still(self): |
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
139 self._running = False |
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
140 |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
141 @instruction(16) |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
142 def load_random_sprite(self, min_idx, amp): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
143 #TODO: use the game's PRNG? |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
144 self.load_sprite(min_idx + randrange(amp)) |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
145 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
146 |
71
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
147 @instruction(19) |
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
148 def move_in(self, x, y, z, duration): |
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
149 self._sprite.move_in(duration, x, y, z, lambda x: x) #TODO: formula |
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
150 |
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
151 |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
152 @instruction(23) |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
153 def set_corner_relative_placement(self): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
154 self._sprite.corner_relative_placement = True #TODO |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
155 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
156 |
71
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
157 @instruction(25) |
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
158 def set_allow_dest_offset(self, value): |
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
159 self._sprite.allow_dest_offset = bool(value) |
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
160 |
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
161 |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
162 @instruction(27) |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
163 def shift_texture_x(self, dx): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
164 tox, toy = self._sprite.texoffsets |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
165 self._sprite.texoffsets = tox + dx, toy |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
166 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
167 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
168 @instruction(28) |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
169 def shift_texture_y(self, dy): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
170 tox, toy = self._sprite.texoffsets |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
171 self._sprite.texoffsets = tox, toy + dy |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
172 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
173 |
71
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
174 @instruction(30) |
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
175 def scale_in(self, sx, sy, duration): |
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
176 self._sprite.scale_in(duration, sx, sy, lambda x: x) #TODO: formula |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
177 |