-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprojectile.lua
More file actions
88 lines (69 loc) · 3.31 KB
/
Copy pathprojectile.lua
File metadata and controls
88 lines (69 loc) · 3.31 KB
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
love = require("love")
vector = require("libs.vector.vector")
function CreateProjectile(start_pos, end_pos, weapon_type, shooter)
local start_end_vector = end_pos - start_pos
start_end_vector:norm()
local projectile = {}
projectile.position = start_pos -- The current position of the projectile
projectile.origin = start_pos -- The starting position of the projectile
projectile.unit_vector = start_end_vector -- The vector between the start and end of the projectile
projectile.hit_list = {} -- List of things already hit, to prevent something being hit every frame
projectile.shooter_id = shooter.id -- The id of the shooter, to prevent the shooter from being hit when the projectile is fired
projectile.time_created = love.timer.getTime()
local current_speed_vector = shooter.state.speed
local current_speed = current_speed_vector:getmag()
if weapon_type == nil then
-- Default/testing weapon type
projectile.range = 5000
projectile.damage = 1
projectile.speed = 3000
projectile.speed_penalty = 1000
local stability = math.min(current_speed/0.5,1)
projectile.spread = (math.random()-0.5) * 0.3 * stability
--print(projectile.spread)
if projectile.spread ~= 0 then
local heading = projectile.unit_vector:heading()
heading = heading + projectile.spread
projectile.unit_vector = vector.fromAngle(heading)
end
projectile.pierce = weapon_type.pierce
projectile.size = 0.15
else
-- Taking the equipped weapon type's projectiles
projectile.range = weapon_type.range
projectile.damage = weapon_type.damage
projectile.lifetime = weapon_type.lifetime
if shooter.state.isStill() then
projectile.damage = projectile.damage * weapon_type.head_shot_multiplier --Normal damage if the player is standing still, headshot damage otherwise
end
projectile.speed = weapon_type.bullet_speed
projectile.speed_penalty = weapon_type.bullet_speed_penalty
local stability = math.min(current_speed/weapon_type.stability,1)
projectile.spread = (math.random()-0.5) * weapon_type.spread * stability
if projectile.spread ~= 0 then
local heading = projectile.unit_vector:heading()
heading = heading + projectile.spread
projectile.unit_vector = vector.fromAngle(heading)
end
projectile.pierce = weapon_type.pierce
projectile.size = weapon_type.size
end
projectile.dead = function () return ((love.timer.getTime() - projectile.time_created) > projectile.lifetime) or projectile.pierce < 0 end
projectile.Progress = function (dt)
projectile.position = projectile.position + ((projectile.unit_vector*dt)*projectile.speed)
projectile.speed = projectile.speed - (projectile.speed_penalty * dt)
end
projectile.Render = function ()
local pos = GAME.functions.getScreenPosition(projectile.position)
love.graphics.circle("fill",pos.x,pos.y, projectile.size*ZOOM_MULT)
end
projectile.idInHitList = function (id)
for i, value in pairs(projectile.hit_list) do
if id == value then
return true
end
end
return false
end
return projectile
end