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/GHZ/FPlatform.txt
1480 views
1
// ----------------------------------
2
// RSDK Project: Sonic 1
3
// Script Description: Fall Platform 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.stood
13
private alias object.value1 : object.collisionOffset.y
14
private alias object.value2 : object.timer
15
private alias object.value3 : object.centerPos.y
16
private alias object.value4 : object.stoodAngle
17
18
// Types
19
private alias 0 : FPLATFORM_FALL
20
private alias 1 : FPLATFORM_STATIC
21
22
// States
23
private alias 0 : FPLATFORM_IDLE
24
private alias 1 : FPLATFORM_FALLING_SOLID
25
private alias 2 : FPLATFORM_FALLING
26
private alias 3 : FPLATFORM_OFFSCREEN
27
28
// Player Aliases
29
private alias object.ypos : player.ypos
30
private alias object.yvel : player.yvel
31
private alias object.gravity : player.gravity
32
33
34
// ========================
35
// Function Declarations
36
// ========================
37
38
reserve function FallPlatform_DebugDraw
39
reserve function FallPlatform_DebugSpawn
40
41
42
// ========================
43
// Function Definitions
44
// ========================
45
46
private function FallPlatform_DebugDraw
47
DrawSprite(0)
48
end function
49
50
51
private function FallPlatform_DebugSpawn
52
CreateTempObject(TypeName[Fall Platform], 0, object.xpos, object.ypos)
53
object[tempObjectPos].centerPos.y = object[tempObjectPos].ypos
54
end function
55
56
57
// ========================
58
// Events
59
// ========================
60
61
event ObjectUpdate
62
if object.stood == true
63
if object.timer == 0
64
object.priority = PRIORITY_ACTIVE
65
object.timer = 30
66
end if
67
68
if object.stoodAngle < 64
69
object.stoodAngle += 4
70
end if
71
else
72
if object.stoodAngle > 0
73
object.stoodAngle -= 4
74
end if
75
end if
76
77
temp0 = object.ypos
78
temp0 &= 0xFFFF0000
79
80
switch object.state
81
case FPLATFORM_IDLE
82
temp1 = object.stoodAngle
83
temp1 <<= 1
84
Sin(temp2, temp1)
85
temp2 <<= 9
86
object.ypos = object.centerPos.y
87
object.ypos += temp2
88
if object.propertyValue == FPLATFORM_FALL
89
if object.timer != 0
90
object.timer--
91
if object.timer == 0
92
object.state++
93
object.timer = 32
94
end if
95
end if
96
end if
97
break
98
99
case FPLATFORM_FALLING_SOLID
100
object.timer--
101
if object.timer == 0
102
object.state++
103
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
104
BoxCollisionTest(C_PLATFORM, object.entityPos, -32, -8, 32, 0, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
105
if checkResult == true
106
player[currentPlayer].ypos += object.yvel
107
player[currentPlayer].yvel = object.yvel
108
player[currentPlayer].yvel -= 0x3800
109
player[currentPlayer].gravity = GRAVITY_AIR
110
end if
111
next
112
end if
113
// [FallThrough]
114
case FPLATFORM_FALLING
115
object.ypos += object.yvel
116
object.yvel += 0x3800
117
if object.outOfBounds == true
118
object.ypos = object.centerPos.y
119
object.yvel = 0
120
object.timer = 0
121
object.state++
122
end if
123
break
124
125
case FPLATFORM_OFFSCREEN
126
if object.outOfBounds == true
127
object.state = FPLATFORM_IDLE
128
object.priority = PRIORITY_BOUNDS
129
end if
130
break
131
132
end switch
133
134
object.collisionOffset.y = object.ypos
135
object.collisionOffset.y &= 0xFFFF0000
136
object.collisionOffset.y -= temp0
137
object.stood = false
138
139
if object.state < FPLATFORM_FALLING
140
temp1 = object.ypos
141
142
object.ypos = temp0
143
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
144
BoxCollisionTest(C_PLATFORM, object.entityPos, -32, -8, 32, 0, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
145
if checkResult == true
146
object.stood = true
147
player[currentPlayer].ypos += object.collisionOffset.y
148
end if
149
next
150
151
object.ypos = temp1
152
end if
153
end event
154
155
156
event ObjectDraw
157
if object.state < FPLATFORM_OFFSCREEN
158
DrawSprite(0)
159
end if
160
end event
161
162
163
event ObjectStartup
164
LoadSpriteSheet("GHZ/Objects.gif")
165
SpriteFrame(-32, -14, 64, 32, 50, 18)
166
167
foreach (TypeName[Fall Platform], arrayPos0, ALL_ENTITIES)
168
object[arrayPos0].centerPos.y = object[arrayPos0].ypos
169
next
170
171
SetTableValue(TypeName[Fall Platform], DebugMode_ObjCount, DebugMode_TypesTable)
172
SetTableValue(FallPlatform_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
173
SetTableValue(FallPlatform_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
174
DebugMode_ObjCount++
175
end event
176
177
178
// ========================
179
// Editor Events
180
// ========================
181
182
event RSDKEdit
183
if editor.returnVariable == true
184
switch editor.variableID
185
case EDIT_VAR_PROPVAL // property value
186
checkResult = object.propertyValue
187
break
188
189
case 0 // type
190
checkResult = object.propertyValue
191
break
192
193
end switch
194
else
195
switch editor.variableID
196
case EDIT_VAR_PROPVAL // property value
197
object.propertyValue = editor.variableValue
198
break
199
200
case 0 // type
201
object.propertyValue = editor.variableValue
202
break
203
204
end switch
205
end if
206
end event
207
208
209
event RSDKDraw
210
DrawSprite(0)
211
212
CheckEqual(editor.showGizmos, true)
213
temp0 = checkResult
214
CheckEqual(object.propertyValue, FPLATFORM_FALL)
215
temp0 &= checkResult
216
if temp0 == true
217
// Draw a dashed line to indicate that this platform is of the falling variety
218
// (Otherwise it's just the generic platform sprite, which is shared between two other objects)
219
220
editor.drawingOverlay = true
221
222
temp0 = object.ypos
223
224
temp1 = object.ypos
225
temp1 += 0x60000
226
227
temp2 = object.ypos
228
temp2 += 0x3E0000
229
230
while temp0 < temp2
231
DrawLine(object.xpos, temp0, object.xpos, temp1, 255, 255, 255)
232
233
temp0 += 0xC0000
234
temp1 += 0xC0000
235
loop
236
237
editor.drawingOverlay = false
238
end if
239
end event
240
241
242
event RSDKLoad
243
LoadSpriteSheet("GHZ/Objects.gif")
244
SpriteFrame(-32, -14, 64, 32, 50, 18)
245
246
AddEditorVariable("type")
247
SetActiveVariable("type")
248
AddEnumVariable("Falling Platform", FPLATFORM_FALL)
249
AddEnumVariable("Static Platform", FPLATFORM_STATIC)
250
end event
251
252