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/Global/RedSpring.txt
1480 views
1
// ----------------------------------
2
// RSDK Project: Sonic 1
3
// Script Description: Red Spring 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.isPlatform
14
private alias object.value7 : object.enabledInAir
15
16
// Player aliases
17
private alias object.state : player.state
18
private alias object.direction : player.direction
19
private alias object.xvel : player.xvel
20
private alias object.yvel : player.yvel
21
private alias object.speed : player.speed
22
private alias object.angle : player.angle
23
private alias object.controlLock : player.controlLock
24
private alias object.pushing : player.pushing
25
private alias object.animation : player.animation
26
private alias object.animationSpeed : player.animationSpeed
27
private alias object.gravity : player.gravity
28
private alias object.collisionMode : player.collisionMode
29
private alias object.tileCollisions : player.tileCollisions
30
private alias object.value1 : player.timer
31
private alias object.value10 : player.animationReserve
32
private alias object.value17 : debugMode.currentSelection
33
34
// ========================
35
// Function Declarations
36
// ========================
37
38
reserve function RedSpring_DebugDraw
39
reserve function RedSpring_DebugSpawn
40
41
42
// ========================
43
// Static Values
44
// ========================
45
46
private value RedSpring_startDebugID = 0
47
48
49
// ========================
50
// Function Declarations
51
// ========================
52
53
private function RedSpring_DebugDraw
54
temp0 = debugMode[0].currentSelection
55
temp0 -= RedSpring_startDebugID
56
57
DrawSprite(temp0)
58
59
temp0 += 4
60
DrawSprite(temp0)
61
end function
62
63
64
private function RedSpring_DebugSpawn
65
temp0 = debugMode[0].currentSelection
66
temp0 -= RedSpring_startDebugID
67
68
CreateTempObject(TypeName[Red Spring], temp0, object.xpos, object.ypos)
69
end function
70
71
72
// ========================
73
// Events
74
// ========================
75
76
event ObjectUpdate
77
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
78
switch object.propertyValue
79
case 0 // Up
80
temp0 = object.isPlatform
81
if player[currentPlayer].gravity == GRAVITY_AIR
82
temp0 = true
83
end if
84
85
if player[currentPlayer].collisionMode > CMODE_FLOOR
86
if player[currentPlayer].yvel < 0
87
temp0 = true
88
end if
89
end if
90
91
if temp0 == false
92
BoxCollisionTest(C_SOLID, object.entityPos, -14, -8, 14, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
93
94
BoxCollisionTest(C_TOUCH, object.entityPos, -14, -10, 14, -6, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
95
if checkResult == true
96
player[currentPlayer].animationReserve = ANI_WALKING
97
if player[currentPlayer].animation == ANI_RUNNING
98
player[currentPlayer].animationReserve = ANI_RUNNING
99
end if
100
101
if player[currentPlayer].animation == ANI_PEELOUT
102
player[currentPlayer].animationReserve = ANI_PEELOUT
103
end if
104
105
object.timer = 1
106
#platform: USE_STANDALONE
107
player[currentPlayer].state = Player_State_Air
108
#endplatform
109
#platform: USE_ORIGINS
110
player[currentPlayer].state = Player_State_Air_NoDropDash
111
#endplatform
112
player[currentPlayer].tileCollisions = true
113
player[currentPlayer].gravity = GRAVITY_AIR
114
player[currentPlayer].speed = player[currentPlayer].xvel
115
player[currentPlayer].yvel = -0x100000
116
player[currentPlayer].animation = ANI_BOUNCING
117
player[currentPlayer].timer = 0
118
PlaySfx(SfxName[Spring], false)
119
end if
120
else
121
if player[currentPlayer].yvel >= 0
122
BoxCollisionTest(C_PLATFORM, object.entityPos, -14, -8, 14, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
123
124
BoxCollisionTest(C_TOUCH, object.entityPos, -14, -10, 14, -6, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
125
if checkResult == true
126
player[currentPlayer].animationReserve = ANI_WALKING
127
if player[currentPlayer].animation == ANI_RUNNING
128
player[currentPlayer].animationReserve = ANI_RUNNING
129
end if
130
131
if player[currentPlayer].animation == ANI_PEELOUT
132
player[currentPlayer].animationReserve = ANI_PEELOUT
133
end if
134
135
object.timer = 1
136
#platform: USE_STANDALONE
137
player[currentPlayer].state = Player_State_Air
138
#endplatform
139
#platform: USE_ORIGINS
140
player[currentPlayer].state = Player_State_Air_NoDropDash
141
#endplatform
142
player[currentPlayer].tileCollisions = true
143
player[currentPlayer].gravity = GRAVITY_AIR
144
player[currentPlayer].speed = player[currentPlayer].xvel
145
player[currentPlayer].yvel = -0x100000
146
player[currentPlayer].animation = ANI_BOUNCING
147
player[currentPlayer].timer = 0
148
PlaySfx(SfxName[Spring], false)
149
end if
150
end if
151
end if
152
break
153
154
case 1 // Right
155
BoxCollisionTest(C_SOLID, object.entityPos, -8, -14, 8, 14, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
156
if player[currentPlayer].gravity == GRAVITY_GROUND
157
BoxCollisionTest(C_TOUCH, object.entityPos, 6, -14, 11, 14, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
158
if checkResult == true
159
object.timer = 1
160
player[currentPlayer].tileCollisions = true
161
player[currentPlayer].angle = 0
162
player[currentPlayer].speed = 0x100000
163
player[currentPlayer].collisionMode = CMODE_FLOOR
164
player[currentPlayer].pushing = 0
165
player[currentPlayer].direction = FACING_RIGHT
166
player[currentPlayer].controlLock = 12
167
PlaySfx(SfxName[Spring], false)
168
169
if player[currentPlayer].state != Player_State_Roll
170
player[currentPlayer].state = Player_State_Ground
171
player[currentPlayer].animation = ANI_RUNNING
172
end if
173
end if
174
else
175
if object.enabledInAir == true
176
BoxCollisionTest(C_TOUCH, object.entityPos, 6, -4, 11, 4, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
177
if checkResult == true
178
object.timer = 1
179
player[currentPlayer].tileCollisions = true
180
player[currentPlayer].angle = 0
181
player[currentPlayer].speed = 0x100000
182
player[currentPlayer].yvel = 0
183
player[currentPlayer].collisionMode = CMODE_FLOOR
184
player[currentPlayer].pushing = 0
185
player[currentPlayer].direction = FACING_RIGHT
186
player[currentPlayer].controlLock = 12
187
PlaySfx(SfxName[Spring], false)
188
if player[currentPlayer].state != Player_State_RollJump
189
player[currentPlayer].animation = ANI_BOUNCING
190
if player[currentPlayer].animation != ANI_JUMPING
191
player[currentPlayer].animation = ANI_RUNNING
192
end if
193
194
object.animationSpeed = object.speed
195
player[currentPlayer].animationSpeed *= 80
196
player[currentPlayer].animationSpeed /= 0x60000
197
end if
198
end if
199
end if
200
end if
201
break
202
203
case 2 // Left
204
BoxCollisionTest(C_SOLID, object.entityPos, -8, -14, 8, 14, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
205
if player[currentPlayer].gravity == GRAVITY_GROUND
206
BoxCollisionTest(C_TOUCH, object.entityPos, -10, -14, -6, 14, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
207
if checkResult == true
208
object.timer = 1
209
player[currentPlayer].tileCollisions = true
210
player[currentPlayer].speed = -0x100000
211
player[currentPlayer].collisionMode = CMODE_FLOOR
212
player[currentPlayer].pushing = 0
213
player[currentPlayer].direction = FACING_LEFT
214
player[currentPlayer].controlLock = 15
215
PlaySfx(SfxName[Spring], false)
216
if player[currentPlayer].state != Player_State_Roll
217
player[currentPlayer].state = Player_State_Ground
218
player[currentPlayer].animation = ANI_RUNNING
219
end if
220
end if
221
else
222
if object.enabledInAir == true
223
BoxCollisionTest(C_TOUCH, object.entityPos, -10, -14, -6, 14, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
224
if checkResult == true
225
object.timer = 1
226
player[currentPlayer].tileCollisions = true
227
player[currentPlayer].speed = -0x100000
228
player[currentPlayer].yvel = 0
229
player[currentPlayer].collisionMode = CMODE_FLOOR
230
player[currentPlayer].pushing = 0
231
player[currentPlayer].direction = FACING_LEFT
232
player[currentPlayer].controlLock = 15
233
PlaySfx(SfxName[Spring], false)
234
if player[currentPlayer].state != Player_State_RollJump
235
player[currentPlayer].animation = ANI_BOUNCING
236
if player[currentPlayer].animation != ANI_JUMPING
237
player[currentPlayer].animation = ANI_RUNNING
238
end if
239
240
object.animationSpeed = object.speed
241
FlipSign(player[currentPlayer].animationSpeed)
242
player[currentPlayer].animationSpeed *= 80
243
player[currentPlayer].animationSpeed /= 0x60000
244
end if
245
end if
246
end if
247
end if
248
break
249
250
case 3 // Down
251
BoxCollisionTest(C_SOLID, object.entityPos, -14, -8, 14, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
252
if player[currentPlayer].yvel <= 0
253
BoxCollisionTest(C_TOUCH, object.entityPos, -14, 6, 14, 10, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
254
if checkResult == true
255
if player[currentPlayer].collisionMode == CMODE_ROOF
256
FlipSign(player[currentPlayer].speed)
257
FlipSign(player[currentPlayer].xvel)
258
end if
259
260
object.timer = 1
261
#platform: USE_STANDALONE
262
player[currentPlayer].state = Player_State_Air
263
#endplatform
264
#platform: USE_ORIGINS
265
player[currentPlayer].state = Player_State_Air_NoDropDash
266
#endplatform
267
player[currentPlayer].tileCollisions = true
268
player[currentPlayer].gravity = GRAVITY_AIR
269
player[currentPlayer].speed = player[currentPlayer].xvel
270
player[currentPlayer].yvel = 0x100000
271
player[currentPlayer].timer = 0
272
PlaySfx(SfxName[Spring], false)
273
end if
274
end if
275
break
276
277
end switch
278
next
279
end event
280
281
282
event ObjectDraw
283
if object.timer == 0
284
temp1 = object.propertyValue
285
DrawSpriteFX(temp1, FX_FLIP, object.xpos, object.ypos)
286
temp1 += 4
287
DrawSpriteFX(temp1, FX_FLIP, object.xpos, object.ypos)
288
else
289
switch object.timer
290
case 2
291
case 3
292
temp1 = object.propertyValue
293
DrawSpriteFX(temp1, FX_FLIP, object.xpos, object.ypos)
294
temp1 += 4
295
DrawSpriteFX(temp1, FX_FLIP, object.xpos, object.ypos)
296
break
297
298
case 1
299
temp1 = object.propertyValue
300
temp1 += 8
301
DrawSpriteFX(temp1, FX_FLIP, object.xpos, object.ypos)
302
break
303
304
case 4
305
case 5
306
case 6
307
case 7
308
case 8
309
case 9
310
temp1 = object.propertyValue
311
temp1 += 12
312
DrawSpriteFX(temp1, FX_FLIP, object.xpos, object.ypos)
313
temp1 += 4
314
DrawSpriteFX(temp1, FX_FLIP, object.xpos, object.ypos)
315
break
316
317
end switch
318
319
object.timer++
320
if object.timer >= 10
321
object.timer = 0
322
end if
323
end if
324
end event
325
326
327
event ObjectStartup
328
LoadSpriteSheet("Global/Items.gif")
329
330
arrayPos0 = 0x20
331
while arrayPos0 < 0x420
332
if object[arrayPos0].type == TypeName[Red Spring]
333
if object[arrayPos0].propertyValue > 3
334
object[arrayPos0].propertyValue -= 4
335
object[arrayPos0].enabledInAir = true
336
end if
337
338
// leftover from CD's spring script, this is supposed to be setup for downwards diag springs but s1 doesn't really have those
339
if object[arrayPos0].propertyValue > 5
340
object[arrayPos0].direction = FLIP_Y
341
end if
342
end if
343
344
arrayPos0++
345
loop
346
347
SpriteFrame(-16, 0, 32, 8, 84, 9)
348
SpriteFrame(-8, -16, 8, 32, 141, 26)
349
SpriteFrame(0, -16, 8, 32, 141, 59)
350
SpriteFrame(-16, -8, 32, 8, 150, 101)
351
352
SpriteFrame(-16, -8, 32, 8, 84, 1)
353
SpriteFrame(0, -16, 8, 32, 149, 26)
354
SpriteFrame(-8, -16, 8, 32, 133, 59)
355
SpriteFrame(-16, 0, 32, 8, 150, 109)
356
357
SpriteFrame(-16, 0, 32, 8, 84, 1)
358
SpriteFrame(-8, -16, 8, 32, 149, 26)
359
SpriteFrame(0, -16, 8, 32, 133, 59)
360
SpriteFrame(-16, -8, 32, 8, 150, 109)
361
362
SpriteFrame(-16, -16, 32, 24, 117, 1)
363
SpriteFrame(-8, -16, 24, 32, 158, 26)
364
SpriteFrame(-16, -16, 24, 32, 158, 59)
365
SpriteFrame(-16, -8, 32, 24, 150, 1)
366
367
SpriteFrame(-16, -24, 32, 8, 84, 1)
368
SpriteFrame(16, -16, 8, 32, 149, 26)
369
SpriteFrame(-24, -16, 8, 32, 133, 59)
370
SpriteFrame(-16, 16, 32, 8, 150, 109)
371
372
temp0 = 0
373
RedSpring_startDebugID = DebugMode_ObjCount
374
while temp0 < 4
375
SetTableValue(TypeName[Red Spring], DebugMode_ObjCount, DebugMode_TypesTable)
376
SetTableValue(RedSpring_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
377
SetTableValue(RedSpring_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
378
DebugMode_ObjCount++
379
temp0++
380
loop
381
end event
382
383
384
// ========================
385
// Editor Events
386
// ========================
387
388
event RSDKEdit
389
if editor.returnVariable == true
390
switch editor.variableID
391
case EDIT_VAR_PROPVAL // property value
392
checkResult = object.propertyValue
393
break
394
395
case 0 // flipFlags
396
checkResult = object.propertyValue
397
checkResult &= 3
398
break
399
400
case 1 // enabledInAir
401
GetBit(checkResult, object.propertyValue, 3)
402
break
403
404
end switch
405
else
406
switch editor.variableID
407
case EDIT_VAR_PROPVAL // property value
408
object.propertyValue = editor.variableValue
409
break
410
411
case 0 // flipFlags
412
temp0 = 3
413
Not(temp0)
414
object.propertyValue &= temp0
415
editor.variableValue &= 3
416
417
object.propertyValue |= editor.variableValue
418
break
419
420
case 1 // enabledInAir
421
CheckNotEqual(editor.variableValue, false)
422
SetBit(object.propertyValue, 3, checkResult)
423
break
424
425
end switch
426
end if
427
end event
428
429
430
event RSDKDraw
431
temp1 = object.propertyValue
432
temp1 &= 3
433
434
DrawSpriteFX(temp1, FX_FLIP, object.xpos, object.ypos)
435
436
temp1 += 4
437
DrawSpriteFX(temp1, FX_FLIP, object.xpos, object.ypos)
438
end event
439
440
441
event RSDKLoad
442
LoadSpriteSheet("Global/Items.gif")
443
SpriteFrame(-16, 0, 32, 8, 84, 9)
444
SpriteFrame(-8, -16, 8, 32, 141, 26)
445
SpriteFrame(0, -16, 8, 32, 141, 59)
446
SpriteFrame(-16, -8, 32, 8, 150, 101)
447
448
SpriteFrame(-16, -8, 32, 8, 84, 1)
449
SpriteFrame(0, -16, 8, 32, 149, 26)
450
SpriteFrame(-8, -16, 8, 32, 133, 59)
451
SpriteFrame(-16, 0, 32, 8, 150, 109)
452
453
SpriteFrame(-16, 0, 32, 8, 84, 1)
454
SpriteFrame(-8, -16, 8, 32, 149, 26)
455
SpriteFrame(0, -16, 8, 32, 133, 59)
456
SpriteFrame(-16, -8, 32, 8, 150, 109)
457
458
SpriteFrame(-16, -16, 32, 24, 117, 1)
459
SpriteFrame(-8, -16, 24, 32, 158, 26)
460
SpriteFrame(-16, -16, 24, 32, 158, 59)
461
SpriteFrame(-16, -8, 32, 24, 150, 1)
462
463
SpriteFrame(-16, -24, 32, 8, 84, 1)
464
SpriteFrame(16, -16, 8, 32, 149, 26)
465
SpriteFrame(-24, -16, 8, 32, 133, 59)
466
SpriteFrame(-16, 16, 32, 8, 150, 109)
467
468
AddEditorVariable("flipFlag")
469
SetActiveVariable("flipFlag")
470
AddEnumVariable("Up", 0)
471
AddEnumVariable("Right", 1)
472
AddEnumVariable("Left", 2)
473
AddEnumVariable("Down", 3)
474
475
AddEditorVariable("enabledInAir")
476
SetActiveVariable("enabledInAir")
477
AddEnumVariable("false", false)
478
AddEnumVariable("true", true)
479
480
SetVariableAlias(ALIAS_VAR_VAL1, "isPlatform")
481
482
// scale is set to 256 (half) in mission M005 but it doesn't really mean anything lol
483
end event
484
485