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/OOZ/EggmanCannon.txt
1487 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Eggman Cannon 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.originPos.x
14
private alias object.value2 : object.originPos.y
15
private alias object.value3 : object.startPos.y
16
private alias object.value4 : object.cannonHeight
17
private alias object.value5 : object.shotCount
18
private alias object.value6 : object.lastAttackHeight
19
20
// States
21
private alias 0 : OOZEGGMANCANNON_SETUP
22
private alias 1 : OOZEGGMANCANNON_RISE
23
private alias 2 : OOZEGGMANCANNON_PREPARE
24
private alias 3 : OOZEGGMANCANNON_ATTACK
25
private alias 4 : OOZEGGMANCANNON_LOWER
26
27
// Player Aliases
28
private alias object.xpos : player.xpos
29
30
31
// ========================
32
// Tables
33
// ========================
34
35
private table OOZEggmanCannon_cannonHeights
36
-0x780000, -0x800000, -0x700000, -0x510000
37
end table
38
39
40
// ========================
41
// Events
42
// ========================
43
44
event ObjectUpdate
45
object.angle += 4
46
object.angle &= 0x1FF
47
if player[0].xpos < object.xpos
48
object.direction = FLIP_NONE
49
else
50
object.direction = FLIP_X
51
end if
52
53
switch object.state
54
case OOZEGGMANCANNON_SETUP
55
object.originPos.x = object.xpos
56
object.originPos.y = object.ypos
57
object.cannonHeight = object.ypos
58
object.cannonHeight -= 0x700000
59
object.startPos.y = object.ypos
60
object.yvel = -0x8000
61
object.state = OOZEGGMANCANNON_RISE
62
break
63
64
case OOZEGGMANCANNON_RISE
65
object.originPos.y += object.yvel
66
if object.originPos.y <= object.cannonHeight
67
object.originPos.y = object.cannonHeight
68
object.shotCount = 3
69
object.timer = 128
70
object.lastAttackHeight = 0
71
object.state++
72
end if
73
break
74
75
case OOZEGGMANCANNON_PREPARE
76
if object.animationTimer > 0
77
object.animationTimer--
78
else
79
object.frame = 0
80
end if
81
82
object.timer--
83
if object.timer == 0
84
if object.shotCount > 0
85
Rand(temp0, 4)
86
while temp0 == object.lastAttackHeight
87
if stage.milliSeconds > 50
88
temp0++
89
else
90
temp0--
91
end if
92
temp0 &= 3
93
loop
94
object.lastAttackHeight = temp0
95
96
GetTableValue(object.cannonHeight, temp0, OOZEggmanCannon_cannonHeights)
97
object.cannonHeight += object.startPos.y
98
if object.cannonHeight < object.originPos.y
99
object.yvel = -0x8000
100
else
101
object.yvel = 0x8000
102
end if
103
object.state = OOZEGGMANCANNON_ATTACK
104
else
105
object.yvel = 0x8000
106
object.state = OOZEGGMANCANNON_LOWER
107
end if
108
end if
109
break
110
111
case OOZEGGMANCANNON_ATTACK
112
object.originPos.y += object.yvel
113
checkResult = false
114
if object.yvel < 0
115
if object.originPos.y <= object.cannonHeight
116
object.originPos.y = object.cannonHeight
117
checkResult = true
118
end if
119
else
120
if object.originPos.y >= object.cannonHeight
121
object.originPos.y = object.cannonHeight
122
checkResult = true
123
end if
124
end if
125
126
if checkResult == true
127
object.animationTimer = 7
128
object.frame = 1
129
object.shotCount--
130
object.timer = 40
131
object.state = OOZEGGMANCANNON_PREPARE
132
133
Cos(object.xpos, object.angle)
134
object.xpos <<= 11
135
object.xpos += object.originPos.x
136
137
Sin(object.ypos, object.angle)
138
object.ypos <<= 9
139
object.ypos += object.originPos.y
140
141
CreateTempObject(TypeName[Eggman Laser], 0, object.xpos, object.ypos)
142
object[tempObjectPos].drawOrder = 2
143
object[tempObjectPos].direction = object.direction
144
if object.direction == FLIP_NONE
145
object[tempObjectPos].xvel = -0x40000
146
else
147
object[tempObjectPos].xvel = 0x40000
148
end if
149
PlaySfx(SfxName[Small Laser], false)
150
end if
151
break
152
153
case OOZEGGMANCANNON_LOWER
154
object.originPos.y += object.yvel
155
if object.originPos.y > object.startPos.y
156
object.type = TypeName[Blank Object]
157
end if
158
break
159
160
end switch
161
end event
162
163
164
event ObjectDraw
165
temp1 = object.angle
166
temp1 -= 288
167
temp1 &= 0x1FF
168
temp0 = 0
169
temp2 = object.originPos.y
170
temp2 += 0x780000
171
while temp0 < 8
172
Cos(object.xpos, temp1)
173
object.xpos <<= 11
174
object.xpos += object.originPos.x
175
176
Sin(object.ypos, temp1)
177
object.ypos <<= 9
178
object.ypos += temp2
179
180
DrawSprite(2)
181
182
temp0++
183
temp1 += 32
184
temp1 &= 0x1FF
185
temp2 -= 0xF0000
186
loop
187
188
Cos(object.xpos, temp1)
189
object.xpos <<= 11
190
object.xpos += object.originPos.x
191
192
Sin(object.ypos, temp1)
193
object.ypos <<= 9
194
object.ypos += temp2
195
196
DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
197
198
// Why is there collision in the draw event?????
199
#platform: USE_ORIGINS
200
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
201
#endplatform
202
BoxCollisionTest(C_TOUCH, object.entityPos, -8, -8, 8, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
203
if checkResult == true
204
CallFunction(Player_Hit)
205
end if
206
#platform: USE_ORIGINS
207
next
208
#endplatform
209
end event
210
211
212
event ObjectStartup
213
CheckCurrentStageFolder("Zone07")
214
if checkResult == true
215
LoadSpriteSheet("OOZ/Objects.gif")
216
SpriteFrame(-32, -8, 40, 16, 141, 207)
217
SpriteFrame(-32, -8, 40, 16, 141, 224)
218
SpriteFrame(-8, -8, 16, 16, 379, 196)
219
else
220
LoadSpriteSheet("MBZ/Objects.gif")
221
SpriteFrame(-32, -8, 40, 16, 512, 180)
222
SpriteFrame(-32, -8, 40, 16, 553, 180)
223
SpriteFrame(-8, -8, 16, 16, 355, 214)
224
end if
225
end event
226
227
228
// ========================
229
// Editor Events
230
// ========================
231
232
event RSDKDraw
233
DrawSprite(0)
234
end event
235
236
237
event RSDKLoad
238
CheckCurrentStageFolder("Zone07")
239
if checkResult == true
240
LoadSpriteSheet("OOZ/Objects.gif")
241
SpriteFrame(-32, -8, 40, 16, 141, 224)
242
else
243
LoadSpriteSheet("MBZ/Objects.gif")
244
SpriteFrame(-32, -8, 40, 16, 553, 180)
245
end if
246
247
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
248
end event
249
250