Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/R3/Moth.txt
1319 views
1
//-------------------Sonic CD Moth Script---------------------//
2
//--------Scripted by Christian Whitehead 'The Taxman'--------//
3
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//
4
5
// Aliases
6
#alias Object.Value0 : Object.Timer
7
#alias Object.Value1 : Object.XVelocity
8
#alias Object.Value2 : Object.YVelocity
9
#alias Object.Value3 : Object.FrameTimer
10
#alias Object.Value4 : Object.XOriginPos
11
#alias Object.Value5 : Object.YOriginPos
12
13
#alias Object.PropertyValue : Object.Quality
14
15
// States
16
#alias 0 : MOTH_IDLE
17
#alias 1 : MOTH_RESPAWN
18
#alias 2 : MOTH_REVEAL
19
#alias 3 : MOTH_FLY
20
21
// Badnik Quality / Property Values
22
#alias 0 : GOOD_QUALITY
23
#alias 1 : BAD_QUALITY
24
25
// Priority
26
#alias 0 : PRIORITY_BOUNDS
27
#alias 1 : PRIORITY_ACTIVE
28
29
30
sub ObjectMain
31
switch Object.State
32
case MOTH_IDLE
33
PlayerObjectCollision(C_TOUCH, -96, -256, 96, 256)
34
if CheckResult == true
35
Object.DrawOrder = 5
36
37
Object.State = MOTH_REVEAL
38
39
Object.FrameTimer = 0
40
Object.Frame = 0
41
42
Object.Priority = PRIORITY_ACTIVE
43
44
Object.XOriginPos = Object.XPos
45
Object.YOriginPos = Object.YPos
46
end if
47
break
48
49
case MOTH_RESPAWN
50
if Object.OutOfBounds == true
51
Object.State = MOTH_IDLE
52
Object.Priority = PRIORITY_BOUNDS
53
end if
54
break
55
56
case MOTH_REVEAL
57
if Object.Timer < 110
58
Object.Timer++
59
60
if Object.Timer == 30
61
Object.Frame++
62
end if
63
64
if Object.Timer == 60
65
Object.Frame++
66
end if
67
68
else
69
if Object.XPos > Player.XPos
70
Object.XVelocity = -0x8000
71
Object.Direction = FACING_RIGHT
72
else
73
Object.XVelocity = 0x8000
74
Object.Direction = FACING_LEFT
75
end if
76
77
Object.State = MOTH_FLY
78
79
Object.Timer = 0
80
81
if Object.Quality > GOOD_QUALITY
82
Object.XVelocity >>= 1
83
end if
84
85
Object.YVelocity = 0x8000
86
end if
87
88
if Object.OutOfBounds == true
89
Object.State = MOTH_RESPAWN
90
91
Object.Timer = 0
92
93
Object.XPos = Object.XOriginPos
94
Object.YPos = Object.YOriginPos
95
end if
96
break
97
98
case MOTH_FLY
99
Object.XPos += Object.XVelocity
100
Object.YPos += Object.YVelocity
101
102
if Object.Timer < 65
103
Object.Timer++
104
else
105
Object.Timer = 0
106
FlipSign(Object.YVelocity)
107
if Object.Quality == GOOD_QUALITY // Only good quality moths drop sparkles
108
CreateTempObject(TypeName[Moth Sparkle], 0, Object.XPos, Object.YPos)
109
Object[TempObjectPos].DrawOrder = 5
110
end if
111
end if
112
113
Object.FrameTimer++
114
Object.FrameTimer %= 20
115
116
Object.Frame = Object.FrameTimer
117
Object.Frame /= 5
118
119
if Object.Quality == GOOD_QUALITY
120
Object.Frame += 3
121
else
122
Object.Frame += 7
123
end if
124
125
if Object.OutOfBounds == true
126
Object.State = MOTH_RESPAWN
127
Object.Timer = 0
128
129
Object.XPos = Object.XOriginPos
130
Object.YPos = Object.YOriginPos
131
end if
132
break
133
134
end switch
135
136
CallFunction(StageSetup_CheckGoodFuture) // Check if it should be a flower
137
end sub
138
139
140
sub ObjectPlayerInteraction
141
if Object.State > MOTH_REVEAL
142
#platform: Use_Standalone
143
PlayerObjectCollision(C_TOUCH, -16, -8, 16, 8)
144
#endplatform
145
#platform: Use_Origins
146
PlayerObjectCollision(C_ENEMY, -16, -8, 16, 8)
147
#endplatform
148
if CheckResult == true
149
CallFunction(Player_BadnikBreak)
150
end if
151
end if
152
end sub
153
154
155
sub ObjectDraw
156
if Object.State > MOTH_RESPAWN
157
DrawSpriteFX(Object.Frame, FX_FLIP, Object.XPos, Object.YPos)
158
end if
159
end sub
160
161
162
sub ObjectStartup
163
LoadSpriteSheet("R3/Objects.gif")
164
165
SpriteFrame(-12, -16, 24, 16, 1, 216) // #0 - Moth Reveal Frame 0
166
SpriteFrame(-12, -16, 24, 24, 26, 216) // #1 - Moth Reveal Frame 1
167
SpriteFrame(-12, -20, 24, 32, 231, 170) // #2 - Moth Reveal Frame 2
168
// New Moth
169
SpriteFrame(-12, -12, 32, 24, 34, 191) // #3 - Moth Fly Frame 0
170
SpriteFrame(-12, -8, 32, 16, 165, 183) // #4 - Moth Fly Frame 1
171
SpriteFrame(-12, -8, 32, 16, 166, 233) // #5 - Moth Fly Frame 2
172
SpriteFrame(-12, -8, 32, 16, 165, 183) // #6 - Moth Fly Frame 3
173
// Old Moth
174
SpriteFrame(-12, -12, 32, 24, 1, 157) // #7 - Moth Fly Frame 0
175
SpriteFrame(-12, -8, 32, 16, 1, 182) // #8 - Moth Fly Frame 1
176
SpriteFrame(-12, -8, 32, 16, 1, 199) // #9 - Moth Fly Frame 2
177
SpriteFrame(-12, -8, 32, 16, 1, 182) // #10 - Moth Fly Frame 3
178
end sub
179
180
181
// ========================
182
// Editor Subs
183
// ========================
184
185
sub RSDKDraw
186
Object.InkEffect = 2
187
Object.Alpha = 196
188
DrawSpriteFX(0, FX_INK, Object.XPos, Object.YPos)
189
end sub
190
191
192
sub RSDKLoad
193
LoadSpriteSheet("R3/Objects.gif")
194
SpriteFrame(-12, -20, 24, 32, 231, 170) // #0 - Moth Reveal
195
196
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
197
end sub
198
199