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/MPZ/HorizontalDoor.txt
1480 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Horizontal 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.value0 : object.timer
13
private alias object.value1 : object.startPos.x
14
15
// Player Aliases
16
private alias object.yvel : player.yvel
17
18
19
// ========================
20
// Function Declarations
21
// ========================
22
23
reserve function HorizontalDoor_Setup
24
reserve function HorizontalDoor_DebugDraw
25
reserve function HorizontalDoor_DebugSpawn
26
27
28
// ========================
29
// Events
30
// ========================
31
32
private function HorizontalDoor_Setup
33
object[arrayPos0].priority = PRIORITY_ACTIVE
34
object[arrayPos0].timer = 0
35
object[arrayPos0].xpos = object[arrayPos0].startPos.x
36
37
if object[arrayPos0].direction == FLIP_X
38
object[arrayPos0].xpos -= 0x400000
39
end if
40
end function
41
42
43
private function HorizontalDoor_DebugDraw
44
temp1 = object.xpos
45
if object.direction == FACING_LEFT
46
temp1 -= 0x400000
47
end if
48
DrawSpriteXY(0, temp1, object.ypos)
49
end function
50
51
52
private function HorizontalDoor_DebugSpawn
53
CreateTempObject(TypeName[Horizontal Door], 0, object.xpos, object.ypos)
54
55
// Door direction is based on the direction of the player when entering Debug Mode
56
object[tempObjectPos].direction = object.direction
57
58
arrayPos0 = object[tempObjectPos].entityPos
59
object[arrayPos0].startPos.x = object.xpos
60
CallFunction(HorizontalDoor_Setup)
61
end function
62
63
64
// ========================
65
// Events
66
// ========================
67
68
event ObjectUpdate
69
temp0 = false
70
71
temp1 = object.xpos
72
73
// Check to see if any players have stepped within range for the door activation
74
object.xpos = object.startPos.x
75
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
76
if object.direction == FLIP_NONE
77
BoxCollisionTest(C_TOUCH, object.entityPos, -32, -16, 96, 64, currentPlayer, -1, -1, 1, 1)
78
if checkResult == true
79
temp0 = true
80
end if
81
else
82
BoxCollisionTest(C_TOUCH, object.entityPos, -160, -16, -32, 64, currentPlayer, -1, -1, 1, 1)
83
if checkResult == true
84
temp0 = true
85
end if
86
end if
87
next
88
89
object.xpos = temp1
90
91
// A player has stepped within range, move the door
92
if temp0 == true
93
if object.timer < 4
94
object.timer++
95
if object.direction == FLIP_NONE
96
object.xpos -= 0x100000
97
else
98
object.xpos += 0x100000
99
end if
100
end if
101
else
102
if object.timer > 0
103
object.timer--
104
if object.direction == FLIP_NONE
105
object.xpos += 0x100000
106
else
107
object.xpos -= 0x100000
108
end if
109
end if
110
end if
111
112
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
113
if player[currentPlayer].yvel >= 0
114
BoxCollisionTest(C_SOLID, object.entityPos, -32, -12, 32, 12, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
115
end if
116
next
117
end event
118
119
120
event ObjectDraw
121
DrawSprite(0)
122
end event
123
124
125
event ObjectStartup
126
LoadSpriteSheet("MPZ/Objects.gif")
127
128
// Horizontal Door Frame
129
SpriteFrame(-32, -12, 64, 24, 383, 207)
130
131
foreach (TypeName[Horizontal Door], arrayPos0, ALL_ENTITIES)
132
object[arrayPos0].startPos.x = object[arrayPos0].xpos
133
CallFunction(HorizontalDoor_Setup)
134
next
135
136
SetTableValue(TypeName[Horizontal Door], DebugMode_ObjCount, DebugMode_TypesTable)
137
SetTableValue(HorizontalDoor_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
138
SetTableValue(HorizontalDoor_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
139
DebugMode_ObjCount++
140
end event
141
142
143
// ========================
144
// Editor Events
145
// ========================
146
147
event RSDKDraw
148
DrawSprite(0)
149
end event
150
151
152
event RSDKLoad
153
LoadSpriteSheet("MPZ/Objects.gif")
154
SpriteFrame(-32, -12, 64, 24, 383, 207)
155
156
// Note that this object actually uses the `direction` variable for its direction, rather than property value
157
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
158
end event
159
160