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/Orbinaut.txt
1482 views
1
// ----------------------------------
2
// RSDK Project: Sonic 1
3
// Script Description: Orbinaut 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.unused
13
private alias object.value1 : object.activeOrbs
14
private alias object.value2 : object.startPos.x
15
private alias object.value3 : object.fireOrbs
16
private alias object.value4 : object.targetPlayer
17
private alias object.value5 : object.backupTargetPlayer // if we cant target any players, target the last player detected (or P1 if none)
18
private alias object.value6 : object.targetPlayerDistance
19
20
private alias 0 : ORBINAUT_NOTARGET
21
private alias 1 : ORBINAUT_FIRINGORBS
22
private alias 2 : ORBINAUT_NOORBS
23
private alias 3 : ORBINAUT_ORB
24
25
// Player Aliases
26
private alias object.xpos : player.xpos
27
private alias object.ypos : player.ypos
28
29
private alias object.value40 : player.hitboxLeft
30
private alias object.value38 : player.hitboxTop
31
private alias object.value41 : player.hitboxRight
32
private alias object.value39 : player.hitboxBottom
33
34
private alias object.value17 : debugMode.currentSelection
35
36
37
// ========================
38
// Function Declarations
39
// ========================
40
41
reserve function Orbinaut_DebugDraw
42
reserve function Orbinaut_DebugSpawn
43
reserve function Orbinaut_HandleCollisions
44
reserve function Orbinaut_HandleCollisions_Orb
45
reserve function Orbinaut_CheckOffScreen
46
47
// ========================
48
// Static Values
49
// ========================
50
51
private value Orbinaut_startDebugID = 0
52
53
54
// ========================
55
// Function Definitions
56
// ========================
57
58
private function Orbinaut_DebugDraw
59
temp0 = debugMode.currentSelection
60
temp0 -= Orbinaut_startDebugID
61
temp0--
62
temp0 ^= 1
63
temp0 <<= 1
64
DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)
65
end function
66
67
68
private function Orbinaut_DebugSpawn
69
temp0 = debugMode.currentSelection
70
temp0 -= Orbinaut_startDebugID
71
CreateTempObject(TypeName[Orbinaut], temp0, object.xpos, object.ypos)
72
object[tempObjectPos].startPos.x = object[tempObjectPos].xpos
73
object[tempObjectPos].activeOrbs = 15
74
75
if object[tempObjectPos].propertyValue > 1
76
object[tempObjectPos].fireOrbs = false
77
object[tempObjectPos].propertyValue &= 1
78
GetBit(temp0, object.direction, 0)
79
if temp0 == FLIP_NONE
80
object[tempObjectPos].direction = FLIP_NONE
81
object[tempObjectPos].xvel = -0x4000
82
else
83
object[tempObjectPos].direction = FLIP_X
84
object[tempObjectPos].xvel = 0x4000
85
end if
86
else
87
object[tempObjectPos].fireOrbs = true
88
object[tempObjectPos].xvel = 0
89
GetBit(temp0, object.direction, 0)
90
if temp0 == FLIP_NONE
91
object[tempObjectPos].direction = FLIP_NONE
92
else
93
object[tempObjectPos].direction = FLIP_X
94
end if
95
end if
96
end function
97
98
99
private function Orbinaut_HandleCollisions
100
temp0 = 0
101
temp7 = object.angle
102
temp1 = object.xpos
103
temp2 = object.ypos
104
while temp0 < 4
105
GetBit(temp6, object.activeOrbs, temp0)
106
if temp6 == true
107
Cos256(object.xpos, temp7)
108
object.xpos <<= 12
109
object.xpos += temp1
110
111
Sin256(object.ypos, temp7)
112
object.ypos <<= 12
113
object.ypos += temp2
114
115
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
116
BoxCollisionTest(C_TOUCH, object.entityPos, -4, -4, 4, 4, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
117
if checkResult == true
118
CallFunction(Player_Hit)
119
end if
120
next
121
end if
122
temp7 += 0x40
123
temp7 &= 0xFF
124
temp0++
125
loop
126
127
object.xpos = temp1
128
object.ypos = temp2
129
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
130
BoxCollisionTest(C_TOUCH, object.entityPos, -8, -8, 8, 8, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)
131
if checkResult == true
132
CallFunction(Player_BadnikBreak)
133
end if
134
next
135
end function
136
137
138
private function Orbinaut_HandleCollisions_Orb
139
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
140
BoxCollisionTest(C_TOUCH, object.entityPos, -4, -4, 4, 4, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
141
if checkResult == true
142
CallFunction(Player_Hit)
143
end if
144
next
145
end function
146
147
148
private function Orbinaut_CheckOffScreen
149
if object.outOfBounds == true
150
temp0 = object.xpos
151
object.xpos = object.startPos.x
152
if object.outOfBounds == true
153
object.xpos = object.startPos.x
154
object.activeOrbs = 15
155
if object.fireOrbs == false
156
if object.propertyValue == 0
157
object.direction = FLIP_NONE
158
object.xvel = -0x4000
159
else
160
object.direction = FLIP_X
161
object.xvel = 0x4000
162
end if
163
else
164
if object.propertyValue == 0
165
object.direction = FLIP_NONE
166
else
167
object.direction = FLIP_X
168
end if
169
object.xvel = 0
170
end if
171
172
object.unused = 0
173
object.animationTimer = 0
174
object.priority = PRIORITY_BOUNDS
175
object.state = ORBINAUT_NOTARGET
176
object.angle = 0
177
else
178
object.xpos = temp0
179
end if
180
end if
181
end function
182
183
184
// ========================
185
// Events
186
// ========================
187
188
event ObjectUpdate
189
switch object.state
190
case ORBINAUT_NOTARGET
191
object.priority = PRIORITY_ACTIVE
192
object.xpos += object.xvel
193
if object.direction == FLIP_NONE
194
object.angle++
195
else
196
object.angle--
197
end if
198
object.angle &= 255
199
CallFunction(Orbinaut_HandleCollisions)
200
201
if object.fireOrbs == true
202
object.targetPlayerDistance = 0x7FFFFFFF
203
object.targetPlayer = 0xFFFF
204
object.backupTargetPlayer = 0
205
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
206
temp0 = player[currentPlayer].ypos
207
temp0 -= object.ypos
208
Abs(temp0)
209
if temp0 < object.targetPlayerDistance
210
object.targetPlayerDistance = temp0
211
object.backupTargetPlayer = currentPlayer
212
end if
213
214
if temp0 < 0x400000
215
if object.targetPlayer != 0xFFFF
216
arrayPos0 = object.targetPlayer
217
temp0 = player[currentPlayer].xpos
218
temp0 -= object.xpos
219
Abs(temp0)
220
temp1 = object[arrayPos0].xpos
221
temp1 -= object.xpos
222
Abs(temp1)
223
if temp0 < temp1
224
object.targetPlayer = currentPlayer
225
end if
226
else
227
object.targetPlayer = currentPlayer
228
end if
229
end if
230
next
231
232
if object.targetPlayer != 0xFFFF
233
arrayPos0 = object.targetPlayer
234
temp0 = object.xpos
235
temp0 -= object[arrayPos0].xpos
236
Abs(temp0)
237
if temp0 <= 0x800000
238
object.state = ORBINAUT_FIRINGORBS
239
object.frame = 1
240
end if
241
else
242
arrayPos0 = object.backupTargetPlayer
243
end if
244
245
if object[arrayPos0].xpos < object.xpos
246
object.direction = FLIP_NONE
247
else
248
object.direction = FLIP_X
249
end if
250
end if
251
CallFunction(Orbinaut_CheckOffScreen)
252
break
253
254
case ORBINAUT_FIRINGORBS
255
if object.direction == FLIP_NONE
256
object.angle++
257
else
258
object.angle--
259
end if
260
object.angle &= 0xFF
261
262
temp0 = 0
263
temp7 = object.angle
264
while temp0 < 4
265
if temp7 == 64
266
GetBit(temp6, object.activeOrbs, temp0)
267
if temp6 == true
268
Cos256(temp1, temp7)
269
temp1 <<= 12
270
temp1 += object.xpos
271
Sin256(temp2, temp7)
272
temp2 <<= 12
273
temp2 += object.ypos
274
SetBit(object.activeOrbs, temp0, false)
275
CreateTempObject(TypeName[Orbinaut], 0, temp1, temp2)
276
object[tempObjectPos].state = ORBINAUT_ORB
277
if object.direction == FLIP_NONE
278
object[tempObjectPos].xvel = -0x20000
279
else
280
object[tempObjectPos].xvel = 0x20000
281
end if
282
end if
283
end if
284
temp7 += 0x40
285
temp7 &= 0xFF
286
temp0++
287
loop
288
289
CallFunction(Orbinaut_HandleCollisions)
290
291
if object.activeOrbs == 0
292
object.state = ORBINAUT_NOORBS
293
if object.direction == FLIP_NONE
294
object.xvel = -0x4000
295
else
296
object.xvel = 0x4000
297
end if
298
end if
299
300
if object.animationTimer < 16
301
object.animationTimer++
302
else
303
object.frame = 2
304
end if
305
306
CallFunction(Orbinaut_CheckOffScreen)
307
break
308
309
case ORBINAUT_NOORBS
310
object.xpos += object.xvel
311
CallFunction(Orbinaut_HandleCollisions)
312
CallFunction(Orbinaut_CheckOffScreen)
313
break
314
315
case ORBINAUT_ORB
316
object.xpos += object.xvel
317
CallFunction(Orbinaut_HandleCollisions_Orb)
318
if object.outOfBounds == true
319
object.type = TypeName[Blank Object]
320
end if
321
break
322
323
end switch
324
end event
325
326
327
event ObjectDraw
328
switch object.state
329
case ORBINAUT_NOTARGET
330
case ORBINAUT_FIRINGORBS
331
temp0 = 0
332
temp7 = object.angle
333
while temp0 < 4
334
GetBit(temp6, object.activeOrbs, temp0)
335
if temp6 == true
336
Cos256(temp1, temp7)
337
temp1 <<= 12
338
temp1 += object.xpos
339
Sin256(temp2, temp7)
340
temp2 <<= 12
341
temp2 += object.ypos
342
DrawSpriteXY(3, temp1, temp2)
343
end if
344
temp7 += 64
345
temp7 &= 255
346
temp0++
347
loop
348
DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
349
break
350
351
case ORBINAUT_NOORBS
352
DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
353
break
354
355
case ORBINAUT_ORB
356
DrawSprite(3)
357
break
358
359
end switch
360
end event
361
362
363
event ObjectStartup
364
CheckCurrentStageFolder("Zone04")
365
if checkResult == true
366
LoadSpriteSheet("LZ/Objects.gif")
367
SpriteFrame(-10, -10, 20, 20, 50, 105)
368
SpriteFrame(-10, -10, 20, 20, 71, 105)
369
SpriteFrame(-10, -10, 20, 20, 50, 154)
370
SpriteFrame(-8, -8, 16, 16, 107, 1)
371
end if
372
373
CheckCurrentStageFolder("Zone05")
374
if checkResult == true
375
LoadSpriteSheet("SLZ/Objects.gif")
376
SpriteFrame(-10, -10, 20, 20, 51, 1)
377
SpriteFrame(-10, -10, 20, 20, 72, 1)
378
SpriteFrame(-10, -10, 20, 20, 93, 1)
379
SpriteFrame(-8, -8, 16, 16, 114, 1)
380
end if
381
382
CheckCurrentStageFolder("Zone06")
383
if checkResult == true
384
LoadSpriteSheet("SBZ/Objects.gif")
385
SpriteFrame(-10, -10, 20, 20, 1, 138)
386
SpriteFrame(-10, -10, 20, 20, 22, 138)
387
SpriteFrame(-10, -10, 20, 20, 43, 138)
388
SpriteFrame(-8, -8, 16, 16, 64, 142)
389
end if
390
391
CheckCurrentStageFolder("Zone07")
392
if checkResult == true
393
LoadSpriteSheet("MBZ/Objects.gif")
394
SpriteFrame(-10, -10, 20, 20, 119, 114)
395
SpriteFrame(-10, -10, 20, 20, 140, 114)
396
SpriteFrame(-10, -10, 20, 20, 119, 135)
397
SpriteFrame(-8, -8, 16, 16, 140, 135)
398
end if
399
400
foreach (TypeName[Orbinaut], arrayPos0, ALL_ENTITIES)
401
object[arrayPos0].startPos.x = object[arrayPos0].xpos
402
object[arrayPos0].activeOrbs = 15
403
if object[arrayPos0].propertyValue > 1
404
object[arrayPos0].fireOrbs = false
405
object[arrayPos0].propertyValue &= 1
406
if object[arrayPos0].propertyValue == 0
407
object[arrayPos0].direction = FLIP_NONE
408
object[arrayPos0].xvel = -0x4000
409
else
410
object[arrayPos0].direction = FLIP_X
411
object[arrayPos0].xvel = 0x4000
412
end if
413
else
414
object[arrayPos0].fireOrbs = true
415
object[arrayPos0].xvel = 0
416
if object[arrayPos0].propertyValue == 0
417
object[arrayPos0].direction = FLIP_NONE
418
else
419
object[arrayPos0].direction = FLIP_X
420
end if
421
end if
422
next
423
424
temp0 = 0
425
Orbinaut_startDebugID = DebugMode_ObjCount
426
Orbinaut_startDebugID--
427
while temp0 < 2
428
SetTableValue(TypeName[Orbinaut], DebugMode_ObjCount, DebugMode_TypesTable)
429
SetTableValue(Orbinaut_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
430
SetTableValue(Orbinaut_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
431
DebugMode_ObjCount++
432
temp0++
433
loop
434
end event
435
436
437
// ========================
438
// Editor Events
439
// ========================
440
441
event RSDKEdit
442
if editor.returnVariable == true
443
switch editor.variableID
444
case EDIT_VAR_PROPVAL // property value
445
checkResult = object.propertyValue
446
break
447
448
case 0 // direction
449
GetBit(checkResult, object.propertyValue, 0)
450
break
451
452
case 1 // fireOrbs
453
GetBit(checkResult, object.propertyValue, 1)
454
checkResult ^= true
455
break
456
457
end switch
458
else
459
switch editor.variableID
460
case EDIT_VAR_PROPVAL // property value
461
object.propertyValue = editor.variableValue
462
break
463
464
case 0 // direction
465
CheckNotEqual(editor.variableValue, false)
466
SetBit(object.propertyValue, 0, checkResult)
467
break
468
469
case 1 // fireOrbs
470
CheckNotEqual(editor.variableValue, false)
471
checkResult ^= true
472
SetBit(object.propertyValue, 1, checkResult)
473
break
474
475
end switch
476
end if
477
end event
478
479
480
event RSDKDraw
481
GetBit(object.direction, object.propertyValue, 0)
482
483
// Draw Orbs
484
temp0 = 0
485
temp7 = object.angle
486
while temp0 < 4
487
Cos256(temp1, temp7)
488
temp1 <<= 12
489
temp1 += object.xpos
490
491
Sin256(temp2, temp7)
492
temp2 <<= 12
493
temp2 += object.ypos
494
495
DrawSpriteXY(3, temp1, temp2)
496
497
temp7 += 64
498
temp7 &= 0xFF
499
temp0++
500
loop
501
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
502
end event
503
504
505
event RSDKLoad
506
// Make sure we have a fall-back, in case the current folder isn't actually a valid one
507
temp0 = false
508
509
CheckCurrentStageFolder("Zone05")
510
temp0 |= checkResult
511
if checkResult == true
512
LoadSpriteSheet("SLZ/Objects.gif")
513
SpriteFrame(-10, -10, 20, 20, 51, 1)
514
SpriteFrame(-10, -10, 20, 20, 72, 1)
515
SpriteFrame(-10, -10, 20, 20, 93, 1)
516
SpriteFrame(-8, -8, 16, 16, 114, 1)
517
end if
518
519
CheckCurrentStageFolder("Zone06")
520
temp0 |= checkResult
521
if checkResult == true
522
LoadSpriteSheet("SBZ/Objects.gif")
523
SpriteFrame(-10, -10, 20, 20, 1, 138)
524
SpriteFrame(-10, -10, 20, 20, 22, 138)
525
SpriteFrame(-10, -10, 20, 20, 43, 138)
526
SpriteFrame(-8, -8, 16, 16, 64, 142)
527
end if
528
529
CheckCurrentStageFolder("Zone07")
530
temp0 |= checkResult
531
if checkResult == true
532
LoadSpriteSheet("MBZ/Objects.gif")
533
SpriteFrame(-10, -10, 20, 20, 119, 114)
534
SpriteFrame(-10, -10, 20, 20, 140, 114)
535
SpriteFrame(-10, -10, 20, 20, 119, 135)
536
SpriteFrame(-8, -8, 16, 16, 140, 135)
537
end if
538
539
if temp0 == false
540
// We use LZ's sprites as the fallback, "Zone04" (LZ's folder) will come here too
541
LoadSpriteSheet("LZ/Objects.gif")
542
SpriteFrame(-10, -10, 20, 20, 50, 105)
543
SpriteFrame(-10, -10, 20, 20, 71, 105)
544
SpriteFrame(-10, -10, 20, 20, 50, 154)
545
SpriteFrame(-8, -8, 16, 16, 107, 1)
546
end if
547
548
AddEditorVariable("direction")
549
SetActiveVariable("direction")
550
AddEnumVariable("Left", 0)
551
AddEnumVariable("Right", 1)
552
553
// the actual value is "cantFireOrbs" but fireOrbs is cleaner
554
AddEditorVariable("fireOrbs")
555
SetActiveVariable("fireOrbs")
556
AddEnumVariable("false", false)
557
AddEnumVariable("true", true)
558
end event
559
560