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/MZ/RideBlock.txt
1483 views
1
// ----------------------------------
2
// RSDK Project: Sonic 1
3
// Script Description: Ride Block 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.drawPos.x
14
private alias object.value2 : object.startPos.x
15
private alias object.value3 : object.startPos.y
16
17
private alias 0 : RIDEBLOCK_AWAITPLAYER
18
private alias 1 : RIDEBLOCK_MOVING
19
private alias 2 : RIDEBLOCK_SINKING
20
private alias 3 : RIDEBLOCK_STOPPED
21
22
// Player Aliases
23
private alias object.xpos: player.xpos
24
private alias object.ypos: player.ypos
25
26
// Tile Flag Aliases
27
private alias 1 : TILE_LAVA
28
29
// Tile Info ID Aliases
30
private alias 8 : TILEINFO_ANGLEB
31
32
// Path ID Aliases
33
private alias 0 : PATH_A
34
35
36
// ========================
37
// Function Declarations
38
// ========================
39
40
reserve function RideBlock_DebugDraw
41
reserve function RideBlock_DebugSpawn
42
43
44
// ========================
45
// Tables
46
// ========================
47
48
private function RideBlock_DebugDraw
49
DrawSprite(0)
50
end function
51
52
53
private function RideBlock_DebugSpawn
54
CreateTempObject(TypeName[Ride Block], 0, object.xpos, object.ypos)
55
object[tempObjectPos].direction = object.direction
56
object[tempObjectPos].startPos.x = object[arrayPos0].xpos
57
object[tempObjectPos].startPos.y = object[arrayPos0].ypos
58
end function
59
60
61
// ========================
62
// Events
63
// ========================
64
65
event ObjectUpdate
66
switch object.state
67
case RIDEBLOCK_AWAITPLAYER
68
object.priority = PRIORITY_ACTIVE
69
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
70
BoxCollisionTest(C_PLATFORM, object.entityPos, -16, -16, 16, 0, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
71
if checkResult == true
72
object.state++
73
if object.direction == FLIP_NONE
74
object.xvel = 0x10000
75
else
76
object.xvel = -0x10000
77
end if
78
end if
79
next
80
break
81
82
case RIDEBLOCK_MOVING
83
temp0 = object.xpos
84
temp0 -= object.drawPos.x
85
temp0 += object.xvel
86
temp0 &= 0xFFFF0000
87
88
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
89
BoxCollisionTest(C_PLATFORM, object.entityPos, -16, -16, 16, 0, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
90
if checkResult == true
91
player[currentPlayer].xpos += temp0
92
end if
93
next
94
95
object.xpos += object.xvel
96
if object.xvel > 0
97
ObjectTileCollision(CSIDE_LWALL, 16, 12, PATH_A)
98
if checkResult == true
99
object.xvel = 0
100
object.timer = 0
101
temp1 = object.iypos
102
temp1 += 12
103
Get16x16TileInfo(temp0, object.ixpos, temp1, TILEINFO_ANGLEB)
104
if temp0 == TILE_LAVA
105
object.state = RIDEBLOCK_SINKING
106
else
107
object.state = RIDEBLOCK_STOPPED
108
end if
109
end if
110
else
111
ObjectTileCollision(CSIDE_RWALL, -16, 12, PATH_A)
112
if checkResult == true
113
object.xvel = 0
114
object.timer = 0
115
temp1 = object.iypos
116
temp1 += 12
117
Get16x16TileInfo(temp0, object.ixpos, temp1, TILEINFO_ANGLEB)
118
if temp0 == TILE_LAVA
119
object.state = RIDEBLOCK_SINKING
120
else
121
object.state = RIDEBLOCK_STOPPED
122
end if
123
end if
124
end if
125
break
126
127
case RIDEBLOCK_SINKING
128
if object.timer < 320
129
object.timer++
130
temp0 = object.timer
131
temp0 &= 7
132
if temp0 == 0
133
temp0 = 0x10000
134
else
135
temp0 = 0
136
end if
137
138
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
139
BoxCollisionTest(C_PLATFORM, object.entityPos, -16, -16, 16, 0, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
140
if checkResult == true
141
player[currentPlayer].ypos += temp0
142
end if
143
next
144
object.ypos += temp0
145
end if
146
break
147
148
case RIDEBLOCK_STOPPED
149
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
150
BoxCollisionTest(C_PLATFORM, object.entityPos, -16, -16, 16, 0, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
151
next
152
break
153
154
end switch
155
156
object.drawPos.x = object.xpos
157
object.drawPos.x &= 0xFFFF0000
158
if object.outOfBounds == true
159
temp0 = object.xpos
160
temp1 = object.ypos
161
object.xpos = object.startPos.x
162
object.ypos = object.startPos.y
163
if object.outOfBounds == true
164
object.yvel = 0
165
object.state = 0
166
else
167
object.xpos = temp0
168
object.ypos = temp1
169
end if
170
end if
171
end event
172
173
174
event ObjectDraw
175
DrawSpriteXY(0, object.drawPos.x, object.ypos)
176
end event
177
178
179
event ObjectStartup
180
LoadSpriteSheet("MZ/Objects.gif")
181
SpriteFrame(-16, -16, 32, 32, 159, 322)
182
183
foreach (TypeName[Ride Block], arrayPos0, ALL_ENTITIES)
184
object[arrayPos0].direction = object[arrayPos0].propertyValue
185
object[arrayPos0].direction &= FLIP_X
186
object[arrayPos0].startPos.x = object[arrayPos0].xpos
187
object[arrayPos0].startPos.y = object[arrayPos0].ypos
188
next
189
190
SetTableValue(TypeName[Ride Block], DebugMode_ObjCount, DebugMode_TypesTable)
191
SetTableValue(RideBlock_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
192
SetTableValue(RideBlock_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
193
DebugMode_ObjCount++
194
end event
195
196
197
// ========================
198
// Editor Events
199
// ========================
200
201
event RSDKEdit
202
if editor.returnVariable == true
203
switch editor.variableID
204
case EDIT_VAR_PROPVAL // property value
205
checkResult = object.propertyValue
206
checkResult &= 1
207
break
208
209
case 0 // direction
210
checkResult = object.propertyValue
211
checkResult &= 1
212
break
213
214
end switch
215
else
216
switch editor.variableID
217
case EDIT_VAR_PROPVAL // property value
218
object.propertyValue = editor.variableValue
219
object.propertyValue &= 1
220
break
221
222
case 0 // direction
223
object.propertyValue = editor.variableValue
224
object.propertyValue &= 1
225
break
226
227
end switch
228
end if
229
end event
230
231
232
event RSDKDraw
233
DrawSprite(0)
234
end event
235
236
237
event RSDKLoad
238
LoadSpriteSheet("MZ/Objects.gif")
239
SpriteFrame(-16, -16, 32, 32, 159, 322)
240
241
AddEditorVariable("direction")
242
SetActiveVariable("direction")
243
AddEnumVariable("Right", 0)
244
AddEnumVariable("Left", 1)
245
end event
246
247