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/Enemies/SpinyFloor.txt
1483 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Spiny Floor 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.startPos.x
13
private alias object.value1 : object.startPos.y
14
private alias object.value2 : object.dirChangeTimer
15
private alias object.value3 : object.shootTimer
16
private alias object.value4 : object.shotVelocity
17
private alias object.value5 : object.targetDistance
18
19
private alias 0 : SPINYFLOOR_MOVING
20
private alias 1 : SPINYFLOOR_IDLE
21
22
// Player Aliases
23
private alias object.xpos : player.xpos
24
private alias object.value40 : player.hitboxLeft
25
private alias object.value38 : player.hitboxTop
26
private alias object.value41 : player.hitboxRight
27
private alias object.value39 : player.hitboxBottom
28
29
30
// ========================
31
// Function Declarations
32
// ========================
33
34
reserve function SpinyFloor_Setup
35
reserve function SpinyFloor_DebugDraw
36
reserve function SpinyFloor_DebugSpawn
37
38
39
// ========================
40
// Function Definitions
41
// ========================
42
43
private function SpinyFloor_Setup
44
object[arrayPos0].xpos = object[arrayPos0].startPos.x
45
object[arrayPos0].ypos = object[arrayPos0].startPos.y
46
object[arrayPos0].dirChangeTimer = 256
47
object[arrayPos0].shootTimer = 128
48
object[arrayPos0].frame = 0
49
object[arrayPos0].animationTimer = 0
50
object[arrayPos0].state = SPINYFLOOR_MOVING
51
if object[arrayPos0].propertyValue == 0
52
object[arrayPos0].direction = FLIP_NONE
53
object[arrayPos0].xvel = -0x4000
54
else
55
object[arrayPos0].direction = FLIP_X
56
object[arrayPos0].xvel = 0x4000
57
end if
58
object[arrayPos0].priority = PRIORITY_BOUNDS
59
end function
60
61
62
private function SpinyFloor_DebugDraw
63
DrawSprite(0)
64
end function
65
66
67
private function SpinyFloor_DebugSpawn
68
CreateTempObject(TypeName[Spiny Floor], temp0, object.xpos, object.ypos)
69
object[tempObjectPos].startPos.x = object.xpos
70
object[tempObjectPos].startPos.y = object.ypos
71
arrayPos0 = object[tempObjectPos].entityPos
72
object[tempObjectPos].propertyValue = object.direction
73
CallFunction(SpinyFloor_Setup)
74
end function
75
76
77
// ========================
78
// Events
79
// ========================
80
81
event ObjectUpdate
82
object.priority = PRIORITY_ACTIVE
83
switch object.state
84
case SPINYFLOOR_MOVING
85
object.dirChangeTimer--
86
if object.dirChangeTimer <= 0
87
object.dirChangeTimer = 256
88
object.shootTimer = 128
89
FlipSign(object.xvel)
90
object.direction ^= FLIP_X
91
end if
92
93
object.xpos += object.xvel
94
95
object.animationTimer++
96
if object.animationTimer == 10
97
object.animationTimer = 0
98
object.frame ^= 1
99
end if
100
101
if object.shootTimer == 0
102
object.targetDistance = 0x7FFFFFFF
103
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
104
BoxCollisionTest(C_TOUCH, object.entityPos, -96, -256, 96, 256, currentPlayer, 1, 1, 1, 1)
105
if checkResult == true
106
object.shootTimer = 40
107
object.frame = 2
108
object.state = SPINYFLOOR_IDLE
109
110
temp0 = object.xpos
111
temp0 -= player[currentPlayer].xpos
112
Abs(temp0)
113
if temp0 < object.targetDistance
114
object.targetDistance = temp0
115
if player[currentPlayer].xpos > object.xpos
116
object.shotVelocity = 0x10000
117
else
118
object.shotVelocity = -0x10000
119
end if
120
end if
121
end if
122
next
123
else
124
object.shootTimer--
125
end if
126
break
127
128
case SPINYFLOOR_IDLE
129
object.shootTimer--
130
if object.shootTimer == 20
131
CreateTempObject(TypeName[Spiny Shot], 0, object.xpos, object.ypos)
132
object[tempObjectPos].xvel = object.shotVelocity
133
object[tempObjectPos].yvel = -0x30000
134
object[tempObjectPos].drawOrder = 2
135
end if
136
137
if object.shootTimer < 0
138
object.shootTimer = 64
139
object.frame = 0
140
object.state = SPINYFLOOR_MOVING
141
end if
142
break
143
144
end switch
145
146
if object.outOfBounds == true
147
temp0 = object.xpos
148
temp1 = object.ypos
149
object.xpos = object.startPos.x
150
object.ypos = object.startPos.y
151
if object.outOfBounds == true
152
arrayPos0 = object.entityPos
153
CallFunction(SpinyFloor_Setup)
154
else
155
object.xpos = temp0
156
object.ypos = temp1
157
end if
158
end if
159
160
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
161
BoxCollisionTest(C_TOUCH, object.entityPos, -8, -8, 8, 8, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)
162
if checkResult == true
163
CallFunction(Player_BadnikBreak)
164
end if
165
next
166
end event
167
168
169
event ObjectDraw
170
DrawSprite(object.frame)
171
end event
172
173
174
event ObjectStartup
175
LoadSpriteSheet("CPZ/Objects.gif") // this was probably meant to be removed when MBZ became a thing, makes no real difference whether its here or not though
176
177
CheckCurrentStageFolder("Zone02")
178
if checkResult == true
179
LoadSpriteSheet("CPZ/Objects.gif")
180
SpriteFrame(-24, -11, 48, 23, 1, 1)
181
SpriteFrame(-22, -11, 44, 23, 50, 1)
182
SpriteFrame(-24, -11, 48, 23, 95, 1)
183
else
184
LoadSpriteSheet("MBZ/Objects.gif")
185
SpriteFrame(-24, -11, 48, 23, 131, 256)
186
SpriteFrame(-22, -11, 44, 23, 180, 256)
187
SpriteFrame(-24, -11, 48, 23, 225, 256)
188
end if
189
190
foreach (TypeName[Spiny Floor], arrayPos0, ALL_ENTITIES)
191
object[arrayPos0].startPos.x = object[arrayPos0].xpos
192
object[arrayPos0].startPos.y = object[arrayPos0].ypos
193
CallFunction(SpinyFloor_Setup)
194
next
195
196
SetTableValue(TypeName[Spiny Floor], DebugMode_ObjCount, DebugMode_TypesTable)
197
SetTableValue(SpinyFloor_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
198
SetTableValue(SpinyFloor_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
199
DebugMode_ObjCount++
200
end event
201
202
203
// ========================
204
// Editor Events
205
// ========================
206
207
event RSDKEdit
208
if editor.returnVariable == true
209
switch editor.variableID
210
case EDIT_VAR_PROPVAL // property value
211
checkResult = object.propertyValue
212
checkResult &= 1
213
break
214
215
case 0 // direction
216
GetBit(checkResult, object.propertyValue, 0)
217
break
218
219
end switch
220
else
221
switch editor.variableID
222
case EDIT_VAR_PROPVAL // property value
223
object.propertyValue = editor.variableValue
224
object.propertyValue &= 1
225
break
226
227
case 0 // direction
228
CheckNotEqual(editor.variableValue, 0)
229
SetBit(object.propertyValue, 0, checkResult)
230
break
231
232
end switch
233
end if
234
end event
235
236
237
event RSDKDraw
238
DrawSprite(0)
239
end event
240
241
242
event RSDKLoad
243
CheckCurrentStageFolder("Zone02")
244
if checkResult == true
245
LoadSpriteSheet("CPZ/Objects.gif")
246
SpriteFrame(-24, -11, 48, 23, 1, 1)
247
else
248
LoadSpriteSheet("MBZ/Objects.gif")
249
SpriteFrame(-24, -11, 48, 23, 131, 256)
250
end if
251
252
AddEditorVariable("direction")
253
SetActiveVariable("direction")
254
AddEnumVariable("Left", 0)
255
AddEnumVariable("Right", 1)
256
end event
257
258