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/LargePiston.txt
1478 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Large 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 : LARGEPISTON_IDLE_UP
19
private alias 1 : LARGEPISTON_MOVEDOWN
20
private alias 2 : LARGEPISTON_IDLE_DOWN
21
private alias 3 : LARGEPISTON_MOVEUP
22
23
// Player Aliases
24
private alias object.ypos : player.ypos
25
private alias object.gravity : player.gravity
26
27
28
// ========================
29
// Function Declarations
30
// ========================
31
32
reserve function LargePiston_Setup
33
reserve function LargePiston_DebugDraw
34
reserve function LargePiston_DebugSpawn
35
36
37
// ========================
38
// Function Definitions
39
// ========================
40
41
private function LargePiston_Setup
42
object[arrayPos0].ypos = object[arrayPos0].startPos.y
43
object[arrayPos0].ypos += object[arrayPos0].wrapOffset.y
44
object[arrayPos0].ypos += 0x400000
45
object[arrayPos0].timer = 90
46
object[arrayPos0].stoodPlayers = 0
47
object[arrayPos0].state = LARGEPISTON_IDLE_DOWN
48
object[arrayPos0].priority = PRIORITY_BOUNDS
49
end function
50
51
52
private function LargePiston_DebugDraw
53
temp0 = object.direction
54
object.direction <<= 1
55
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
56
object.direction = temp0
57
end function
58
59
60
private function LargePiston_DebugSpawn
61
CreateTempObject(TypeName[Large Piston], 0, object.xpos, object.ypos)
62
arrayPos0 = object[tempObjectPos].entityPos
63
object[arrayPos0].startPos.y = object.ypos
64
object[arrayPos0].direction = object.direction
65
object[arrayPos0].direction <<= 1
66
CallFunction(LargePiston_Setup)
67
end function
68
69
70
// ========================
71
// Events
72
// ========================
73
74
event ObjectUpdate
75
temp0 = object.ypos
76
switch object.state
77
case LARGEPISTON_IDLE_UP
78
object.timer--
79
if object.timer == 0
80
object.priority = PRIORITY_ACTIVE
81
object.timer = 8
82
object.state = LARGEPISTON_MOVEDOWN
83
end if
84
break
85
86
case LARGEPISTON_MOVEDOWN
87
object.ypos += 0x80000
88
89
object.timer--
90
if object.timer == 0
91
object.timer = 90
92
object.state = LARGEPISTON_IDLE_DOWN
93
end if
94
break
95
96
case LARGEPISTON_IDLE_DOWN
97
object.timer--
98
if object.timer == 0
99
object.timer = 8
100
object.state = LARGEPISTON_MOVEUP
101
end if
102
break
103
104
case LARGEPISTON_MOVEUP
105
object.ypos -= 0x80000
106
107
object.timer--
108
if object.timer == 0
109
object.timer = 90
110
object.state = LARGEPISTON_IDLE_UP
111
end if
112
break
113
114
end switch
115
116
temp1 = object.ypos
117
temp1 -= temp0
118
119
temp2 = 0
120
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
121
GetBit(temp0, object.stoodPlayers, temp2)
122
if temp0 == true
123
player[currentPlayer].ypos += temp1
124
end if
125
126
SetBit(object.stoodPlayers, temp2, false)
127
BoxCollisionTest(C_SOLID, object.entityPos, -64, -12, 64, 12, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
128
switch checkResult
129
case COL_TOP
130
SetBit(object.stoodPlayers, temp2, true)
131
break
132
133
case COL_BOTTOM
134
if player[currentPlayer].gravity == 0
135
CallFunction(Player_Kill)
136
end if
137
break
138
139
end switch
140
temp2++
141
next
142
143
if object.outOfBounds == true
144
arrayPos0 = object.entityPos
145
CallFunction(LargePiston_Setup)
146
end if
147
end event
148
149
150
event ObjectDraw
151
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
152
end event
153
154
155
event ObjectStartup
156
LoadSpriteSheet("MPZ/Objects.gif")
157
SpriteFrame(-64, -12, 128, 120, 1, 135)
158
159
foreach (TypeName[Large Piston], arrayPos0, ALL_ENTITIES)
160
object[arrayPos0].startPos.y = object[arrayPos0].ypos
161
CallFunction(LargePiston_Setup)
162
next
163
164
SetTableValue(TypeName[Large Piston], DebugMode_ObjCount, DebugMode_TypesTable)
165
SetTableValue(LargePiston_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
166
SetTableValue(LargePiston_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
167
DebugMode_ObjCount++
168
end event
169
170
171
// ========================
172
// Editor Events
173
// ========================
174
175
event RSDKDraw
176
// It probably would look better if retracted position was shown normally and then extended position was
177
// the gizmo, but that would be incorrecty showing how the object actually is placed
178
179
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
180
181
if editor.showGizmos == true
182
editor.drawingOverlay = true
183
184
temp1 = object.ypos
185
temp1 += 0x400000
186
187
DrawSpriteFX(0, FX_FLIP, object.xpos, temp1)
188
189
DrawArrow(object.xpos, object.ypos, object.xpos, temp1, 0x00, 0xFF, 0x00)
190
191
editor.drawingOverlay = false
192
end if
193
end event
194
195
196
event RSDKLoad
197
LoadSpriteSheet("MPZ/Objects.gif")
198
SpriteFrame(-64, -12, 128, 120, 1, 135)
199
200
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
201
end event
202
203