-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbullet.lua
86 lines (72 loc) · 2.66 KB
/
bullet.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
-- custom obj fields
define_custom_obj_fields({
oBulletOwner = 'u32',
})
---@param o Object
local function bullet_init(o)
o.oFlags = OBJ_FLAG_UPDATE_GFX_POS_AND_ANGLE | OBJ_FLAG_SET_FACE_ANGLE_TO_MOVE_ANGLE
o.hitboxRadius = 200
o.hitboxHeight = 200
obj_set_billboard(o)
local localOwner = network_local_index_from_global(o.oBulletOwner)
local m = gMarioStates[localOwner]
if gGlobalSyncTable.modifier == MODIFIER_FLY
or m.action & ACT_GROUP_MASK == ACT_GROUP_SUBMERGED then
o.oMoveAnglePitch = m.faceAngle.x
end
o.oMoveAngleYaw = m.faceAngle.y
local speed = m.forwardVel + 150
-- shoot backwards
if m.controller.buttonDown & D_JPAD ~= 0 then
speed = -speed
end
-- flip if our action is set to turning around
if m.action == ACT_SIDE_FLIP
or m.action == ACT_SIDE_FLIP_LAND then
speed = -speed
end
o.oVelX = speed * coss(o.oFaceAnglePitch) * sins(o.oFaceAngleYaw)
if gGlobalSyncTable.modifier == MODIFIER_FLY
or m.action & ACT_GROUP_MASK == ACT_GROUP_SUBMERGED then
o.oVelY = speed * sins(o.oFaceAnglePitch)
o.oVelY = -o.oVelY
end
o.oVelZ = speed * coss(o.oFaceAnglePitch) * coss(o.oFaceAngleYaw)
end
---@param o Object
local function bullet_loop(o)
if o.oTimer > 1 * 30 then
obj_mark_for_deletion(o)
end
cur_obj_move_using_vel()
if collision_find_floor(o.oPosX, o.oPosY, o.oPosZ) == nil then
obj_mark_for_deletion(o)
end
local localOwner = network_local_index_from_global(o.oBulletOwner)
local m = nearest_mario_state_to_object(o)
-- if we get hit, and we are the victim, handle pvp
if dist_between_objects(o, m.marioObj) < 200
and m.playerIndex == 0
and m.invincTimer <= 0
and localOwner ~= 0 then
handle_projectile_pvp(localOwner, m.playerIndex, o)
obj_mark_for_deletion(o)
end
end
function hud_bullet(gunCooldown, maxGunCooldown)
if gPlayerSyncTable[0].state == SPECTATOR
or gPlayerSyncTable[0].state == WILDCARD_ROLE then return end
if gGlobalSyncTable.roundState == ROUND_ACTIVE
and gGlobalSyncTable.gamemode == SARDINES
and gPlayerSyncTable[0].state == RUNNER then return end
-- clamp gun cooldown
gunCooldown = clampf(gunCooldown, 0, maxGunCooldown)
local text = ""
if gunCooldown < maxGunCooldown then
text = "Recharging (" .. math.floor((maxGunCooldown - gunCooldown) / 30 * 10) / 10 .. ")"
else
text = "Shoot (" .. button_to_text(binds[BIND_GUN].btn) .. ")"
end
render_bar(text, gunCooldown, 0, maxGunCooldown, 0, 162, 255)
end
id_bhvBullet = hook_behavior(nil, OBJ_LIST_DESTRUCTIVE, false, bullet_init, bullet_loop)