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/HPZ/TubePath.txt
1479 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Tube Path 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.value1 : object.targetPlayer
13
private alias object.value2 : object.nextNode
14
15
private alias 0 : TUBEPATH_ENTRY
16
private alias 1 : TUBEPATH_EXIT
17
private alias 2 : TUBEPATH_CONTROL
18
19
// Player Aliases
20
private alias object.state : player.state
21
private alias object.xpos : player.xpos
22
private alias object.ypos : player.ypos
23
private alias object.xvel : player.xvel
24
private alias object.yvel : player.yvel
25
private alias object.speed : player.speed
26
private alias object.gravity : player.gravity
27
private alias object.animation : player.animation
28
private alias object.tileCollisions : player.tileCollisions
29
30
31
// ========================
32
// Events
33
// ========================
34
35
event ObjectUpdate
36
switch object.propertyValue
37
case TUBEPATH_ENTRY
38
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
39
if player[currentPlayer].state != Player_State_Static
40
if player[currentPlayer].gravity == GRAVITY_GROUND
41
BoxCollisionTest(C_TOUCH, object.entityPos, -16, -16, 16, 16, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
42
if checkResult == true
43
player[currentPlayer].state = Player_State_Static
44
player[currentPlayer].tileCollisions = false
45
if player[currentPlayer].animation != ANI_JUMPING
46
PlaySfx(SfxName[Rolling], false)
47
end if
48
49
CreateTempObject(TypeName[Tube Path], TUBEPATH_CONTROL, object.xpos, object.ypos)
50
object[tempObjectPos].targetPlayer = currentPlayer
51
object[tempObjectPos].nextNode = object.entityPos
52
object[tempObjectPos].nextNode++
53
end if
54
end if
55
end if
56
next
57
break
58
59
case TUBEPATH_EXIT
60
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
61
if player[currentPlayer].state == Player_State_Static
62
BoxCollisionTest(C_TOUCH, object.entityPos, -16, -16, 16, 16, currentPlayer, 0, 0, 0, 0)
63
if checkResult == true
64
player[currentPlayer].state = Player_State_TubeRoll
65
player[currentPlayer].xpos = object.xpos
66
player[currentPlayer].ypos = object.ypos
67
player[currentPlayer].yvel = 0
68
player[currentPlayer].speed = 0xC0000
69
player[currentPlayer].tileCollisions = true
70
end if
71
end if
72
next
73
break
74
75
case TUBEPATH_CONTROL
76
currentPlayer = object.targetPlayer
77
if player[currentPlayer].state == Player_State_Static
78
// Glide the player over on to the next node
79
80
arrayPos0 = object.nextNode
81
82
temp0 = player[currentPlayer].xpos
83
temp0 -= object[arrayPos0].xpos
84
temp0 >>= 16
85
86
temp1 = player[currentPlayer].ypos
87
temp1 -= object[arrayPos0].ypos
88
temp1 >>= 16
89
90
ATan2(temp2, temp0, temp1)
91
Cos256(player[currentPlayer].xvel, temp2)
92
Sin256(player[currentPlayer].yvel, temp2)
93
player[currentPlayer].xvel *= -0xC00
94
player[currentPlayer].yvel *= -0xC00
95
96
// A non-blank object signifies the end of the chain
97
if object[arrayPos0].type == TypeName[Blank Object]
98
temp2 = temp0
99
temp2 *= temp0
100
temp0 = temp1
101
temp0 *= temp1
102
temp0 += temp2
103
if temp0 < 256
104
object.nextNode++
105
end if
106
end if
107
else
108
// Player got interrupted somehow, abort
109
110
object.type = TypeName[Blank Object]
111
end if
112
break
113
114
end switch
115
end event
116
117
118
// ========================
119
// Editor Events
120
// ========================
121
122
event RSDKEdit
123
if editor.returnVariable == true
124
switch editor.variableID
125
case EDIT_VAR_PROPVAL // property value
126
checkResult = object.propertyValue
127
checkResult &= 1
128
break
129
130
case 0 // isExit
131
checkResult = object.propertyValue
132
checkResult &= 1
133
break
134
135
end switch
136
else
137
switch editor.variableID
138
case EDIT_VAR_PROPVAL // property value
139
object.propertyValue = editor.variableValue
140
object.propertyValue &= 1
141
break
142
143
case 0 // isExit
144
object.propertyValue = editor.variableValue
145
object.propertyValue &= 1
146
break
147
148
end switch
149
end if
150
end event
151
152
153
event RSDKDraw
154
DrawSprite(0)
155
156
CheckEqual(object.propertyValue, TUBEPATH_ENTRY)
157
temp0 = checkResult
158
CheckEqual(editor.showGizmos, true)
159
temp0 &= checkResult
160
if temp0 == true
161
editor.drawingOverlay = true
162
163
// One of my favourite little things in this game, draw all the nodes that make up the path
164
165
arrayPos0 = object.entityPos
166
arrayPos1 = object[+1].entityPos
167
168
while object[arrayPos1].type == 0
169
DrawArrow(object[arrayPos0].xpos, object[arrayPos0].ypos, object[arrayPos1].xpos, object[arrayPos1].ypos, 0xFF, 0xFF, 0x00)
170
arrayPos0++
171
arrayPos1++
172
loop
173
174
// Final one;
175
// no checks for type to match in-game behvaiour, but it should be a Tube Path obj with a prop val of 1
176
DrawArrow(object[arrayPos0].xpos, object[arrayPos0].ypos, object[arrayPos1].xpos, object[arrayPos1].ypos, 0xFF, 0xFF, 0x00)
177
178
editor.drawingOverlay = false
179
end if
180
end event
181
182
183
event RSDKLoad
184
LoadSpriteSheet("Global/Display.gif")
185
SpriteFrame(-8, -8, 16, 16, 168, 18)
186
187
AddEditorVariable("isExit")
188
SetActiveVariable("isExit")
189
AddEnumVariable("false", false)
190
AddEnumVariable("true", true)
191
end event
192
193