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/WFZ/Turret.txt
1480 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Turret 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
14
// States
15
private alias 0 : TURRET_SEARCHING
16
private alias 1 : TURRET_ACTIVATED
17
18
// Player Aliases
19
private alias object.xpos : player.xpos
20
private alias object.ypos : player.ypos
21
22
23
// ========================
24
// Function Declarations
25
// ========================
26
27
reserve function Turret_DebugDraw
28
reserve function Turret_DebugSpawn
29
30
31
// ========================
32
// Function Definitions
33
// ========================
34
35
private function Turret_DebugDraw
36
DrawSprite(0)
37
end function
38
39
40
private function Turret_DebugSpawn
41
CreateTempObject(TypeName[Turret], 0, object.xpos, object.ypos)
42
end function
43
44
45
// ========================
46
// Events
47
// ========================
48
49
event ObjectUpdate
50
if object.state == TURRET_SEARCHING
51
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
52
if player[currentPlayer].ypos >= object.ypos
53
temp0 = player[currentPlayer].xpos
54
temp0 -= object.xpos
55
Abs(temp0)
56
if temp0 < 0x600000
57
temp0 = player[currentPlayer].ypos
58
temp0 -= object.ypos
59
if temp0 < 0x900000
60
object.timer = 2
61
object.state++
62
end if
63
end if
64
end if
65
next
66
else
67
// Pick a direction based on closest player
68
temp1 = 0x7FFFFFFF
69
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
70
temp0 = player[currentPlayer].xpos
71
temp0 -= object.xpos
72
Abs(temp0)
73
if temp0 < temp1
74
if temp0 >= 0x200000
75
if player[currentPlayer].xpos < object.xpos
76
object.frame = 1
77
else
78
object.frame = 2
79
end if
80
else
81
object.frame = 0
82
end if
83
end if
84
next
85
86
object.timer--
87
if object.timer == 0
88
object.timer = 96
89
PlaySfx(SfxName[Octus Shot], false)
90
CreateTempObject(TypeName[Turret Bullet], 0, object.xpos, object.ypos)
91
switch object.frame
92
case 0
93
object[tempObjectPos].ypos += 0x180000
94
object[tempObjectPos].yvel = 0x10000
95
break
96
97
case 1
98
object[tempObjectPos].xpos -= 0x110000
99
object[tempObjectPos].ypos += 0x100000
100
object[tempObjectPos].xvel = -0x10000
101
object[tempObjectPos].yvel = 0x10000
102
break
103
104
case 2
105
object[tempObjectPos].xpos += 0x110000
106
object[tempObjectPos].ypos += 0x100000
107
object[tempObjectPos].xvel = 0x10000
108
object[tempObjectPos].yvel = 0x10000
109
break
110
end switch
111
end if
112
end if
113
end event
114
115
116
event ObjectDraw
117
DrawSprite(object.frame)
118
end event
119
120
121
event ObjectStartup
122
CheckCurrentStageFolder("Zone11")
123
if checkResult == true
124
LoadSpriteSheet("SCZ/Objects.gif")
125
SpriteFrame(-16, -16, 32, 38, 431, 88)
126
SpriteFrame(-17, -16, 33, 32, 430, 127)
127
SpriteFrame(-16, -16, 33, 32, 430, 160)
128
else
129
LoadSpriteSheet("MBZ/Objects.gif")
130
SpriteFrame(-16, -16, 32, 38, 934, 574)
131
SpriteFrame(-17, -16, 33, 32, 933, 613)
132
SpriteFrame(-16, -16, 33, 32, 933, 646)
133
end if
134
135
SetTableValue(TypeName[Turret], DebugMode_ObjCount, DebugMode_TypesTable)
136
SetTableValue(Turret_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
137
SetTableValue(Turret_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
138
DebugMode_ObjCount++
139
end event
140
141
142
// ========================
143
// Editor Events
144
// ========================
145
146
event RSDKDraw
147
DrawSprite(0)
148
end event
149
150
151
event RSDKLoad
152
CheckCurrentStageFolder("Zone11")
153
if checkResult == true
154
LoadSpriteSheet("SCZ/Objects.gif")
155
SpriteFrame(-16, -16, 32, 38, 431, 88)
156
else
157
LoadSpriteSheet("MBZ/Objects.gif")
158
SpriteFrame(-16, -16, 32, 38, 934, 574)
159
end if
160
161
SetVariableAlias(ALIAS_VAR_PROPVAL, "delay")
162
end event
163
164