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/MCZ/SpikedLedge.txt
1483 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Spiked Ledge 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.originX
14
private alias object.value2 : object.collisionOffset.x
15
16
private alias 0 : SPIKEDLEDGE_WAITING
17
private alias 1 : SPIKEDLEDGE_MOVING
18
private alias 2 : SPIKEDLEDGE_MOVED
19
20
// Player Aliases
21
private alias object.xpos : player.xpos
22
23
private alias object.value42 : player.prevGravity
24
25
26
// ========================
27
// Function Declarations
28
// ========================
29
30
reserve function SpikedLedge_DebugDraw
31
reserve function SpikedLedge_DebugSpawn
32
33
34
// ========================
35
// Function Definitions
36
// ========================
37
38
private function SpikedLedge_DebugDraw
39
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
40
end function
41
42
43
private function SpikedLedge_DebugSpawn
44
CreateTempObject(TypeName[Spiked Ledge], 0, object.xpos, object.ypos)
45
object[tempObjectPos].direction = object.direction
46
if object.direction == FACING_RIGHT
47
object[tempObjectPos].xvel = -0x10000
48
else
49
object[tempObjectPos].xvel = 0x10000
50
end if
51
end function
52
53
54
// ========================
55
// Events
56
// ========================
57
58
event ObjectUpdate
59
switch object.state
60
case SPIKEDLEDGE_WAITING
61
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
62
if player[currentPlayer].prevGravity == 0
63
// Check if the ledge should advance if the player is in range
64
if object.direction == FLIP_NONE
65
BoxCollisionTest(C_TOUCH, object.entityPos, -192, -16, -64, -14, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
66
else
67
BoxCollisionTest(C_TOUCH, object.entityPos, 64, -16, 192, -14, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
68
end if
69
else
70
checkResult = false
71
end if
72
73
if checkResult == true
74
if object.priority != PRIORITY_XBOUNDS_DESTROY
75
object.priority = PRIORITY_ACTIVE
76
end if
77
78
object.state = SPIKEDLEDGE_MOVING
79
object.collisionOffset.x = object.xvel
80
end if
81
next
82
break
83
84
case SPIKEDLEDGE_MOVING
85
object.xpos += object.xvel
86
object.timer++
87
if object.timer == 128
88
object.timer = 0
89
object.collisionOffset.x = 0
90
object.state++
91
end if
92
break
93
94
case SPIKEDLEDGE_MOVED
95
break
96
97
end switch
98
99
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
100
BoxCollisionTest(C_SOLID2, object.entityPos, -64, -16, 64, 16, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
101
switch checkResult
102
case COL_TOP
103
// Move the player along with the Ledge
104
player[currentPlayer].xpos += object.collisionOffset.x
105
break
106
107
case COL_LEFT
108
if object.direction == FLIP_NONE
109
// Spikes on the left
110
CallFunction(Player_Hit)
111
end if
112
break
113
114
case COL_RIGHT
115
if object.direction == FLIP_X
116
// Spikes on the right
117
CallFunction(Player_Hit)
118
end if
119
break
120
121
end switch
122
next
123
124
if object.outOfBounds == true
125
// If the object's out of bounds, then only unload it if its origin position is OOB as well
126
temp0 = object.xpos
127
object.xpos = object.originX
128
if object.outOfBounds == true
129
if object.priority != PRIORITY_XBOUNDS_DESTROY
130
object.priority = PRIORITY_BOUNDS
131
end if
132
133
// Reset the object
134
object.collisionOffset.x = 0
135
object.state = SPIKEDLEDGE_WAITING
136
else
137
object.xpos = temp0
138
end if
139
end if
140
end event
141
142
143
event ObjectDraw
144
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
145
end event
146
147
148
event ObjectStartup
149
LoadSpriteSheet("MCZ/Objects.gif")
150
SpriteFrame(-64, -16, 128, 32, 1, 99)
151
152
foreach (TypeName[Spiked Ledge], arrayPos0, ALL_ENTITIES)
153
object[arrayPos0].originX = object[arrayPos0].xpos
154
155
object[arrayPos0].direction = object[arrayPos0].propertyValue
156
object[arrayPos0].direction &= FLIP_X
157
158
if object[arrayPos0].direction == FLIP_NONE
159
object[arrayPos0].xvel = -0x10000
160
else
161
object[arrayPos0].xvel = 0x10000
162
end if
163
next
164
165
SetTableValue(TypeName[Spiked Ledge], DebugMode_ObjCount, DebugMode_TypesTable)
166
SetTableValue(SpikedLedge_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
167
SetTableValue(SpikedLedge_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
168
DebugMode_ObjCount++
169
end event
170
171
172
// ========================
173
// Editor Events
174
// ========================
175
176
event RSDKEdit
177
if editor.returnVariable == true
178
switch editor.variableID
179
case EDIT_VAR_PROPVAL // property value
180
checkResult = object.propertyValue
181
break
182
183
case 0 // direction
184
checkResult = object.propertyValue
185
checkResult &= 1
186
break
187
188
end switch
189
else
190
switch editor.variableID
191
case EDIT_VAR_PROPVAL // property value
192
object.propertyValue = editor.variableValue
193
break
194
195
case 0 // direction
196
object.propertyValue = editor.variableValue
197
object.propertyValue &= 1
198
break
199
200
end switch
201
end if
202
end event
203
204
205
event RSDKDraw
206
GetBit(object.direction, object.propertyValue, 0)
207
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
208
209
if editor.showGizmos == true
210
if object.direction == FLIP_NONE
211
temp0 = -128
212
else
213
temp0 = 128
214
end if
215
temp0 += object.ixpos
216
217
// Two alternate takes here, which one to do?
218
// One doesn't even play kindly with flipping...
219
220
object.inkEffect = INK_BLEND
221
DrawSpriteFX(0, FX_INK, temp0, object.ypos)
222
223
temp0 -= 64
224
temp1 = object.iypos; temp1 -= 16
225
DrawRectOutline(temp0, temp1, 128, 32, 255, 0, 0, 255)
226
end if
227
end event
228
229
230
event RSDKLoad
231
LoadSpriteSheet("MCZ/Objects.gif")
232
SpriteFrame(-64, -16, 128, 32, 1, 99)
233
234
AddEditorVariable("direction")
235
SetActiveVariable("direction")
236
AddEnumVariable("Left", 0)
237
AddEnumVariable("Right", 1)
238
end event
239
240