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/Ball.txt
1480 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Ball 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.value1 : object.startPos.x
13
private alias object.value2 : object.startPos.y
14
15
private alias object.value2 : object.targetPlayer // this is probably NOT meant to be value2, but the code says otherwise so it's prolly a bug
16
17
private alias 0 : BALL_HOVER
18
private alias 1 : BALL_ATTACKING
19
20
// Player Aliases
21
private alias object.xpos : player.xpos
22
private alias object.ypos : player.ypos
23
24
25
// ========================
26
// Function Declarations
27
// ========================
28
29
reserve function Ball_DebugDraw
30
reserve function Ball_DebugSpawn
31
32
33
// ========================
34
// Function Definitions
35
// ========================
36
37
private function Ball_DebugDraw
38
DrawSprite(0)
39
end function
40
41
42
private function Ball_DebugSpawn
43
CreateTempObject(TypeName[Ball], 0, object.xpos, object.ypos)
44
object[tempObjectPos].targetPlayer = -1
45
end function
46
47
48
// ========================
49
// Events
50
// ========================
51
52
event ObjectUpdate
53
object.priority = PRIORITY_ACTIVE
54
switch object.state
55
case BALL_HOVER
56
if object.direction == FLIP_X
57
object.yvel += 0x800
58
if object.yvel >= 0xC000
59
object.direction = FLIP_NONE
60
end if
61
else
62
object.yvel -= 0x800
63
if object.yvel <= -0xC000
64
object.direction = FLIP_X
65
end if
66
end if
67
68
object.ypos += object.yvel
69
70
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
71
if object.state == 0
72
BoxCollisionTest(C_TOUCH, object.entityPos, -256, -192, 256, 192, currentPlayer, 0, 0, 0, 0)
73
if checkResult == true
74
object.targetPlayer = currentPlayer
75
object.state = BALL_ATTACKING
76
end if
77
end if
78
next
79
break
80
81
case BALL_ATTACKING
82
currentPlayer = object.targetPlayer
83
if object.xpos > player[currentPlayer].xpos
84
object.xvel -= 0x1000
85
if object.xvel < -0x20000
86
object.xvel = -0x20000
87
end if
88
else
89
object.xvel += 0x1000
90
if object.xvel > 0x20000
91
object.xvel = 0x20000
92
end if
93
end if
94
95
temp0 = player[currentPlayer].ypos
96
temp0 -= 0x400000
97
if object.ypos > temp0
98
object.yvel -= 0x1000
99
if object.yvel < -0x20000
100
object.yvel = -0x20000
101
end if
102
else
103
object.yvel += 0x1000
104
if object.yvel > 0x20000
105
object.yvel = 0x20000
106
end if
107
end if
108
object.xpos += object.xvel
109
object.ypos += object.yvel
110
111
temp0 = object.xpos
112
temp0 -= player[currentPlayer].xpos
113
Abs(temp0)
114
if temp0 <= 0x100000
115
temp0 = player[currentPlayer].ypos
116
temp0 -= object.ypos
117
if temp0 >= 0x400000
118
if temp0 <= 0x600000
119
if object.outOfBounds == false
120
CreateTempObject(TypeName[Smoke Puff], 0, object.xpos, object.ypos)
121
object[tempObjectPos].drawOrder = 4
122
123
CreateTempObject(TypeName[Chemical Drop], 0, object.xpos, object.ypos)
124
object[tempObjectPos].drawOrder = 2
125
126
object.type = TypeName[Blank Object]
127
PlaySfx(SfxName[Destroy], false)
128
end if
129
end if
130
end if
131
end if
132
133
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
134
BoxCollisionTest(C_TOUCH, object.entityPos, -10, -10, 10, 10, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
135
if checkResult == true
136
CallFunction(Player_Hit)
137
138
CreateTempObject(TypeName[Smoke Puff], 0, object.xpos, object.ypos)
139
object[tempObjectPos].drawOrder = 4
140
141
CreateTempObject(TypeName[Chemical Drop], 0, object.xpos, object.ypos)
142
object[tempObjectPos].drawOrder = 2
143
144
object.type = TypeName[Blank Object]
145
PlaySfx(SfxName[Destroy], false)
146
end if
147
next
148
break
149
150
end switch
151
152
if object.outOfBounds == true
153
temp0 = object.xpos
154
temp1 = object.ypos
155
object.xpos = object.startPos.x
156
object.ypos = object.startPos.y
157
if object.outOfBounds == true
158
object.priority = PRIORITY_BOUNDS
159
object.state = BALL_HOVER
160
object.targetPlayer = -1
161
else
162
object.xpos = temp0
163
object.ypos = temp1
164
end if
165
end if
166
167
object.animationTimer++
168
if object.animationTimer >= 3
169
object.animationTimer = 0
170
object.frame++
171
if object.frame >= 3
172
object.frame = 0
173
end if
174
end if
175
end event
176
177
178
event ObjectDraw
179
DrawSprite(object.frame)
180
end event
181
182
183
event ObjectStartup
184
CheckCurrentStageFolder("Zone02")
185
if checkResult == true
186
LoadSpriteSheet("CPZ/Objects.gif")
187
SpriteFrame(-12, -12, 24, 24, 166, 1)
188
SpriteFrame(-12, -12, 24, 24, 166, 26)
189
SpriteFrame(-12, -12, 24, 24, 166, 51)
190
else
191
LoadSpriteSheet("MBZ/Objects.gif")
192
193
// These are just duplicates of the CPZ sheet's values, so they don't line up with the actual MBZ sheet where the Ball sprites don't even exist
194
// -> Interestingly, this frame is also in the... Bubbler script? Strange...
195
SpriteFrame(-12, -12, 24, 24, 166, 1)
196
SpriteFrame(-12, -12, 24, 24, 166, 26)
197
SpriteFrame(-12, -12, 24, 24, 166, 51)
198
end if
199
200
foreach (TypeName[Ball], arrayPos0, ALL_ENTITIES)
201
object[arrayPos0].startPos.x = object[arrayPos0].xpos
202
object[arrayPos0].startPos.y = object[arrayPos0].ypos
203
object[arrayPos0].targetPlayer = -1
204
next
205
206
SetTableValue(TypeName[Ball], DebugMode_ObjCount, DebugMode_TypesTable)
207
SetTableValue(Ball_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
208
SetTableValue(Ball_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
209
DebugMode_ObjCount++
210
end event
211
212
213
// ========================
214
// Editor Events
215
// ========================
216
217
event RSDKDraw
218
DrawSprite(0)
219
end event
220
221
222
event RSDKLoad
223
CheckCurrentStageFolder("Zone02")
224
if checkResult == true
225
LoadSpriteSheet("CPZ/Objects.gif")
226
SpriteFrame(-12, -12, 24, 24, 166, 1)
227
else
228
LoadSpriteSheet("MBZ/Objects.gif")
229
SpriteFrame(-12, -12, 24, 24, 166, 1)
230
end if
231
232
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
233
end event
234
235