annotate pytouhou/game/sprite.py @ 61:0886994029e4

Fix toggle_mirror.
author Thibaut Girka <thib@sitedethib.com>
date Wed, 24 Aug 2011 21:14:07 +0200
parents 3da4de9decd0
children a142e57218a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
52
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
1 # -*- encoding: utf-8 -*-
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
2 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com>
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
4 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
5 ## This program is free software; you can redistribute it and/or modify
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
6 ## it under the terms of the GNU General Public License as published
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
7 ## by the Free Software Foundation; version 3 only.
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
8 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
9 ## This program is distributed in the hope that it will be useful,
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
12 ## GNU General Public License for more details.
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
13 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
14
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
15
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 54
diff changeset
16 from random import randrange
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
17 from struct import unpack
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
18
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
19 from pytouhou.utils.matrix import Matrix
58
3da4de9decd0 Use logging module
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
20 from pytouhou.utils.helpers import get_logger
3da4de9decd0 Use logging module
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
21
3da4de9decd0 Use logging module
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
22 logger = get_logger(__name__)
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
23
21
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 17
diff changeset
24
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 17
diff changeset
25 class AnmWrapper(object):
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 17
diff changeset
26 def __init__(self, anm_files):
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 17
diff changeset
27 self.anm_files = list(anm_files)
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 17
diff changeset
28
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 17
diff changeset
29 def get_sprite(self, script_index):
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 17
diff changeset
30 for anm in self.anm_files:
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 17
diff changeset
31 if script_index in anm.scripts:
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 17
diff changeset
32 return anm, Sprite(anm, script_index)
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 17
diff changeset
33
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 17
diff changeset
34
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 17
diff changeset
35
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
36 class Sprite(object):
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
37 def __init__(self, anm, script_index):
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
38 self.anm = anm
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
39 self.script_index = script_index
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
40 self.texcoords = (0, 0, 0, 0) # x, y, width, height
41
93c8dc2de923 Add (hopefully) "texture shifting" in animations
Thibaut Girka <thib@sitedethib.com>
parents: 38
diff changeset
41 self.texoffsets = (0., 0.)
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
42 self.mirrored = False
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
43 self.rescale = (1., 1.)
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 54
diff changeset
44 self.scale_speed = (0., 0.)
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
45 self.rotations_3d = (0., 0., 0.)
27
b65d6bc55793 Add rotating sprite support
Thibaut Girka <thib@sitedethib.com>
parents: 26
diff changeset
46 self.rotations_speed_3d = (0., 0., 0.)
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
47 self.corner_relative_placement = False
30
e3ba2fa966f6 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 29
diff changeset
48 self.instruction_pointer = 0
34
4d93d45ecb62 Fix animation script flow handling
Thibaut Girka <thib@sitedethib.com>
parents: 31
diff changeset
49 self.keep_still = False
4d93d45ecb62 Fix animation script flow handling
Thibaut Girka <thib@sitedethib.com>
parents: 31
diff changeset
50 self.playing = True
17
d940d004b840 Make game.sprite.Sprite use its own frame counter.
Thibaut Girka <thib@sitedethib.com>
parents: 15
diff changeset
51 self.frame = 0
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 54
diff changeset
52 self.color = (255, 255, 255)
37
a10e3f44a883 Add alpha (anm0 instruction 3) support
Thibaut Girka <thib@sitedethib.com>
parents: 34
diff changeset
53 self.alpha = 255
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
54 self._uvs = []
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
55 self._vertices = []
37
a10e3f44a883 Add alpha (anm0 instruction 3) support
Thibaut Girka <thib@sitedethib.com>
parents: 34
diff changeset
56 self._colors = []
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
57
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
58
37
a10e3f44a883 Add alpha (anm0 instruction 3) support
Thibaut Girka <thib@sitedethib.com>
parents: 34
diff changeset
59 def update_vertices_uvs_colors(self, override_width=0, override_height=0):
28
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 27
diff changeset
60 vertmat = Matrix([[-.5, .5, .5, -.5],
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 27
diff changeset
61 [-.5, -.5, .5, .5],
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 27
diff changeset
62 [ .0, .0, .0, .0],
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 27
diff changeset
63 [ 1., 1., 1., 1.]])
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
64
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
65 tx, ty, tw, th = self.texcoords
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
66 sx, sy = self.rescale
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
67 width = override_width or (tw * sx)
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
68 height = override_height or (th * sy)
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
69
31
55973a3f1222 Some more optimization!
Thibaut Girka <thib@sitedethib.com>
parents: 30
diff changeset
70 vertmat.scale2d(width, height)
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
71 if self.mirrored:
28
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 27
diff changeset
72 vertmat.flip()
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
73 if self.rotations_3d != (0., 0., 0.):
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
74 rx, ry, rz = self.rotations_3d
28
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 27
diff changeset
75 if rx:
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 27
diff changeset
76 vertmat.rotate_x(-rx)
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 27
diff changeset
77 if ry:
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 27
diff changeset
78 vertmat.rotate_y(ry)
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 27
diff changeset
79 if rz:
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 27
diff changeset
80 vertmat.rotate_z(-rz) #TODO: minus, really?
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
81 if self.corner_relative_placement: # Reposition
28
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 27
diff changeset
82 vertmat.translate(width / 2., height / 2., 0.)
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
83
30
e3ba2fa966f6 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 29
diff changeset
84 x_1 = 1. / self.anm.size[0]
e3ba2fa966f6 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 29
diff changeset
85 y_1 = 1. / self.anm.size[1]
41
93c8dc2de923 Add (hopefully) "texture shifting" in animations
Thibaut Girka <thib@sitedethib.com>
parents: 38
diff changeset
86 tox, toy = self.texoffsets
93c8dc2de923 Add (hopefully) "texture shifting" in animations
Thibaut Girka <thib@sitedethib.com>
parents: 38
diff changeset
87 uvs = [(tx * x_1 + tox, 1. - (ty * y_1) + toy),
93c8dc2de923 Add (hopefully) "texture shifting" in animations
Thibaut Girka <thib@sitedethib.com>
parents: 38
diff changeset
88 ((tx + tw) * x_1 + tox, 1. - (ty * y_1) + toy),
93c8dc2de923 Add (hopefully) "texture shifting" in animations
Thibaut Girka <thib@sitedethib.com>
parents: 38
diff changeset
89 ((tx + tw) * x_1 + tox, 1. - ((ty + th) * y_1 + toy)),
93c8dc2de923 Add (hopefully) "texture shifting" in animations
Thibaut Girka <thib@sitedethib.com>
parents: 38
diff changeset
90 (tx * x_1 + tox, 1. - ((ty + th) * y_1 + toy))]
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
91
30
e3ba2fa966f6 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 29
diff changeset
92 d = vertmat.data
e3ba2fa966f6 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 29
diff changeset
93 assert (d[3][0], d[3][1], d[3][2], d[3][3]) == (1., 1., 1., 1.)
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 54
diff changeset
94 self._colors = [(self.color[0], self.color[1], self.color[2], self.alpha)] * 4
30
e3ba2fa966f6 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 29
diff changeset
95 self._uvs, self._vertices = uvs, zip(d[0], d[1], d[2])
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
96
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
97
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
98
29
afa91be769ae Don't lose time updating off-screen enemies' sprites
Thibaut Girka <thib@sitedethib.com>
parents: 28
diff changeset
99 def update(self):
34
4d93d45ecb62 Fix animation script flow handling
Thibaut Girka <thib@sitedethib.com>
parents: 31
diff changeset
100 if not self.playing:
4d93d45ecb62 Fix animation script flow handling
Thibaut Girka <thib@sitedethib.com>
parents: 31
diff changeset
101 return False
4d93d45ecb62 Fix animation script flow handling
Thibaut Girka <thib@sitedethib.com>
parents: 31
diff changeset
102
30
e3ba2fa966f6 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 29
diff changeset
103 changed = False
34
4d93d45ecb62 Fix animation script flow handling
Thibaut Girka <thib@sitedethib.com>
parents: 31
diff changeset
104 if not self.keep_still:
4d93d45ecb62 Fix animation script flow handling
Thibaut Girka <thib@sitedethib.com>
parents: 31
diff changeset
105 script = self.anm.scripts[self.script_index]
54
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
106 frame = self.frame
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
107 while True:
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
108 try:
38
cb5b27011044 Small refactoring and proper anm0's instruction 5 handling
Thibaut Girka <thib@sitedethib.com>
parents: 37
diff changeset
109 frame, instr_type, args = script[self.instruction_pointer]
54
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
110 except IndexError:
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
111 self.playing = False
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
112 return False
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
113
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
114 if frame > self.frame:
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
115 break
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
116 else:
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
117 self.instruction_pointer += 1
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
118 if frame == self.frame:
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
119 changed = True
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
120 if instr_type == 0:
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
121 self.playing = False
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
122 return False
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
123 if instr_type == 1:
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 54
diff changeset
124 #TODO: handle out-of-anm sprites
54
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
125 self.texcoords = self.anm.sprites[args[0]]
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
126 elif instr_type == 2:
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
127 self.rescale = args
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
128 elif instr_type == 3:
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
129 self.alpha = args[0] % 256 #TODO
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 54
diff changeset
130 elif instr_type == 4:
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 54
diff changeset
131 b, g, r = args
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 54
diff changeset
132 self.color = (r, g, b)
54
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
133 elif instr_type == 5:
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
134 self.instruction_pointer, = args
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
135 self.frame = script[self.instruction_pointer][0]
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
136 elif instr_type == 7:
61
0886994029e4 Fix toggle_mirror.
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
137 self.mirrored = not self.mirrored
54
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
138 elif instr_type == 9:
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
139 self.rotations_3d = args
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
140 elif instr_type == 10:
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
141 self.rotations_speed_3d = args
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 54
diff changeset
142 elif instr_type == 11:
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 54
diff changeset
143 self.scale_speed = args
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 54
diff changeset
144 elif instr_type == 16:
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 54
diff changeset
145 #TODO: handle out-of-anm sprites
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 54
diff changeset
146 #TODO: use the game's PRNG?
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 54
diff changeset
147 self.texcoords = self.anm.sprites[args[0] + randrange(args[1])]
54
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
148 elif instr_type == 23:
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
149 self.corner_relative_placement = True #TODO
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
150 elif instr_type == 27:
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
151 tox, toy = self.texoffsets
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
152 self.texoffsets = tox + args[0], toy
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
153 elif instr_type == 28:
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
154 tox, toy = self.texoffsets
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
155 self.texoffsets = tox, toy + args[0]
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 54
diff changeset
156 elif instr_type in (15, 21):
54
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
157 self.keep_still = True
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
158 break
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
159 else:
58
3da4de9decd0 Use logging module
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
160 logger.warn('unhandled instruction %d (args: %r)', instr_type, args)
17
d940d004b840 Make game.sprite.Sprite use its own frame counter.
Thibaut Girka <thib@sitedethib.com>
parents: 15
diff changeset
161 self.frame += 1
d940d004b840 Make game.sprite.Sprite use its own frame counter.
Thibaut Girka <thib@sitedethib.com>
parents: 15
diff changeset
162
30
e3ba2fa966f6 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 29
diff changeset
163 ax, ay, az = self.rotations_3d
e3ba2fa966f6 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 29
diff changeset
164 sax, say, saz = self.rotations_speed_3d
e3ba2fa966f6 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 29
diff changeset
165 self.rotations_3d = ax + sax, ay + say, az + saz
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 54
diff changeset
166 self.rescale = self.rescale[0] + self.scale_speed[0], self.rescale[1] + self.scale_speed[1]
27
b65d6bc55793 Add rotating sprite support
Thibaut Girka <thib@sitedethib.com>
parents: 26
diff changeset
167
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 54
diff changeset
168 if self.rotations_speed_3d != (0., 0., 0.) or self.scale_speed != (0., 0.):
27
b65d6bc55793 Add rotating sprite support
Thibaut Girka <thib@sitedethib.com>
parents: 26
diff changeset
169 return True
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
170
30
e3ba2fa966f6 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 29
diff changeset
171 return changed
e3ba2fa966f6 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 29
diff changeset
172