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/Batbrain2.txt
1480 views
1
// ----------------------------------
2
// RSDK Project: Sonic 1
3
// Script Description: Batbrain 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 Batbrain script, just with a check to see if the object's visible before playing sfx
9
// ..yes that's it, that's the only change
10
11
// ========================
12
// Aliases
13
// ========================
14
15
private alias object.value0 : object.startPos.x
16
private alias object.value1 : object.startPos.y
17
private alias object.value2 : object.backupPlayer
18
private alias object.value3 : object.targetPlayer
19
private alias object.value4 : object.targetDistance
20
private alias object.value5 : object.dropPos.y
21
22
// States
23
private alias 0 : BATBRAIN_AWAITPLAYER
24
private alias 1 : BATBRAIN_DROPPING
25
private alias 2 : BATBRAIN_FLYING
26
private alias 3 : BATBRAIN_RETURNTOROOF
27
28
// Animations
29
private alias 0 : BATBRAIN_ANI_IDLE
30
private alias 1 : BATBRAIN_ANI_DROPPING
31
private alias 2 : BATBRAIN_ANI_FLYING
32
33
// Player Aliases
34
private alias object.xpos : player.xpos
35
private alias object.ypos : player.ypos
36
private alias object.value40 : player.hitboxLeft
37
private alias object.value38 : player.hitboxTop
38
private alias object.value41 : player.hitboxRight
39
private alias object.value39 : player.hitboxBottom
40
41
// Path ID Aliases
42
private alias 0 : PATH_A
43
44
45
// ========================
46
// Function Declarations
47
// ========================
48
49
reserve function Batbrain_DebugDraw
50
reserve function Batbrain_DebugSpawn
51
reserve function Batbrain_CheckOutOfRange
52
53
54
// ========================
55
// Function Definitions
56
// ========================
57
58
private function Batbrain_DebugDraw
59
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
60
end function
61
62
63
private function Batbrain_DebugSpawn
64
CreateTempObject(TypeName[Batbrain], 0, object.xpos, object.ypos)
65
object[tempObjectPos].startPos.x = object.xpos
66
object[tempObjectPos].startPos.y = object.ypos
67
end function
68
69
70
private function Batbrain_CheckOutOfRange
71
// This function is new to Batbrain2
72
// There's not really much to say about it, it just sees if the object is visible at all
73
74
temp1 = object.ixpos
75
temp1 -= screen.xoffset
76
CheckLower(temp1, 0)
77
temp0 = checkResult
78
79
CheckGreater(temp1, screen.xsize)
80
temp0 |= checkResult
81
82
temp1 = object.iypos
83
temp1 -= screen.yoffset
84
CheckLower(temp1, 0)
85
temp0 |= checkResult
86
87
CheckGreater(temp1, screen.ysize)
88
checkResult |= temp0
89
end function
90
91
92
// ========================
93
// Events
94
// ========================
95
96
97
event ObjectUpdate
98
switch object.state
99
case BATBRAIN_AWAITPLAYER
100
object.priority = PRIORITY_ACTIVE
101
102
object.targetDistance = 0x7FFFFFFF
103
object.backupPlayer = 0
104
object.targetPlayer = 0xFFFF
105
106
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
107
temp0 = player[currentPlayer].xpos
108
temp0 -= object.xpos
109
Abs(temp0)
110
if temp0 < object.targetDistance
111
object.targetDistance = temp0
112
object.backupPlayer = currentPlayer
113
end if
114
115
if temp0 < 0x800000
116
if player[currentPlayer].ypos >= object.ypos
117
if object.targetPlayer != 0xFFFF
118
arrayPos0 = object.targetPlayer
119
if player[currentPlayer].ypos < player[arrayPos0].ypos
120
object.targetPlayer = currentPlayer
121
end if
122
else
123
object.targetPlayer = currentPlayer
124
end if
125
end if
126
end if
127
next
128
129
if object.targetPlayer != 0xFFFF
130
arrayPos0 = object.targetPlayer
131
temp0 = player[arrayPos0].ypos
132
temp0 -= object.ypos
133
if temp0 >= 0
134
if temp0 <= 0x800000
135
Rand(temp0, 8)
136
if temp0 == 0
137
object.state = BATBRAIN_DROPPING
138
object.dropPos.y = player[arrayPos0].ypos
139
object.animation = BATBRAIN_ANI_DROPPING
140
end if
141
end if
142
end if
143
else
144
arrayPos0 = object.backupPlayer
145
end if
146
147
if player[arrayPos0].xpos < object.xpos
148
object.direction = FLIP_NONE
149
else
150
object.direction = FLIP_X
151
end if
152
break
153
154
case BATBRAIN_DROPPING
155
object.ypos += object.yvel
156
object.yvel += 0x1800
157
arrayPos0 = object.targetPlayer
158
if player[arrayPos0].xpos < object.xpos
159
object.direction = FLIP_NONE
160
else
161
object.direction = FLIP_X
162
end if
163
164
temp0 = object.dropPos.y
165
temp0 -= object.ypos
166
if temp0 < 0x100000
167
if object.direction == FLIP_NONE
168
object.xvel = -0x10000
169
else
170
object.xvel = 0x10000
171
end if
172
object.yvel = 0
173
object.animation = BATBRAIN_ANI_FLYING
174
object.state = BATBRAIN_FLYING
175
end if
176
break
177
178
case BATBRAIN_FLYING
179
object.xpos += object.xvel
180
arrayPos0 = object.targetPlayer
181
temp0 = player[arrayPos0].xpos
182
temp0 -= object.xpos
183
Abs(temp0)
184
if temp0 >= 0x800000
185
Rand(temp0, 8)
186
if temp0 == 0
187
object.state = BATBRAIN_RETURNTOROOF
188
end if
189
end if
190
break
191
192
case BATBRAIN_RETURNTOROOF
193
object.xpos += object.xvel
194
object.ypos += object.yvel
195
object.yvel -= 0x1800
196
197
ObjectTileCollision(CSIDE_ROOF, 0, -12, PATH_A)
198
if checkResult == true
199
object.xvel = 0
200
object.yvel = 0
201
object.state = BATBRAIN_AWAITPLAYER
202
object.animation = BATBRAIN_ANI_IDLE
203
end if
204
break
205
206
end switch
207
208
if object.outOfBounds == true
209
temp0 = object.xpos
210
temp1 = object.ypos
211
object.xpos = object.startPos.x
212
object.ypos = object.startPos.y
213
if object.outOfBounds == true
214
object.xvel = 0
215
object.yvel = 0
216
object.direction = FLIP_NONE
217
object.animation = BATBRAIN_ANI_IDLE
218
object.frame = 0
219
object.priority = PRIORITY_BOUNDS
220
object.state = BATBRAIN_AWAITPLAYER
221
else
222
object.xpos = temp0
223
object.ypos = temp1
224
end if
225
end if
226
227
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
228
BoxCollisionTest(C_TOUCH, object.entityPos, -12, -18, 12, 18, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)
229
if checkResult == true
230
CallFunction(Player_BadnikBreak)
231
end if
232
next
233
234
switch object.animation
235
case BATBRAIN_ANI_IDLE
236
object.frame = 0
237
break
238
239
case BATBRAIN_ANI_DROPPING
240
object.frame = 1
241
break
242
243
case BATBRAIN_ANI_FLYING
244
if object.animationTimer == 0
245
// this is the only change in this (Batbrain2) script
246
// ..thanks ig?
247
CallFunction(Batbrain_CheckOutOfRange)
248
if checkResult == false
249
PlaySfx(SfxName[Batbrain Fly], false)
250
end if
251
end if
252
object.frame = object.animationTimer
253
object.frame >>= 2
254
object.frame++
255
object.animationTimer++
256
object.animationTimer &= 15
257
break
258
259
end switch
260
end event
261
262
263
event ObjectDraw
264
DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
265
end event
266
267
268
event ObjectStartup
269
CheckCurrentStageFolder("Zone02")
270
temp0 = checkResult
271
if game.playMode == BOOT_PLAYMODE_MISSION
272
// In Origins's missions, GHZ and SYZ qualify for loading MZ sprites too
273
CheckCurrentStageFolder("Zone01")
274
temp0 |= checkResult
275
CheckCurrentStageFolder("Zone03")
276
temp0 |= checkResult
277
end if
278
279
if temp0 == true
280
LoadSpriteSheet("MZ/Objects.gif")
281
SpriteFrame(-7, -12, 14, 24, 37, 98)
282
SpriteFrame(-12, -14, 32, 30, 52, 81)
283
SpriteFrame(-15, -6, 35, 20, 1, 106)
284
SpriteFrame(-12, -8, 29, 28, 85, 81)
285
SpriteFrame(-15, -6, 35, 20, 1, 106)
286
end if
287
288
CheckCurrentStageFolder("Zone07")
289
if checkResult == true
290
LoadSpriteSheet("MBZ/Objects.gif")
291
SpriteFrame(-7, -12, 14, 24, 52, 68)
292
SpriteFrame(-12, -14, 32, 30, 1, 93)
293
SpriteFrame(-15, -6, 35, 20, 64, 99)
294
SpriteFrame(-12, -8, 29, 28, 34, 93)
295
SpriteFrame(-15, -6, 35, 20, 64, 99)
296
end if
297
298
foreach (TypeName[Batbrain], arrayPos0, ALL_ENTITIES)
299
object[arrayPos0].startPos.x = object[arrayPos0].xpos
300
object[arrayPos0].startPos.y = object[arrayPos0].ypos
301
object[arrayPos0].drawOrder = 5
302
next
303
304
SetTableValue(TypeName[Batbrain], DebugMode_ObjCount, DebugMode_TypesTable)
305
SetTableValue(Batbrain_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
306
SetTableValue(Batbrain_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
307
DebugMode_ObjCount++
308
end event
309
310
311
// ========================
312
// Editor Events
313
// ========================
314
315
event RSDKDraw
316
DrawSprite(0)
317
end event
318
319
320
event RSDKLoad
321
CheckCurrentStageFolder("Zone07")
322
if checkResult == true
323
LoadSpriteSheet("MBZ/Objects.gif")
324
SpriteFrame(-7, -12, 14, 24, 52, 68)
325
else
326
// We just load MZ sprites as the backup, not checking for MZ (or GHZ or SYZ) here
327
LoadSpriteSheet("MZ/Objects.gif")
328
SpriteFrame(-7, -12, 14, 24, 37, 98)
329
end if
330
331
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
332
end event
333
334