-
Notifications
You must be signed in to change notification settings - Fork 25
/
sprites.py
11875 lines (9229 loc) · 378 KB
/
sprites.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Miyamoto! Level Editor - New Super Mario Bros. U Level Editor
# Copyright (C) 2009-2021 Treeki, Tempus, angelsl, JasonP27, Kinnay,
# MalStar1000, RoadrunnerWMC, MrRean, Grop, AboodXD, Gota7, John10v10,
# mrbengtsson
# This file is part of Miyamoto!.
# Miyamoto! is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# Miyamoto! is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with Miyamoto!. If not, see <http://www.gnu.org/licenses/>.
# sprites.py
# Contains code to render NSMBU sprite images
# not even close to done...
# IMPORTANT!!!! An offset value of 16 is one block!
################################################################
################################################################
############ Imports ############
import math
from PyQt5 import QtCore, QtGui
from PyQt5.QtCore import *
from PyQt5.QtGui import *
Qt = QtCore.Qt
from miyamoto import *
import spritelib as SLib
#################################
ImageCache = SLib.ImageCache
# Global varible for rotations.
Rotations = [0, 0, 0]
StoneRotation = 0
################################################################
################################################################
# GETTING SPRITEDATA:
# You can get the spritedata that is set on a sprite to alter
# the image that is shown. To do this, add a datachanged method,
# with the parameter self. In this method, you can access the
# spritedata through self.parent.spritedata[n], which returns
# the (n+1)th byte of the spritedata. To find the n for nybble
# x, use this formula:
# n = (x/2) - 1
#
# If the nybble you want is the upper 4 bits of n (x is odd),
# you can get the value of x like this:
# val_x = n >> 4
class SpriteImage_Pipe(SLib.SpriteImage_MovementControlled):
types = {
'Normal': (
'',
('Green', 'green'),
('Red', 'red'),
('Yellow', 'yellow'),
('Purple', 'purple'),
),
'Painted': (
'_painted',
('Green', 'green'),
('Red', 'red'),
('Yellow', 'yellow'),
('Blue', 'blue'),
),
'Big': (
'_big',
('Green', 'green'),
),
'Mini': (
'_mini',
('Green', 'green'),
),
}
def __init__(self, parent, scale=3.75):
super().__init__(parent, scale)
self.hasTop = True
self.direction = 0 # 0: Up, 1: Down, 2: Left, 3: Right
self.type = 'Normal'
self.color = 'Green'
self.width, self.height = 32, 32
self.pipeWidth, self.pipeHeight = 120, 60
self.topX, self.topY = 0, 0
self.middleX, self.middleY = 0, 0
self.parent.setZValue(24999)
@staticmethod
def loadImages():
if 'PipeVTopNormalGreen' not in ImageCache:
for typeName in SpriteImage_Pipe.types:
type = SpriteImage_Pipe.types[typeName]; suffix = type[0]
for C, c in type[1:]:
for D, d in (('V', ''), ('H', '_horizontal')):
ImageCache['Pipe%sTop%s%s' % (D, typeName, C)] = SLib.GetImg('pipe%s_top%s_%s.png' % (d, suffix, c))
ImageCache['Pipe%sTopMiddle%s%s' % (D, typeName, C)] = SLib.GetImg('pipe%s_middle%s_%s.png' % (d, suffix, c))
ImageCache['Pipe%sBottom%s%s' % (D, typeName, C)] = SLib.GetImg('pipe%s_bottom%s_%s.png' % (d, suffix, c))
ImageCache['Pipe%sBottomMiddle%s%s' % (D, typeName, C)] = ImageCache['Pipe%sTopMiddle%s%s' % (D, typeName, C)].transformed(
QTransform().scale(1, -1) if D == 'V' else QTransform().scale(-1, 1)
)
def getMovementID(self):
return 0
def allowedMovementControllers(self):
return tuple()
def getParamsForDirection(self):
direction = self.direction
if direction == 0:
return 'V', 'Top'
elif direction == 1:
return 'V', 'Bottom'
elif direction == 2:
return 'H', 'Top'
return 'H', 'Bottom'
def dataChanged(self):
d, t = self.getParamsForDirection()
pix = QtGui.QPixmap(round(self.width * 3.75), round(self.height * 3.75))
pix.fill(Qt.transparent)
painter = QtGui.QPainter(pix)
painter.drawTiledPixmap(QtCore.QRectF(self.middleX, self.middleY, self.pipeWidth, self.pipeHeight), ImageCache['Pipe%s%sMiddle%s%s' % (d, t, self.type, self.color)])
if self.hasTop:
painter.drawPixmap(QtCore.QPointF(self.topX, self.topY), ImageCache['Pipe%s%s%s%s' % (d, t, self.type, self.color)])
painter.end()
del painter
self.image = pix
super().dataChanged()
class SpriteImage_Crash(SLib.SpriteImage_Static): # X
def __init__(self, parent):
super().__init__(
parent,
3.75,
ImageCache['Crash'],
)
@staticmethod
def loadImages():
SLib.loadIfNotInImageCache('Crash', 'crash.png')
class SpriteImage_LiquidOrFog(SLib.SpriteImage): # 88, 89, 90, 91, 92, 93, 198, 201
def __init__(self, parent):
super().__init__(parent)
self.crest = None
self.mid = None
self.rise = None
self.riseCrestless = None
self.top = 0
self.drawCrest = False
self.risingHeight = 0
self.locId = 0
self.findZone()
def findZone(self):
self.zoneId = SLib.MapPositionToZoneID(globals.Area.zones, self.parent.objx, self.parent.objy, True)
def positionChanged(self):
self.findZone()
self.parent.scene().update()
super().positionChanged()
def dataChanged(self):
self.parent.scene().update()
super().dataChanged()
def paintZone(self):
return self.locId == 0 and self.zoneId != -1
def realViewZone(self, painter, zoneRect):
"""
Real view zone painter for liquids/fog
"""
# (0, 0) is the top-left corner of the zone
_, zy, zw, zh = zoneRect.getRect()
drawRise = self.risingHeight != 0
drawCrest = self.drawCrest
# Get positions
offsetFromTop = (self.top * 3.75) - zy
if offsetFromTop > zh:
# the sprite is below the zone; don't draw anything
return
if offsetFromTop <= 4:
offsetFromTop = 4
drawCrest = False # off the top of the zone; no crest
# If all that fits in the zone is some of the crest, determine how much
if drawCrest:
crestSizeRemoval = (zy + offsetFromTop + self.crest.height()) - (zy + zh) + 4
if crestSizeRemoval < 0: crestSizeRemoval = 0
crestHeight = self.crest.height() - crestSizeRemoval
# Determine where to put the rise image
offsetRise = offsetFromTop - (self.risingHeight * 60)
riseToDraw = self.rise
if offsetRise < 4: # close enough to the top zone border
offsetRise = 4
riseToDraw = self.riseCrestless
if not drawCrest:
riseToDraw = self.riseCrestless
if drawCrest:
painter.drawTiledPixmap(QtCore.QRectF(4, offsetFromTop, zw - 8, crestHeight), self.crest)
painter.drawTiledPixmap(QtCore.QRectF(4, offsetFromTop + crestHeight, zw - 8, zh - crestHeight - offsetFromTop - 4),
self.mid)
else:
painter.drawTiledPixmap(QtCore.QRectF(4, offsetFromTop, zw - 8, zh - offsetFromTop - 4), self.mid)
if drawRise:
painter.drawTiledPixmap(QtCore.QRectF(4, offsetRise, zw - 8, riseToDraw.height()), riseToDraw)
def realViewLocation(self, painter, zoneRect):
"""
Real view location painter for liquids/fog
"""
zoneId = self.zoneId
if zoneId == -1:
return
for zone in globals.Area.zones:
if zone.id == zoneId:
break
zx, zy = zoneRect.x(), zoneRect.y()
zoneRect &= zone.sceneBoundingRect()
zx, zy = zoneRect.x() - zx, zoneRect.y() - zy
zw, zh = zoneRect.width(), zoneRect.height()
if zw <= 0 or zh <= 0:
return
drawCrest = False
crestHeight = 0
if self.drawCrest:
crestHeight = self.crest.height()
drawCrest = zy < crestHeight
if drawCrest:
crestHeight -= zy
if crestHeight >= zh:
painter.drawTiledPixmap(QtCore.QRectF(zx, zy, zw, zh), self.crest, QtCore.QPointF(zx, zy))
else:
painter.drawTiledPixmap(QtCore.QRectF(zx, zy, zw, crestHeight), self.crest, QtCore.QPointF(zx, zy))
painter.drawTiledPixmap(QtCore.QRectF(zx, zy + crestHeight, zw, zh - crestHeight), self.mid, QtCore.QPointF(zx, 0))
else:
painter.drawTiledPixmap(QtCore.QRectF(zx, zy, zw, zh), self.mid, QtCore.QPointF(zx, zy - crestHeight))
class SpriteImage_PlatformBase(SLib.SpriteImage): # X
def __init__(self, parent, hasAux=False):
super().__init__(parent, 3.75)
self.spritebox.shown = False
self.hasAux = hasAux
if self.hasAux:
self.aux.append(SLib.AuxiliaryTrackObject(parent, 0, 0, 0))
self.aux.append(SLib.AuxiliaryImage(parent, 0, 0))
self.aux[1].alpha = 0.5
@staticmethod
def loadImages():
SLib.loadIfNotInImageCache('MovPlatNL', 'wood_platform_left.png')
SLib.loadIfNotInImageCache('MovPlatNM', 'wood_platform_middle.png')
SLib.loadIfNotInImageCache('MovPlatNR', 'wood_platform_right.png')
SLib.loadIfNotInImageCache('MovPlatSL', 'wood_platform_snow_left.png')
SLib.loadIfNotInImageCache('MovPlatSM', 'wood_platform_snow_middle.png')
SLib.loadIfNotInImageCache('MovPlatSR', 'wood_platform_snow_right.png')
SLib.loadIfNotInImageCache('MovPlatRL', 'metal_platform_left.png')
SLib.loadIfNotInImageCache('MovPlatRM', 'metal_platform_middle.png')
SLib.loadIfNotInImageCache('MovPlatRR', 'metal_platform_right.png')
SLib.loadIfNotInImageCache('MovPlatBL', 'bone_platform_left.png')
SLib.loadIfNotInImageCache('MovPlatBM', 'bone_platform_middle.png')
SLib.loadIfNotInImageCache('MovPlatBR', 'bone_platform_right.png')
SLib.loadIfNotInImageCache('MovPlatCL', 'cloud_platform_left.png')
SLib.loadIfNotInImageCache('MovPlatCM', 'wood_platform_middle.png') # No middle type exists for cloud
SLib.loadIfNotInImageCache('MovPlatCR', 'cloud_platform_right.png')
def getPlatformWidth(self):
"""
Return an integer specifying the length of the platform.
Should not be pre-multiplied with 16 or 60.
"""
return 2.5
def getPlatformType(self):
"""
Returns a string with 'N', 'S', 'R', 'B' or 'C' depending on the type of platform.
"""
return 'N'
def getPlatformOffset(self):
"""
Returns a tuple with an x and y offset.
"""
return (-4, 0)
def getPlatformMoveDir(self):
"""
Return a string with 'U', 'D', 'L' or 'R' specifying the movement direction of the platform.
"""
return 'U'
def getPlatformMoveDist(self):
"""
Return an integer specifying the movement distance of the platform.
"""
return 0
def paintPlatform(self, painter):
left = ImageCache['MovPlat%sL' % self.imgType]
mid = ImageCache['MovPlat%sM' % self.imgType]
right = ImageCache['MovPlat%sR' % self.imgType]
painter.drawPixmap(0, 0, left)
painter.drawPixmap(round(self.width * 3.75) - right.width(), 0, right)
if round(self.width * 3.75) > (left.width() + right.width()):
painter.drawTiledPixmap(left.width(), 0, round(self.width * 3.75) - (left.width() + right.width()), mid.height(), mid)
def dataChanged(self):
self.offset = self.getPlatformOffset()
self.imgType = self.getPlatformType()
self.width = self.getPlatformWidth() * 16
self.height = max(ImageCache['MovPlat%sL' % self.imgType].height(), ImageCache['MovPlat%sM' % self.imgType].height(), ImageCache['MovPlat%sR' % self.imgType].height()) / 3.75
if self.hasAux:
pix = QtGui.QPixmap(round(self.width * 3.75), round(self.height * 3.75))
pix.fill(Qt.transparent)
painter = QtGui.QPainter(pix)
self.paintPlatform(painter)
painter = None
moveDir = self.getPlatformMoveDir()
moveDist = self.getPlatformMoveDist()
if moveDir == 'L' or moveDir == 'R':
self.aux[0].setSize((moveDist + 1) * 16, 16)
self.aux[0].direction = SLib.AuxiliaryTrackObject.Horizontal
else:
self.aux[0].setSize(16, (moveDist + 1) * 16)
self.aux[0].direction = SLib.AuxiliaryTrackObject.Vertical
xOffset = 0
yOffset = 0
if moveDir == 'L':
xOffset = -moveDist * 16
elif moveDir == 'U':
yOffset = -moveDist * 16
self.aux[0].setPos((xOffset + self.width * 0.5 - 8) * 3.75, yOffset * 3.75)
if moveDir == 'R':
xOffset = moveDist * 16
elif moveDir == 'D':
yOffset = moveDist * 16
self.aux[1].setImage(pix, xOffset, yOffset, True)
super().dataChanged()
def paint(self, painter):
super().paint(painter)
self.paintPlatform(painter)
class SpriteImage_Goomba(SLib.SpriteImage_Static): # 0
def __init__(self, parent):
super().__init__(
parent,
3.75,
ImageCache['Goomba'],
(-4, -4)
)
@staticmethod
def loadImages():
SLib.loadIfNotInImageCache('Goomba', 'goomba.png')
class SpriteImage_Paragoomba(SLib.SpriteImage_Static): # 1
def __init__(self, parent):
super().__init__(
parent,
3.75,
ImageCache['Paragoomba'],
(-4, -12),
)
@staticmethod
def loadImages():
SLib.loadIfNotInImageCache('Paragoomba', 'paragoomba.png')
class SpriteImage_PipePiranhaUp(SLib.SpriteImage_Static): # 2
def __init__(self, parent):
super().__init__(
parent,
3.75,
ImageCache['PipePiranhaUp'],
(0, -32),
)
@staticmethod
def loadImages():
SLib.loadIfNotInImageCache('PipePiranhaUp', 'pipe_piranha.png')
class SpriteImage_PipePiranhaDown(SLib.SpriteImage_Static): # 3
def __init__(self, parent):
super().__init__(
parent,
3.75,
ImageCache['PipePiranhaDown'],
(0, 32),
)
@staticmethod
def loadImages():
SLib.loadIfNotInImageCache('PipePiranhaDown', 'pipe_piranha_down.png')
class SpriteImage_PipePiranhaLeft(SLib.SpriteImage_Static): # 4
def __init__(self, parent):
super().__init__(
parent,
3.75,
ImageCache['PipePiranhaLeft'],
(-32, 0),
)
@staticmethod
def loadImages():
SLib.loadIfNotInImageCache('PipePiranhaLeft', 'pipe_piranha_left.png')
class SpriteImage_PipePiranhaRight(SLib.SpriteImage_Static): # 5
def __init__(self, parent):
super().__init__(
parent,
3.75,
ImageCache['PipePiranhaRight'],
(32, 0),
)
@staticmethod
def loadImages():
SLib.loadIfNotInImageCache('PipePiranhaRight', 'pipe_piranha_right.png')
class SpriteImage_PipePiranhaUpFire(SLib.SpriteImage_Static): # 6
def __init__(self, parent):
super().__init__(
parent,
3.75,
ImageCache['PipePiranhaUpFire'],
(-4, -32),
)
@staticmethod
def loadImages():
SLib.loadIfNotInImageCache('PipePiranhaUpFire', 'firetrap_pipe_up.png')
class SpriteImage_PipePiranhaDownFire(SLib.SpriteImage_Static): # 7
def __init__(self, parent):
super().__init__(
parent,
3.75,
ImageCache['PipePiranhaDownFire'],
(-4, 32),
)
@staticmethod
def loadImages():
SLib.loadIfNotInImageCache('PipePiranhaDownFire', 'firetrap_pipe_down.png')
class SpriteImage_PipePiranhaLeftFire(SLib.SpriteImage_Static): # 8
def __init__(self, parent):
super().__init__(
parent,
3.75,
ImageCache['PipePiranhaLeftFire'],
(-32, -4),
)
@staticmethod
def loadImages():
SLib.loadIfNotInImageCache('PipePiranhaLeftFire', 'firetrap_pipe_left.png')
class SpriteImage_PipePiranhaRightFire(SLib.SpriteImage_Static): # 9
def __init__(self, parent):
super().__init__(
parent,
3.75,
ImageCache['PipePiranhaRightFire'],
(32, -4),
)
@staticmethod
def loadImages():
SLib.loadIfNotInImageCache('PipePiranhaRightFire', 'firetrap_pipe_right.png')
class SpriteImage_GroundPiranha(SLib.SpriteImage_StaticMultiple): # 14, 698, 712
def __init__(self, parent):
super().__init__(parent, 3.75)
self.xOffset = -6.4
@staticmethod
def loadImages():
if 'GroundPiranha' in ImageCache: return
GP = SLib.GetImg('grounded_piranha.png', True)
ImageCache['GroundPiranha'] = QtGui.QPixmap.fromImage(GP)
ImageCache['GroundPiranhaU'] = QtGui.QPixmap.fromImage(GP.mirrored(False, True))
def dataChanged(self):
upsideDown = self.parent.spritedata[5] & 0xF
if upsideDown != 8:
self.yOffset = 28 / 60 * 16
self.image = ImageCache['GroundPiranha']
else:
self.yOffset = 109 / 60 * 16
self.image = ImageCache['GroundPiranhaU']
super().dataChanged()
class SpriteImage_GroundVenustrap(SLib.SpriteImage_StaticMultiple): # 15, 16
def __init__(self, parent):
super().__init__(parent, 3.75)
self.xOffset = 14 / 60 * 16
@staticmethod
def loadImages():
if 'GroundVenustrap' in ImageCache: return
GF = SLib.GetImg('grounded_venus_trap.png', True)
ImageCache['GroundVenustrap'] = QtGui.QPixmap.fromImage(GF)
ImageCache['GroundVenustrapU'] = QtGui.QPixmap.fromImage(GF.mirrored(False, True))
def dataChanged(self):
upsideDown = self.parent.spritedata[5] & 0xF
if upsideDown != 8:
self.yOffset = -34 / 60 * 16
self.image = ImageCache['GroundVenustrap']
else:
self.yOffset = 30.4
self.image = ImageCache['GroundVenustrapU']
super().dataChanged()
class SpriteImage_BigGroundPiranha(SLib.SpriteImage_StaticMultiple): # 17
def __init__(self, parent):
super().__init__(parent, 3.75)
self.xOffset = -143 / 60 * 16
@staticmethod
def loadImages():
if 'BigGroundPiranha' in ImageCache: return
BGP = SLib.GetImg('big_grounded_piranha.png', True)
ImageCache['BigGroundPiranha'] = QtGui.QPixmap.fromImage(BGP)
ImageCache['BigGroundPiranhaU'] = QtGui.QPixmap.fromImage(BGP.mirrored(False, True))
def dataChanged(self):
upsideDown = self.parent.spritedata[5] & 0xF
if upsideDown != 8:
self.yOffset = 127 / 60 * 16
self.image = ImageCache['BigGroundPiranha']
else:
self.yOffset = 289 / 60 * 16
self.image = ImageCache['BigGroundPiranhaU']
super().dataChanged()
class SpriteImage_BigGroundVenustrap(SLib.SpriteImage_StaticMultiple): # 18
def __init__(self, parent):
super().__init__(parent, 3.75)
self.xOffset = -16
@staticmethod
def loadImages():
if 'BigGroundVenustrap' in ImageCache: return
BGF = SLib.GetImg('big_grounded_venus_trap.png', True)
ImageCache['BigGroundVenustrap'] = QtGui.QPixmap.fromImage(BGF)
ImageCache['BigGroundVenustrapU'] = QtGui.QPixmap.fromImage(BGF.mirrored(False, True))
def dataChanged(self):
upsideDown = self.parent.spritedata[5] & 0xF
if upsideDown != 8:
self.yOffset = -2.4
self.image = ImageCache['BigGroundVenustrap']
else:
self.yOffset = 76.8
self.image = ImageCache['BigGroundVenustrapU']
super().dataChanged()
class SpriteImage_KoopaTroopa(SLib.SpriteImage_StaticMultiple): # 19, 55
def __init__(self, parent):
super().__init__(
parent,
3.75,
)
self.xOffset = -4
@staticmethod
def loadImages():
SLib.loadIfNotInImageCache('KoopaShellG', 'koopatroopa_shell_green.png')
SLib.loadIfNotInImageCache('KoopaShellR', 'koopatroopa_shell_red.png')
SLib.loadIfNotInImageCache('KoopatroopaG', 'koopatroopa_green.png')
SLib.loadIfNotInImageCache('KoopatroopaR', 'koopatroopa_red.png')
def dataChanged(self):
shellcolour = self.parent.spritedata[5] & 1
inshell = (self.parent.spritedata[5] >> 4) & 1
if inshell:
self.yOffset = 0
self.image = ImageCache['KoopaShellR' if shellcolour else 'KoopaShellG']
else:
self.yOffset = -16
self.image = ImageCache['KoopatroopaR' if shellcolour else 'KoopatroopaG']
super().dataChanged()
class SpriteImage_KoopaParatroopa(SLib.SpriteImage_StaticMultiple): # 20
def __init__(self, parent):
super().__init__(
parent,
3.75,
)
self.offset = (-4, -16)
self.aux.append(SLib.AuxiliaryTrackObject(parent, 0, 0, 0))
@staticmethod
def loadImages():
SLib.loadIfNotInImageCache('KoopaParatroopaG', 'koopa_paratroopa_green.png')
SLib.loadIfNotInImageCache('KoopaParatroopaR', 'koopa_paratroopa_red.png')
def dataChanged(self):
color = self.parent.spritedata[5] & 1
mode = self.parent.spritedata[5] >> 4 & 3
direction = self.parent.spritedata[4] >> 4 & 3
if color == 0:
self.image = ImageCache['KoopaParatroopaG']
else:
self.image = ImageCache['KoopaParatroopaR']
track = self.aux[0]
if mode not in (1, 2) or direction not in (1, 2):
track.setSize(0, 0)
else:
onEdge = self.parent.spritedata[4] & 1
width = round(self.width * 3.75)
height = round(self.height * 3.75)
if mode == 1:
track.direction = SLib.AuxiliaryTrackObject.Horizontal
track.setSize(9 * 16, 16)
if onEdge:
if direction == 1:
track.setPos(-0.625 * 60 + width / 2, -0.625 * 60 + height / 2)
else:
track.setPos(-8.625 * 60 + width / 2, -0.625 * 60 + height / 2)
else:
track.setPos(-4.625 * 60 + width / 2, -0.625 * 60 + height / 2)
else:
track.direction = SLib.AuxiliaryTrackObject.Vertical
track.setSize(16, 9 * 16)
if onEdge:
if direction == 1:
track.setPos(-0.625 * 60 + width / 2, -9.125 * 60 + height / 2)
else:
track.setPos(-0.625 * 60 + width / 2, -0.125 * 60 + height / 2)
else:
track.setPos(-0.625 * 60 + width / 2, -4.125 * 60 + height / 2)
super().dataChanged()
class SpriteImage_BuzzyBeetle(SLib.SpriteImage_StaticMultiple): # 22
def __init__(self, parent):
super().__init__(
parent,
3.75,
)
self.directions = [
('L', ''),
('R', '_right'),
]
self.types = [
('U', ''),
('D', '_down'),
('US', '_shell'),
('DS', '_shell_down'),
]
@staticmethod
def loadImages():
if 'BuzzyLU' not in ImageCache:
directions = [
('L', ''),
('R', '_right'),
]
types = [
('U', ''),
('D', '_down'),
('US', '_shell'),
('DS', '_shell_down'),
]
for direction in directions:
for type_ in types:
ImageCache['Buzzy%s%s' % (direction[0], type_[0])] = SLib.GetImg('buzzy_beetle%s%s.png' % (direction[1], type_[1]))
def dataChanged(self):
direction = self.parent.spritedata[4] & 0xF; direction = 0 if direction > 1 else direction
type_ = self.parent.spritedata[5] & 0xF; type_ = 0 if type_ > 3 else type_
self.image = ImageCache['Buzzy%s%s' % (self.directions[direction][0], self.types[type_][0])]
self.yOffset = -4 if type_ == 1 else 0
super().dataChanged()
class SpriteImage_Spiny(SLib.SpriteImage_StaticMultiple): # 23
def __init__(self, parent):
super().__init__(
parent,
3.75,
)
@staticmethod
def loadImages():
SLib.loadIfNotInImageCache('Spiny', 'spiny.png')
SLib.loadIfNotInImageCache('SpinyBall', 'spiny_ball.png')
SLib.loadIfNotInImageCache('SpinyShell', 'spiny_shell.png')
SLib.loadIfNotInImageCache('SpinyShellU', 'spiny_shell_u.png')
def dataChanged(self):
spawntype = self.parent.spritedata[5]
if spawntype == 1:
self.image = ImageCache['SpinyBall']
self.xOffset = 0
self.yOffset = 4
elif spawntype == 2:
self.image = ImageCache['SpinyShell']
self.xOffset = -4
self.yOffset = -4
elif spawntype == 3:
self.image = ImageCache['SpinyShellU']
self.xOffset = -4
self.yOffset = 0
else:
self.image = ImageCache['Spiny']
self.xOffset = -4
self.yOffset = -4
super().dataChanged()
class SpriteImage_SpinyU(SLib.SpriteImage_Static): # 24
def __init__(self, parent):
super().__init__(
parent,
3.75,
ImageCache['SpinyU'],
(-4, 0),
)
@staticmethod
def loadImages():
SLib.loadIfNotInImageCache('SpinyU', 'spiny_u.png')
class SpriteImage_MidwayFlag(SLib.SpriteImage_Static): # 25
def __init__(self, parent):
super().__init__(
parent,
3.75,
ImageCache['MidwayFlag'],
(0, -40),
)
@staticmethod
def loadImages():
SLib.loadIfNotInImageCache('MidwayFlag', 'midway_flag.png')
class SpriteImage_ZoomArea(SLib.SpriteImage): # 26
def __init__(self, parent):
super().__init__(parent, 3.75)
self.aux.append(SLib.AuxiliaryRectOutline(parent, 0, 0))
def dataChanged(self):
super().dataChanged()
h = self.parent.spritedata[4]
w = self.parent.spritedata[5]
if w == 0:
w = 1
if h == 0:
h = 1
if w == 1 and h == 1: # no point drawing a 1x1 outline behind the self.parent
self.aux[0].setSize(0, 0, 0, 0)
return
self.aux[0].setSize(w * 60, h * 60, 0, -h * 60 + 60)
class SpriteImage_LimitU(SLib.SpriteImage_StaticMultiple): # 29
def __init__(self, parent):
super().__init__(
parent,
3.75,
)
@staticmethod
def loadImages():
SLib.loadIfNotInImageCache('LimitUR', 'limit_u_r.png')
SLib.loadIfNotInImageCache('LimitUL', 'limit_u_l.png')
def dataChanged(self):
direction = self.parent.spritedata[2]
if direction == 0:
self.image = ImageCache['LimitUR']
elif direction == 16 or direction == 17 or direction == 18 or direction == 19 or direction == 20 or direction == 21 or direction == 22 or direction == 23 or direction == 24 or direction == 25 or direction == 26 or direction == 27 or direction == 28 or direction == 29 or direction == 30 or direction == 31:
self.image = ImageCache['LimitUL']
else:
self.image = ImageCache['LimitUR']
super().dataChanged()
class SpriteImage_LimitD(SLib.SpriteImage_StaticMultiple): # 30
def __init__(self, parent):
super().__init__(
parent,
3.75,
)
@staticmethod
def loadImages():
SLib.loadIfNotInImageCache('LimitDR', 'limit_d_r.png')
SLib.loadIfNotInImageCache('LimitDL', 'limit_d_l.png')
def dataChanged(self):
direction = self.parent.spritedata[2]
if direction == 0:
self.image = ImageCache['LimitDR']
elif direction == 16 or direction == 17 or direction == 18 or direction == 19 or direction == 20 or direction == 21 or direction == 22 or direction == 23 or direction == 24 or direction == 25 or direction == 26 or direction == 27 or direction == 28 or direction == 29 or direction == 30 or direction == 31:
self.image = ImageCache['LimitDL']
else:
self.image = ImageCache['LimitDR']
super().dataChanged()
class SpriteImage_Flagpole(SLib.SpriteImage_StaticMultiple): # 31, 503, 630, 631
def __init__(self, parent):
super().__init__(
parent,
3.75,
)
self.xOffset = -36
self.yOffset = -144
self.parent.setZValue(24999)
self.aux.append(SLib.AuxiliaryImage(parent, 390, 375))
self.aux[0].setPos(135 + 13*60, 4*60 - 15)
self.aux[0].alpha = 0.5
self.aux.append(SLib.AuxiliaryImage(parent, 390, 375))
self.aux[1].setImage(ImageCache['Chest'], 488, 132, True)
self.aux[1].alpha = 0.5
self.aux.append(SLib.AuxiliaryImage(parent, 390, 375))
self.aux[2].setImage(ImageCache['ToadL'], 540, 128, True)
self.aux[2].alpha = 0.5
self.painted = self.parent.type in (503, 631)
self.dataChanged()
@staticmethod
def loadImages():
SLib.loadIfNotInImageCache('FlagPole', 'flag_pole.png')
SLib.loadIfNotInImageCache('FlagPolePaint', 'flag_pole_paint.png')
SLib.loadIfNotInImageCache('FlagPoleSecret', 'flag_pole_secret.png')
SLib.loadIfNotInImageCache('FlagPoleSecretPaint', 'flag_pole_secret_paint.png')
SLib.loadIfNotInImageCache('Castle', 'castle.png')
SLib.loadIfNotInImageCache('CastlePaint', 'castle_paint.png')
SLib.loadIfNotInImageCache('CastleSnow', 'castle_snow.png')
SLib.loadIfNotInImageCache('CastleSecret', 'castle_secret.png')
SLib.loadIfNotInImageCache('CastleSecretPaint', 'castle_secret_paint.png')
SLib.loadIfNotInImageCache('CastleSecretSnow', 'castle_secret_snow.png')
SLib.loadIfNotInImageCache('Chest', 'chest.png')
SLib.loadIfNotInImageCache('ToadL', 'toad.png')
def dataChanged(self):
super().dataChanged()
secret = (self.parent.spritedata[2] & 0x10) != 0
castle = (self.parent.spritedata[5] & 0x10) == 0
snow = (self.parent.spritedata[5] & 1) != 0
if secret:
self.image = ImageCache['FlagPoleSecret' + ('Paint' if self.painted else '')]
if snow and not self.painted:
self.aux[0].image = ImageCache['CastleSecretSnow']
else:
self.aux[0].image = ImageCache['CastleSecret' + ('Paint' if self.painted else '')]
else:
self.image = ImageCache['FlagPole' + ('Paint' if self.painted else '')]
if snow and not self.painted:
self.aux[0].image = ImageCache['CastleSnow']
else:
self.aux[0].image = ImageCache['Castle' + ('Paint' if self.painted else '')]
if not castle:
self.aux[0].image = None