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/SBZ/Piston.txt
1483 views
1
// ----------------------------------
2
// RSDK Project: Sonic 1
3
// Script Description: 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.moveDistance
13
private alias object.value1 : object.movePos
14
private alias object.value2 : object.timer
15
16
// Player Aliases
17
private alias object.ypos : player.ypos
18
private alias object.gravity : player.gravity
19
20
private alias object.value17 : debugMode.currentSelection
21
22
23
// ========================
24
// Function Declarations
25
// ========================
26
27
reserve function Piston_DebugDraw
28
reserve function Piston_DebugSpawn
29
30
31
// ========================
32
// Static Values
33
// ========================
34
35
private value Piston_startDebugID = 0
36
37
38
// ========================
39
// Tables
40
// ========================
41
42
private table Piston_moveDistances
43
0x380000, 0x400000, 0x600000
44
end table
45
46
47
// ========================
48
// Function Definitions
49
// ========================
50
51
private function Piston_DebugDraw
52
temp0 = debugMode[0].currentSelection
53
temp0 -= Piston_startDebugID
54
DrawSprite(0)
55
end function
56
57
58
private function Piston_DebugSpawn
59
temp0 = debugMode[0].currentSelection
60
temp0 -= Piston_startDebugID
61
CreateTempObject(TypeName[Piston], temp0, object.xpos, object.ypos)
62
GetTableValue(object[tempObjectPos].moveDistance, object[tempObjectPos].propertyValue, Piston_moveDistances)
63
end function
64
65
66
// ========================
67
// Events
68
// ========================
69
70
event ObjectUpdate
71
if object.timer != 0
72
object.timer--
73
object.yvel = 0
74
else
75
if object.direction == FLIP_NONE
76
object.yvel = 0x80000
77
object.movePos += object.yvel
78
79
if object.movePos >= object.moveDistance
80
object.direction ^= FLIP_X
81
if object.propertyValue != 0
82
object.timer = 60
83
end if
84
end if
85
else
86
if object.propertyValue != 0
87
object.yvel = -0x80000
88
else
89
object.yvel = -0x10000
90
end if
91
92
object.movePos += object.yvel
93
if object.movePos <= 0
94
object.direction ^= FLIP_X
95
object.timer = 60
96
end if
97
end if
98
end if
99
100
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
101
BoxCollisionTest(C_SOLID2, object.entityPos, -28, -32, 28, 32, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
102
switch checkResult
103
case COL_TOP
104
player[currentPlayer].ypos += object.yvel
105
break
106
107
case COL_BOTTOM
108
if player[currentPlayer].gravity == GRAVITY_GROUND
109
if object.yvel > 0
110
CallFunction(Player_Kill)
111
end if
112
end if
113
break
114
115
end switch
116
next
117
118
object.ypos += object.yvel
119
end event
120
121
122
event ObjectDraw
123
DrawSprite(0)
124
end event
125
126
127
event ObjectStartup
128
LoadSpriteSheet("SBZ/Objects.gif")
129
SpriteFrame(-28, -32, 56, 64, 132, 1)
130
131
foreach (TypeName[Piston], arrayPos0, ALL_ENTITIES)
132
GetTableValue(object[arrayPos0].moveDistance, object[arrayPos0].propertyValue, Piston_moveDistances)
133
next
134
135
temp0 = 0
136
Piston_startDebugID = DebugMode_ObjCount
137
while temp0 < 3
138
SetTableValue(TypeName[Piston], DebugMode_ObjCount, DebugMode_TypesTable)
139
SetTableValue(Piston_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
140
SetTableValue(Piston_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
141
DebugMode_ObjCount++
142
temp0++
143
loop
144
end event
145
146
147
// ========================
148
// Editor Events
149
// ========================
150
151
event RSDKEdit
152
if editor.returnVariable == true
153
switch editor.variableID
154
case EDIT_VAR_PROPVAL // property value
155
checkResult = object.propertyValue
156
checkResult %= 3
157
break
158
159
case 0 // moveDist
160
checkResult = object.propertyValue
161
checkResult %= 3
162
break
163
164
end switch
165
else
166
switch editor.variableID
167
case EDIT_VAR_PROPVAL // property value
168
object.propertyValue = editor.variableValue
169
object.propertyValue %= 3
170
break
171
172
case 0 // moveDist
173
object.propertyValue = editor.variableValue
174
object.propertyValue %= 3
175
break
176
177
end switch
178
end if
179
end event
180
181
182
event RSDKDraw
183
DrawSprite(0)
184
185
if editor.showGizmos == true
186
editor.drawingOverlay = true
187
188
temp0 = object.propertyValue
189
temp0 %= 3
190
GetTableValue(object.moveDistance, temp0, Piston_moveDistances)
191
192
temp1 = object.ypos
193
temp1 += object.moveDistance
194
195
object.inkEffect = INK_BLEND
196
DrawSpriteFX(0, FX_INK, object.xpos, temp1)
197
198
editor.drawingOverlay = false
199
end if
200
end event
201
202
203
event RSDKLoad
204
LoadSpriteSheet("SBZ/Objects.gif")
205
SpriteFrame(-28, -32, 56, 64, 132, 1)
206
207
AddEditorVariable("moveDist")
208
SetActiveVariable("moveDist")
209
AddEnumVariable("56 Pixels", 0)
210
AddEnumVariable("64 Pixels", 1)
211
AddEnumVariable("96 Pixels", 2)
212
end event
213
214