Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-1-Sonic-2-2013-Script-Decompilation
Path: blob/master/Sonic 1/Scripts/Enemies/NewtronFly.txt
1483 views
1
// ----------------------------------
2
// RSDK Project: Sonic 1
3
// Script Description: Newtron Fly Object
4
// Script Author: Christian Whitehead/Simon Thomley
5
// Unpacked by Rubberduckycooly's script unpacker
6
// ----------------------------------
7
8
// ========================
9
// Aliases
10
// ========================
11
12
private alias object.propertyValue : object.appearFrame
13
14
private alias object.value1 : object.startPos.x
15
private alias object.value2 : object.startPos.y
16
17
private alias 0 : NEWTRONFLY_WAITFORPLAYER
18
private alias 1 : NEWTRONFLY_APPEARING
19
private alias 2 : NEWTRONFLY_APPEARED
20
private alias 3 : NEWTRONFLY_MOVING
21
22
private alias 0 : NEWTRONFLY_ANI_IDLE
23
private alias 1 : NEWTRONFLY_ANI_APPEAR
24
private alias 2 : NEWTRONFLY_ANI_MOVING
25
26
// Player Aliases
27
private alias object.xpos : player.xpos
28
private alias object.value40 : player.hitboxLeft
29
private alias object.value38 : player.hitboxTop
30
private alias object.value41 : player.hitboxRight
31
private alias object.value39 : player.hitboxBottom
32
33
// Path ID Aliases
34
private alias 0 : PATH_A
35
36
37
// ========================
38
// Function Declarations
39
// ========================
40
41
reserve function NewtronFly_DebugDraw
42
reserve function NewtronFly_DebugSpawn
43
44
45
// ========================
46
// Function Definitions
47
// ========================
48
49
private function NewtronFly_DebugDraw
50
DrawSprite(object.direction)
51
end function
52
53
54
private function NewtronFly_DebugSpawn
55
CreateTempObject(TypeName[Newtron Fly], object.direction, object.xpos, object.ypos)
56
object[tempObjectPos].inkEffect = INK_ALPHA
57
object[tempObjectPos].alpha = 0
58
object[tempObjectPos].startPos.x = object.xpos
59
object[tempObjectPos].startPos.y = object.ypos
60
end function
61
62
63
// ========================
64
// Events
65
// ========================
66
67
event ObjectUpdate
68
switch object.state
69
case NEWTRONFLY_WAITFORPLAYER
70
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
71
BoxCollisionTest(C_TOUCH, object.entityPos, -128, -64, 128, 64, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
72
if checkResult == true
73
object.state = NEWTRONFLY_APPEARING
74
end if
75
next
76
break
77
78
case NEWTRONFLY_APPEARING
79
object.priority = PRIORITY_ACTIVE
80
if object.alpha < 0xF8
81
object.alpha += 4
82
if player[0].xpos > object.xpos
83
object.appearFrame = FLIP_NONE
84
else
85
object.appearFrame = FLIP_X
86
end if
87
else
88
object.alpha = 0xFF
89
object.animation = NEWTRONFLY_ANI_APPEAR
90
if object.appearFrame == FLIP_NONE
91
object.xvel = 0x20000
92
else
93
object.xvel = -0x20000
94
end if
95
object.direction = object.appearFrame
96
object.state++
97
end if
98
break
99
100
case NEWTRONFLY_APPEARED
101
object.ypos += object.yvel
102
object.yvel += 0x3800
103
ObjectTileCollision(CSIDE_FLOOR, 0, 8, PATH_A)
104
if checkResult == true
105
object.yvel = 0
106
object.animationTimer = 0
107
object.animation = NEWTRONFLY_ANI_MOVING
108
object.state++
109
end if
110
break
111
112
case NEWTRONFLY_MOVING
113
object.xpos += object.xvel
114
ObjectTileGrip(CSIDE_FLOOR, 0, 8, PATH_A)
115
break
116
117
end switch
118
119
if object.outOfBounds == true
120
temp0 = object.xpos
121
temp1 = object.ypos
122
object.xpos = object.startPos.x
123
object.ypos = object.startPos.y
124
if object.outOfBounds == true
125
object.yvel = 0
126
object.xpos = object.startPos.x
127
object.ypos = object.startPos.y
128
object.animation = NEWTRONFLY_ANI_IDLE
129
object.animationTimer = 0
130
object.priority = PRIORITY_BOUNDS
131
object.alpha = 0
132
object.state = NEWTRONFLY_WAITFORPLAYER
133
else
134
object.xpos = temp0
135
object.ypos = temp1
136
end if
137
end if
138
139
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
140
switch object.state
141
default
142
case NEWTRONFLY_WAITFORPLAYER
143
case NEWTRONFLY_APPEARING
144
break
145
146
case NEWTRONFLY_APPEARED
147
case NEWTRONFLY_MOVING
148
BoxCollisionTest(C_TOUCH, object.entityPos, -16, -8, 16, 8, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)
149
if checkResult == true
150
CallFunction(Player_BadnikBreak)
151
end if
152
break
153
154
end switch
155
next
156
157
switch object.animation
158
case NEWTRONFLY_ANI_IDLE
159
break
160
161
case NEWTRONFLY_ANI_APPEAR
162
if object.animationTimer < 41
163
object.frame = object.animationTimer
164
object.frame /= 20
165
object.animationTimer++
166
end if
167
object.frame += 2
168
break
169
170
case NEWTRONFLY_ANI_MOVING
171
object.frame = object.animationTimer
172
object.frame /= 3
173
object.frame += 5
174
object.animationTimer++
175
object.animationTimer %= 6
176
break
177
178
end switch
179
end event
180
181
182
event ObjectDraw
183
switch object.animation
184
case NEWTRONFLY_ANI_IDLE
185
DrawSpriteFX(object.appearFrame, FX_INK, object.xpos, object.ypos)
186
break
187
188
case NEWTRONFLY_ANI_APPEAR
189
DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
190
break
191
192
case NEWTRONFLY_ANI_MOVING
193
DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
194
DrawSpriteFX(4, FX_FLIP, object.xpos, object.ypos)
195
break
196
197
end switch
198
end event
199
200
201
event ObjectStartup
202
CheckCurrentStageFolder("Zone01")
203
if checkResult == true
204
LoadSpriteSheet("GHZ/Objects2.gif")
205
SpriteFrame(-20, -20, 39, 39, 161, 1)
206
SpriteFrame(-19, -20, 39, 39, 201, 1)
207
SpriteFrame(-18, -20, 37, 35, 218, 41)
208
SpriteFrame(-15, -18, 36, 22, 1, 41)
209
SpriteFrame(-20, -16, 40, 16, 38, 41)
210
SpriteFrame(-28, -9, 8, 8, 79, 41)
211
SpriteFrame(-34, -10, 14, 8, 88, 41)
212
end if
213
214
CheckCurrentStageFolder("Zone07")
215
if checkResult == true
216
LoadSpriteSheet("MBZ/Objects.gif")
217
SpriteFrame(-20, -20, 39, 39, 1, 124)
218
SpriteFrame(-19, -20, 39, 39, 41, 124)
219
SpriteFrame(-18, -20, 37, 35, 81, 128)
220
SpriteFrame(-15, -18, 36, 22, 1, 204)
221
SpriteFrame(-20, -16, 40, 16, 38, 204)
222
SpriteFrame(-28, -9, 8, 8, 79, 204)
223
SpriteFrame(-34, -10, 14, 8, 88, 204)
224
end if
225
226
foreach (TypeName[Newtron Fly], arrayPos0, ALL_ENTITIES)
227
object[arrayPos0].startPos.x = object[arrayPos0].xpos
228
object[arrayPos0].startPos.y = object[arrayPos0].ypos
229
object[arrayPos0].inkEffect = INK_ALPHA
230
object[arrayPos0].alpha = 0
231
next
232
233
SetTableValue(TypeName[Newtron Fly], DebugMode_ObjCount, DebugMode_TypesTable)
234
SetTableValue(NewtronFly_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
235
SetTableValue(NewtronFly_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
236
DebugMode_ObjCount++
237
end event
238
239
240
// ========================
241
// Editor Events
242
// ========================
243
244
event RSDKDraw
245
DrawSprite(0)
246
end event
247
248
249
event RSDKLoad
250
CheckCurrentStageFolder("Zone07")
251
if checkResult == true
252
LoadSpriteSheet("MBZ/Objects.gif")
253
SpriteFrame(-20, -20, 39, 39, 1, 124)
254
else
255
LoadSpriteSheet("GHZ/Objects2.gif")
256
SpriteFrame(-20, -20, 39, 39, 161, 1)
257
end if
258
259
// Not to be set from the editor
260
// It's set to 0 because that's how it was in the original game (the two Newtrons were the same obj type, behaviour was subtype)
261
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
262
263
// TODO: double check that val1 isn't used by this object;
264
// it's set in the editor in m006
265
// also prop val goes up to two there (y-flip), is that normal?
266
end event
267
268