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/DEZ/DERTarget.txt
1479 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: DER Target 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.sfxTimer
14
private alias object.value2 : object.sfxDelay // Gradually decreases in order to make the SFX play more and more often
15
private alias object.value3 : object.reticleFrame
16
17
// States
18
private alias 0 : DERTARGET_INIT
19
private alias 1 : DERTARGET_TRACKING
20
private alias 2 : DERTARGET_TARGETTED // No longer moving, this is where the DER's gonna land
21
22
// Player aliases
23
private alias 0 : SLOT_PLAYER1
24
private alias object.xpos : player.xpos
25
private alias object.ypos : player.ypos
26
27
28
// ========================
29
// Tables
30
// ========================
31
32
private table DERTarget_xpos_backups
33
0, 0, 0, 0
34
end table
35
36
private table DERTarget_ypos_backups
37
0, 0, 0, 0
38
end table
39
40
41
// ========================
42
// Events
43
// ========================
44
45
event ObjectUpdate
46
switch object.state
47
case DERTARGET_INIT
48
object.timer = 160
49
object.sfxDelay = 24
50
object.sfxTimer = 24
51
52
object.xpos = player[SLOT_PLAYER1].xpos
53
object.ypos = player[SLOT_PLAYER1].ypos
54
55
// Set all the table values to just be P1's pos right now
56
SetTableValue(player[SLOT_PLAYER1].xpos, 0, DERTarget_xpos_backups)
57
SetTableValue(player[SLOT_PLAYER1].ypos, 0, DERTarget_ypos_backups)
58
SetTableValue(player[SLOT_PLAYER1].xpos, 1, DERTarget_xpos_backups)
59
SetTableValue(player[SLOT_PLAYER1].ypos, 1, DERTarget_ypos_backups)
60
SetTableValue(player[SLOT_PLAYER1].xpos, 2, DERTarget_xpos_backups)
61
SetTableValue(player[SLOT_PLAYER1].ypos, 2, DERTarget_ypos_backups)
62
SetTableValue(player[SLOT_PLAYER1].xpos, 3, DERTarget_xpos_backups)
63
SetTableValue(player[SLOT_PLAYER1].ypos, 3, DERTarget_ypos_backups)
64
65
object.drawOrder = 5
66
object.priority = PRIORITY_ACTIVE
67
object.state = DERTARGET_TRACKING
68
break
69
70
case DERTARGET_TRACKING
71
object.timer--
72
if object.timer < 0
73
object.state++
74
object.timer = 64
75
object.sfxTimer = 4
76
77
object.xpos = player[SLOT_PLAYER1].xpos
78
object.ypos = player[SLOT_PLAYER1].ypos
79
else
80
// In order to make the target have a delay when following the player,
81
// there's this whole table to store old player pos's
82
83
// Make this target's position be where the player was 3 cycles ago
84
GetTableValue(object.xpos, 3, DERTarget_xpos_backups)
85
GetTableValue(object.ypos, 3, DERTarget_ypos_backups)
86
87
// Shift all the values by 1 around the table
88
GetTableValue(temp0, 2, DERTarget_xpos_backups)
89
GetTableValue(temp1, 2, DERTarget_ypos_backups)
90
SetTableValue(temp0, 3, DERTarget_xpos_backups)
91
SetTableValue(temp1, 3, DERTarget_ypos_backups)
92
GetTableValue(temp0, 1, DERTarget_xpos_backups)
93
GetTableValue(temp1, 1, DERTarget_ypos_backups)
94
SetTableValue(temp0, 2, DERTarget_xpos_backups)
95
SetTableValue(temp1, 2, DERTarget_ypos_backups)
96
GetTableValue(temp0, 0, DERTarget_xpos_backups)
97
GetTableValue(temp1, 0, DERTarget_ypos_backups)
98
SetTableValue(temp0, 1, DERTarget_xpos_backups)
99
SetTableValue(temp1, 1, DERTarget_ypos_backups)
100
101
// And then put the _actual_ player position at the front of the table
102
SetTableValue(player[SLOT_PLAYER1].xpos, 0, DERTarget_xpos_backups)
103
SetTableValue(player[SLOT_PLAYER1].ypos, 0, DERTarget_ypos_backups)
104
end if
105
106
object.sfxTimer--
107
if object.sfxTimer < 0
108
object.sfxDelay--
109
object.sfxTimer = object.sfxDelay
110
PlaySfx(SfxName[Beep], false)
111
end if
112
break
113
114
case DERTARGET_TARGETTED
115
object.timer--
116
if object.timer < 0
117
// Object [-6] is the Death Egg Robot, make it land where its target shows
118
object[-6].timer = 1
119
object[-6].xpos = object.xpos
120
121
// Reset this object, not needed anymore
122
object.state = 0
123
object.type = TypeName[Blank Object]
124
else
125
object.sfxTimer--
126
127
if object.sfxTimer < 0
128
object.sfxTimer = 4
129
PlaySfx(SfxName[Beep], false)
130
end if
131
end if
132
break
133
134
end switch
135
136
// Update the object's animation
137
object.animationTimer++
138
if object.animationTimer == 4
139
object.animationTimer = 0
140
object.frame++
141
if object.frame >= 5
142
object.frame = 0
143
end if
144
object.reticleFrame ^= 1
145
end if
146
end event
147
148
149
event ObjectDraw
150
DrawSprite(object.frame)
151
152
if object.state == 2
153
// Draw the inner reticle
154
temp0 = object.reticleFrame
155
temp0 += 5
156
DrawSprite(temp0)
157
end if
158
end event
159
160
161
event ObjectStartup
162
CheckCurrentStageFolder("Zone12")
163
if checkResult == true
164
LoadSpriteSheet("DEZ/Objects.gif")
165
166
// 0-4 - Target Frames
167
SpriteFrame(-53, -53, 106, 106, 249, 149)
168
SpriteFrame(-45, -45, 90, 90, 158, 165)
169
SpriteFrame(-37, -37, 74, 74, 82, 181)
170
SpriteFrame(-29, -29, 58, 58, 23, 197)
171
SpriteFrame(-21, -21, 42, 42, 356, 213)
172
173
// 5-6 - Inner Reticle Frames
174
SpriteFrame(-8, -8, 16, 16, 356, 196)
175
SpriteFrame(-8, -8, 16, 16, 373, 196)
176
else
177
LoadSpriteSheet("MBZ/Objects.gif")
178
179
// 0-4 - Target Frames
180
SpriteFrame(-53, -53, 106, 106, 761, 149)
181
SpriteFrame(-45, -45, 90, 90, 670, 165)
182
SpriteFrame(-37, -37, 74, 74, 594, 181)
183
SpriteFrame(-29, -29, 58, 58, 535, 197)
184
SpriteFrame(-21, -21, 42, 42, 868, 213)
185
186
// 5-6 - Inner Reticle Frames
187
SpriteFrame(-8, -8, 16, 16, 868, 196)
188
SpriteFrame(-8, -8, 16, 16, 885, 196)
189
end if
190
end event
191
192
193
// ========================
194
// Editor Events
195
// ========================
196
197
event RSDKDraw
198
DrawSprite(0)
199
end event
200
201
202
event RSDKLoad
203
CheckCurrentStageFolder("Zone12")
204
if checkResult == true
205
LoadSpriteSheet("DEZ/Objects.gif")
206
SpriteFrame(-21, -21, 42, 42, 356, 213)
207
else
208
LoadSpriteSheet("MBZ/Objects.gif")
209
SpriteFrame(-21, -21, 42, 42, 868, 213)
210
end if
211
212
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
213
end event
214
215