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/Mission/BallHog2.txt
1487 views
1
// ----------------------------------
2
// RSDK Project: Sonic 1
3
// Script Description: Ball Hog Object
4
// Script Author: Christian Whitehead/Simon Thomley
5
// Unpacked by Rubberduckycooly's script unpacker
6
// ----------------------------------
7
8
// This script is a copy of the normal Ball Hog script but with tile collisions removed so that the badnik can be placed on Mission Blocks
9
10
// ========================
11
// Aliases
12
// ========================
13
14
// value0 is unused...
15
private alias object.value1 : object.timer
16
private alias object.value2 : object.originY
17
18
// Ball Hog Bomb Aliases
19
private alias object.value0 : object.time
20
private alias object.value1 : object.bouncePos
21
22
// Player Aliases
23
private alias object.value38 : player.hitboxTop
24
private alias object.value39 : player.hitboxBottom
25
private alias object.value40 : player.hitboxLeft
26
private alias object.value41 : player.hitboxRight
27
28
29
// ========================
30
// Function Declarations
31
// ========================
32
33
reserve function BallHog_DebugDraw
34
reserve function BallHog_DebugSpawn
35
36
37
// ========================
38
// Tables
39
// ========================
40
41
private table BallHog_frameTable
42
0, 2, 3, 2, 0, 2, 3, 2, 0, 2, 3, 2, 0, 1, 0
43
end table
44
45
private table BallHog_frameDelayTable
46
20, 20, 10, 10, 20, 20, 10, 10, 20, 20, 10, 10, 20, 10
47
end table
48
49
50
// ========================
51
// Function Definitions
52
// ========================
53
54
private function BallHog_DebugDraw
55
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
56
end function
57
58
59
private function BallHog_DebugSpawn
60
CreateTempObject(TypeName[Ball Hog], 0, object.xpos, object.ypos)
61
object[tempObjectPos].direction = object.direction
62
object[tempObjectPos].propertyValue = 1
63
end function
64
65
66
// ========================
67
// Events
68
// ========================
69
70
event ObjectUpdate
71
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
72
BoxCollisionTest(C_TOUCH, object.entityPos, -12, -18, 12, 18, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)
73
if checkResult == true
74
CallFunction(Player_BadnikBreak)
75
end if
76
next
77
78
// Sidestep a little
79
if object.frame == 3
80
object.ypos += object.yvel
81
object.yvel += 0x95C0
82
83
// (This bit is different in BallHog2, normally tile collisions are checked here but instead we're just checking against originY directly
84
if object.ypos < object.originY
85
object.animationTimer = 2
86
end if
87
end if
88
89
// Update animation & ball lobbing
90
object.animationTimer--
91
if object.animationTimer <= 0
92
GetTableValue(object.animationTimer, object.timer, BallHog_frameDelayTable)
93
GetTableValue(object.frame, object.timer, BallHog_frameTable)
94
95
object.timer++
96
if object.timer >= 14
97
object.timer = 0
98
end if
99
100
if object.frame == 3
101
object.yvel = -0x29999
102
object.ypos += object.yvel
103
object.yvel += 0x95C0
104
end if
105
106
if object.frame == 1
107
// Drop a bomb ball
108
109
CreateTempObject(TypeName[Ball Hog Bomb], 0, object.xpos, object.ypos)
110
if object.direction == FLIP_NONE
111
object[tempObjectPos].xpos -= 0x40000
112
object[tempObjectPos].xvel = -0x10000
113
else
114
object[tempObjectPos].xpos += 0x40000
115
object[tempObjectPos].xvel = 0x10000
116
end if
117
118
object[tempObjectPos].ypos += 0xC0000
119
120
// This part is more new BallHog2 stuff
121
// Since the bomb can't check tile collisions let's just make it bounce when it's 13 pixels below the Ball Hog's own position
122
object[tempObjectPos].bouncePos = object.ypos
123
object[tempObjectPos].bouncePos += 0xD0000
124
125
object[tempObjectPos].time = object.propertyValue
126
object[tempObjectPos].time *= 60
127
end if
128
end if
129
end event
130
131
132
event ObjectDraw
133
DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
134
end event
135
136
137
event ObjectStartup
138
CheckCurrentStageFolder("Zone06")
139
if checkResult == true
140
LoadSpriteSheet("SBZ/Objects.gif")
141
SpriteFrame(-11, -17, 22, 37, 1, 170)
142
SpriteFrame(-11, -17, 22, 37, 24, 170)
143
SpriteFrame(-12, -12, 24, 32, 47, 175)
144
SpriteFrame(-11, -20, 22, 40, 72, 167)
145
end if
146
147
CheckCurrentStageFolder("Zone07")
148
if checkResult == true
149
LoadSpriteSheet("MBZ/Objects.gif")
150
SpriteFrame(-11, -17, 22, 37, 76, 292)
151
SpriteFrame(-11, -17, 22, 37, 99, 292)
152
SpriteFrame(-12, -12, 24, 32, 122, 297)
153
SpriteFrame(-11, -20, 22, 40, 147, 289)
154
end if
155
156
foreach (TypeName[Ball Hog], arrayPos0, ALL_ENTITIES)
157
temp0 = object[arrayPos0].propertyValue
158
temp0 &= 0x80
159
if temp0 != 0
160
object[arrayPos0].direction = FLIP_X
161
object[arrayPos0].propertyValue &= 0x7F
162
end if
163
164
// (This line is new to BallHog2)
165
object[arrayPos0].originY = object[arrayPos0].ypos
166
next
167
168
SetTableValue(TypeName[Ball Hog], DebugMode_ObjCount, DebugMode_TypesTable)
169
SetTableValue(BallHog_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
170
SetTableValue(BallHog_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
171
DebugMode_ObjCount++
172
end event
173
174
175
// ========================
176
// Editor Events
177
// ========================
178
179
event RSDKEdit
180
if editor.returnVariable == true
181
switch editor.variableID
182
case EDIT_VAR_PROPVAL // property value
183
checkResult = object.propertyValue
184
break
185
186
case 0 // bombTime
187
checkResult = object.propertyValue
188
checkResult &= 0x7F
189
break
190
191
case 1 // direction
192
GetBit(checkResult, object.propertyValue, 7)
193
break
194
195
end switch
196
else
197
switch editor.variableID
198
case EDIT_VAR_PROPVAL // property value
199
object.propertyValue = editor.variableValue
200
break
201
202
case 0 // bombTime
203
object.propertyValue &= 0x80
204
editor.variableValue &= 0x7F
205
206
object.propertyValue |= editor.variableValue
207
break
208
209
case 1 // direction
210
CheckNotEqual(editor.variableValue, false)
211
SetBit(object.propertyValue, 7, checkResult)
212
break
213
214
end switch
215
end if
216
end event
217
218
219
event RSDKDraw
220
GetBit(object.direction, object.propertyValue, 7)
221
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
222
end event
223
224
225
event RSDKLoad
226
CheckCurrentStageFolder("Zone07")
227
if checkResult == true
228
LoadSpriteSheet("MBZ/Objects.gif")
229
SpriteFrame(-11, -17, 22, 37, 76, 292)
230
SpriteFrame(-11, -17, 22, 37, 99, 292)
231
SpriteFrame(-12, -12, 24, 32, 122, 297)
232
SpriteFrame(-11, -20, 22, 40, 147, 289)
233
else
234
LoadSpriteSheet("SBZ/Objects.gif")
235
SpriteFrame(-11, -17, 22, 37, 1, 170)
236
SpriteFrame(-11, -17, 22, 37, 24, 170)
237
SpriteFrame(-12, -12, 24, 32, 47, 175)
238
SpriteFrame(-11, -20, 22, 40, 72, 167)
239
end if
240
241
AddEditorVariable("bombTime")
242
243
AddEditorVariable("direction")
244
SetActiveVariable("direction")
245
AddEnumVariable("Left", 0)
246
AddEnumVariable("Right", 1)
247
end event
248
249