-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdoors.lua
114 lines (96 loc) · 3.58 KB
/
doors.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
local doorsClosing = false
local doorsCanClose = false
-- make doors open when mario gets close to it
---@param m MarioState
---@param o Object
local function should_push_or_pull_door(m, o)
local dx = o.oPosX - m.pos.x
local dz = o.oPosZ - m.pos.z
local dYaw = o.oMoveAngleYaw - atan2s(dz, dx)
if dYaw >= -0x4000 and dYaw <= 0x4000 then
return 1
else
return 0
end
end
---@param o Object
local function door_loop(o)
local selectedLevel = levels[gGlobalSyncTable.selectedLevel]
if selectedLevel.disabledBhvs ~= nil then
for _, bhv in pairs(selectedLevel.disabledBhvs) do
if bhv == id_bhvDoor then
o.oAction = 0
o.collisionData = gGlobalObjectCollisionData.door_seg3_collision_0301CE78
return
end
end
end
if o.oAction == 0 then
-- if mario is close enough, set action to the custom open door action, 5
if dist_between_objects(o, gMarioStates[0].marioObj) <= 400 then
o.oAction = 5
end
end
if o.oAction == 5 then
if o.oTimer == 0 then
-- when the object timer is 0 (when we first set the action to 5) play a soudn and init the animation based off of if we are pulling or pushing the door
if should_push_or_pull_door(gMarioStates[0], o) == 1 then
-- push
cur_obj_init_animation(1)
else
-- pull
cur_obj_init_animation(2)
end
cur_obj_play_sound_2(SOUND_GENERAL_OPEN_WOOD_DOOR)
end
-- 40 is the anim frame where the door is fully opened
if o.header.gfx.animInfo.animFrame >= 40 then
o.header.gfx.animInfo.animFrame = 40
o.header.gfx.animInfo.prevAnimFrame = 40
end
-- if we are far from the door, go to the custom close door action, 6
if dist_between_objects(o, gMarioStates[0].marioObj) > 400 then
o.oAction = 6
end
end
if o.oAction == 6 then
-- since the action is no longer 5, the animation continues, 78 is the end of the animation
if o.header.gfx.animInfo.animFrame >= 78 then
-- play object sound, and set action to 0
cur_obj_play_sound_2(SOUND_GENERAL_CLOSE_WOOD_DOOR)
o.oAction = 0
end
end
end
id_bhvDoor = hook_behavior(id_bhvDoor, OBJ_LIST_SURFACE, false, function (o) o.collisionData = nil end, door_loop, "door")
-- make star door open when mario gets close to it
-- this code is by Sunk and Blocky
function star_door_loop(o)
local selectedLevel = levels[gGlobalSyncTable.selectedLevel]
if selectedLevel.disabledBhvs ~= nil then
for _, bhv in pairs(selectedLevel.disabledBhvs) do
if bhv == id_bhvDoor then
o.oAction = 0
o.collisionData = gGlobalObjectCollisionData.inside_castle_seg7_collision_star_door
return
end
end
end
if dist_between_objects(gMarioStates[0].marioObj, o) <= 400 then
if o.oAction == 0 then
o.oAction = 1
doorsClosing = false
elseif o.oAction == 3 and not doorsClosing then
o.oAction = 2
end
doorsCanClose = false
elseif o.oAction == 3 then
if not doorsCanClose and not doorsClosing then
o.oAction = 2
doorsCanClose = true
else
doorsClosing = true
end
end
end
id_bhvStarDoor = hook_behavior(id_bhvStarDoor, OBJ_LIST_SURFACE, false, function (o) o.collisionData = nil end, star_door_loop, "star-door")