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/Redz.txt
1480 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Redz 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.startPos.x
14
private alias object.value2 : object.startPos.y
15
private alias object.value3 : object.attackDelay
16
17
// States
18
private alias 0 : REDZ_WALK
19
private alias 1 : REDZ_TURN
20
private alias 2 : REDZ_PREPAREATTACK
21
private alias 3 : REDZ_ATTACK
22
23
// Animations
24
private alias 0 : REDZ_ANI_MOVING
25
private alias 1 : REDZ_ANI_STILL
26
27
// Player Aliases
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
// Path ID Aliases
34
private alias 0 : PATH_A
35
36
37
// ========================
38
// Function Declarations
39
// ========================
40
41
reserve function Redz_DebugDraw
42
reserve function Redz_DebugSpawn
43
44
45
// ========================
46
// Function Definitions
47
// ========================
48
49
private function Redz_DebugDraw
50
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
51
end function
52
53
54
private function Redz_DebugSpawn
55
CreateTempObject(TypeName[Redz], 0, object.xpos, object.ypos)
56
if object.direction == FACING_RIGHT
57
object[tempObjectPos].direction = FLIP_NONE
58
object[tempObjectPos].xvel = -0x8000
59
else
60
object[tempObjectPos].direction = FLIP_X
61
object[tempObjectPos].xvel = 0x8000
62
end if
63
end function
64
65
66
// ========================
67
// Events
68
// ========================
69
70
event ObjectUpdate
71
switch object.state
72
case REDZ_WALK
73
if object.priority != PRIORITY_XBOUNDS_DESTROY
74
object.priority = PRIORITY_ACTIVE
75
end if
76
77
object.xpos += object.xvel
78
if object.direction == FLIP_NONE
79
ObjectTileGrip(CSIDE_FLOOR, -8, 16, PATH_A)
80
else
81
ObjectTileGrip(CSIDE_FLOOR, 8, 16, PATH_A)
82
end if
83
84
if checkResult == false
85
object.state = REDZ_TURN
86
object.animation = REDZ_ANI_STILL
87
object.animationTimer = 0
88
object.frame = 0
89
end if
90
91
if stage.actNum == 2
92
// Different behaviour for Proto Palace, where we should never attack
93
object.attackDelay = 300
94
end if
95
96
if object.attackDelay < 1
97
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
98
if object.direction == FLIP_NONE
99
BoxCollisionTest(C_TOUCH, object.entityPos, -64, -96, 0, -8, currentPlayer, 0, 0, 0, 0)
100
else
101
BoxCollisionTest(C_TOUCH, object.entityPos, 0, -96, 64, -8, currentPlayer, 0, 0, 0, 0)
102
end if
103
104
if checkResult == true
105
object.state = REDZ_PREPAREATTACK
106
object.animation = REDZ_ANI_STILL
107
object.frame = 0
108
object.attackDelay = 60
109
end if
110
next
111
else
112
object.attackDelay--
113
end if
114
break
115
116
case REDZ_TURN
117
if object.timer < 59
118
object.timer++
119
else
120
object.timer = 0
121
object.state = REDZ_WALK
122
object.animation = REDZ_ANI_MOVING
123
object.direction ^= FLIP_X
124
FlipSign(object.xvel)
125
end if
126
break
127
128
case REDZ_PREPAREATTACK
129
if object.timer < 30
130
object.timer++
131
else
132
object.timer = 0
133
object.frame = 4
134
object.state = REDZ_ATTACK
135
PlaySfx(SfxName[Flame Thrower], false)
136
end if
137
break
138
139
case REDZ_ATTACK
140
if object.timer < 90
141
temp0 = object.timer
142
temp0 &= 3
143
if temp0 == 0
144
CreateTempObject(TypeName[Redz Fire], 0, object.xpos, object.ypos)
145
object[tempObjectPos].drawOrder = 4
146
object[tempObjectPos].ypos -= 0x40000
147
temp0 = object.timer
148
temp0 <<= 3
149
temp0 &= 0x1FF
150
Sin(object.angle, temp0)
151
object.angle >>= 5
152
object.angle -= 0x30
153
object.angle &= 0x1FF
154
Cos(object[tempObjectPos].xvel, object.angle)
155
object[tempObjectPos].xvel <<= 8
156
Sin(object[tempObjectPos].yvel, object.angle)
157
object[tempObjectPos].yvel <<= 8
158
if object.direction == FLIP_NONE
159
object[tempObjectPos].xpos -= 0x80000
160
FlipSign(object[tempObjectPos].xvel)
161
else
162
object[tempObjectPos].xpos += 0x80000
163
end if
164
end if
165
166
object.timer++
167
else
168
object.timer = 0
169
object.frame = 0
170
object.state = REDZ_WALK
171
object.animation = REDZ_ANI_MOVING
172
end if
173
break
174
175
end switch
176
177
if object.outOfBounds == true
178
temp0 = object.xpos
179
temp1 = object.ypos
180
object.xpos = object.startPos.x
181
object.ypos = object.startPos.y
182
if object.outOfBounds == true
183
if object.propertyValue == 0
184
object.direction = FLIP_NONE
185
object.xvel = -0x8000
186
else
187
object.direction = FLIP_X
188
object.xvel = 0x8000
189
end if
190
191
object.timer = 0
192
object.animation = REDZ_ANI_MOVING
193
if object.priority != PRIORITY_XBOUNDS_DESTROY
194
object.priority = PRIORITY_BOUNDS
195
end if
196
197
object.state = REDZ_WALK
198
else
199
object.xpos = temp0
200
object.ypos = temp1
201
end if
202
end if
203
204
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
205
BoxCollisionTest(C_TOUCH, object.entityPos, -14, -14, 14, 14, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)
206
if checkResult == true
207
CallFunction(Player_BadnikBreak)
208
end if
209
next
210
211
if object.animation == REDZ_ANI_MOVING
212
object.frame = object.animationTimer
213
object.frame /= 10
214
object.animationTimer++
215
object.animationTimer %= 40
216
end if
217
end event
218
219
220
event ObjectDraw
221
DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
222
end event
223
224
225
event ObjectStartup
226
LoadSpriteSheet("HPZ/Objects.gif")
227
228
SpriteFrame(-16, -16, 31, 32, 1, 118) // 0 - Standing frame
229
230
SpriteFrame(-16, -16, 30, 32, 1, 85) // 1 - 3 - Walking frames
231
SpriteFrame(-16, -16, 31, 32, 1, 118)
232
SpriteFrame(-16, -16, 32, 32, 1, 151)
233
234
SpriteFrame(-16, -16, 31, 32, 143, 140) // 4 - Firing fire frame
235
236
foreach (TypeName[Redz], arrayPos0, ALL_ENTITIES)
237
object[arrayPos0].startPos.x = object[arrayPos0].xpos
238
object[arrayPos0].startPos.y = object[arrayPos0].ypos
239
if object[arrayPos0].propertyValue == 0
240
object[arrayPos0].direction = FLIP_NONE
241
object[arrayPos0].xvel = -0x8000
242
else
243
object[arrayPos0].direction = FLIP_X
244
object[arrayPos0].xvel = 0x8000
245
end if
246
next
247
248
SetTableValue(TypeName[Redz], DebugMode_ObjCount, DebugMode_TypesTable)
249
SetTableValue(Redz_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
250
SetTableValue(Redz_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
251
DebugMode_ObjCount++
252
end event
253
254
255
// ========================
256
// Editor Events
257
// ========================
258
259
event RSDKEdit
260
if editor.returnVariable == true
261
switch editor.variableID
262
case EDIT_VAR_PROPVAL // property value
263
checkResult = object.propertyValue
264
checkResult &= 1
265
break
266
267
case 0 // direction
268
GetBit(checkResult, object.propertyValue, 0)
269
break
270
271
end switch
272
else
273
switch editor.variableID
274
case EDIT_VAR_PROPVAL // property value
275
object.propertyValue = editor.variableValue
276
object.propertyValue &= 1
277
break
278
279
case 0 // direction
280
CheckNotEqual(editor.variableValue, 0)
281
SetBit(object.propertyValue, 0, checkResult)
282
break
283
284
end switch
285
end if
286
end event
287
288
289
event RSDKDraw
290
GetBit(object.direction, object.propertyValue, 0)
291
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
292
end event
293
294
295
event RSDKLoad
296
LoadSpriteSheet("HPZ/Objects.gif")
297
SpriteFrame(-16, -16, 31, 32, 1, 118)
298
299
AddEditorVariable("direction")
300
SetActiveVariable("direction")
301
AddEnumVariable("Left", 0)
302
AddEnumVariable("Right", 1)
303
end event
304
305