Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-1-Sonic-2-2013-Script-Decompilation
Path: blob/master/Sonic 2/Scripts/CNZ/HFlipper.txt
1483 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: H Flipper 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.heightArrayTop
14
private alias object.value2 : object.heightArrayBottom
15
private alias object.value3 : object.sensorPosM
16
private alias object.value4 : object.sensorPosL
17
private alias object.value5 : object.sensorPosR
18
private alias object.value6 : object.sensorHeightM
19
private alias object.value7 : object.sensorHeightL
20
private alias object.value8 : object.sensorHeightR
21
private alias object.value9 : object.hitboxT
22
private alias object.value10 : object.hitboxB
23
24
// States
25
private alias 0 : HFLIPPER_IDLE
26
private alias 1 : HFLIPPER_ACTIVATED
27
28
// Player Aliases
29
private alias object.state : player.state
30
private alias object.xpos : player.xpos
31
private alias object.ypos : player.ypos
32
private alias object.ixpos : player.ixpos
33
private alias object.iypos : player.iypos
34
private alias object.xvel : player.xvel
35
private alias object.yvel : player.yvel
36
private alias object.speed : player.speed
37
private alias object.gravity : player.gravity
38
private alias object.prevAnimation : player.prevAnimation
39
private alias object.animation : player.animation
40
private alias object.controlLock : player.controlLock
41
private alias object.scrollTracking : player.scrollTracking
42
private alias object.collisionLeft : player.collisionLeft
43
private alias object.collisionRight : player.collisionRight
44
private alias object.collisionBottom : player.collisionBottom
45
private alias object.jumpPress : player.jumpPress
46
47
private alias object.value1 : player.timer
48
private alias object.value30 : player.jumpOffset
49
50
51
// ========================
52
// Function Declarations
53
// ========================
54
55
reserve function HFlipper_DebugDraw
56
reserve function HFlipper_DebugSpawn
57
reserve function HFlipper_LaunchPlayer
58
59
60
// ========================
61
// Tables
62
// ========================
63
64
private table HFlipper_heightArrayT_Right
65
-8, -8, -8, -8, -9, -9, -9, -9, -9, -9, -9, -8, -8, -7, -7, -6, -6, -5, -5, -4, -4, -3, -3, -2, -2, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 10, 11
66
end table
67
68
private table HFlipper_heightArrayB_Right
69
5, 6, 7, 7, 8, 8, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18
70
end table
71
72
private table HFlipper_heightArrayT_Left
73
11, 10, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6, -7, -7, -8, -8, -9, -9, -9, -9, -9, -9, -9, -8, -8, -8, -8
74
end table
75
76
private table HFlipper_heightArrayB_Left
77
18, 18, 18, 18, 18, 18, 18, 17, 17, 17, 17, 16, 16, 16, 16, 15, 15, 15, 15, 14, 14, 14, 14, 13, 13, 13, 13, 12, 12, 12, 12, 11, 11, 11, 11, 10, 10, 10, 10, 9, 9, 9, 8, 8, 7, 7, 6, 5
78
end table
79
80
81
// ========================
82
// Function Definitions
83
// ========================
84
85
private function HFlipper_DebugDraw
86
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
87
end function
88
89
90
private function HFlipper_DebugSpawn
91
CreateTempObject(TypeName[H Flipper], 0, object.xpos, object.ypos)
92
object[tempObjectPos].direction = object.direction
93
if object[tempObjectPos].direction == FACING_RIGHT
94
object[tempObjectPos].heightArrayTop = HFlipper_heightArrayT_Right
95
object[tempObjectPos].heightArrayBottom = HFlipper_heightArrayB_Right
96
else
97
object[tempObjectPos].heightArrayTop = HFlipper_heightArrayT_Left
98
object[tempObjectPos].heightArrayBottom = HFlipper_heightArrayB_Left
99
end if
100
end function
101
102
103
private function HFlipper_LaunchPlayer
104
temp0 = player[currentPlayer].ixpos
105
temp0 -= object.ixpos
106
if object.direction == FLIP_X
107
FlipSign(temp0)
108
end if
109
temp0 += 35
110
111
temp2 = temp0
112
if temp2 > 64
113
temp2 = 64
114
end if
115
temp2 <<= 5
116
temp2 += 0x800
117
FlipSign(temp2)
118
119
temp3 = temp0
120
temp3 >>= 2
121
temp3 += 64
122
123
Sin256(temp0, temp3)
124
Cos256(temp1, temp3)
125
temp0 *= temp2
126
temp1 *= temp2
127
128
player[currentPlayer].yvel = temp0
129
if object.direction == FLIP_X
130
FlipSign(temp1)
131
end if
132
player[currentPlayer].speed = temp1
133
player[currentPlayer].xvel = temp1
134
end function
135
136
137
// ========================
138
// Events
139
// ========================
140
141
event ObjectUpdate
142
switch object.state
143
default
144
case HFLIPPER_IDLE
145
break
146
147
case HFLIPPER_ACTIVATED
148
object.frame = object.timer
149
object.frame >>= 2
150
object.frame++
151
if object.timer < 12
152
object.timer++
153
else
154
object.timer = 0
155
object.frame = 0
156
object.state = HFLIPPER_IDLE
157
end if
158
break
159
160
end switch
161
162
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
163
CheckEqual(player[currentPlayer].state, Player_State_Death)
164
temp0 = checkResult
165
CheckEqual(player[currentPlayer].state, Player_State_GotHit)
166
temp0 |= checkResult
167
if temp0 == false
168
object.sensorPosL = player[currentPlayer].xpos
169
object.sensorPosL -= object.xpos
170
object.sensorPosL >>= 16
171
172
object.sensorPosM = object.sensorPosL
173
object.sensorPosM += player[currentPlayer].collisionLeft
174
175
object.sensorPosR = object.sensorPosL
176
object.sensorPosR += player[currentPlayer].collisionRight
177
178
object.sensorPosM += 24
179
180
if object.sensorPosM < 0
181
object.sensorPosM = 0
182
end if
183
184
if object.sensorPosM > 47
185
object.sensorPosM = 47
186
end if
187
188
object.sensorPosL += 24
189
if object.sensorPosL < 0
190
object.sensorPosL = 0
191
end if
192
193
if object.sensorPosL > 47
194
object.sensorPosL = 47
195
end if
196
197
object.sensorPosR += 24
198
if object.sensorPosR < 0
199
object.sensorPosR = 0
200
end if
201
202
if object.sensorPosR > 47
203
object.sensorPosR = 47
204
end if
205
206
GetTableValue(object.sensorHeightM, object.sensorPosM, object.heightArrayTop)
207
GetTableValue(object.sensorHeightL, object.sensorPosL, object.heightArrayTop)
208
GetTableValue(object.sensorHeightR, object.sensorPosR, object.heightArrayTop)
209
210
object.hitboxT = object.sensorHeightM
211
if object.sensorHeightL < object.hitboxT
212
object.hitboxT = object.sensorHeightL
213
end if
214
215
if object.sensorHeightR < object.hitboxT
216
object.hitboxT = object.sensorHeightR
217
end if
218
219
GetTableValue(object.sensorHeightM, object.sensorPosM, object.heightArrayBottom)
220
GetTableValue(object.sensorHeightL, object.sensorPosL, object.heightArrayBottom)
221
GetTableValue(object.sensorHeightR, object.sensorPosR, object.heightArrayBottom)
222
223
object.hitboxB = object.sensorHeightM
224
if object.sensorHeightL > object.hitboxB
225
object.hitboxB = object.sensorHeightL
226
end if
227
228
if object.sensorHeightR > object.hitboxB
229
object.hitboxB = object.sensorHeightR
230
end if
231
232
if player[currentPlayer].state != Player_State_Static
233
BoxCollisionTest(C_SOLID, object.entityPos, -24, object.hitboxT, 24, object.hitboxB, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
234
if checkResult == COL_BOTTOM
235
CheckEqual(player[currentPlayer].state, Player_State_Climb)
236
temp0 = checkResult
237
CheckEqual(player[currentPlayer].state, Player_State_GlideLeft)
238
temp0 |= checkResult
239
CheckEqual(player[currentPlayer].state, Player_State_GlideRight)
240
temp0 |= checkResult
241
CheckEqual(player[currentPlayer].state, Player_State_Fly)
242
temp0 |= checkResult
243
CheckEqual(player[currentPlayer].state, Player_State_TubeRoll)
244
temp0 |= checkResult
245
CheckEqual(player[currentPlayer].state, Player_State_TubeAirRoll)
246
temp0 |= checkResult
247
if temp0 == false
248
#platform: USE_STANDALONE
249
player[currentPlayer].state = Player_State_Air
250
#endplatform
251
#platform: USE_ORIGINS
252
player[currentPlayer].state = Player_State_Air_NoDropDash
253
#endplatform
254
player[currentPlayer].gravity = GRAVITY_AIR
255
end if
256
end if
257
258
temp0 = 4
259
else
260
temp0 = 12
261
end if
262
263
object.hitboxT -= temp0
264
object.hitboxB = object.hitboxT
265
object.hitboxB += 8
266
BoxCollisionTest(C_TOUCH, object.entityPos, -24, object.hitboxT, 24, object.hitboxB, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
267
if checkResult == true
268
player[currentPlayer].ypos = object.hitboxT
269
player[currentPlayer].ypos += temp0
270
player[currentPlayer].ypos -= player[currentPlayer].collisionBottom
271
player[currentPlayer].ypos <<= 16
272
player[currentPlayer].ypos += object.ypos
273
if object.state == HFLIPPER_IDLE
274
if object.direction == FLIP_X
275
BoxCollisionTest(C_TOUCH, object.entityPos, -26, -12, 20, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
276
else
277
BoxCollisionTest(C_TOUCH, object.entityPos, -20, -12, 26, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
278
end if
279
280
if checkResult == true
281
CheckEqual(player[currentPlayer].state, Player_State_TubeRoll)
282
temp0 = checkResult
283
CheckEqual(player[currentPlayer].state, Player_State_TubeAirRoll)
284
temp0 |= checkResult
285
if temp0 == false
286
player[currentPlayer].state = Player_State_Roll
287
player[currentPlayer].animation = ANI_JUMPING
288
end if
289
290
player[currentPlayer].scrollTracking = false
291
player[currentPlayer].gravity = GRAVITY_GROUND
292
player[currentPlayer].controlLock = 8
293
if player[currentPlayer].jumpPress == true
294
CheckEqual(player[currentPlayer].state, Player_State_TubeRoll)
295
temp0 = checkResult
296
CheckEqual(player[currentPlayer].state, Player_State_TubeAirRoll)
297
temp0 |= checkResult
298
if temp0 == false
299
#platform: USE_STANDALONE
300
player[currentPlayer].state = Player_State_Air
301
#endplatform
302
#platform: USE_ORIGINS
303
player[currentPlayer].state = Player_State_Air_NoDropDash
304
#endplatform
305
end if
306
307
player[currentPlayer].gravity = 1
308
player[currentPlayer].timer = 0
309
player[currentPlayer].controlLock = 0
310
CallFunction(HFlipper_LaunchPlayer)
311
object.state = HFLIPPER_ACTIVATED
312
StopSfx(SfxName[Jump])
313
PlaySfx(SfxName[Flipper], false)
314
else
315
player[currentPlayer].speed = object.xvel
316
player[currentPlayer].xvel = object.xvel
317
player[currentPlayer].yvel = 0
318
end if
319
else
320
CheckEqual(player[currentPlayer].state, Player_State_TubeRoll)
321
temp0 = checkResult
322
CheckEqual(player[currentPlayer].state, Player_State_TubeAirRoll)
323
temp0 |= checkResult
324
if temp0 == false
325
#platform: USE_STANDALONE
326
player[currentPlayer].state = Player_State_Air
327
#endplatform
328
#platform: USE_ORIGINS
329
player[currentPlayer].state = Player_State_Air_NoDropDash
330
#endplatform
331
end if
332
333
player[currentPlayer].gravity = 1
334
player[currentPlayer].timer = 0
335
end if
336
337
player[currentPlayer].animation = ANI_JUMPING
338
if player[currentPlayer].prevAnimation != ANI_JUMPING
339
player[currentPlayer].iypos -= player[currentPlayer].jumpOffset
340
end if
341
else
342
CheckEqual(player[currentPlayer].state, Player_State_TubeRoll)
343
temp0 = checkResult
344
CheckEqual(player[currentPlayer].state, Player_State_TubeAirRoll)
345
temp0 |= checkResult
346
if temp0 == false
347
#platform: USE_STANDALONE
348
player[currentPlayer].state = Player_State_Air
349
#endplatform
350
#platform: USE_ORIGINS
351
player[currentPlayer].state = Player_State_Air_NoDropDash
352
#endplatform
353
end if
354
355
CallFunction(HFlipper_LaunchPlayer)
356
player[currentPlayer].gravity = 1
357
player[currentPlayer].timer = 0
358
end if
359
end if
360
end if
361
next
362
end event
363
364
365
event ObjectDraw
366
DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
367
end event
368
369
370
event ObjectStartup
371
CheckCurrentStageFolder("Zone04")
372
if checkResult == true
373
LoadSpriteSheet("CNZ/Objects.gif")
374
SpriteFrame(-25, -9, 47, 26, 26, 185)
375
SpriteFrame(-24, -8, 48, 16, 26, 212)
376
SpriteFrame(-25, -17, 47, 26, 26, 229)
377
SpriteFrame(-24, -8, 48, 16, 26, 212)
378
else
379
LoadSpriteSheet("MBZ/Objects.gif")
380
SpriteFrame(-25, -9, 47, 26, 189, 402)
381
SpriteFrame(-24, -8, 48, 16, 189, 429)
382
SpriteFrame(-25, -17, 47, 26, 189, 446)
383
SpriteFrame(-24, -8, 48, 16, 189, 429)
384
end if
385
386
foreach (TypeName[H Flipper], arrayPos0, ALL_ENTITIES)
387
object[arrayPos0].direction = object[arrayPos0].propertyValue
388
if object[arrayPos0].direction == FLIP_NONE
389
object[arrayPos0].heightArrayTop = HFlipper_heightArrayT_Right
390
object[arrayPos0].heightArrayBottom = HFlipper_heightArrayB_Right
391
object[arrayPos0].xvel = 0x10000
392
else
393
object[arrayPos0].heightArrayTop = HFlipper_heightArrayT_Left
394
object[arrayPos0].heightArrayBottom = HFlipper_heightArrayB_Left
395
object[arrayPos0].xvel = -0x10000
396
end if
397
next
398
399
SetTableValue(TypeName[H Flipper], DebugMode_ObjCount, DebugMode_TypesTable)
400
SetTableValue(HFlipper_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
401
SetTableValue(HFlipper_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
402
DebugMode_ObjCount++
403
end event
404
405
406
// ========================
407
// Editor Events
408
// ========================
409
410
event RSDKEdit
411
if editor.returnVariable == true
412
switch editor.variableID
413
case EDIT_VAR_PROPVAL // property value
414
checkResult = object.propertyValue
415
break
416
417
case 0 // direction
418
checkResult = object.propertyValue
419
break
420
421
end switch
422
else
423
switch editor.variableID
424
case EDIT_VAR_PROPVAL // property value
425
object.propertyValue = editor.variableValue
426
break
427
428
case 0 // direction
429
object.propertyValue = editor.variableValue
430
break
431
432
end switch
433
end if
434
end event
435
436
437
event RSDKDraw
438
object.direction = object.propertyValue
439
object.direction &= 1
440
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
441
end event
442
443
444
event RSDKLoad
445
CheckCurrentStageFolder("Zone04")
446
if checkResult == true
447
LoadSpriteSheet("CNZ/Objects.gif")
448
SpriteFrame(-25, -9, 47, 26, 26, 185)
449
else
450
LoadSpriteSheet("MBZ/Objects.gif")
451
SpriteFrame(-25, -9, 47, 26, 189, 402)
452
end if
453
454
// Flippers also have FLIP_X attr set too sometimes but that's unused
455
AddEditorVariable("direction")
456
SetActiveVariable("direction")
457
AddEnumVariable("Right", 0)
458
AddEnumVariable("Left", 1)
459
end event
460
461