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/MPZ/SteamPiston.txt
1480 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Steam Piston 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.startPos.y
14
private alias object.value2 : object.stoodPlayers
15
private alias object.value31 : object.wrapOffset.y
16
17
// States
18
private alias 0 : STEAMPISTON_CLOSED
19
private alias 1 : STEAMPISTON_OPENING
20
private alias 2 : STEAMPISTON_OPENED
21
private alias 3 : STEAMPISTON_CLOSING
22
23
// Animations
24
private alias 0 : STEAMPISTON_ANI_CLOSED
25
private alias 1 : STEAMPISTON_ANI_ACTIVE
26
27
// Player Aliases
28
private alias object.state : player.state
29
private alias object.ypos : player.ypos
30
private alias object.yvel : player.yvel
31
private alias object.gravity : player.gravity
32
private alias object.frame : player.frame
33
private alias object.prevAnimation : player.prevAnimation
34
private alias object.animationSpeed : player.animationSpeed
35
private alias object.animation : player.animation
36
private alias object.pushing : player.pushing
37
private alias object.collisionMode : player.collisionMode
38
private alias object.tileCollisions : player.tileCollisions
39
40
private alias object.value1 : player.timer
41
private alias object.value25 : player.gravityStrength
42
43
44
// ========================
45
// Function Declarations
46
// ========================
47
48
reserve function SteamPiston_DebugDraw
49
reserve function SteamPiston_DebugSpawn
50
51
52
// ========================
53
// Function Definitions
54
// ========================
55
56
private function SteamPiston_DebugDraw
57
DrawSprite(8)
58
end function
59
60
61
private function SteamPiston_DebugSpawn
62
CreateTempObject(TypeName[Steam Piston], object.direction, object.xpos, object.ypos) // this obj's prop val doesn't really matter
63
object[tempObjectPos].ypos += 0x100000
64
object[tempObjectPos].startPos.y = object.ypos
65
end function
66
67
68
// ========================
69
// Events
70
// ========================
71
72
event ObjectUpdate
73
temp7 = 0
74
switch object.state
75
case STEAMPISTON_CLOSED
76
temp0 = oscillation
77
temp0 &= 0x7F
78
if temp0 == 0
79
object.priority = PRIORITY_ACTIVE
80
object.timer = 2
81
object.state = STEAMPISTON_OPENING
82
end if
83
break
84
85
case STEAMPISTON_OPENING
86
object.ypos -= 0x80000
87
temp7 = -0x80000
88
89
object.timer--
90
if object.timer == 0
91
object.state = STEAMPISTON_OPENED
92
object.frame = 0
93
object.animation = STEAMPISTON_ANI_ACTIVE
94
end if
95
break
96
97
case STEAMPISTON_OPENED
98
temp0 = oscillation
99
temp0 &= 0x3F
100
if temp0 == 0
101
object.priority = PRIORITY_ACTIVE
102
object.timer = 2
103
object.state = STEAMPISTON_CLOSING
104
end if
105
break
106
107
case STEAMPISTON_CLOSING
108
object.ypos += 0x80000
109
temp7 = 0x80000
110
111
object.timer--
112
if object.timer == 0
113
object.state = STEAMPISTON_CLOSED
114
end if
115
break
116
117
end switch
118
119
if object.animation == STEAMPISTON_ANI_ACTIVE
120
object.frame = object.animationTimer
121
object.frame >>= 3
122
123
object.animationTimer++
124
if object.frame == 7
125
object.animationTimer = 0
126
object.animation = STEAMPISTON_ANI_CLOSED
127
end if
128
end if
129
130
temp2 = 0
131
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
132
GetBit(temp0, object.stoodPlayers, temp2)
133
if temp0 == true
134
player[currentPlayer].ypos += temp7
135
end if
136
137
SetBit(object.stoodPlayers, temp2, false)
138
BoxCollisionTest(C_SOLID, object.entityPos, -16, -16, 16, 16, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
139
if checkResult == COL_TOP
140
SetBit(object.stoodPlayers, temp2, true)
141
if object.state == STEAMPISTON_OPENING
142
#platform: USE_STANDALONE
143
// Technically not a bug, but this value is a bit bigger compared to the Genesis version,
144
// causing issues like a piston in Act 3 launching you straight into a group of spikes
145
player[currentPlayer].yvel = -0xA0000
146
#endplatform
147
#platform: USE_ORIGINS
148
// Origins Plus fixed the above issue
149
player[currentPlayer].yvel = -0x9B000
150
#endplatform
151
152
player[currentPlayer].yvel -= player[currentPlayer].gravityStrength
153
#platform: USE_STANDALONE
154
player[currentPlayer].state = Player_State_Air
155
#endplatform
156
#platform: USE_ORIGINS
157
player[currentPlayer].state = Player_State_Air_NoDropDash
158
#endplatform
159
player[currentPlayer].tileCollisions = true
160
player[currentPlayer].gravity = 1
161
player[currentPlayer].timer = 0
162
player[currentPlayer].collisionMode = 0
163
player[currentPlayer].pushing = 0
164
player[currentPlayer].animation = ANI_TWIRL
165
player[currentPlayer].prevAnimation = ANI_TWIRL
166
player[currentPlayer].frame = 0
167
player[currentPlayer].animationSpeed = 40
168
PlaySfx(SfxName[Spring], false)
169
end if
170
else
171
if object.frame == 3
172
BoxCollisionTest(C_TOUCH, object.entityPos, -50, -4, -30, 4, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
173
if checkResult == true
174
CallFunction(Player_Hit)
175
else
176
BoxCollisionTest(C_TOUCH, object.entityPos, 30, -4, 50, 4, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
177
if checkResult == true
178
CallFunction(Player_Hit)
179
end if
180
end if
181
end if
182
end if
183
184
temp2++
185
next
186
187
if object.outOfBounds == true
188
object.ypos = object.startPos.y
189
object.ypos += object.wrapOffset.y
190
object.timer = 0
191
object.stoodPlayers = 0
192
object.animation = STEAMPISTON_ANI_CLOSED
193
object.animationTimer = 0
194
object.priority = PRIORITY_BOUNDS
195
object.state = STEAMPISTON_CLOSED
196
end if
197
end event
198
199
200
event ObjectDraw
201
DrawSprite(8)
202
203
if object.animation == STEAMPISTON_ANI_ACTIVE
204
object.direction = FLIP_X
205
object.xpos -= 0x280000
206
DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
207
208
object.direction = FLIP_NONE
209
object.xpos += 0x500000
210
DrawSprite(object.frame)
211
212
object.xpos -= 0x280000
213
end if
214
end event
215
216
217
event ObjectStartup
218
LoadSpriteSheet("MPZ/Objects.gif")
219
SpriteFrame(-24, 1, 8, 4, 102, 98)
220
SpriteFrame(-24, -1, 14, 8, 102, 103)
221
SpriteFrame(-20, -3, 15, 13, 102, 112)
222
SpriteFrame(-16, -4, 23, 16, 118, 92)
223
SpriteFrame(-8, -4, 23, 16, 119, 109)
224
SpriteFrame(-3, -4, 22, 14, 143, 96)
225
SpriteFrame(9, -2, 14, 12, 143, 111)
226
SpriteFrame(9, -2, 1, 1, 143, 111)
227
SpriteFrame(-16, -16, 32, 32, 166, 93)
228
229
foreach (TypeName[Steam Piston], arrayPos0, ALL_ENTITIES)
230
object[arrayPos0].ypos += 0x100000
231
object[arrayPos0].startPos.y = object[arrayPos0].ypos
232
next
233
234
SetTableValue(TypeName[Steam Piston], DebugMode_ObjCount, DebugMode_TypesTable)
235
SetTableValue(SteamPiston_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
236
SetTableValue(SteamPiston_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
237
DebugMode_ObjCount++
238
end event
239
240
241
// ========================
242
// Editor Events
243
// ========================
244
245
event RSDKDraw
246
DrawSprite(8)
247
end event
248
249
250
event RSDKLoad
251
LoadSpriteSheet("MPZ/Objects.gif")
252
SpriteFrame(-24, 1, 8, 4, 102, 98)
253
SpriteFrame(-24, -1, 14, 8, 102, 103)
254
SpriteFrame(-20, -3, 15, 13, 102, 112)
255
SpriteFrame(-16, -4, 23, 16, 118, 92)
256
SpriteFrame(-8, -4, 23, 16, 119, 109)
257
SpriteFrame(-3, -4, 22, 14, 143, 96)
258
SpriteFrame(9, -2, 14, 12, 143, 111)
259
SpriteFrame(9, -2, 1, 1, 143, 111)
260
SpriteFrame(-16, -16, 32, 32, 166, 93)
261
262
// Despite them all having Property Values of 1 for some reason, the value isn't actually used
263
// (The value *was* used in the original game, though, where it dictated the behaviour of the piston)
264
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
265
end event
266
267