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/CPZ/OneWayDoor.txt
1480 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: One Way Door 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.state : object.isOpen
13
private alias object.value0 : object.movePos
14
15
// Player Aliases
16
private alias object.xvel : player.xvel
17
18
19
// ========================
20
// Function Declarations
21
// ========================
22
23
reserve function OneWayDoor_DebugDraw
24
reserve function OneWayDoor_DebugSpawn
25
26
27
// ========================
28
// Function Definitions
29
// ========================
30
31
private function OneWayDoor_DebugDraw
32
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
33
end function
34
35
36
private function OneWayDoor_DebugSpawn
37
CreateTempObject(TypeName[One Way Door], object.direction, object.xpos, object.ypos)
38
object[tempObjectPos].direction = object.direction
39
end function
40
41
42
// ========================
43
// Events
44
// ========================
45
46
event ObjectUpdate
47
if object.isOpen == false
48
if object.movePos > 0
49
object.movePos -= 0x80000
50
end if
51
else
52
if object.movePos < 0x400000
53
object.movePos += 0x80000
54
end if
55
end if
56
57
object.ypos -= object.movePos
58
if object.movePos == 0
59
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
60
BoxCollisionTest(C_SOLID, object.entityPos, -8, -32, 8, 32, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
61
next
62
else
63
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
64
BoxCollisionTest(C_SOLID, object.entityPos, -8, -32, 8, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
65
next
66
end if
67
68
object.ypos += object.movePos
69
object.isOpen = false
70
if object.propertyValue == 0
71
// Door opens from left
72
73
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
74
if player[currentPlayer].xvel < 0x60000
75
BoxCollisionTest(C_TOUCH, object.entityPos, -64, -32, 8, 32, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
76
else
77
BoxCollisionTest(C_TOUCH, object.entityPos, -88, -32, 8, 32, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
78
end if
79
80
object.isOpen |= checkResult
81
next
82
else
83
// Door opens from right
84
85
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
86
if player[currentPlayer].xvel > -0x60000
87
BoxCollisionTest(C_TOUCH, object.entityPos, -8, -32, 64, 32, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
88
else
89
BoxCollisionTest(C_TOUCH, object.entityPos, -8, -32, 88, 32, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
90
end if
91
92
object.isOpen |= checkResult
93
next
94
end if
95
end event
96
97
98
event ObjectDraw
99
temp0 = object.movePos
100
FlipSign(temp0)
101
temp0 += object.ypos
102
DrawSpriteFX(0, FX_FLIP, object.xpos, temp0)
103
end event
104
105
106
event ObjectStartup
107
LoadSpriteSheet("CPZ/Objects.gif")
108
SpriteFrame(-8, -32, 16, 64, 206, 142)
109
110
foreach (TypeName[One Way Door], arrayPos0, ALL_ENTITIES)
111
if object[arrayPos0].propertyValue == 1
112
// Door opens from right, flip the sprite around to look like such too
113
object[arrayPos0].direction = FLIP_X
114
end if
115
next
116
117
SetTableValue(TypeName[One Way Door], DebugMode_ObjCount, DebugMode_TypesTable)
118
SetTableValue(OneWayDoor_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
119
SetTableValue(OneWayDoor_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
120
DebugMode_ObjCount++
121
end event
122
123
124
// ========================
125
// Editor Events
126
// ========================
127
128
event RSDKEdit
129
if editor.returnVariable == true
130
switch editor.variableID
131
case EDIT_VAR_PROPVAL // property value
132
checkResult = object.propertyValue
133
break
134
135
case 0 // type
136
checkResult = object.propertyValue
137
break
138
139
end switch
140
else
141
switch editor.variableID
142
case EDIT_VAR_PROPVAL // property value
143
object.propertyValue = editor.variableValue
144
break
145
146
case 0 // type
147
object.propertyValue = editor.variableValue
148
break
149
150
end switch
151
end if
152
end event
153
154
155
event RSDKDraw
156
DrawSprite(0)
157
end event
158
159
160
event RSDKLoad
161
LoadSpriteSheet("CPZ/Objects.gif")
162
SpriteFrame(-8, -32, 16, 64, 206, 142)
163
164
AddEditorVariable("type")
165
SetActiveVariable("type")
166
AddEnumVariable("Left Only", 0)
167
AddEnumVariable("Right Only", 1)
168
end event
169
170