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/OOZ/HPushSpring.txt
1478 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: H Push 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.value1 : object.pushOffset
13
private alias object.value2 : object.beingPushed
14
15
// States
16
private alias 0 : HPUSHSPRING_AWAITPUSH
17
private alias 1 : HPUSHSPRING_PUSHING
18
private alias 2 : HPUSHSPRING_RELEASE
19
20
// Player Aliases
21
private alias object.state : player.state
22
private alias object.xpos : player.xpos
23
private alias object.speed : player.speed
24
private alias object.direction : player.direction
25
private alias object.animation : player.animation
26
private alias object.pushing : player.pushing
27
private alias object.controlLock : player.controlLock
28
private alias object.collisionMode : player.collisionMode
29
30
31
// ========================
32
// Function Declarations
33
// ========================
34
35
reserve function HPushSpring_DebugDraw
36
reserve function HPushSpring_DebugSpawn
37
38
39
// ========================
40
// Function Definitions
41
// ========================
42
43
private function HPushSpring_DebugDraw
44
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
45
end function
46
47
48
private function HPushSpring_DebugSpawn
49
CreateTempObject(TypeName[H Push Spring], 0, object.xpos, object.ypos)
50
object[tempObjectPos].xpos &= 0xFFFF0000
51
object[tempObjectPos].ypos &= 0xFFFF0000
52
object[tempObjectPos].direction = object.direction
53
end function
54
55
56
// ========================
57
// Events
58
// ========================
59
60
event ObjectUpdate
61
switch object.state
62
case HPUSHSPRING_AWAITPUSH
63
if object.beingPushed == true
64
object.state = HPUSHSPRING_PUSHING
65
end if
66
break
67
68
case HPUSHSPRING_PUSHING
69
object.pushOffset += 0x4000
70
if object.pushOffset > 0x120000
71
object.pushOffset = 0x120000
72
end if
73
74
if object.beingPushed == false
75
object.state = HPUSHSPRING_RELEASE
76
end if
77
break
78
79
case HPUSHSPRING_RELEASE
80
object.pushOffset -= 0x40000
81
if object.pushOffset <= 0
82
object.pushOffset = 0
83
object.state = HPUSHSPRING_AWAITPUSH
84
end if
85
86
if object.beingPushed == true
87
object.state = HPUSHSPRING_PUSHING
88
end if
89
break
90
91
end switch
92
93
if object.direction == FLIP_NONE
94
temp0 = -20
95
temp1 = object.pushOffset
96
temp1 >>= 16
97
FlipSign(temp1)
98
temp1 += 22
99
else
100
temp0 = object.pushOffset
101
temp0 >>= 16
102
temp0 -= 22
103
temp1 = 20
104
end if
105
106
object.beingPushed = false
107
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
108
BoxCollisionTest(C_SOLID, object.entityPos, temp0, -16, temp1, 16, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
109
switch checkResult
110
case COL_LEFT
111
if object.direction == FLIP_X
112
if player[currentPlayer].direction == FACING_RIGHT
113
player[currentPlayer].xpos += 0x20000
114
end if
115
116
if player[currentPlayer].pushing > 0
117
object.beingPushed |= true
118
end if
119
120
if object.state == HPUSHSPRING_RELEASE
121
if object.pushOffset > 0x10000
122
player[currentPlayer].speed = -12
123
player[currentPlayer].speed *= object.pushOffset
124
player[currentPlayer].speed /= 18
125
player[currentPlayer].collisionMode = CMODE_FLOOR
126
player[currentPlayer].pushing = 0
127
player[currentPlayer].direction = object.direction
128
player[currentPlayer].controlLock = 15
129
if player[currentPlayer].state != Player_State_Roll
130
player[currentPlayer].state = Player_State_Ground
131
player[currentPlayer].animation = ANI_RUNNING
132
end if
133
PlaySfx(SfxName[Spring], false)
134
end if
135
end if
136
end if
137
break
138
139
case COL_RIGHT
140
if object.direction == FLIP_NONE
141
if player[currentPlayer].direction == FACING_LEFT
142
player[currentPlayer].xpos -= 0x20000
143
end if
144
145
if player[currentPlayer].pushing > 0
146
object.beingPushed |= true
147
end if
148
149
if object.state == HPUSHSPRING_RELEASE
150
if object.pushOffset > 0x10000
151
player[currentPlayer].speed = 12
152
player[currentPlayer].speed *= object.pushOffset
153
player[currentPlayer].speed /= 18
154
player[currentPlayer].collisionMode = CMODE_FLOOR
155
player[currentPlayer].pushing = 0
156
player[currentPlayer].direction = object.direction
157
player[currentPlayer].controlLock = 15
158
if player[currentPlayer].state != Player_State_Roll
159
player[currentPlayer].state = Player_State_Ground
160
player[currentPlayer].animation = ANI_RUNNING
161
end if
162
PlaySfx(SfxName[Spring], false)
163
end if
164
end if
165
end if
166
break
167
168
end switch
169
next
170
end event
171
172
173
event ObjectDraw
174
if object.pushOffset == 0
175
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
176
else
177
if object.direction == FLIP_NONE
178
temp0 = object.pushOffset
179
FlipSign(temp0)
180
temp0 += object.xpos
181
DrawSpriteFX(1, FX_FLIP, temp0, object.ypos)
182
183
temp0 = object.pushOffset
184
temp0 *= -2
185
temp0 /= 3
186
temp0 += object.xpos
187
DrawSpriteFX(2, FX_FLIP, temp0, object.ypos)
188
189
temp0 = object.pushOffset
190
temp0 /= -3
191
temp0 += object.xpos
192
DrawSpriteFX(3, FX_FLIP, temp0, object.ypos)
193
194
DrawSpriteFX(4, FX_FLIP, object.xpos, object.ypos)
195
else
196
temp0 = object.pushOffset
197
temp0 += object.xpos
198
DrawSpriteFX(1, FX_FLIP, temp0, object.ypos)
199
200
temp0 = object.pushOffset
201
temp0 *= 2
202
temp0 /= 3
203
temp0 += object.xpos
204
DrawSpriteFX(2, FX_FLIP, temp0, object.ypos)
205
206
temp0 = object.pushOffset
207
temp0 /= 3
208
temp0 += object.xpos
209
DrawSpriteFX(3, FX_FLIP, temp0, object.ypos)
210
211
DrawSpriteFX(4, FX_FLIP, object.xpos, object.ypos)
212
end if
213
end if
214
end event
215
216
217
event ObjectStartup
218
CheckCurrentStageFolder("Zone07")
219
if checkResult == true
220
LoadSpriteSheet("OOZ/Objects.gif")
221
SpriteFrame(-20, -16, 40, 32, 272, 223)
222
SpriteFrame(4, -16, 16, 32, 296, 223)
223
SpriteFrame(-4, -16, 8, 32, 288, 223)
224
SpriteFrame(-12, -16, 8, 32, 280, 223)
225
SpriteFrame(-20, -16, 8, 32, 272, 223)
226
else
227
LoadSpriteSheet("MBZ/Objects.gif")
228
SpriteFrame(-20, -16, 40, 32, 756, 778)
229
SpriteFrame(4, -16, 16, 32, 780, 778)
230
SpriteFrame(-4, -16, 8, 32, 772, 778)
231
SpriteFrame(-12, -16, 8, 32, 764, 778)
232
SpriteFrame(-20, -16, 8, 32, 756, 778)
233
end if
234
235
foreach (TypeName[H Push Spring], arrayPos0, ALL_ENTITIES)
236
object[arrayPos0].direction = object[arrayPos0].propertyValue
237
object[arrayPos0].direction &= FLIP_X
238
object[arrayPos0].xpos &= 0xFFFF0000
239
object[arrayPos0].ypos &= 0xFFFF0000
240
next
241
242
SetTableValue(TypeName[H Push Spring], DebugMode_ObjCount, DebugMode_TypesTable)
243
SetTableValue(HPushSpring_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
244
SetTableValue(HPushSpring_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
245
DebugMode_ObjCount++
246
end event
247
248
249
// ========================
250
// Editor Events
251
// ========================
252
253
event RSDKEdit
254
if editor.returnVariable == true
255
switch editor.variableID
256
case EDIT_VAR_PROPVAL // property value
257
checkResult = object.propertyValue
258
break
259
260
case 0 // direction
261
checkResult = object.propertyValue
262
checkResult &= 1
263
break
264
265
end switch
266
else
267
switch editor.variableID
268
case EDIT_VAR_PROPVAL // property value
269
object.propertyValue = editor.variableValue
270
break
271
272
case 0 // direction
273
editor.variableValue &= 1
274
object.propertyValue = editor.variableValue
275
break
276
277
end switch
278
end if
279
end event
280
281
282
event RSDKDraw
283
GetBit(object.direction, object.propertyValue, 0)
284
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
285
end event
286
287
288
event RSDKLoad
289
CheckCurrentStageFolder("Zone07")
290
if checkResult == true
291
LoadSpriteSheet("OOZ/Objects.gif")
292
SpriteFrame(-20, -16, 40, 32, 272, 223)
293
else
294
LoadSpriteSheet("MBZ/Objects.gif")
295
SpriteFrame(-20, -16, 40, 32, 756, 778)
296
end if
297
298
AddEditorVariable("direction")
299
SetActiveVariable("direction")
300
AddEnumVariable("Right", 0)
301
AddEnumVariable("Left", 1)
302
end event
303
304