annotate pytouhou/vm/anmrunner.py @ 443:cae83b963695

Make pytouhou.game.effect an extension type.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 17 Aug 2013 02:36:05 +0200
parents 1222341ea22c
children 98995d8ac744
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
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
16 from random import randrange, random
69
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
430
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
26 __slots__ = ('_anm', '_sprite', 'running', 'sprite_index_offset', 'script',
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
27 'instruction_pointer', 'frame', 'waiting', 'handlers',
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
28 'variables', 'version', 'timeout')
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
29
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
30 #TODO: check!
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
31 formulae = {0: lambda x: x,
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
32 1: lambda x: x ** 2,
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
33 2: lambda x: x ** 3,
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
34 3: lambda x: x ** 4,
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
35 4: lambda x: 2 * x - x ** 2,
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
36 5: lambda x: 2 * x - x ** 3,
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
37 6: lambda x: 2 * x - x ** 4,
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
38 7: lambda x: x,
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
39 255: lambda x: x} #XXX
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
40
430
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
41 def __init__(self, anm, script_id, sprite, sprite_index_offset=0):
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
42 self._anm = anm
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
43 self._sprite = sprite
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 294
diff changeset
44 self.running = True
236
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
45 self.waiting = False
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
46
430
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
47 self.script = anm.scripts[script_id]
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
48 self.version = anm.version
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
49 self.handlers = self._handlers[{0: 6, 2: 7}[anm.version]]
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
50 self.frame = 0
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
51 self.timeout = -1
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
52 self.instruction_pointer = 0
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
53 self.variables = [0, 0, 0, 0,
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
54 0., 0., 0., 0.,
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
55 0, 0, 0, 0]
81
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
56
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
57 self.sprite_index_offset = sprite_index_offset
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
58
433
1222341ea22c Always run the first frame of an ANMRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
59 self.run_frame()
1222341ea22c Always run the first frame of an ANMRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
60
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
61
236
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
62 def interrupt(self, interrupt):
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
63 new_ip = self.script.interrupts.get(interrupt, None)
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
64 if new_ip is None:
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
65 new_ip = self.script.interrupts.get(-1, None)
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
66 if new_ip is None:
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
67 return False
239
901489c21d19 Fix a few crashes in the anmrunner, disable fullscreen switch, change alt+Fx to shift+Fx
Thibaut Girka <thib@sitedethib.com>
parents: 238
diff changeset
68 self.instruction_pointer = new_ip
901489c21d19 Fix a few crashes in the anmrunner, disable fullscreen switch, change alt+Fx to shift+Fx
Thibaut Girka <thib@sitedethib.com>
parents: 238
diff changeset
69 self.frame, opcode, args = self.script[self.instruction_pointer]
901489c21d19 Fix a few crashes in the anmrunner, disable fullscreen switch, change alt+Fx to shift+Fx
Thibaut Girka <thib@sitedethib.com>
parents: 238
diff changeset
70 self.waiting = False
245
d3ba32a9096e Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents: 243
diff changeset
71 self._sprite.visible = True
239
901489c21d19 Fix a few crashes in the anmrunner, disable fullscreen switch, change alt+Fx to shift+Fx
Thibaut Girka <thib@sitedethib.com>
parents: 238
diff changeset
72 return True
236
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
73
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
74
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
75 def run_frame(self):
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 294
diff changeset
76 if not self.running:
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
77 return False
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
78
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 294
diff changeset
79 while self.running and not self.waiting:
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
80 frame, opcode, args = self.script[self.instruction_pointer]
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
81
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
82 if frame > self.frame:
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
83 break
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
84 else:
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
85 self.instruction_pointer += 1
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
86
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
87 if frame == self.frame:
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
88 try:
376
69ec72b990a4 Support more than one version of a vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
89 callback = self.handlers[opcode]
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
90 except KeyError:
129
284ac8f97a96 Fix potential crash
Thibaut Girka <thib@sitedethib.com>
parents: 122
diff changeset
91 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
92 else:
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
93 logger.debug('[%d - %04d] anm_%d%r', id(self),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
94 self.frame, opcode, args)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
95 callback(self, *args)
432
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 430
diff changeset
96 self._sprite.changed = True
240
02de1563fa18 Fix ANM wait, translation/rotation order, and partially implement ANM0 instruction 24
Thibaut Girka <thib@sitedethib.com>
parents: 239
diff changeset
97
243
3893a6fc66f1 Update sprite's property even while waiting
Thibaut Girka <thib@sitedethib.com>
parents: 240
diff changeset
98 if not self.waiting:
3893a6fc66f1 Update sprite's property even while waiting
Thibaut Girka <thib@sitedethib.com>
parents: 240
diff changeset
99 self.frame += 1
432
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 430
diff changeset
100 elif self.timeout == self._sprite.frame: #TODO: check if it’s happening at the correct frame.
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
101 self.waiting = False
120
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
102
432
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 430
diff changeset
103 self._sprite.update()
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
104
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 294
diff changeset
105 return self.running
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
106
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
107
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
108 def _setval(self, variable_id, value):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
109 if self.version == 2:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
110 if 10000 <= variable_id <= 10011:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
111 self.variables[int(variable_id-10000)] = value
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
112
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
113
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
114 def _getval(self, value):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
115 if self.version == 2:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
116 if 10000 <= value <= 10011:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
117 return self.variables[int(value-10000)]
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
118 return value
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
119
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
120
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
121 @instruction(0)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
122 @instruction(1, 7)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
123 def remove(self):
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 294
diff changeset
124 self._sprite.removed = True
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 294
diff changeset
125 self.running = False
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
126
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
127
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
128 @instruction(1)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
129 @instruction(3, 7)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
130 def load_sprite(self, sprite_index):
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
131 #TODO: version 2 only: do not crash when assigning a non-existant sprite.
430
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
132 self._sprite.anm, self._sprite.texcoords = self._anm, self._anm.sprites[sprite_index + self.sprite_index_offset]
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
133
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
134
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
135 @instruction(2)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
136 @instruction(7, 7)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
137 def set_scale(self, sx, sy):
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
138 self._sprite.rescale = self._getval(sx), self._getval(sy)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
139
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
140
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
141 @instruction(3)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
142 @instruction(8, 7)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
143 def set_alpha(self, alpha):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
144 self._sprite.alpha = alpha % 256 #TODO
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
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
147 @instruction(4)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
148 @instruction(9, 7)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
149 def set_color(self, b, g, r):
294
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 245
diff changeset
150 if not self._sprite.fade_interpolator:
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 245
diff changeset
151 self._sprite.color = (r, g, b)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
152
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
153
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
154 @instruction(5)
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
155 def jump(self, instruction_pointer):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
156 #TODO: is that really how it works?
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
157 self.instruction_pointer = instruction_pointer
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
158 self.frame = self.script[self.instruction_pointer][0]
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
159
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
160
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
161 @instruction(7)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
162 @instruction(10, 7)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
163 def toggle_mirrored(self):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
164 self._sprite.mirrored = not self._sprite.mirrored
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
165
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 @instruction(9)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
168 @instruction(12, 7)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
169 def set_rotations_3d(self, rx, ry, rz):
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
170 self._sprite.rotations_3d = self._getval(rx), self._getval(ry), self._getval(rz)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
171
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 @instruction(10)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
174 @instruction(13, 7)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
175 def set_rotations_speed_3d(self, srx, sry, srz):
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
176 self._sprite.rotations_speed_3d = self._getval(srx), self._getval(sry), self._getval(srz)
69
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
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
179 @instruction(11)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
180 @instruction(14, 7)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
181 def set_scale_speed(self, ssx, ssy):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
182 self._sprite.scale_speed = ssx, ssy
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
183
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
184
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
185 @instruction(12)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
186 @instruction(15, 7)
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
187 def fade(self, new_alpha, duration):
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
188 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
189
72
6a08f44fa01b Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents: 71
diff changeset
190
6a08f44fa01b Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents: 71
diff changeset
191 @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
192 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
193 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
194
6a08f44fa01b Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents: 71
diff changeset
195
6a08f44fa01b Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents: 71
diff changeset
196 @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
197 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
198 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
199
6a08f44fa01b Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents: 71
diff changeset
200
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
201 @instruction(15)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
202 @instruction(2, 7)
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
203 def keep_still(self):
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 294
diff changeset
204 self.running = False
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
205
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
206 @instruction(16)
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
207 def load_random_sprite(self, min_idx, amp):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
208 #TODO: use the game's PRNG?
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
209 self.load_sprite(min_idx + randrange(amp))
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
210
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
211
170
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
212 @instruction(17)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
213 @instruction(6, 7)
170
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
214 def move(self, x, y, z):
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
215 self._sprite.dest_offset = (x, y, z)
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
216
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
217
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
218 @instruction(18)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
219 @instruction(17, 7)
170
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
220 def move_in_linear(self, x, y, z, duration):
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
221 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
222
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
223
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
224 @instruction(19)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
225 @instruction(18, 7)
170
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
226 def move_in_decel(self, x, y, z, duration):
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
227 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
228
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
229
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
230 @instruction(20)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
231 @instruction(19, 7)
170
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
232 def move_in_accel(self, x, y, z, duration):
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
233 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
234
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
235
236
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
236 @instruction(21)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
237 @instruction(20, 7)
236
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
238 def wait(self):
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
239 """Wait for an interrupt.
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
240 """
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
241 self.waiting = True
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
242
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
243
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
244 @instruction(22)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
245 @instruction(21, 7)
236
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
246 def interrupt_label(self, interrupt):
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
247 """Noop"""
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
248 pass
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
249
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
250
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
251 @instruction(23)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
252 @instruction(22, 7)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
253 def set_corner_relative_placement(self):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
254 self._sprite.corner_relative_placement = True #TODO
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
255
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
256
240
02de1563fa18 Fix ANM wait, translation/rotation order, and partially implement ANM0 instruction 24
Thibaut Girka <thib@sitedethib.com>
parents: 239
diff changeset
257 @instruction(24)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
258 @instruction(23, 7)
240
02de1563fa18 Fix ANM wait, translation/rotation order, and partially implement ANM0 instruction 24
Thibaut Girka <thib@sitedethib.com>
parents: 239
diff changeset
259 def wait_ex(self):
245
d3ba32a9096e Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents: 243
diff changeset
260 """Hide the sprite and wait for an interrupt.
240
02de1563fa18 Fix ANM wait, translation/rotation order, and partially implement ANM0 instruction 24
Thibaut Girka <thib@sitedethib.com>
parents: 239
diff changeset
261 """
245
d3ba32a9096e Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents: 243
diff changeset
262 self._sprite.visible = False
240
02de1563fa18 Fix ANM wait, translation/rotation order, and partially implement ANM0 instruction 24
Thibaut Girka <thib@sitedethib.com>
parents: 239
diff changeset
263 self.waiting = True
02de1563fa18 Fix ANM wait, translation/rotation order, and partially implement ANM0 instruction 24
Thibaut Girka <thib@sitedethib.com>
parents: 239
diff changeset
264
02de1563fa18 Fix ANM wait, translation/rotation order, and partially implement ANM0 instruction 24
Thibaut Girka <thib@sitedethib.com>
parents: 239
diff changeset
265
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
266 @instruction(25)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
267 @instruction(24, 7)
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
268 def set_allow_dest_offset(self, value):
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
269 self._sprite.allow_dest_offset = bool(value)
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
270
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
271
81
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
272 @instruction(26)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
273 @instruction(25, 7)
81
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
274 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
275 """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
276 """
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
277 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
278
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
279
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
280 @instruction(27)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
281 @instruction(26, 7)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
282 def shift_texture_x(self, dx):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
283 tox, toy = self._sprite.texoffsets
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
284 self._sprite.texoffsets = tox + dx, toy
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
285
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
286
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
287 @instruction(28)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
288 @instruction(27, 7)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
289 def shift_texture_y(self, dy):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
290 tox, toy = self._sprite.texoffsets
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
291 self._sprite.texoffsets = tox, toy + dy
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
292
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
293
245
d3ba32a9096e Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents: 243
diff changeset
294 @instruction(29)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
295 @instruction(28, 7)
245
d3ba32a9096e Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents: 243
diff changeset
296 def set_visible(self, visible):
d3ba32a9096e Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents: 243
diff changeset
297 self._sprite.visible = bool(visible & 1)
d3ba32a9096e Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents: 243
diff changeset
298
d3ba32a9096e Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents: 243
diff changeset
299
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
300 @instruction(30)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
301 @instruction(29, 7)
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
302 def scale_in(self, sx, sy, duration):
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
303 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
304
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
305
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
306 # Now are the instructions new to anm2.
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
307
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
308
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
309 @instruction(0, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
310 def noop(self):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
311 pass
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
312
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
313
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
314 @instruction(4, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
315 def jump_bis(self, instruction_pointer, frame):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
316 self.instruction_pointer = instruction_pointer
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
317 self.frame = frame
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
318
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
319
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
320 @instruction(5, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
321 def jump_ex(self, variable_id, instruction_pointer, frame):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
322 """If the given variable is non-zero, decrease it by 1 and jump to a
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
323 relative offset in the same subroutine.
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
324 """
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
325 counter_value = self._getval(variable_id) - 1
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
326 if counter_value > 0:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
327 self._setval(variable_id, counter_value)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
328 self.instruction_pointer = instruction_pointer
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
329 self.frame = frame
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
330
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
331
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
332 @instruction(16, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
333 def set_blendfunc(self, value):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
334 self._sprite.blendfunc = bool(value & 1)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
335
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
336
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
337 @instruction(32, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
338 def move_in_bis(self, duration, formula, x, y, z):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
339 self._sprite.move_in(duration, x, y, z, self.formulae[formula])
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
340
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
341
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
342 @instruction(33, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
343 def change_color_in(self, duration, formula, r, g, b):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
344 self._sprite.change_color_in(duration, r, g, b, self.formulae[formula])
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
345
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
346
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
347 @instruction(34, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
348 def fade_bis(self, duration, formula, new_alpha):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
349 self._sprite.fade(duration, new_alpha, self.formulae[formula])
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
350
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
351
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
352 @instruction(35, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
353 def rotate_in_bis(self, duration, formula, rx, ry, rz):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
354 self._sprite.rotate_in(duration, rx, ry, rz, self.formulae[formula])
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
355
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
356
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
357 @instruction(36, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
358 def scale_in_bis(self, duration, formula, sx, sy):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
359 self._sprite.scale_in(duration, sx, sy, self.formulae[formula])
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
360
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
361
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
362 @instruction(37, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
363 @instruction(38, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
364 def set_variable(self, variable_id, value):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
365 self._setval(variable_id, value)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
366
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
367
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
368 @instruction(42, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
369 def decrement(self, variable_id, value):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
370 self._setval(variable_id, self._getval(variable_id) - self._getval(value))
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
371
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
372
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
373 @instruction(50, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
374 def add(self, variable_id, a, b):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
375 self._setval(variable_id, self._getval(a) + self._getval(b))
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
376
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
377
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
378 @instruction(52, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
379 def substract(self, variable_id, a, b):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
380 self._setval(variable_id, self._getval(a) - self._getval(b))
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
381
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
382
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
383 @instruction(55, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
384 def divide_int(self, variable_id, a, b):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
385 self._setval(variable_id, self._getval(a) // self._getval(b))
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
386
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
387
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
388 @instruction(59, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
389 def set_random_int(self, variable_id, amp):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
390 #TODO: use the game's PRNG?
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
391 self._setval(variable_id, randrange(amp))
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
392
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
393
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
394 @instruction(60, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
395 def set_random_float(self, variable_id, amp):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
396 #TODO: use the game's PRNG?
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
397 self._setval(variable_id, amp * random())
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
398
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
399
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
400 @instruction(69, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
401 def branch_if_not_equal(self, variable_id, value, instruction_pointer, frame):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
402 if self._getval(variable_id) != value:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
403 self.instruction_pointer = instruction_pointer
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
404 self.frame = frame
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
405 assert self.frame == self.script[self.instruction_pointer][0]
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
406
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
407
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
408 @instruction(79, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
409 def wait_duration(self, duration):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
410 self.timeout = self._sprite.frame + duration
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
411 self.waiting = True