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/Mission/Motobug2.txt
1482 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
// This bit of code is new to Motobug2, let's check collision with Mission Blocks and use them as an extension of normal ground
83
84
// If we just turned around, then let's see if there's actually more Mission Blocks in the direction we were going
85
if object.state == MOTOBUG_PAUSED
86
foreach (TypeName[MissionBlock], arrayPos0, ACTIVE_ENTITIES)
87
temp1 = false
88
89
temp2 = object[arrayPos0].ixpos
90
temp2 -= object.ixpos
91
CheckGreater(temp2, -18)
92
temp1 = checkResult
93
CheckLower(temp2, 18)
94
temp1 &= checkResult
95
96
temp2 = object[arrayPos0].iypos
97
temp2 -= object.iypos
98
CheckGreater(temp2, 15)
99
temp1 &= checkResult
100
CheckLower(temp2, 40)
101
temp1 &= checkResult
102
103
if temp1 == true
104
// There's still more Mission Blocks for us to drive on, so instead of turning around let's just keep going
105
object.state = MOTOBUG_MOVING
106
object.animation = MOTOBUG_ANI_MOVING
107
end if
108
next
109
end if
110
111
// If we're moving, then let's see if there are more Mission Blocks ahead of us
112
if object.state == MOTOBUG_MOVING
113
temp0 = false
114
115
foreach (TypeName[MissionBlock], arrayPos0, ACTIVE_ENTITIES)
116
temp1 = false
117
118
temp2 = object[arrayPos0].ixpos
119
temp2 -= object.ixpos
120
CheckGreater(temp2, -36)
121
temp1 = checkResult
122
CheckLower(temp2, 36)
123
temp1 &= checkResult
124
125
temp2 = object[arrayPos0].iypos
126
temp2 -= object.iypos
127
CheckGreater(temp2, -30)
128
temp1 &= checkResult
129
CheckLower(temp2, 30)
130
temp1 &= checkResult
131
132
temp0 |= temp1
133
next
134
135
if temp0 != false
136
// If we're at the end of the row of Mission Blocks, then let's turn around
137
object.state = MOTOBUG_PAUSED
138
object.animation = MOTOBUG_ANI_IDLE
139
end if
140
end if
141
142
// Update exhaust process
143
if object.exhaustTimer < 20
144
object.exhaustTimer++
145
else
146
object.exhaustTimer = 0
147
148
CreateTempObject(TypeName[Motobug Exhaust], 0, object.xpos, object.ypos)
149
150
// Offset the exhaust based on the Motobug's direction
151
if object.direction == FLIP_NONE
152
object[tempObjectPos].xpos += 0x160000
153
else
154
object[tempObjectPos].xpos -= 0x160000
155
end if
156
157
// Set the exhaust to match the Motobug's direction
158
object[tempObjectPos].direction = object.direction
159
end if
160
break
161
162
case MOTOBUG_PAUSED
163
if object.timer < 59
164
// Stay still for a moment...
165
object.timer++
166
else
167
// Start moving again
168
object.timer = 0
169
170
object.state = MOTOBUG_MOVING
171
object.animation = MOTOBUG_ANI_MOVING
172
173
// Flip the Motobug
174
object.direction ^= FLIP_X
175
FlipSign(object.xvel)
176
end if
177
break
178
179
end switch
180
181
if object.outOfBounds == true
182
temp0 = object.xpos
183
temp1 = object.ypos
184
185
object.xpos = object.startPos.x
186
object.ypos = object.startPos.y
187
188
if object.outOfBounds == true
189
if object.propertyValue == 0
190
object.direction = FLIP_NONE
191
object.xvel = -0x10000
192
else
193
object.direction = FLIP_X
194
object.xvel = 0x10000
195
end if
196
197
object.animation = MOTOBUG_ANI_MOVING
198
object.priority = PRIORITY_BOUNDS
199
object.state = MOTOBUG_MOVING
200
else
201
object.xpos = temp0
202
object.ypos = temp1
203
end if
204
end if
205
206
// Check collision with players
207
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
208
BoxCollisionTest(C_TOUCH, object.entityPos, -14, -14, 14, 14, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)
209
if checkResult == true
210
CallFunction(Player_BadnikBreak)
211
end if
212
next
213
214
if object.animation == MOTOBUG_ANI_MOVING
215
object.frame = object.animationTimer
216
object.frame >>= 3
217
object.animationTimer++
218
object.animationTimer &= 31
219
end if
220
end event
221
222
223
event ObjectDraw
224
if object.state != 2 // This state doesn't exist??? (this check is new to Motobug2 too btw, normal Motobug doesn't have this)
225
DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
226
end if
227
end event
228
229
230
event ObjectStartup
231
if game.playMode == BOOT_PLAYMODE_MISSION
232
LoadSpriteSheet("GHZ/Objects.gif")
233
SpriteFrame(-21, -13, 40, 28, 98, 127)
234
SpriteFrame(-20, -14, 39, 29, 139, 127)
235
SpriteFrame(-20, -13, 39, 28, 98, 156)
236
SpriteFrame(-20, -14, 39, 29, 139, 127)
237
end if
238
239
// (They removed the MBZ sheet checks and such here, more power to 'em I suppose)
240
241
// Setup all Motobugs
242
foreach (TypeName[Motobug], arrayPos0, ALL_ENTITIES)
243
object[arrayPos0].startPos.x = object[arrayPos0].xpos
244
object[arrayPos0].startPos.y = object[arrayPos0].ypos
245
246
// Set their direction based on their propertyValue
247
if object[arrayPos0].propertyValue == 0
248
object[arrayPos0].direction = FLIP_NONE
249
object[arrayPos0].xvel = -0x10000
250
else
251
object[arrayPos0].direction = FLIP_X
252
object[arrayPos0].xvel = 0x10000
253
end if
254
next
255
256
// Add Motobug to the debug item list
257
SetTableValue(TypeName[Motobug], DebugMode_ObjCount, DebugMode_TypesTable)
258
SetTableValue(Motobug_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
259
SetTableValue(Motobug_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
260
DebugMode_ObjCount++
261
end event
262
263
264
// ========================
265
// Editor Events
266
// ========================
267
268
event RSDKEdit
269
if editor.returnVariable == true
270
switch editor.variableID
271
case EDIT_VAR_PROPVAL // property value
272
checkResult = object.propertyValue
273
checkResult &= 1
274
break
275
276
case 0 // direction
277
checkResult = object.propertyValue
278
checkResult &= 1
279
break
280
281
end switch
282
else
283
switch editor.variableID
284
case EDIT_VAR_PROPVAL // property value
285
object.propertyValue = editor.variableValue
286
object.propertyValue &= 1
287
break
288
289
case 0 // direction
290
object.propertyValue = editor.variableValue
291
object.propertyValue &= 1
292
break
293
294
end switch
295
end if
296
end event
297
298
299
event RSDKDraw
300
GetBit(object.direction, object.propertyValue, 0)
301
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
302
end event
303
304
305
event RSDKLoad
306
LoadSpriteSheet("GHZ/Objects.gif")
307
SpriteFrame(-21, -13, 40, 28, 98, 127)
308
309
AddEditorVariable("direction")
310
SetActiveVariable("direction")
311
AddEnumVariable("Left", 0)
312
AddEnumVariable("Right", 1)
313
end event
314
315