annotate pytouhou/vm/anmrunner.py @ 182:20843875ad8f

(Hopefully) use difficulty as it should. The difficulty[0] (also called rank) varies from 0 to 32 and affects various parts of the game. The difficulty now impact those parts, but how it is modified during the gameplay is not clear. Such changes to the difficulty are not handled yet. [0] http://en.touhouwiki.net/wiki/Embodiment_of_Scarlet_Devil/Gameplay#Rank
author Thibaut Girka <thib@sitedethib.com>
date Tue, 25 Oct 2011 01:29:40 +0200
parents e7902309305c
children 741860192b56
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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',
81
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
27 'sprite_index_offset',
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
28 'script', 'instruction_pointer', 'frame')
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
81
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
31 def __init__(self, anm_wrapper, script_id, sprite, sprite_index_offset=0):
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
32 self._anm_wrapper = anm_wrapper
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
33 self._sprite = sprite
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
34 self._running = True
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
35
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
36 anm, self.script = anm_wrapper.get_script(script_id)
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
37 self.frame = 0
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
38 self.instruction_pointer = 0
81
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
39
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
40 self.sprite_index_offset = sprite_index_offset
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
41
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
42
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
43 def run_frame(self):
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
44 if not self._running:
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
45 return False
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
46
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
47 sprite = self._sprite
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
48
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
49 while self._running:
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
50 frame, opcode, args = self.script[self.instruction_pointer]
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
51
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
52 if frame > self.frame:
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
53 break
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
54 else:
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
55 self.instruction_pointer += 1
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
56
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
57 if frame == self.frame:
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
58 try:
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
59 callback = self._handlers[opcode]
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
60 except KeyError:
129
284ac8f97a96 Fix potential crash
Thibaut Girka <thib@sitedethib.com>
parents: 122
diff changeset
61 logger.warn('unhandled opcode %d (args: %r)', opcode, args)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
62 else:
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
63 callback(self, *args)
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
64 sprite._changed = True
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
65 self.frame += 1
120
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
66
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
67 # Update sprite
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
68 sprite.frame += 1
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
69
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
70 if sprite.rotations_speed_3d != (0., 0., 0.):
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
71 ax, ay, az = sprite.rotations_3d
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
72 sax, say, saz = sprite.rotations_speed_3d
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
73 sprite.rotations_3d = ax + sax, ay + say, az + saz
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
74 sprite._changed = True
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
75
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
76 if sprite.scale_speed != (0., 0.):
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
77 rx, ry = sprite.rescale
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
78 rsx, rsy = sprite.scale_speed
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
79 sprite.rescale = rx + rsx, ry + rsy
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
80 sprite._changed = True
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
81
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
82 if sprite.fade_interpolator:
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
83 sprite.fade_interpolator.update(sprite.frame)
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
84 sprite.alpha = int(sprite.fade_interpolator.values[0])
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
85 sprite._changed = True
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
86
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
87 if sprite.scale_interpolator:
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
88 sprite.scale_interpolator.update(sprite.frame)
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
89 sprite.rescale = sprite.scale_interpolator.values
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
90 sprite._changed = True
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
91
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
92 if sprite.offset_interpolator:
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
93 sprite.offset_interpolator.update(sprite.frame)
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
94 sprite.dest_offset = sprite.offset_interpolator.values
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
95 sprite._changed = True
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
96
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
97 return self._running
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
98
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 @instruction(0)
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
101 def remove(self):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
102 self._sprite._removed = True
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
103 self._running = False
69
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(1)
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
107 def load_sprite(self, sprite_index):
81
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
108 self._sprite.anm, self._sprite.texcoords = self._anm_wrapper.get_sprite(sprite_index + self.sprite_index_offset)
69
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(2)
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
112 def set_scale(self, sx, sy):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
113 self._sprite.rescale = sx, sy
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(3)
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
117 def set_alpha(self, alpha):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
118 self._sprite.alpha = alpha % 256 #TODO
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
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
121 @instruction(4)
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
122 def set_color(self, b, g, r):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
123 self._sprite.color = (r, g, b)
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
124
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
125
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
126 @instruction(5)
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
127 def jump(self, instruction_pointer):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
128 #TODO: is that really how it works?
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
129 self.instruction_pointer = instruction_pointer
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
130 self.frame = self.script[self.instruction_pointer][0]
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
131
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
132
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
133 @instruction(7)
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
134 def toggle_mirrored(self):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
135 self._sprite.mirrored = not self._sprite.mirrored
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
136
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
137
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
138 @instruction(9)
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
139 def set_rotations_3d(self, rx, ry, rz):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
140 self._sprite.rotations_3d = rx, ry, rz
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
141
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
142
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
143 @instruction(10)
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
144 def set_rotations_speed_3d(self, srx, sry, srz):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
145 self._sprite.rotations_speed_3d = srx, sry, srz
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
146
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
147
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
148 @instruction(11)
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
149 def set_scale_speed(self, ssx, ssy):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
150 self._sprite.scale_speed = ssx, ssy
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
151
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
152
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
153 @instruction(12)
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
154 def fade(self, new_alpha, duration):
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
155 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
156
72
6a08f44fa01b Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents: 71
diff changeset
157
6a08f44fa01b Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents: 71
diff changeset
158 @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
159 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
160 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
161
6a08f44fa01b Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents: 71
diff changeset
162
6a08f44fa01b Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents: 71
diff changeset
163 @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
164 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
165 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
166
6a08f44fa01b Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents: 71
diff changeset
167
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
168 @instruction(15)
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
169 @instruction(21) #TODO
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
170 def keep_still(self):
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
171 self._running = False
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
172
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
173 @instruction(16)
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
174 def load_random_sprite(self, min_idx, amp):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
175 #TODO: use the game's PRNG?
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
176 self.load_sprite(min_idx + randrange(amp))
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
177
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
178
170
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
179 @instruction(17)
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
180 def move(self, x, y, z):
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
181 self._sprite.dest_offset = (x, y, z)
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
182
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
183
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
184 @instruction(18)
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
185 def move_in_linear(self, x, y, z, duration):
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
186 self._sprite.move_in(duration, x, y, z, lambda x: x)
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
187
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
188
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
189 @instruction(19)
170
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
190 def move_in_decel(self, x, y, z, duration):
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
191 self._sprite.move_in(duration, x, y, z, lambda x: 2. * x - x ** 2)
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
192
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
193
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
194 @instruction(20)
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
195 def move_in_accel(self, x, y, z, duration):
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
196 self._sprite.move_in(duration, x, y, z, lambda x: x ** 2)
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
197
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
198
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
199 @instruction(23)
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
200 def set_corner_relative_placement(self):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
201 self._sprite.corner_relative_placement = True #TODO
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
202
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
203
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
204 @instruction(25)
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
205 def set_allow_dest_offset(self, value):
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
206 self._sprite.allow_dest_offset = bool(value)
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
207
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
208
81
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
209 @instruction(26)
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
210 def set_automatic_orientation(self, value):
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
211 """If true, rotate by pi-angle around the z axis.
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
212 """
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
213 self._sprite.automatic_orientation = bool(value)
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
214
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
215
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
216 @instruction(27)
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
217 def shift_texture_x(self, dx):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
218 tox, toy = self._sprite.texoffsets
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
219 self._sprite.texoffsets = tox + dx, toy
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
220
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
221
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
222 @instruction(28)
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
223 def shift_texture_y(self, dy):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
224 tox, toy = self._sprite.texoffsets
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
225 self._sprite.texoffsets = tox, toy + dy
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
226
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
227
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
228 @instruction(30)
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
229 def scale_in(self, sx, sy, duration):
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
230 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
231