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/Special/PlayerObject.txt
1478 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Player Object 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.type : player.type
13
private alias object.entityPos : player.entityPos
14
private alias object.state : player.state
15
private alias object.priority : player.priority
16
private alias object.visible : player.visible
17
private alias object.xpos : player.xpos
18
private alias object.ypos : player.ypos
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.rotation : player.rotation
23
private alias object.angle : player.angle
24
private alias object.frame : player.frame
25
private alias object.animation : player.animation
26
private alias object.animationSpeed : player.animationSpeed
27
private alias object.animationTimer : player.animationTimer
28
private alias object.gravity : player.gravity
29
private alias object.controlMode : player.controlMode
30
31
// Object input values
32
private alias object.up : player.up
33
private alias object.down : player.down
34
private alias object.left : player.left
35
private alias object.right : player.right
36
private alias object.jumpPress : player.jumpPress
37
private alias object.jumpHold : player.jumpHold
38
39
// Value Aliases
40
private alias object.value0 : player.rings
41
private alias object.value1 : player.timer
42
private alias object.value2 : player.zpos
43
private alias object.value3 : player.xBoundsR
44
private alias object.value4 : player.frameOffset
45
// value5 is unused
46
private alias object.value6 : player.spinTimer
47
private alias object.value7 : player.invincibilityTimer
48
// value8 is unused
49
private alias object.value9 : player.xBoundsL
50
private alias object.value10 : player.groundPos
51
private alias object.value11 : player.localShadowPos.x
52
private alias object.value12 : player.localShadowPos.y
53
private alias object.value13 : player.localShadowPos.u
54
private alias object.value14 : player.localPos.z
55
private alias object.value15 : player.localPos.x
56
private alias object.value16 : player.localPos.y
57
private alias object.value17 : player.tailFrame
58
private alias object.value18 : player.stateInput
59
private alias object.value19 : player.vsCheckpointID
60
private alias object.value20 : player.vsCheckpoint1Rings
61
private alias object.value21 : player.vsCheckpoint2Rings
62
private alias object.value22 : player.vsCheckpoint3Rings
63
private alias object.value23 : player.playerTagFrame
64
private alias object.value24 : player.currentLeader
65
private alias object.value25 : player.changedLeader
66
private alias object.value26 : player.automoveActive
67
private alias object.value27 : player.jumpInTimer
68
69
// Halfpipe Aliases
70
private alias object.value13 : halfpipe.playerPos.z
71
private alias object.value14 : halfpipe.worldTranslation.x
72
private alias object.value15 : halfpipe.worldTranslation.y
73
private alias object.value16 : halfpipe.worldTranslation.z
74
private alias object.value17 : halfpipe.worldRotation.x
75
private alias object.value18 : halfpipe.worldRotation.y
76
private alias object.value19 : halfpipe.worldRotation.z
77
78
// LoseRing Aliases
79
private alias object.value1 : loseRing.gravityStrength
80
81
// Title Card aliases
82
private alias 8 : TITLECARD_FADETOTITLE
83
84
// Face Buffer Flag Aliases
85
private alias 6 : FACE_TEXTURED_C_BLEND
86
private alias 7 : FACE_SPRITE_3D
87
88
89
// ========================
90
// Function Declarations
91
// ========================
92
93
reserve function Player_Input_Gamepad
94
reserve function Player_Input_AI_Follow
95
reserve function Player_State_Ground
96
reserve function Player_State_Air
97
reserve function Player_State_Hurt
98
reserve function Player_LoseRings
99
reserve function Player_Draw_Normal
100
reserve function Player_Input_Gamepad_2P
101
reserve function Player_Input_VSPlayer_2P
102
103
104
// ========================
105
// Static Values
106
// ========================
107
108
private value Player_stateUp = 0
109
private value Player_stateDown = 0
110
private value Player_stateLeft = 0
111
private value Player_stateRight = 0
112
private value Player_stateJumpPress = 0
113
private value Player_stateJumpHold = 0
114
115
private value Player_attractTable = 0
116
private value Player_attractTablePos = 0
117
private value Player_attractTableSize = 0
118
private value Player_attractFrameCount = 0
119
private value Player_attractDuration = 0
120
private value Player_playerSlot = 0
121
122
// What player is in front right now
123
private value Player_leadingPlayer = 0
124
125
// ========================
126
// Tables
127
// ========================
128
129
// Shadow Y Positions, with index 0 being as far left/right as it goes, and the last index being the center
130
private table Player_shadowYPosTable
131
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -127, -127, -127, -127
132
-127, -127, -127, -127, -126, -126, -126, -126, -126, -126, -125, -125, -125, -125, -124, -124
133
-124, -124, -123, -123, -123, -123, -122, -122, -122, -121, -121, -121, -120, -120, -119, -119
134
-119, -118, -118, -117, -117, -116, -116, -116, -115, -115, -114, -114, -113, -112, -112, -111
135
-111, -110, -110, -109, -108, -108, -107, -106, -106, -105, -104, -104, -103, -102, -101, -101
136
-100, -99, -98, -97, -96, -96, -95, -94, -93, -92, -91, -90, -89, -88, -87, -85
137
-84, -83, -82, -81, -79, -78, -77, -75, -74, -72, -71, -69, -68, -66, -64, -62
138
-61, -59, -57, -54, -52, -50, -47, -45, -42, -39, -35, -31, -27, -21, -13, 0
139
end table
140
141
142
// ========================
143
// Function Definitions
144
// ========================
145
146
public function Player_Draw_Normal
147
MatrixRotateXYZ(MAT_WORLD, halfpipe[0].worldRotation.x, halfpipe[0].worldRotation.y, halfpipe[0].worldRotation.z)
148
MatrixTranslateXYZ(MAT_TEMP, halfpipe[0].worldTranslation.x, halfpipe[0].worldTranslation.y, halfpipe[0].worldTranslation.z)
149
MatrixMultiply(MAT_WORLD, MAT_TEMP)
150
151
arrayPos0 = scene3D.vertexCount
152
arrayPos1 = scene3D.faceCount
153
154
// Draw Shadow
155
faceBuffer[arrayPos1].flag = FACE_TEXTURED_C_BLEND
156
faceBuffer[arrayPos1].a = arrayPos0
157
vertexBuffer[arrayPos0].x = player.localShadowPos.x
158
vertexBuffer[arrayPos0].y = player.localShadowPos.y
159
vertexBuffer[arrayPos0].z = player.zpos
160
vertexBuffer[arrayPos0].u = player.localShadowPos.u
161
vertexBuffer[arrayPos0].v = 50
162
arrayPos2 = arrayPos0
163
arrayPos0++
164
TransformVertices(MAT_WORLD, arrayPos2, arrayPos0)
165
166
faceBuffer[arrayPos1].b = arrayPos0
167
vertexBuffer[arrayPos0].x = vertexBuffer[arrayPos2].x
168
vertexBuffer[arrayPos0].y = vertexBuffer[arrayPos2].y
169
vertexBuffer[arrayPos0].z = vertexBuffer[arrayPos2].z
170
if player.zpos > 0x800
171
vertexBuffer[arrayPos0].u = 0x600
172
vertexBuffer[arrayPos0].v = 0x600
173
else
174
vertexBuffer[arrayPos0].u = 0x580
175
vertexBuffer[arrayPos0].v = 0x580
176
end if
177
arrayPos0++
178
179
faceBuffer[arrayPos1].c = arrayPos0
180
vertexBuffer[arrayPos0].x = vertexBuffer[arrayPos2].x
181
vertexBuffer[arrayPos0].y = vertexBuffer[arrayPos2].y
182
vertexBuffer[arrayPos0].z = vertexBuffer[arrayPos2].z
183
vertexBuffer[arrayPos0].u = 17
184
vertexBuffer[arrayPos0].v = 16
185
arrayPos0++
186
187
faceBuffer[arrayPos1].d = arrayPos0
188
vertexBuffer[arrayPos0].x = vertexBuffer[arrayPos2].x
189
vertexBuffer[arrayPos0].y = vertexBuffer[arrayPos2].y
190
vertexBuffer[arrayPos0].z = vertexBuffer[arrayPos2].z
191
arrayPos0++
192
193
arrayPos1++
194
scene3D.vertexCount += 4
195
scene3D.faceCount++
196
197
// Draw the Player
198
if player.visible == true
199
arrayPos2 = arrayPos0
200
arrayPos0++
201
202
faceBuffer[arrayPos1].flag = FACE_SPRITE_3D
203
faceBuffer[arrayPos1].a = arrayPos2
204
vertexBuffer[arrayPos2].x = player.xpos
205
vertexBuffer[arrayPos2].x >>= 1
206
player.localPos.x = vertexBuffer[arrayPos2].x
207
208
vertexBuffer[arrayPos2].y = player.ypos
209
vertexBuffer[arrayPos2].y >>= 1
210
player.localPos.y = vertexBuffer[arrayPos2].y
211
212
vertexBuffer[arrayPos2].z = player.zpos
213
TransformVertices(MAT_WORLD, arrayPos2, arrayPos0)
214
215
vertexBuffer[arrayPos2].u = TypeName[Player Object]
216
vertexBuffer[arrayPos2].v = FX_ROTATE
217
faceBuffer[arrayPos1].b = arrayPos0
218
vertexBuffer[arrayPos0].x = vertexBuffer[arrayPos2].x
219
vertexBuffer[arrayPos0].y = vertexBuffer[arrayPos2].y
220
vertexBuffer[arrayPos0].z = vertexBuffer[arrayPos2].z
221
vertexBuffer[arrayPos0].u = player.frame
222
vertexBuffer[arrayPos0].v = 0
223
arrayPos0++
224
225
faceBuffer[arrayPos1].c = arrayPos0
226
vertexBuffer[arrayPos0].x = vertexBuffer[arrayPos2].x
227
vertexBuffer[arrayPos0].y = vertexBuffer[arrayPos2].y
228
vertexBuffer[arrayPos0].z = vertexBuffer[arrayPos2].z
229
vertexBuffer[arrayPos0].u = 0x200
230
vertexBuffer[arrayPos0].v = player.rotation
231
arrayPos0++
232
233
faceBuffer[arrayPos1].d = arrayPos0
234
vertexBuffer[arrayPos0].x = vertexBuffer[arrayPos2].x
235
vertexBuffer[arrayPos0].y = vertexBuffer[arrayPos2].y
236
vertexBuffer[arrayPos0].z = vertexBuffer[arrayPos2].z
237
scene3D.vertexCount += 4
238
scene3D.faceCount++
239
240
// If the character is Tails, then draw his Tails
241
if player.frameOffset == 16
242
if player.animation == 0
243
arrayPos0++
244
arrayPos1++
245
faceBuffer[arrayPos1].flag = FACE_SPRITE_3D
246
faceBuffer[arrayPos1].a = arrayPos0
247
vertexBuffer[arrayPos0].x = vertexBuffer[arrayPos2].x
248
vertexBuffer[arrayPos0].y = vertexBuffer[arrayPos2].y
249
vertexBuffer[arrayPos0].z = vertexBuffer[arrayPos2].z
250
vertexBuffer[arrayPos0].u = TypeName[Player Object]
251
vertexBuffer[arrayPos0].v = FX_ROTATE
252
arrayPos0++
253
254
faceBuffer[arrayPos1].b = arrayPos0
255
vertexBuffer[arrayPos0].x = vertexBuffer[arrayPos2].x
256
vertexBuffer[arrayPos0].y = vertexBuffer[arrayPos2].y
257
vertexBuffer[arrayPos0].z = vertexBuffer[arrayPos2].z
258
vertexBuffer[arrayPos0].u = player.tailFrame
259
vertexBuffer[arrayPos0].u >>= 2
260
vertexBuffer[arrayPos0].u += 48
261
vertexBuffer[arrayPos0].v = 0
262
arrayPos0++
263
264
faceBuffer[arrayPos1].c = arrayPos0
265
vertexBuffer[arrayPos0].x = vertexBuffer[arrayPos2].x
266
vertexBuffer[arrayPos0].y = vertexBuffer[arrayPos2].y
267
vertexBuffer[arrayPos0].z = vertexBuffer[arrayPos2].z
268
vertexBuffer[arrayPos0].u = 0x200
269
vertexBuffer[arrayPos0].v = player.rotation
270
arrayPos0++
271
272
faceBuffer[arrayPos1].d = arrayPos0
273
vertexBuffer[arrayPos0].x = vertexBuffer[arrayPos2].x
274
vertexBuffer[arrayPos0].y = vertexBuffer[arrayPos2].y
275
vertexBuffer[arrayPos0].z = vertexBuffer[arrayPos2].z
276
scene3D.vertexCount += 4
277
scene3D.faceCount++
278
end if
279
end if
280
end if
281
282
// If active, draw 1P/2P Tag
283
if player.playerTagFrame > 0
284
arrayPos0++
285
arrayPos1++
286
faceBuffer[arrayPos1].flag = FACE_SPRITE_3D
287
faceBuffer[arrayPos1].a = arrayPos0
288
vertexBuffer[arrayPos0].x = vertexBuffer[arrayPos2].x
289
vertexBuffer[arrayPos0].y = vertexBuffer[arrayPos2].y
290
vertexBuffer[arrayPos0].z = vertexBuffer[arrayPos2].z
291
vertexBuffer[arrayPos0].u = TypeName[Player Object]
292
vertexBuffer[arrayPos0].v = FX_ROTATE
293
arrayPos0++
294
295
faceBuffer[arrayPos1].b = arrayPos0
296
vertexBuffer[arrayPos0].x = vertexBuffer[arrayPos2].x
297
vertexBuffer[arrayPos0].y = vertexBuffer[arrayPos2].y
298
vertexBuffer[arrayPos0].z = vertexBuffer[arrayPos2].z
299
vertexBuffer[arrayPos0].u = player.playerTagFrame
300
vertexBuffer[arrayPos0].v = 0
301
arrayPos0++
302
303
faceBuffer[arrayPos1].c = arrayPos0
304
vertexBuffer[arrayPos0].x = vertexBuffer[arrayPos2].x
305
vertexBuffer[arrayPos0].y = vertexBuffer[arrayPos2].y
306
vertexBuffer[arrayPos0].z = vertexBuffer[arrayPos2].z
307
vertexBuffer[arrayPos0].u = 0x200
308
vertexBuffer[arrayPos0].v = 0
309
arrayPos0++
310
311
faceBuffer[arrayPos1].d = arrayPos0
312
vertexBuffer[arrayPos0].x = vertexBuffer[arrayPos2].x
313
vertexBuffer[arrayPos0].y = vertexBuffer[arrayPos2].y
314
vertexBuffer[arrayPos0].z = vertexBuffer[arrayPos2].z
315
scene3D.vertexCount += 4
316
scene3D.faceCount++
317
end if
318
end function
319
320
321
public function Player_Input_Gamepad
322
if options.attractMode == false
323
#platform: USE_STANDALONE
324
if options.touchControls == true
325
if player.controlMode == CONTROLMODE_P1
326
CheckTouchRect(0, 96, screen.xcenter, screen.ysize)
327
if checkResult > -1
328
arrayPos0 = checkResult
329
temp0 = touchscreen[arrayPos0].xpos
330
temp0 -= saveRAM[39]
331
if temp0 > 0
332
keyDown[1].right = true
333
else
334
keyDown[1].left = true
335
end if
336
end if
337
338
CheckTouchRect(screen.xcenter, 96, screen.xsize, 240)
339
if checkResult > -1
340
keyDown[1].buttonA = true
341
end if
342
343
if touchJump == false
344
keyPress[1].buttonA |= keyDown[1].buttonA
345
end if
346
347
touchJump = keyDown[1].buttonA
348
if stage.debugMode == true
349
CheckTouchRect(0, 0, 112, 56)
350
if checkResult > -1
351
keyDown[1].buttonB = true
352
end if
353
354
if touchDebug == false
355
keyPress[1].buttonB |= keyDown[1].buttonB
356
end if
357
358
touchDebug = keyDown[1].buttonB
359
end if
360
361
CheckTouchRect(240, 0, screen.xsize, 40)
362
if checkResult > -1
363
if options.vsMode == false
364
PlaySfx(SfxName[Menu Back], false)
365
engine.state = 5
366
end if
367
end if
368
369
if keyPress[0].start == true
370
if options.vsMode == false
371
PlaySfx(SfxName[Menu Back], false)
372
engine.state = 5
373
end if
374
end if
375
end if
376
end if
377
#endplatform
378
379
#platform: USE_ORIGINS
380
if keyPress[0].start == true
381
if options.vsMode == false
382
// These SFX should never even be playing in the Special Stage...
383
StopSfx(SfxName[Flying])
384
StopSfx(SfxName[Tired])
385
engine.state = 5
386
end if
387
end if
388
#endplatform
389
390
ProcessObjectControl()
391
392
if options.vsMode == true
393
player.currentLeader = Player_leadingPlayer
394
CallNativeFunction2(SendEntity, 2, false)
395
end if
396
else
397
// There aren't even any demos in the Special Stages, but may as well leave in the implementation for it anyway...
398
399
#platform: USE_STANDALONE
400
CheckTouchRect(0, 0, screen.xsize, screen.ysize)
401
if keyPress[0].start == true
402
checkResult = false
403
end if
404
405
if checkResult > -1
406
if Player_attractDuration > 1
407
Player_attractDuration = 1
408
end if
409
end if
410
#endplatform
411
412
if keyPress[0].start == true
413
Player_attractDuration = 1
414
end if
415
416
Player_attractFrameCount--
417
if Player_attractFrameCount < 1
418
if Player_attractTablePos < Player_attractTableSize
419
GetTableValue(temp0, Player_attractTablePos, Player_attractTable)
420
GetBit(player.up, temp0, 0)
421
GetBit(player.down, temp0, 1)
422
GetBit(player.left, temp0, 2)
423
GetBit(player.right, temp0, 3)
424
GetBit(player.jumpPress, temp0, 4)
425
GetBit(player.jumpHold, temp0, 5)
426
Player_attractTablePos++
427
428
GetTableValue(Player_attractFrameCount, Player_attractTablePos, Player_attractTable)
429
Player_attractTablePos++
430
end if
431
else
432
if player.jumpPress == true
433
player.jumpPress = false
434
end if
435
end if
436
437
if Player_attractDuration > 0
438
Player_attractDuration--
439
if Player_attractDuration < 1
440
// This code is copied directly from S1 SS's version of the demo handler, including a fade out for ending the demo
441
// However, this includes a mention of the Title Card object, which doesn't exist in Sonic 2 Special Stages...
442
// (TypeName[Title Card] will resolve as 0, a Blank Object, for the reason above)
443
444
arrayPos0 = Player_playerSlot
445
object[arrayPos0].type = TypeName[Title Card]
446
object[arrayPos0].state = TITLECARD_FADETOTITLE
447
object[arrayPos0].priority = PRIORITY_ACTIVE
448
object[arrayPos0].drawOrder = 6
449
end if
450
end if
451
end if
452
453
if player.invincibilityTimer > 0
454
player.invincibilityTimer--
455
GetBit(temp0, player.invincibilityTimer, 2)
456
if temp0 == true
457
player.visible = false
458
else
459
player.visible = true
460
end if
461
end if
462
end function
463
464
465
public function Player_Input_AI_Follow
466
Player_stateUp <<= 1
467
Player_stateUp |= player[2].up
468
Player_stateUp &= 0xFFFF
469
470
Player_stateDown <<= 1
471
Player_stateDown |= player[2].down
472
Player_stateDown &= 0xFFFF
473
474
Player_stateLeft <<= 1
475
Player_stateLeft |= player[2].left
476
Player_stateLeft &= 0xFFFF
477
478
Player_stateRight <<= 1
479
Player_stateRight |= player[2].right
480
Player_stateRight &= 0xFFFF
481
482
Player_stateJumpPress <<= 1
483
Player_stateJumpPress |= player[2].jumpPress
484
Player_stateJumpPress &= 0xFFFF
485
486
Player_stateJumpHold <<= 1
487
Player_stateJumpHold |= player[2].jumpHold
488
Player_stateJumpHold &= 0xFFFF
489
490
temp0 = Player_stateUp
491
temp0 >>= 15
492
player.up = temp0
493
494
temp0 = Player_stateDown
495
temp0 >>= 15
496
player.down = temp0
497
498
temp0 = Player_stateLeft
499
temp0 >>= 15
500
player.left = temp0
501
502
temp0 = Player_stateRight
503
temp0 >>= 15
504
player.right = temp0
505
506
temp0 = Player_stateJumpPress
507
temp0 >>= 15
508
player.jumpPress = temp0
509
510
temp0 = Player_stateJumpHold
511
temp0 >>= 15
512
player.jumpHold = temp0
513
514
if player.invincibilityTimer > 0
515
player.invincibilityTimer--
516
GetBit(temp0, player.invincibilityTimer, 2)
517
if temp0 == true
518
player.visible = false
519
else
520
player.visible = true
521
end if
522
end if
523
524
#platform: USE_ORIGINS
525
temp0 = keyDown[2].left
526
temp0 |= keyDown[2].right
527
temp0 |= keyDown[2].buttonA
528
temp0 |= keyDown[2].buttonB
529
temp0 |= keyDown[2].buttonC
530
if temp0 == true
531
player.jumpInTimer = 0
532
player.stateInput = Player_Input_Gamepad_2P
533
end if
534
#endplatform
535
end function
536
537
538
public function Player_Input_Gamepad_2P
539
#platform: USE_ORIGINS
540
ProcessObjectControl()
541
if player.invincibilityTimer > 0
542
player.invincibilityTimer--
543
GetBit(temp0, player.invincibilityTimer, 2)
544
if temp0 == true
545
player.visible = false
546
else
547
player.visible = true
548
end if
549
end if
550
551
temp0 = player.left
552
temp0 |= player.right
553
temp0 |= player.jumpHold
554
if temp0 == false
555
player.jumpInTimer++
556
if player.jumpInTimer >= 600
557
player.stateInput = Player_Input_AI_Follow
558
AssignInputSlotToDevice(2, -1)
559
end if
560
else
561
player.jumpInTimer = 0
562
end if
563
#endplatform
564
end function
565
566
567
public function Player_Input_VSPlayer_2P
568
#platform: USE_STANDALONE
569
temp0 = player.playerTagFrame
570
CallNativeFunction2(ReceiveEntity, 3, true)
571
player.type = TypeName[Player Object]
572
player.stateInput = Player_Input_VSPlayer_2P
573
player.playerTagFrame = temp0
574
#endplatform
575
576
#platform: USE_ORIGINS
577
ProcessObjectControl()
578
#endplatform
579
580
if vs.playerID == 1
581
Player_leadingPlayer = player.currentLeader
582
end if
583
584
if player.invincibilityTimer > 0
585
player.invincibilityTimer--
586
GetBit(temp0, player.invincibilityTimer, 2)
587
if temp0 == true
588
player.visible = false
589
else
590
player.visible = true
591
end if
592
end if
593
end function
594
595
596
public function Player_State_Ground
597
if player.right == true
598
player.speed -= 48
599
if player.speed < -0x600
600
player.speed = -0x600
601
end if
602
603
player.automoveActive = false
604
player.timer = 0
605
else
606
if player.left == true
607
player.speed += 48
608
if player.speed > 0x600
609
player.speed = 0x600
610
end if
611
612
player.automoveActive = false
613
player.timer = 0
614
else
615
if player.automoveActive == false
616
player.timer = 60
617
player.automoveActive = true
618
end if
619
620
temp0 = player.speed
621
temp0 >>= 4
622
player.speed -= temp0
623
end if
624
end if
625
626
temp0 = player.speed
627
if player.rotation != 0
628
temp0 /= 256
629
temp0 *= 128
630
else
631
temp0 >>= 1
632
end if
633
634
player.angle += temp0
635
player.angle &= 0xFFFF
636
player.rotation = player.angle
637
player.rotation >>= 7
638
639
// Wait for it....
640
if player.timer > 0
641
player.timer--
642
else
643
// Move to center
644
temp1 = player.rotation
645
temp1 >>= 1
646
Sin256(temp0, temp1)
647
temp0 *= -80
648
temp0 >>= 9
649
player.speed += temp0
650
end if
651
652
Sin(player.xpos, player.rotation)
653
player.xpos *= player.xBoundsL
654
player.xpos >>= 9
655
656
Cos(player.ypos, player.rotation)
657
player.ypos *= player.xBoundsL
658
player.ypos >>= 9
659
660
player.animation = 0
661
player.animationSpeed = 60
662
temp0 = player.rotation
663
player.changedLeader = false
664
665
if player.jumpPress == true
666
player.speed = 0
667
Sin(player.xvel, player.rotation)
668
player.xvel *= 0x5A0
669
player.xvel >>= 9
670
Cos(player.yvel, player.rotation)
671
player.yvel *= 0x980
672
player.yvel >>= 9
673
player.state = Player_State_Air
674
player.rotation = 0
675
player.frame = 8
676
player.frame += player.frameOffset
677
player.animation = 8
678
player.animationSpeed = 60
679
player.animationTimer = 0
680
player.gravity = GRAVITY_AIR
681
PlaySfx(SfxName[Jump], false)
682
else
683
if player.rotation > 152
684
if player.rotation < 360
685
if player.speed < 128
686
if player.speed > -128
687
player.xvel = player.speed
688
player.speed = 0
689
player.state = Player_State_Air
690
player.yvel = 0
691
end if
692
end if
693
end if
694
end if
695
end if
696
if temp0 > 128
697
if temp0 < 384
698
temp0 += 256
699
FlipSign(temp0)
700
temp0 &= 511
701
end if
702
end if
703
704
Sin(player.localShadowPos.x, temp0)
705
player.localShadowPos.x *= -52
706
player.localShadowPos.x >>= 1
707
708
Cos(player.localShadowPos.y, temp0)
709
player.localShadowPos.y *= -52
710
player.localShadowPos.y >>= 1
711
712
player.localShadowPos.u = 116
713
714
if temp0 < 256
715
if temp0 > 112
716
player.localShadowPos.u = 224
717
else
718
if temp0 > 39
719
player.localShadowPos.u = 149
720
end if
721
end if
722
else
723
if temp0 < 400
724
player.localShadowPos.u = 215
725
else
726
if temp0 < 473
727
player.localShadowPos.u = 182
728
end if
729
end if
730
end if
731
732
if player.rotation < 40
733
player.rotation = 0
734
end if
735
736
if player.rotation > 472
737
player.rotation = 0
738
end if
739
end function
740
741
742
public function Player_State_Air
743
if options.vsMode == true
744
if player.changedLeader == false
745
Player_leadingPlayer ^= 1
746
player.changedLeader = true
747
end if
748
end if
749
750
player.xpos += player.xvel
751
if player.xpos <= player.xBoundsL
752
player.xpos = player.xBoundsL
753
end if
754
755
if player.xpos >= player.xBoundsR
756
player.xpos = player.xBoundsR
757
end if
758
759
if player.left == true
760
player.xvel -= 32
761
end if
762
763
if player.right == true
764
player.xvel += 32
765
end if
766
767
player.ypos += player.yvel
768
player.yvel -= 88
769
if player.ypos < 0
770
temp0 = player.xpos
771
temp0 *= player.xpos
772
temp1 = player.ypos
773
temp1 *= player.ypos
774
temp0 += temp1
775
if temp0 > player.groundPos
776
player.state = Player_State_Ground
777
player.gravity = GRAVITY_GROUND
778
ATan2(player.angle, player.ypos, player.xpos)
779
player.angle += 128
780
player.angle <<= 8
781
end if
782
end if
783
784
if player.rotation < 0x100
785
if player.rotation > 0
786
player.rotation -= 8
787
else
788
player.rotation = 0
789
end if
790
else
791
if player.rotation < 0x200
792
player.rotation += 8
793
else
794
player.rotation = 0
795
end if
796
end if
797
798
player.localShadowPos.x = player.xpos
799
player.localShadowPos.x *= 144
800
player.localShadowPos.x >>= 8
801
802
temp0 = player.xpos
803
temp0 *= 45
804
temp0 >>= 13
805
Abs(temp0)
806
GetTableValue(player.localShadowPos.y, temp0, Player_shadowYPosTable)
807
temp0 = player.localShadowPos.y
808
player.localShadowPos.y *= 105
809
810
player.localShadowPos.u = 116
811
812
// Shadow frame funky stuff
813
if temp0 > -112
814
if temp0 > -24
815
if player.xpos < 0
816
player.localShadowPos.u = 224
817
else
818
player.localShadowPos.u = 215
819
end if
820
else
821
if player.xpos < 0
822
player.localShadowPos.u = 149
823
else
824
player.localShadowPos.u = 182
825
end if
826
end if
827
end if
828
end function
829
830
831
public function Player_State_Hurt
832
if options.vsMode == true
833
if vs.playerID == 0
834
if player.changedLeader == false
835
Player_leadingPlayer = player.entityPos
836
Player_leadingPlayer -= 2
837
Player_leadingPlayer ^= vs.playerID
838
Player_leadingPlayer ^= 1
839
player.changedLeader = true
840
end if
841
end if
842
end if
843
844
if player.spinTimer < 512
845
player.spinTimer += 16
846
player.rotation += 16
847
else
848
player.speed = 0
849
player.spinTimer = 0
850
player.invincibilityTimer = 60
851
if player.gravity == 0
852
player.state = Player_State_Ground
853
else
854
player.state = Player_State_Air
855
end if
856
end if
857
end function
858
859
860
public function Player_LoseRings
861
if player[currentPlayer].rings > 0
862
PlaySfx(SfxName[Lose Rings], false)
863
player[currentPlayer].rings -= 10
864
865
temp0 = 10
866
if player[currentPlayer].rings < 0
867
temp0 += player[currentPlayer].rings
868
player[currentPlayer].rings = 0
869
end if
870
871
temp2 = temp0
872
temp2 >>= 1
873
temp2 <<= 5
874
temp1 = 384
875
temp1 -= temp2
876
temp2 = player.angle
877
temp2 >>= 7
878
temp1 += temp2
879
temp3 = player[currentPlayer].xpos
880
temp3 *= 224
881
temp4 = player[currentPlayer].ypos
882
temp4 *= -220
883
temp5 = player[2].ypos
884
temp5 *= -48
885
temp4 += 0x600000
886
temp4 += temp5
887
while temp0 > 0
888
CreateTempObject(TypeName[Lose Ring], 0, temp3, temp4)
889
Cos(object[tempObjectPos].xvel, temp1)
890
Sin(object[tempObjectPos].yvel, temp1)
891
object[tempObjectPos].xvel <<= 9
892
object[tempObjectPos].yvel <<= 10
893
object[tempObjectPos].scale = 0x140
894
Rand(loseRing[tempObjectPos].gravityStrength, 0x2000)
895
loseRing[tempObjectPos].gravityStrength += 0x7000
896
Rand(object[tempObjectPos].animationSpeed, 128)
897
object[tempObjectPos].animationSpeed += 64
898
temp0--
899
temp1 += 32
900
loop
901
end if
902
end function
903
904
905
// ========================
906
// Events
907
// ========================
908
909
event ObjectUpdate
910
CallFunction(player.stateInput)
911
CallFunction(player.state)
912
913
if options.vsMode == true
914
temp0 = player.entityPos
915
temp0 -= 2
916
temp0 ^= vs.playerID
917
temp0 ^= Player_leadingPlayer
918
if temp0 == 0
919
if player.zpos < 0x1000
920
player.zpos += 64
921
end if
922
else
923
if player.zpos > 0x400
924
player.zpos -= 64
925
end if
926
end if
927
end if
928
929
player.localPos.z = player.zpos
930
player.localPos.z <<= 8
931
player.localPos.z += halfpipe[0].playerPos.z
932
player.localPos.z += 0xC0000
933
934
player.animationTimer += player.animationSpeed
935
if player.animationTimer >= 240
936
player.animationTimer -= 240
937
player.frame++
938
player.frame &= 7
939
player.frame += player.animation
940
player.frame += player.frameOffset
941
end if
942
943
CallFunction(Player_Draw_Normal)
944
player.tailFrame++
945
player.tailFrame %= 28
946
end event
947
948
949
event ObjectStartup
950
LoadSpriteSheet("Special/Objects.gif")
951
952
// Running - Sonic
953
SpriteFrame(-16, -28, 32, 56, 1, 68)
954
SpriteFrame(-16, -28, 32, 56, 34, 68)
955
SpriteFrame(-16, -28, 32, 56, 67, 68)
956
SpriteFrame(-16, -28, 32, 56, 100, 68)
957
SpriteFrame(-16, -28, 32, 56, 1, 125)
958
SpriteFrame(-16, -28, 32, 56, 34, 125)
959
SpriteFrame(-16, -28, 32, 56, 67, 125)
960
SpriteFrame(-16, -28, 32, 56, 100, 125)
961
962
// Jumping - Sonic
963
SpriteFrame(-16, -20, 32, 40, 133, 67)
964
SpriteFrame(-16, -20, 32, 40, 166, 67)
965
SpriteFrame(-16, -20, 32, 40, 133, 67)
966
SpriteFrame(-16, -20, 32, 40, 166, 67)
967
SpriteFrame(-16, -20, 32, 40, 133, 67)
968
SpriteFrame(-16, -20, 32, 40, 166, 67)
969
SpriteFrame(-16, -20, 32, 40, 133, 67)
970
SpriteFrame(-16, -20, 32, 40, 166, 67)
971
972
// Running - Tails
973
SpriteFrame(-12, -24, 24, 48, 199, 67)
974
SpriteFrame(-16, -24, 32, 48, 224, 67)
975
SpriteFrame(-16, -24, 32, 48, 257, 67)
976
SpriteFrame(-16, -24, 32, 48, 290, 67)
977
SpriteFrame(-12, -24, 24, 48, 199, 116)
978
SpriteFrame(-16, -24, 32, 48, 224, 116)
979
SpriteFrame(-16, -24, 32, 48, 257, 116)
980
SpriteFrame(-16, -24, 32, 48, 290, 116)
981
982
// Jumping - Tails
983
SpriteFrame(-16, -16, 32, 32, 133, 108)
984
SpriteFrame(-16, -16, 32, 32, 166, 108)
985
SpriteFrame(-16, -16, 32, 32, 133, 108)
986
SpriteFrame(-16, -16, 32, 32, 166, 108)
987
SpriteFrame(-16, -16, 32, 32, 133, 108)
988
SpriteFrame(-16, -16, 32, 32, 166, 108)
989
SpriteFrame(-16, -16, 32, 32, 133, 108)
990
SpriteFrame(-16, -16, 32, 32, 166, 108)
991
992
// Running - Knux
993
SpriteFrame(-16, -28, 32, 56, 1, 182)
994
SpriteFrame(-16, -28, 32, 56, 34, 182)
995
SpriteFrame(-16, -28, 32, 56, 67, 182)
996
SpriteFrame(-16, -28, 32, 56, 100, 182)
997
SpriteFrame(-16, -28, 32, 56, 133, 182)
998
SpriteFrame(-16, -28, 32, 56, 166, 182)
999
SpriteFrame(-16, -28, 32, 56, 199, 182)
1000
SpriteFrame(-16, -28, 32, 56, 232, 182)
1001
1002
// Jumping - Knux
1003
SpriteFrame(-16, -20, 32, 40, 133, 141)
1004
SpriteFrame(-16, -20, 32, 40, 166, 141)
1005
SpriteFrame(-16, -20, 32, 40, 133, 141)
1006
SpriteFrame(-16, -20, 32, 40, 166, 141)
1007
SpriteFrame(-16, -20, 32, 40, 133, 141)
1008
SpriteFrame(-16, -20, 32, 40, 166, 141)
1009
SpriteFrame(-16, -20, 32, 40, 133, 141)
1010
SpriteFrame(-16, -20, 32, 40, 166, 141)
1011
1012
// Tails's Tails
1013
SpriteFrame(-6, -6, 16, 24, 323, 58)
1014
SpriteFrame(-8, 0, 24, 24, 340, 58)
1015
SpriteFrame(-8, 8, 24, 16, 365, 58)
1016
SpriteFrame(-9, -1, 16, 24, 390, 58)
1017
SpriteFrame(-11, -9, 16, 32, 407, 58)
1018
SpriteFrame(-16, -9, 24, 24, 424, 58)
1019
SpriteFrame(-16, -9, 24, 24, 323, 83)
1020
1021
// 1P/2P tags, with flipped versions for Mirror Mode
1022
// See playerTagFrame
1023
#platform: USE_ORIGINS
1024
if game.playMode == BOOT_PLAYMODE_MIRRORING
1025
SpriteFrame(-8, -40, 16, 7, 348, 145)
1026
SpriteFrame(-8, -40, 16, 7, 348, 153)
1027
else
1028
#endplatform
1029
SpriteFrame(-8, -40, 16, 7, 348, 100)
1030
SpriteFrame(-8, -40, 16, 7, 348, 108)
1031
#platform: USE_ORIGINS
1032
end if
1033
1034
// Duplicates of Amy's first running sprite
1035
// These were added in 2.0.1 to fix a bug. Yes, I am serious.
1036
SpriteFrame(-15, -26, 30, 52, 1, 373)
1037
SpriteFrame(-15, -26, 30, 52, 1, 373)
1038
SpriteFrame(-15, -26, 30, 52, 1, 373)
1039
SpriteFrame(-15, -26, 30, 52, 1, 373)
1040
SpriteFrame(-15, -26, 30, 52, 1, 373)
1041
SpriteFrame(-15, -26, 30, 52, 1, 373)
1042
SpriteFrame(-15, -26, 30, 52, 1, 373)
1043
1044
// Running - Amy
1045
SpriteFrame(-15, -26, 30, 52, 1, 373)
1046
SpriteFrame(-15, -26, 30, 52, 32, 373)
1047
SpriteFrame(-15, -26, 30, 52, 63, 373)
1048
SpriteFrame(-15, -26, 30, 52, 94, 373)
1049
SpriteFrame(-15, -26, 30, 52, 1, 426)
1050
SpriteFrame(-15, -26, 30, 52, 32, 426)
1051
SpriteFrame(-15, -26, 30, 52, 63, 426)
1052
SpriteFrame(-15, -26, 30, 52, 94, 426)
1053
1054
// Jumping - Amy
1055
SpriteFrame(-14, -16, 28, 32, 125, 361)
1056
SpriteFrame(-14, -16, 28, 32, 125, 394)
1057
SpriteFrame(-14, -16, 28, 32, 125, 361)
1058
SpriteFrame(-14, -16, 28, 32, 125, 394)
1059
SpriteFrame(-14, -16, 28, 32, 125, 361)
1060
SpriteFrame(-14, -16, 28, 32, 125, 394)
1061
SpriteFrame(-14, -16, 28, 32, 125, 361)
1062
SpriteFrame(-14, -16, 28, 32, 125, 394)
1063
#endplatform
1064
1065
player[2].type = TypeName[Player Object]
1066
player[2].priority = PRIORITY_ACTIVE
1067
player[2].zpos = 0x1000
1068
player[2].state = Player_State_Ground
1069
player[2].stateInput = Player_Input_Gamepad
1070
switch stage.playerListPos
1071
case PLAYER_SONIC_A
1072
player[2].xBoundsR = 88
1073
player[2].frameOffset = 0
1074
break
1075
1076
case PLAYER_TAILS_A
1077
player[2].xBoundsR = 90
1078
player[2].frameOffset = 16
1079
break
1080
1081
case PLAYER_KNUCKLES_A
1082
player[2].xBoundsR = 88
1083
player[2].frameOffset = 32
1084
break
1085
1086
#platform: USE_ORIGINS
1087
case PLAYER_AMY_A
1088
player[2].xBoundsR = 89
1089
player[2].frameOffset = 64
1090
break
1091
#endplatform
1092
end switch
1093
1094
player[2].xBoundsR <<= 8
1095
player[2].xBoundsL = player[2].xBoundsR
1096
FlipSign(player[2].xBoundsL)
1097
player[2].groundPos = player[2].xBoundsR
1098
player[2].groundPos *= player[2].xBoundsR
1099
player[2].groundPos -= 0x10000
1100
player[2].frame = player[2].frameOffset
1101
1102
if options.vsMode == true
1103
player[3].type = TypeName[Player Object]
1104
player[3].priority = PRIORITY_ACTIVE
1105
#platform: USE_STANDALONE
1106
player[3].playerTagFrame = vs.playerID
1107
player[3].playerTagFrame ^= 1
1108
player[3].playerTagFrame += 55
1109
#endplatform
1110
#platform: USE_ORIGINS
1111
player[2].playerTagFrame = 55
1112
player[3].playerTagFrame = 56
1113
#endplatform
1114
if vs.playerID == 0
1115
player[2].zpos = 0x1000
1116
player[3].zpos = 0x400
1117
else
1118
player[2].zpos = 0x400
1119
player[3].zpos = 0x1000
1120
end if
1121
1122
player[3].state = Player_State_Ground
1123
#platform: USE_ORIGINS
1124
player[3].controlMode = CONTROLMODE_P2
1125
#endplatform
1126
player[3].stateInput = Player_Input_VSPlayer_2P
1127
switch vs.player2Type
1128
case PLAYER_SONIC_A
1129
player[3].xBoundsR = 88
1130
player[3].frameOffset = 0
1131
break
1132
1133
case PLAYER_TAILS_A
1134
player[3].xBoundsR = 90
1135
player[3].frameOffset = 16
1136
break
1137
1138
case PLAYER_KNUCKLES_A
1139
player[3].xBoundsR = 88
1140
player[3].frameOffset = 32
1141
break
1142
1143
#platform: USE_ORIGINS
1144
case PLAYER_AMY_A
1145
player[3].xBoundsR = 89
1146
player[3].frameOffset = 64
1147
break
1148
#endplatform
1149
end switch
1150
1151
player[3].xBoundsR <<= 8
1152
player[3].xBoundsL = player[3].xBoundsR
1153
FlipSign(player[3].xBoundsL)
1154
player[3].groundPos = player[3].xBoundsR
1155
player[3].groundPos *= player[3].xBoundsR
1156
player[3].groundPos -= 0x10000
1157
player[3].frame = player[3].frameOffset
1158
1159
stage.player2Enabled = false
1160
playerCount = 2
1161
CallNativeFunction2(ReceiveEntity, 0x400, true)
1162
ResetObjectEntity(0x400, TypeName[Blank Object], 0, 0, 0)
1163
end if
1164
1165
if stage.player2Enabled == true
1166
player[3].type = TypeName[Player Object]
1167
player[3].priority = PRIORITY_ACTIVE
1168
player[3].zpos = 0x400
1169
player[3].state = Player_State_Ground
1170
#platform: USE_ORIGINS
1171
object[3].controlMode = CONTROLMODE_P2
1172
#endplatform
1173
player[3].stateInput = Player_Input_AI_Follow
1174
player[3].xBoundsR = 90
1175
player[3].frameOffset = 16
1176
player[3].xBoundsR <<= 8
1177
player[3].xBoundsL = player[3].xBoundsR
1178
FlipSign(player[3].xBoundsL)
1179
player[3].groundPos = player[3].xBoundsR
1180
player[3].groundPos *= player[3].xBoundsR
1181
player[3].groundPos -= 0x10000
1182
player[3].frame = player[3].frameOffset
1183
#platform: USE_ORIGINS
1184
AssignInputSlotToDevice(2, -1)
1185
#endplatform
1186
end if
1187
end event
1188
1189
1190
// ========================
1191
// Editor Events
1192
// ========================
1193
1194
event RSDKDraw
1195
DrawSprite(0)
1196
end event
1197
1198
1199
event RSDKLoad
1200
LoadSpriteSheet("Global/Display.gif")
1201
SpriteFrame(-16, -16, 32, 32, 1, 143)
1202
1203
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
1204
end event
1205
1206