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/Motobug.txt
1483 views
1
// ----------------------------------
2
// RSDK Project: Sonic 1
3
// Script Description: Motobug 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.value0 : object.timer
13
private alias object.value1 : object.startPos.x
14
private alias object.value2 : object.startPos.y
15
private alias object.value3 : object.exhaustTimer
16
17
private alias 0 : MOTOBUG_MOVING
18
private alias 1 : MOTOBUG_PAUSED
19
20
private alias 0 : MOTOBUG_ANI_MOVING
21
private alias 1 : MOTOBUG_ANI_IDLE
22
23
// Player Aliases
24
private alias object.value40 : player.hitboxLeft
25
private alias object.value38 : player.hitboxTop
26
private alias object.value41 : player.hitboxRight
27
private alias object.value39 : player.hitboxBottom
28
29
// Path ID Aliases
30
private alias 0 : PATH_A
31
32
33
// ========================
34
// Function Declarations
35
// ========================
36
37
reserve function Motobug_DebugDraw
38
reserve function Motobug_DebugSpawn
39
40
41
// ========================
42
// Function Definitions
43
// ========================
44
45
private function Motobug_DebugDraw
46
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
47
end function
48
49
50
private function Motobug_DebugSpawn
51
CreateTempObject(TypeName[Motobug], 0, object.xpos, object.ypos)
52
GetBit(temp0, object.direction, 0)
53
if temp0 == FLIP_NONE
54
object[tempObjectPos].direction = FLIP_NONE
55
object[tempObjectPos].xvel = -0x10000
56
else
57
object[tempObjectPos].direction = FLIP_X
58
object[tempObjectPos].xvel = 0x10000
59
end if
60
end function
61
62
63
// ========================
64
// Events
65
// ========================
66
67
event ObjectUpdate
68
switch object.state
69
case MOTOBUG_MOVING
70
object.priority = PRIORITY_ACTIVE
71
72
object.xpos += object.xvel
73
74
// Check object collision
75
ObjectTileGrip(CSIDE_FLOOR, 0, 15, PATH_A)
76
if checkResult == false
77
// If on the edge, then pause to turn around
78
object.state = MOTOBUG_PAUSED
79
object.animation = MOTOBUG_ANI_IDLE
80
end if
81
82
// Update exhaust process
83
if object.exhaustTimer < 20
84
object.exhaustTimer++
85
else
86
object.exhaustTimer = 0
87
88
CreateTempObject(TypeName[Motobug Exhaust], 0, object.xpos, object.ypos)
89
90
// Offset the exhaust based on the Motobug's direction
91
if object.direction == FLIP_NONE
92
object[tempObjectPos].xpos += 0x160000
93
else
94
object[tempObjectPos].xpos -= 0x160000
95
end if
96
97
// Set the exhaust to match the Motobug's direction
98
object[tempObjectPos].direction = object.direction
99
end if
100
break
101
102
case MOTOBUG_PAUSED
103
if object.timer < 59
104
// Stay still for a moment...
105
object.timer++
106
else
107
// Start moving again
108
object.timer = 0
109
110
object.state = MOTOBUG_MOVING
111
object.animation = MOTOBUG_ANI_MOVING
112
113
// Flip the Motobug
114
object.direction ^= FLIP_X
115
FlipSign(object.xvel)
116
end if
117
break
118
119
end switch
120
121
if object.outOfBounds == true
122
temp0 = object.xpos
123
temp1 = object.ypos
124
125
object.xpos = object.startPos.x
126
object.ypos = object.startPos.y
127
128
if object.outOfBounds == true
129
if object.propertyValue == 0
130
object.direction = FLIP_NONE
131
object.xvel = -0x10000
132
else
133
object.direction = FLIP_X
134
object.xvel = 0x10000
135
end if
136
137
object.animation = MOTOBUG_ANI_MOVING
138
object.priority = PRIORITY_BOUNDS
139
object.state = MOTOBUG_MOVING
140
else
141
object.xpos = temp0
142
object.ypos = temp1
143
end if
144
end if
145
146
// Check collision with players
147
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
148
BoxCollisionTest(C_TOUCH, object.entityPos, -14, -14, 14, 14, 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
next
153
154
if object.animation == MOTOBUG_ANI_MOVING
155
object.frame = object.animationTimer
156
object.frame >>= 3
157
object.animationTimer++
158
object.animationTimer &= 31
159
end if
160
end event
161
162
163
event ObjectDraw
164
DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
165
end event
166
167
168
event ObjectStartup
169
// Check which sprites to load based on current folder
170
CheckCurrentStageFolder("Zone01")
171
#platform: USE_ORIGINS
172
// Motobugs are big fans of the phrase "being in Mission Mode"
173
temp0 = checkResult
174
CheckEqual(game.playMode, BOOT_PLAYMODE_MISSION)
175
checkResult |= temp0
176
#endplatform
177
if checkResult == true
178
// Motobug in GHZ (or a mission) - load GHZ frames
179
LoadSpriteSheet("GHZ/Objects.gif")
180
SpriteFrame(-21, -13, 40, 28, 98, 127)
181
SpriteFrame(-20, -14, 39, 29, 139, 127)
182
SpriteFrame(-20, -13, 39, 28, 98, 156)
183
SpriteFrame(-20, -14, 39, 29, 139, 127)
184
end if
185
186
CheckCurrentStageFolder("Zone07")
187
if checkResult == true
188
// Motobug in MBZ - load MBZ frames
189
LoadSpriteSheet("MBZ/Objects.gif")
190
SpriteFrame(-21, -13, 40, 28, 170, 145)
191
SpriteFrame(-20, -14, 39, 29, 171, 174)
192
SpriteFrame(-20, -13, 39, 28, 171, 204)
193
SpriteFrame(-20, -14, 39, 29, 171, 174)
194
end if
195
196
// Setup all Motobugs
197
foreach (TypeName[Motobug], arrayPos0, ALL_ENTITIES)
198
object[arrayPos0].startPos.x = object[arrayPos0].xpos
199
object[arrayPos0].startPos.y = object[arrayPos0].ypos
200
201
// Set their direction based on their propertyValue
202
if object[arrayPos0].propertyValue == 0
203
object[arrayPos0].direction = FLIP_NONE
204
object[arrayPos0].xvel = -0x10000
205
else
206
object[arrayPos0].direction = FLIP_X
207
object[arrayPos0].xvel = 0x10000
208
end if
209
next
210
211
// Add Motobug to the debug item list
212
SetTableValue(TypeName[Motobug], DebugMode_ObjCount, DebugMode_TypesTable)
213
SetTableValue(Motobug_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
214
SetTableValue(Motobug_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
215
DebugMode_ObjCount++
216
end event
217
218
219
// ========================
220
// Editor Events
221
// ========================
222
223
event RSDKEdit
224
if editor.returnVariable == true
225
switch editor.variableID
226
case EDIT_VAR_PROPVAL // property value
227
checkResult = object.propertyValue
228
checkResult &= 1
229
break
230
231
case 0 // direction
232
checkResult = object.propertyValue
233
checkResult &= 1
234
break
235
236
end switch
237
else
238
switch editor.variableID
239
case EDIT_VAR_PROPVAL // property value
240
object.propertyValue = editor.variableValue
241
object.propertyValue &= 1
242
break
243
244
case 0 // direction
245
object.propertyValue = editor.variableValue
246
object.propertyValue &= 1
247
break
248
249
end switch
250
end if
251
end event
252
253
254
event RSDKDraw
255
GetBit(object.direction, object.propertyValue, 0)
256
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
257
end event
258
259
260
event RSDKLoad
261
// Check which sprites to load based on current folder
262
CheckCurrentStageFolder("Zone07")
263
if checkResult == true
264
// Motobug in in MBZ - load MBZ frames
265
266
LoadSpriteSheet("MBZ/Objects.gif")
267
SpriteFrame(-21, -13, 40, 28, 170, 145)
268
else
269
// Thanks to Origins using Motobugs everywhere, just load the GHZ sheet as a fallback, even if not in GHZ
270
271
LoadSpriteSheet("GHZ/Objects.gif")
272
SpriteFrame(-21, -13, 40, 28, 98, 127)
273
end if
274
275
AddEditorVariable("direction")
276
SetActiveVariable("direction")
277
AddEnumVariable("Left", 0)
278
AddEnumVariable("Right", 1)
279
end event
280
281