annotate pytouhou/game/sprite.py @ 523:6e3b3d5d4691

Make matrix a struct.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 18 Dec 2013 17:53:29 +0100 (2013-12-18)
parents 723a3e67a223
children
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
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
15 class Sprite(object):
120
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 108
diff changeset
16 def __init__(self, width_override=0, height_override=0):
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 61
diff changeset
17 self.anm = None
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 280
diff changeset
18 self.removed = False
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 280
diff changeset
19 self.changed = True
245
d3ba32a9096e Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents: 150
diff changeset
20 self.visible = True
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 61
diff changeset
21
120
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 108
diff changeset
22 self.width_override = width_override
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 108
diff changeset
23 self.height_override = height_override
90
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
24 self.angle = 0
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
25 self.force_rotation = False
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
26
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
27 self.scale_interpolator = None
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
28 self.fade_interpolator = None
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
29 self.offset_interpolator = None
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
30 self.rotation_interpolator = None
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
31 self.color_interpolator = None
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
32
81
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 75
diff changeset
33 self.automatic_orientation = False
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 75
diff changeset
34
72
6a08f44fa01b Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents: 71
diff changeset
35 self.blendfunc = 0 # 0 = Normal, 1 = saturate #TODO: proper constants
6a08f44fa01b Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents: 71
diff changeset
36
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
37 self.texcoords = (0, 0, 0, 0) # x, y, width, height
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
38 self.dest_offset = (0., 0., 0.)
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
39 self.allow_dest_offset = False
41
93c8dc2de923 Add (hopefully) "texture shifting" in animations
Thibaut Girka <thib@sitedethib.com>
parents: 38
diff changeset
40 self.texoffsets = (0., 0.)
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
41 self.mirrored = False
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
42 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
43 self.scale_speed = (0., 0.)
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
44 self.rotations_3d = (0., 0., 0.)
27
b65d6bc55793 Add rotating sprite support
Thibaut Girka <thib@sitedethib.com>
parents: 26
diff changeset
45 self.rotations_speed_3d = (0., 0., 0.)
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
46 self.corner_relative_placement = False
17
d940d004b840 Make game.sprite.Sprite use its own frame counter.
Thibaut Girka <thib@sitedethib.com>
parents: 15
diff changeset
47 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
48 self.color = (255, 255, 255)
37
a10e3f44a883 Add alpha (anm0 instruction 3) support
Thibaut Girka <thib@sitedethib.com>
parents: 34
diff changeset
49 self.alpha = 255
108
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents: 97
diff changeset
50
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents: 97
diff changeset
51 self._rendering_data = None
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
52
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
53
439
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
54 def fade(self, duration, alpha, formula=None):
280
e04c3e1957c8 Fix ANM interpolators.
Thibaut Girka <thib@sitedethib.com>
parents: 245
diff changeset
55 self.fade_interpolator = Interpolator((self.alpha,), self.frame,
e04c3e1957c8 Fix ANM interpolators.
Thibaut Girka <thib@sitedethib.com>
parents: 245
diff changeset
56 (alpha,), self.frame + duration,
e04c3e1957c8 Fix ANM interpolators.
Thibaut Girka <thib@sitedethib.com>
parents: 245
diff changeset
57 formula)
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
58
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
59
439
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
60 def scale_in(self, duration, sx, sy, formula=None):
280
e04c3e1957c8 Fix ANM interpolators.
Thibaut Girka <thib@sitedethib.com>
parents: 245
diff changeset
61 self.scale_interpolator = Interpolator(self.rescale, self.frame,
e04c3e1957c8 Fix ANM interpolators.
Thibaut Girka <thib@sitedethib.com>
parents: 245
diff changeset
62 (sx, sy), self.frame + duration,
e04c3e1957c8 Fix ANM interpolators.
Thibaut Girka <thib@sitedethib.com>
parents: 245
diff changeset
63 formula)
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
64
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
65
439
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
66 def move_in(self, duration, x, y, z, formula=None):
280
e04c3e1957c8 Fix ANM interpolators.
Thibaut Girka <thib@sitedethib.com>
parents: 245
diff changeset
67 self.offset_interpolator = Interpolator(self.dest_offset, self.frame,
e04c3e1957c8 Fix ANM interpolators.
Thibaut Girka <thib@sitedethib.com>
parents: 245
diff changeset
68 (x, y, z), self.frame + duration,
e04c3e1957c8 Fix ANM interpolators.
Thibaut Girka <thib@sitedethib.com>
parents: 245
diff changeset
69 formula)
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
70
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
71
439
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
72 def rotate_in(self, duration, rx, ry, rz, formula=None):
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
73 self.rotation_interpolator = Interpolator(self.rotations_3d, self.frame,
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
74 (rx, ry, rz), self.frame + duration,
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
75 formula)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
76
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
77
439
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
78 def change_color_in(self, duration, r, g, b, formula=None):
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
79 self.color_interpolator = Interpolator(self.color, self.frame,
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
80 (r, g, b), self.frame + duration,
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
81 formula)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
82
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
83
120
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 108
diff changeset
84 def update_orientation(self, angle_base=0., force_rotation=False):
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 108
diff changeset
85 if (self.angle != angle_base or self.force_rotation != force_rotation):
92
85f3b8ba3f24 Minor refactoring and optimizations. Drop stageviewer.
Thibaut Girka <thib@sitedethib.com>
parents: 90
diff changeset
86 self.angle = angle_base
85f3b8ba3f24 Minor refactoring and optimizations. Drop stageviewer.
Thibaut Girka <thib@sitedethib.com>
parents: 90
diff changeset
87 self.force_rotation = force_rotation
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 280
diff changeset
88 self.changed = True
94
ca571697ec83 Various minor optimisations and refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 92
diff changeset
89
432
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
90
439
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
91 def copy(self):
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
92 sprite = Sprite(self.width_override, self.height_override)
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
93
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
94 sprite.blendfunc = self.blendfunc
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
95 sprite.frame = self.frame
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
96 sprite.angle = self.angle
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
97
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
98 sprite.removed = self.removed
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
99 sprite.changed = self.changed
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
100 sprite.visible = self.visible
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
101 sprite.force_rotation = self.force_rotation
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
102 sprite.automatic_orientation = self.automatic_orientation
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
103 sprite.allow_dest_offset = self.allow_dest_offset
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
104 sprite.mirrored = self.mirrored
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
105 sprite.corner_relative_placement = self.corner_relative_placement
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
106
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
107 sprite.scale_interpolator = self.scale_interpolator
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
108 sprite.fade_interpolator = self.fade_interpolator
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
109 sprite.offset_interpolator = self.offset_interpolator
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
110 sprite.rotation_interpolator = self.rotation_interpolator
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
111 sprite.color_interpolator = self.color_interpolator
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
112
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
113 sprite.texcoords = self.texcoords
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
114 sprite.dest_offset = self.dest_offset
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
115 sprite.texoffsets = self.texoffsets
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
116 sprite.rescale = self.rescale
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
117 sprite.scale_speed = self.scale_speed
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
118 sprite.rotations_3d = self.rotations_3d
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
119 sprite.rotations_speed_3d = self.rotations_speed_3d
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
120 sprite.color = self.color
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
121
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
122 sprite.alpha = self.alpha
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
123 sprite.anm = self.anm
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
124 sprite._rendering_data = self._rendering_data
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
125
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
126 return sprite
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
127
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
128
432
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
129 def update(self):
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
130 self.frame += 1
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
131
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
132 if self.rotations_speed_3d != (0., 0., 0.):
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
133 ax, ay, az = self.rotations_3d
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
134 sax, say, saz = self.rotations_speed_3d
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
135 self.rotations_3d = ax + sax, ay + say, az + saz
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
136 self.changed = True
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
137 elif self.rotation_interpolator:
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
138 self.rotation_interpolator.update(self.frame)
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
139 self.rotations_3d = self.rotation_interpolator.values
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
140 self.changed = True
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
141
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
142 if self.scale_speed != (0., 0.):
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
143 rx, ry = self.rescale
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
144 rsx, rsy = self.scale_speed
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
145 self.rescale = rx + rsx, ry + rsy
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
146 self.changed = True
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
147
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
148 if self.fade_interpolator:
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
149 self.fade_interpolator.update(self.frame)
439
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
150 self.alpha = self.fade_interpolator.values[0]
432
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
151 self.changed = True
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
152
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
153 if self.scale_interpolator:
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
154 self.scale_interpolator.update(self.frame)
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
155 self.rescale = self.scale_interpolator.values
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
156 self.changed = True
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
157
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
158 if self.offset_interpolator:
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
159 self.offset_interpolator.update(self.frame)
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
160 self.dest_offset = self.offset_interpolator.values
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
161 self.changed = True
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
162
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
163 if self.color_interpolator:
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
164 self.color_interpolator.update(self.frame)
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
165 self.color = self.color_interpolator.values
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
166 self.changed = True