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/Yadrin.txt
1480 views
1
// ----------------------------------
2
// RSDK Project: Sonic 1
3
// Script Description: Yadrin 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
16
private alias 0 : YADRIN_MOVING
17
private alias 1 : YADRIN_IDLE
18
19
private alias 0 : YADRIN_ANI_MOVING
20
private alias 1 : YADRIN_ANI_IDLE
21
22
// Player aliases
23
private alias object.value40 : player.hitboxLeft
24
private alias object.value38 : player.hitboxTop
25
private alias object.value41 : player.hitboxRight
26
private alias object.value39 : player.hitboxBottom
27
28
// Path ID Aliases
29
private alias 0 : PATH_A
30
31
32
// ========================
33
// Function Declarations
34
// ========================
35
36
reserve function Yadrin_DebugDraw
37
reserve function Yadrin_DebugSpawn
38
39
40
// ========================
41
// Function Definitions
42
// ========================
43
44
private function Yadrin_DebugDraw
45
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
46
end function
47
48
49
private function Yadrin_DebugSpawn
50
CreateTempObject(TypeName[Yadrin], 0, object.xpos, object.ypos)
51
52
GetBit(temp0, object.direction, 0)
53
if temp0 == FLIP_NONE
54
object[tempObjectPos].direction = FLIP_NONE
55
object[tempObjectPos].xvel = -0x10000
56
else
57
object[tempObjectPos].direction = FLIP_X
58
object[tempObjectPos].xvel = 0x10000
59
end if
60
61
object[tempObjectPos].startPos.x = object.xpos
62
object[tempObjectPos].startPos.y = object.ypos
63
end function
64
65
66
// ========================
67
// Events
68
// ========================
69
70
event ObjectUpdate
71
switch object.state
72
case YADRIN_MOVING
73
object.priority = PRIORITY_ACTIVE
74
object.xpos += object.xvel
75
temp0 = false
76
ObjectTileGrip(CSIDE_FLOOR, 0, 18, PATH_A)
77
if checkResult == false
78
temp0 = true
79
end if
80
81
ObjectTileCollision(CSIDE_RWALL, -20, 0, PATH_A)
82
temp0 |= checkResult
83
ObjectTileCollision(CSIDE_LWALL, 20, 0, PATH_A)
84
temp0 |= checkResult
85
if temp0 != false
86
object.state = YADRIN_IDLE
87
object.animation = YADRIN_ANI_IDLE
88
object.frame = 0
89
end if
90
break
91
92
case YADRIN_IDLE
93
if object.timer < 59
94
object.timer++
95
else
96
object.timer = 0
97
object.state = YADRIN_MOVING
98
object.animation = YADRIN_ANI_MOVING
99
object.direction ^= FLIP_X
100
FlipSign(object.xvel)
101
end if
102
break
103
104
end switch
105
106
if object.outOfBounds == true
107
temp0 = object.xpos
108
temp1 = object.ypos
109
object.xpos = object.startPos.x
110
object.ypos = object.startPos.y
111
if object.outOfBounds == true
112
object.xpos = object.startPos.x
113
object.ypos = object.startPos.y
114
115
if object.propertyValue == 0
116
object.direction = FLIP_NONE
117
object.xvel = -0x10000
118
else
119
object.direction = FLIP_X
120
object.xvel = 0x10000
121
end if
122
123
object.animation = YADRIN_ANI_MOVING
124
object.frame = 0
125
object.priority = PRIORITY_BOUNDS
126
object.state = YADRIN_MOVING
127
else
128
object.xpos = temp0
129
object.ypos = temp1
130
end if
131
end if
132
133
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
134
temp0 = false
135
BoxCollisionTest(C_TOUCH, object.entityPos, -18, -10, 18, 18, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)
136
if checkResult == true
137
CallFunction(Player_BadnikBreak)
138
end if
139
140
if temp0 == false
141
if object.direction == FLIP_NONE
142
BoxCollisionTest(C_TOUCH, object.entityPos, -8, -18, 18, -10, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
143
else
144
BoxCollisionTest(C_TOUCH, object.entityPos, -18, -18, 8, -10, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
145
end if
146
147
if checkResult == true
148
CallFunction(Player_Hit)
149
end if
150
end if
151
next
152
153
if object.animation == YADRIN_ANI_MOVING
154
object.frame = object.animationTimer
155
object.frame >>= 3
156
object.animationTimer++
157
object.animationTimer &= 63
158
end if
159
end event
160
161
162
event ObjectDraw
163
DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
164
end event
165
166
167
event ObjectStartup
168
CheckCurrentStageFolder("Zone02")
169
if checkResult == true
170
LoadSpriteSheet("MZ/Objects.gif")
171
SpriteFrame(-20, -20, 40, 38, 1, 2)
172
SpriteFrame(-20, -20, 40, 38, 1, 42)
173
SpriteFrame(-20, -20, 40, 39, 42, 1)
174
SpriteFrame(-20, -20, 40, 39, 42, 41)
175
SpriteFrame(-20, -20, 40, 38, 1, 2)
176
SpriteFrame(-20, -20, 40, 38, 1, 42)
177
SpriteFrame(-15, -20, 35, 39, 83, 1)
178
SpriteFrame(-15, -20, 35, 39, 83, 41)
179
end if
180
181
CheckCurrentStageFolder("Zone03")
182
if checkResult == true
183
LoadSpriteSheet("SYZ/Objects.gif")
184
SpriteFrame(-20, -20, 40, 38, 1, 2)
185
SpriteFrame(-20, -20, 40, 38, 1, 42)
186
SpriteFrame(-20, -20, 40, 39, 42, 1)
187
SpriteFrame(-20, -20, 40, 39, 42, 41)
188
SpriteFrame(-20, -20, 40, 38, 1, 2)
189
SpriteFrame(-20, -20, 40, 38, 1, 42)
190
SpriteFrame(-15, -20, 35, 39, 83, 1)
191
SpriteFrame(-15, -20, 35, 39, 83, 41)
192
end if
193
194
CheckCurrentStageFolder("Zone07")
195
if checkResult == true
196
LoadSpriteSheet("MBZ/Objects.gif")
197
SpriteFrame(-20, -20, 40, 38, 138, 2)
198
SpriteFrame(-20, -20, 40, 38, 138, 42)
199
SpriteFrame(-20, -20, 40, 39, 179, 1)
200
SpriteFrame(-20, -20, 40, 39, 179, 41)
201
SpriteFrame(-20, -20, 40, 38, 138, 2)
202
SpriteFrame(-20, -20, 40, 38, 138, 42)
203
SpriteFrame(-15, -20, 35, 39, 220, 1)
204
SpriteFrame(-15, -20, 35, 39, 220, 41)
205
end if
206
207
foreach (TypeName[Yadrin], arrayPos0, ALL_ENTITIES)
208
object[arrayPos0].startPos.x = object[arrayPos0].xpos
209
object[arrayPos0].startPos.y = object[arrayPos0].ypos
210
if object[arrayPos0].propertyValue == 0
211
object[arrayPos0].direction = FLIP_NONE
212
object[arrayPos0].xvel = -0x10000
213
else
214
object[arrayPos0].direction = FLIP_X
215
object[arrayPos0].xvel = 0x10000
216
end if
217
next
218
219
SetTableValue(TypeName[Yadrin], DebugMode_ObjCount, DebugMode_TypesTable)
220
SetTableValue(Yadrin_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
221
SetTableValue(Yadrin_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
222
DebugMode_ObjCount++
223
end event
224
225
226
// ========================
227
// Editor Events
228
// ========================
229
230
event RSDKEdit
231
if editor.returnVariable == true
232
switch editor.variableID
233
case EDIT_VAR_PROPVAL // property value
234
checkResult = object.propertyValue
235
checkResult &= 1
236
break
237
238
case 0 // direction
239
checkResult = object.propertyValue
240
checkResult &= 1
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
object.propertyValue &= 1
249
break
250
251
case 0 // direction
252
object.propertyValue = editor.variableValue
253
object.propertyValue &= 1
254
break
255
256
end switch
257
end if
258
end event
259
260
261
event RSDKDraw
262
GetBit(object.direction, object.propertyValue, 0)
263
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
264
end event
265
266
267
event RSDKLoad
268
// Make sure we have a fall-back, in case the current folder isn't actually a valid one
269
temp0 = false
270
271
CheckCurrentStageFolder("Zone03")
272
temp0 |= checkResult
273
if checkResult == true
274
LoadSpriteSheet("SYZ/Objects.gif")
275
SpriteFrame(-20, -20, 40, 38, 1, 2)
276
end if
277
278
CheckCurrentStageFolder("Zone07")
279
temp0 |= checkResult
280
if checkResult == true
281
LoadSpriteSheet("MBZ/Objects.gif")
282
SpriteFrame(-20, -20, 40, 38, 138, 2)
283
end if
284
285
if temp0 == false
286
// We use MZ's sprites as the fallback, "Zone02" (MZ's folder) will come here too
287
LoadSpriteSheet("MZ/Objects.gif")
288
SpriteFrame(-20, -20, 40, 38, 1, 2)
289
end if
290
291
AddEditorVariable("direction")
292
SetActiveVariable("direction")
293
AddEnumVariable("Left", 0)
294
AddEnumVariable("Right", 1)
295
end event
296
297