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/Coconuts.txt
1479 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Coconuts 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.targetDelay
14
private alias object.value2 : object.throwID
15
private alias object.value3 : object.startPos.x
16
private alias object.value4 : object.startPos.y
17
private alias object.value5 : object.targetPlayer
18
private alias object.value6 : object.unused
19
private alias object.value7 : object.targetDistance
20
21
// States
22
private alias 0 : COCONUTS_AWAITPLAYER
23
private alias 1 : COCONUTS_MOVING
24
private alias 2 : COCONUTS_THROW
25
private alias 3 : COCONUTS_HASTHROWN
26
27
// Player Aliases
28
private alias object.xpos : player.xpos
29
private alias object.value38 : player.hitboxLeft
30
private alias object.value39 : player.hitboxRight
31
private alias object.value40 : player.hitboxTop
32
private alias object.value41 : player.hitboxBottom
33
34
35
// ========================
36
// Function Declarations
37
// ========================
38
39
reserve function Coconuts_DebugDraw
40
reserve function Coconuts_DebugSpawn
41
42
43
// ========================
44
// Tables
45
// ========================
46
47
private table Coconuts_throwDelays
48
32, 24, 16, 40, 32, 16
49
end table
50
51
52
// ========================
53
// Function Definitions
54
// ========================
55
56
private function Coconuts_DebugDraw
57
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
58
end function
59
60
61
private function Coconuts_DebugSpawn
62
CreateTempObject(TypeName[Coconuts], 0, object.xpos, object.ypos)
63
end function
64
65
66
// ========================
67
// Events
68
// ========================
69
70
event ObjectUpdate
71
switch object.state
72
case COCONUTS_AWAITPLAYER
73
object.priority = PRIORITY_ACTIVE
74
object.targetDistance = 0x7FFFFFFF
75
object.targetPlayer = 0
76
object.unused = 0xFFFF
77
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
78
temp0 = player[currentPlayer].xpos
79
temp0 -= object.xpos
80
if temp0 < 0
81
temp1 = FLIP_NONE
82
FlipSign(temp0)
83
else
84
temp1 = FLIP_X
85
end if
86
87
if temp0 < object.targetDistance
88
object.targetDistance = temp0
89
object.targetPlayer = currentPlayer
90
object.direction = temp1
91
end if
92
next
93
94
temp0 = false
95
if object.targetDelay == 0
96
if object.targetDistance > -0x600000
97
if object.targetDistance < 0x600000
98
object.timer = 8
99
object.targetDelay = 32
100
object.frame = 1
101
object.state = COCONUTS_THROW
102
temp0 = true
103
end if
104
end if
105
else
106
object.targetDelay--
107
end if
108
109
if temp0 == false
110
object.timer--
111
if object.timer < 0
112
GetBit(temp0, object.throwID, 0)
113
if temp0 == false
114
object.yvel = -0x10000
115
else
116
object.yvel = 0x10000
117
end if
118
119
GetTableValue(object.timer, object.throwID, Coconuts_throwDelays)
120
121
object.throwID++
122
if object.throwID > 5
123
object.throwID = 0
124
end if
125
126
object.state = COCONUTS_MOVING
127
end if
128
end if
129
break
130
131
case COCONUTS_MOVING
132
object.animationTimer++
133
if object.animationTimer == 6
134
object.frame = 1
135
end if
136
137
if object.animationTimer == 12
138
object.frame = 0
139
object.animationTimer = 0
140
end if
141
142
object.ypos += object.yvel
143
144
object.timer--
145
if object.timer < 0
146
object.timer = 16
147
object.state = COCONUTS_AWAITPLAYER
148
end if
149
break
150
151
case COCONUTS_THROW
152
object.timer--
153
if object.timer < 0
154
CreateTempObject(TypeName[Coconut], 0, object.xpos, object.ypos)
155
if object.direction == FLIP_NONE
156
object[tempObjectPos].xpos += 0xB0000
157
object[tempObjectPos].xvel = -0x10000
158
else
159
object[tempObjectPos].xpos -= 0xB0000
160
object[tempObjectPos].xvel = 0x10000
161
end if
162
object[tempObjectPos].ypos -= 0xD0000
163
object[tempObjectPos].yvel = -0x10000
164
object[tempObjectPos].direction = object.direction
165
object[tempObjectPos].priority = PRIORITY_ACTIVE
166
object.timer = 8
167
object.frame = 2
168
object.state = COCONUTS_HASTHROWN
169
end if
170
break
171
172
case COCONUTS_HASTHROWN
173
object.timer--
174
if object.timer < 0
175
GetBit(temp0, object.throwID, 0)
176
if temp0 == false
177
object.yvel = -0x10000
178
else
179
object.yvel = 0x10000
180
end if
181
182
GetTableValue(object.timer, object.throwID, Coconuts_throwDelays)
183
object.throwID++
184
if object.throwID > 5
185
object.throwID = 0
186
end if
187
188
object.frame = 0
189
object.state = COCONUTS_MOVING
190
end if
191
break
192
193
end switch
194
195
if object.outOfBounds == true
196
temp0 = object.xpos
197
temp1 = object.ypos
198
object.xpos = object.startPos.x
199
object.ypos = object.startPos.y
200
201
if object.outOfBounds == true
202
object.targetDelay = 0
203
object.timer = 16
204
object.state = COCONUTS_AWAITPLAYER
205
object.priority = PRIORITY_BOUNDS
206
else
207
object.xpos = temp0
208
object.ypos = temp1
209
end if
210
end if
211
212
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
213
BoxCollisionTest(C_TOUCH, object.entityPos, -12, -16, 12, 16, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)
214
if checkResult == true
215
CallFunction(Player_BadnikBreak)
216
end if
217
next
218
end event
219
220
221
event ObjectDraw
222
DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
223
end event
224
225
226
event ObjectStartup
227
CheckCurrentStageFolder("Zone01")
228
if checkResult == true
229
LoadSpriteSheet("EHZ/Objects.gif")
230
SpriteFrame(-8, -14, 26, 45, 1, 63)
231
SpriteFrame(-8, -14, 26, 45, 28, 63)
232
SpriteFrame(-8, -14, 26, 45, 55, 63)
233
else
234
LoadSpriteSheet("MBZ/Objects.gif")
235
SpriteFrame(-8, -14, 26, 45, 50, 256)
236
SpriteFrame(-8, -14, 26, 45, 77, 256)
237
SpriteFrame(-8, -14, 26, 45, 104, 256)
238
end if
239
240
foreach (TypeName[Coconuts], arrayPos0, ALL_ENTITIES)
241
object[arrayPos0].startPos.x = object[arrayPos0].xpos
242
object[arrayPos0].startPos.y = object[arrayPos0].ypos
243
object[arrayPos0].timer = 16
244
245
// this is a lie, its later set based on what dir the player is in anyway so this doesn't matter much
246
// that is also a lie sorta, the propertyValues in the scene are like "30" so it was prolly smth related to movement anyway LOL
247
if object[arrayPos0].propertyValue == 0
248
object[arrayPos0].direction = FLIP_NONE
249
else
250
object[arrayPos0].direction = FLIP_X
251
end if
252
next
253
254
SetTableValue(TypeName[Coconuts], DebugMode_ObjCount, DebugMode_TypesTable)
255
SetTableValue(Coconuts_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
256
SetTableValue(Coconuts_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
257
DebugMode_ObjCount++
258
end event
259
260
261
// ========================
262
// Editor Events
263
// ========================
264
265
event RSDKDraw
266
DrawSprite(0)
267
end event
268
269
270
event RSDKLoad
271
CheckCurrentStageFolder("Zone01")
272
if checkResult == true
273
LoadSpriteSheet("EHZ/Objects.gif")
274
SpriteFrame(-8, -14, 26, 45, 1, 63)
275
else
276
LoadSpriteSheet("MBZ/Objects.gif")
277
SpriteFrame(-8, -14, 26, 45, 50, 256)
278
end if
279
280
// Not "technically" unused, but it doesn't do anything meaningful
281
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
282
end event
283
284