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/Animals/Cucky.txt
1482 views
1
// ----------------------------------
2
// RSDK Project: Sonic 1
3
// Script Description: Cucky 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.delay
13
14
private alias object.value0 : object.timer // its this in ANIMAL_WAIT
15
private alias object.value0 : object.bounceDir // its this in every other state
16
private alias object.value1 : object.randomizeDir
17
18
private alias 0 : ANIMAL_WAIT
19
private alias 1 : ANIMAL_FALL
20
private alias 2 : ANIMAL_BOUNCING_PLACED
21
private alias 3 : ANIMAL_BOUNCING_FIXED
22
private alias 4 : ANIMAL_BOUNCING_FOLLOW
23
private alias 5 : ANIMAL_BOUNCING_FREE
24
25
private alias 0x20000 : ANIMAL_XVEL
26
private alias -0x30000 : ANIMAL_YVEL
27
28
// Player Aliases
29
private alias object.xpos : player.xpos
30
31
// Path ID Aliases
32
private alias 0 : PATH_A
33
34
35
// ========================
36
// Function Declarations
37
// ========================
38
39
reserve function Cucky_DebugDraw
40
reserve function Cucky_DebugSpawn
41
42
43
// ========================
44
// Function Definitions
45
// ========================
46
47
private function Cucky_DebugDraw
48
DrawSprite(2)
49
end function
50
51
52
private function Cucky_DebugSpawn
53
CreateTempObject(TypeName[Cucky], 0, object.xpos, object.ypos)
54
55
GetBit(temp0, object.direction, 0)
56
if temp0 == FACING_RIGHT
57
object[tempObjectPos].state = ANIMAL_BOUNCING_FIXED
58
object[tempObjectPos].xvel = ANIMAL_XVEL
59
object[tempObjectPos].yvel = ANIMAL_YVEL
60
61
Rand(checkResult, 32)
62
if checkResult < 16
63
object[tempObjectPos].direction = FACING_LEFT
64
FlipSign(object[tempObjectPos].xvel)
65
end if
66
else
67
object[tempObjectPos].state = ANIMAL_BOUNCING_FOLLOW
68
end if
69
end function
70
71
72
// ========================
73
// Events
74
// ========================
75
76
event ObjectUpdate
77
switch object.state
78
case ANIMAL_WAIT
79
if object.timer < object.delay
80
object.timer++
81
else
82
object.xvel = ANIMAL_XVEL
83
84
if object.randomizeDir == true
85
object.drawOrder = 4
86
Rand(checkResult, 32)
87
if checkResult < 16
88
object.direction = FACING_LEFT
89
FlipSign(object.xvel)
90
end if
91
else
92
object.direction = FACING_LEFT
93
FlipSign(object.xvel)
94
end if
95
96
// Jump & then apply gravity
97
object.yvel = -0x40000
98
object.state++
99
end if
100
break
101
102
case ANIMAL_FALL
103
object.ypos += object.yvel
104
object.yvel += 0x3800
105
106
if object.yvel > 0
107
ObjectTileCollision(CSIDE_FLOOR, 0, 8, PATH_A)
108
if checkResult == true
109
object.yvel = ANIMAL_YVEL
110
object.state++
111
end if
112
end if
113
break
114
115
case ANIMAL_BOUNCING_FOLLOW
116
if player[0].xpos < object.xpos
117
object.direction = FACING_LEFT
118
else
119
object.direction = FACING_RIGHT
120
end if
121
// [Fallthrough]
122
case ANIMAL_BOUNCING_PLACED
123
case ANIMAL_BOUNCING_FIXED
124
case ANIMAL_BOUNCING_FREE
125
object.xpos += object.xvel
126
object.ypos += object.yvel
127
object.yvel += 0x3800
128
129
if object.yvel > 0
130
ObjectTileCollision(CSIDE_FLOOR, 0, 8, PATH_A)
131
if checkResult == true
132
if object.state == ANIMAL_BOUNCING_FIXED
133
if object.bounceDir == FACING_LEFT
134
FlipSign(object.xvel)
135
object.direction ^= FACING_LEFT
136
end if
137
138
object.bounceDir ^= FACING_LEFT
139
end if
140
141
object.yvel = ANIMAL_YVEL
142
end if
143
end if
144
145
object.frame = object.animationTimer
146
object.frame >>= 1
147
object.animationTimer++
148
object.animationTimer &= 3
149
break
150
151
end switch
152
153
if object.state < ANIMAL_BOUNCING_FIXED
154
if object.outOfBounds == true
155
object.type = TypeName[Blank Object]
156
end if
157
end if
158
end event
159
160
161
event ObjectDraw
162
switch object.state
163
case ANIMAL_WAIT
164
case ANIMAL_FALL
165
DrawSprite(2)
166
break
167
168
case ANIMAL_BOUNCING_PLACED
169
case ANIMAL_BOUNCING_FIXED
170
case ANIMAL_BOUNCING_FOLLOW
171
case ANIMAL_BOUNCING_FREE
172
DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
173
break
174
175
end switch
176
end event
177
178
179
event ObjectStartup
180
LoadSpriteSheet("Global/Items.gif")
181
SpriteFrame(-8, -8, 16, 16, 174, 215)
182
SpriteFrame(-8, -8, 16, 16, 97, 227)
183
SpriteFrame(-7, -12, 15, 24, 207, 197)
184
185
foreach (TypeName[Cucky], arrayPos0, ALL_ENTITIES)
186
if object[arrayPos0].propertyValue == 1
187
object[arrayPos0].state = ANIMAL_BOUNCING_FIXED
188
object[arrayPos0].xvel = ANIMAL_XVEL
189
object[arrayPos0].yvel = ANIMAL_YVEL
190
191
Rand(checkResult, 32)
192
if checkResult < 16
193
object[arrayPos0].direction = FACING_LEFT
194
FlipSign(object[arrayPos0].xvel)
195
end if
196
else
197
if object[arrayPos0].propertyValue == 2
198
object[arrayPos0].state = ANIMAL_BOUNCING_FOLLOW
199
end if
200
201
if object[arrayPos0].propertyValue == 3
202
object[arrayPos0].state = ANIMAL_BOUNCING_FREE
203
object[arrayPos0].xvel = ANIMAL_XVEL
204
FlipSign(object[arrayPos0].xvel)
205
object[arrayPos0].direction = FACING_LEFT
206
end if
207
end if
208
209
object[arrayPos0].propertyValue = 0
210
next
211
212
SetTableValue(TypeName[Cucky], DebugMode_ObjCount, DebugMode_TypesTable)
213
SetTableValue(Cucky_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
214
SetTableValue(Cucky_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
215
DebugMode_ObjCount++
216
end event
217
218
219
// ========================
220
// Editor Events
221
// ========================
222
223
event RSDKEdit
224
if editor.returnVariable == true
225
switch editor.variableID
226
case EDIT_VAR_PROPVAL // property value
227
checkResult = object.propertyValue
228
break
229
230
case 0 // behavior
231
checkResult = object.propertyValue
232
break
233
234
end switch
235
else
236
switch editor.variableID
237
case EDIT_VAR_PROPVAL // property value
238
object.propertyValue = editor.variableValue
239
break
240
241
case 0 // behavior
242
object.propertyValue = editor.variableValue
243
break
244
245
end switch
246
end if
247
end event
248
249
250
event RSDKDraw
251
DrawSprite(0)
252
end event
253
254
255
event RSDKLoad
256
LoadSpriteSheet("Global/Items.gif")
257
SpriteFrame(-7, -12, 15, 24, 207, 197)
258
259
AddEditorVariable("behavior")
260
SetActiveVariable("behavior")
261
AddEnumVariable("Placed", 0)
262
AddEnumVariable("Fixed", 1)
263
AddEnumVariable("Follow", 2)
264
AddEnumVariable("Free", 3)
265
end event
266
267