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/Enemies/NewtronShoot.txt
1483 views
1
// ----------------------------------
2
// RSDK Project: Sonic 1
3
// Script Description: Newtron Shoot 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.propertyValue : object.fireDirection
13
14
private alias object.value0 : object.timer
15
private alias object.value1 : object.fireInDir
16
17
private alias 0 : NEWTRONSHOOT_WAITFORPLAYER
18
private alias 1 : NEWTRONSHOOT_APPEAR
19
private alias 2 : NEWTRONSHOOT_SHOOT
20
private alias 3 : NEWTRONSHOOT_SHOOTDELAY
21
private alias 4 : NEWTRONSHOOT_DISAPPEAR
22
23
private alias 0 : NEWTRONSHOOT_ANI_IDLE
24
private alias 1 : NEWTRONSHOOT_ANI_SHOOT
25
26
// Player Aliases
27
private alias object.xpos : player.xpos
28
private alias object.value40 : player.hitboxLeft
29
private alias object.value38 : player.hitboxTop
30
private alias object.value41 : player.hitboxRight
31
private alias object.value39 : player.hitboxBottom
32
33
34
// ========================
35
// Function Declarations
36
// ========================
37
38
reserve function NewtronShoot_DebugDraw
39
reserve function NewtronShoot_DebugSpawn
40
41
42
// ========================
43
// Function Definitions
44
// ========================
45
46
private function NewtronShoot_DebugDraw
47
DrawSprite(object.direction)
48
end function
49
50
51
private function NewtronShoot_DebugSpawn
52
CreateTempObject(TypeName[Newtron Shoot], object.direction, object.xpos, object.ypos)
53
object[tempObjectPos].inkEffect = INK_ALPHA
54
object[tempObjectPos].alpha = 0
55
end function
56
57
58
// ========================
59
// Events
60
// ========================
61
62
event ObjectUpdate
63
switch object.state
64
case NEWTRONSHOOT_WAITFORPLAYER
65
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
66
BoxCollisionTest(C_TOUCH, object.entityPos, -128, -64, 128, 64, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
67
if checkResult == true
68
#platform: USE_ORIGINS
69
if game.playMode != BOOT_PLAYMODE_MISSION
70
#endplatform
71
object.state = NEWTRONSHOOT_APPEAR
72
if player[currentPlayer].xpos < object.xpos
73
// Firing to the left
74
object.fireDirection = FLIP_X
75
else
76
// Firing to the right
77
object.fireDirection = FLIP_NONE
78
end if
79
#platform: USE_ORIGINS
80
else
81
// fireInDir is set from the editor, in Missions where the Newtrons should only fire in a specific direction (M006)
82
if object.fireInDir != false
83
// woah that's actually like, a really cool way of doing it, especially when compared to how Origins does a bunch of other stuff
84
CheckLower(player[currentPlayer].xpos, object.xpos)
85
CheckEqual(object.fireDirection, checkResult)
86
object.state = checkResult
87
else
88
CheckLower(player[currentPlayer].xpos, object.xpos)
89
object.fireDirection = checkResult
90
object.state = NEWTRONSHOOT_APPEAR
91
end if
92
end if
93
#endplatform
94
end if
95
next
96
break
97
98
case NEWTRONSHOOT_APPEAR
99
if object.alpha < 0xF8
100
object.alpha += 4
101
else
102
object.alpha = 0xFF
103
object.state++
104
end if
105
break
106
107
case NEWTRONSHOOT_SHOOT
108
if object.timer < 29
109
object.timer++
110
else
111
object.timer = 0
112
CreateTempObject(TypeName[Newtron Shot], 0, object.xpos, object.ypos)
113
if object.fireDirection == FLIP_X
114
// Shooting left
115
116
object[tempObjectPos].xpos -= 0x140000
117
object[tempObjectPos].xvel = -0x20000
118
else
119
// Shooting right
120
121
object[tempObjectPos].xpos += 0x140000
122
object[tempObjectPos].xvel = 0x20000
123
end if
124
object[tempObjectPos].ypos -= 0x80000
125
object.animation = NEWTRONSHOOT_ANI_SHOOT
126
object.state++
127
end if
128
break
129
130
case NEWTRONSHOOT_SHOOTDELAY
131
if object.timer < 59
132
if object.timer == 15
133
object.animation = NEWTRONSHOOT_ANI_IDLE
134
end if
135
object.timer++
136
else
137
object.timer = 0
138
object.alpha = 0xF8
139
object.state++
140
end if
141
break
142
143
case NEWTRONSHOOT_DISAPPEAR
144
if object.alpha > 0
145
object.alpha -= 4
146
else
147
object.type = TypeName[Blank Object]
148
end if
149
break
150
151
end switch
152
153
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
154
switch object.state
155
default
156
case NEWTRONSHOOT_WAITFORPLAYER
157
case NEWTRONSHOOT_APPEAR
158
case NEWTRONSHOOT_DISAPPEAR
159
break
160
161
case NEWTRONSHOOT_SHOOT
162
case NEWTRONSHOOT_SHOOTDELAY
163
BoxCollisionTest(C_TOUCH, object.entityPos, -12, -14, 12, 14, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)
164
if checkResult == true
165
CallFunction(Player_BadnikBreak)
166
end if
167
break
168
169
end switch
170
next
171
end event
172
173
174
event ObjectDraw
175
switch object.animation
176
case NEWTRONSHOOT_ANI_IDLE
177
// Fire Direction matches with a Sprite Frame (0 for right, 1 for left)
178
// FX effects don't allow for flipping sprites, which is why we used pre-flipped sprites instead
179
DrawSpriteFX(object.fireDirection, FX_INK, object.xpos, object.ypos)
180
break
181
182
case NEWTRONSHOOT_ANI_SHOOT
183
// Same from above applies here too about Fire Direction, yup
184
temp0 = object.fireDirection
185
temp0 += 2
186
DrawSprite(temp0)
187
break
188
189
end switch
190
end event
191
192
193
event ObjectStartup
194
CheckCurrentStageFolder("Zone01")
195
if checkResult == true
196
LoadSpriteSheet("GHZ/Objects2.gif")
197
SpriteFrame(-20, -20, 39, 39, 1, 1) // 0 - Idle facing right frame
198
SpriteFrame(-19, -20, 39, 39, 81, 1) // 1 - Idle facing left frame
199
SpriteFrame(-20, -20, 39, 39, 41, 1) // 2 - Shooting facing left
200
SpriteFrame(-19, -20, 39, 39, 121, 1) // 3 - Shoting facing right frame
201
end if
202
203
CheckCurrentStageFolder("Zone07")
204
if checkResult == true
205
LoadSpriteSheet("MBZ/Objects.gif")
206
SpriteFrame(-20, -20, 39, 39, 1, 164) // 0 - Idle facing right frame
207
SpriteFrame(-19, -20, 39, 39, 81, 164) // 1 - Idle facing left frame
208
SpriteFrame(-20, -20, 39, 39, 41, 164) // 2 - Shooting facing left
209
SpriteFrame(-19, -20, 39, 39, 121, 164) // 3 - Shoting facing right frame
210
end if
211
212
foreach (TypeName[Newtron Shoot], arrayPos0, ALL_ENTITIES)
213
object[arrayPos0].inkEffect = INK_ALPHA
214
object[arrayPos0].alpha = 0
215
next
216
217
SetTableValue(TypeName[Newtron Shoot], DebugMode_ObjCount, DebugMode_TypesTable)
218
SetTableValue(NewtronShoot_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
219
SetTableValue(NewtronShoot_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
220
DebugMode_ObjCount++
221
end event
222
223
224
// ========================
225
// Editor Events
226
// ========================
227
228
event RSDKEdit
229
if editor.returnVariable == true
230
switch editor.variableID
231
case EDIT_VAR_PROPVAL // property value
232
checkResult = object.propertyValue
233
break
234
235
case 0 // fireInDir
236
GetBit(checkResult, object.fireInDir, 0)
237
break
238
239
case 1 // fireDirection
240
GetBit(checkResult, object.propertyValue, 0)
241
break
242
243
end switch
244
else
245
switch editor.variableID
246
case EDIT_VAR_PROPVAL // property value
247
object.propertyValue = editor.variableValue
248
break
249
250
case 0 // fireInDir
251
CheckNotEqual(editor.variableValue, false)
252
SetBit(object.fireInDir, 0, checkResult)
253
break
254
255
case 1 // fireDirection
256
CheckNotEqual(editor.variableValue, false)
257
SetBit(object.propertyValue, 0, checkResult)
258
break
259
260
end switch
261
end if
262
end event
263
264
265
event RSDKDraw
266
GetBit(temp0, object.propertyValue, 0)
267
DrawSprite(temp0)
268
end event
269
270
271
event RSDKLoad
272
CheckCurrentStageFolder("Zone07")
273
if checkResult == true
274
LoadSpriteSheet("MBZ/Objects.gif")
275
SpriteFrame(-20, -20, 39, 39, 1, 164)
276
SpriteFrame(-19, -20, 39, 39, 81, 164)
277
else
278
LoadSpriteSheet("GHZ/Objects2.gif")
279
SpriteFrame(-20, -20, 39, 39, 1, 1)
280
SpriteFrame(-19, -20, 39, 39, 81, 1)
281
end if
282
283
// If the Newtron should only Shoot when the player is in a specific direction
284
// Only used in Origins's Mission Mode
285
AddEditorVariable("fireInDir")
286
SetActiveVariable("fireInDir")
287
AddEnumVariable("False", 0)
288
AddEnumVariable("True", 1)
289
290
// Related to above, also only used in Mission Mode
291
// Otherwise, it's ignored
292
AddEditorVariable("fireDirection")
293
SetActiveVariable("fireDirection")
294
AddEnumVariable("Right", 0)
295
AddEnumVariable("Left", 1)
296
end event
297
298