-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenemy.lua
More file actions
129 lines (101 loc) · 4.71 KB
/
enemy.lua
File metadata and controls
129 lines (101 loc) · 4.71 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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
_G.enemyID = 1
function ReturnEnemy(type, position)
local enemy = {}
enemy.id = enemyID
enemyID = enemyID + 1
if type == nil then
local state = {}
local stats = {}
stats.acceleration = 200
stats.max_speed = 100
stats.detect_range = 300
state.position = vector.new(math.random(-500,500),math.random(-500,500))
state.health = 5
state.size = 20
state.speed = vector.new(0,0)
state.scoped_in = false
state.player_in_sight = true
state.dead = function () return enemy.state.health <= 0 end
state.fireConditionsMet = function() return enemy.state.position:dist(GAME.player.state.position) < 200 end
state.secondaryConditonsMet = function () return false end
state.movementConditionsMet = function() return enemy.state.position:dist(GAME.player.state.position) < 300 end
state.isStill = function () return (enemy.state.speed == vector.new(0,0)) end
enemy.equips = {}
local gun_file = require("Weapons.Guns.G19")
enemy.equips.gun = ReturnGun()
enemy.stats = stats
enemy.state = state
enemy.Render = function ()
local x,y = (GAME.functions.getScreenPosition(enemy.state.position)):unpack()
love.graphics.setColor(0.8,0.1,0.1)
love.graphics.circle("fill", x,y, enemy.state.size*ZOOM_MULT)
love.graphics.setColor(1, 1, 1)
end
enemy.DesiredMovementVector = function (move_to_point)
local desired_movement = move_to_point - enemy.state.position + GAME.player.state.position
--print("move_to_point: ", move_to_point)
return desired_movement:norm()
end
enemy.Acceleration = function (dt, point)
local desired_movement = enemy.DesiredMovementVector(point)
local max_speed, acceleration = enemy.stats.max_speed, enemy.stats.acceleration*dt
if enemy.equips and enemy.equips.gun and enemy.equips.gun ~= nil then
if enemy.state.scoped_in then
max_speed = max_speed - enemy.equips.gun.aiming_walk_speed_penalty
end
end
local max_speed_x, max_speed_y = (desired_movement * max_speed):unpack()
local new_speed_x, new_speed_y = (enemy.state.speed + (acceleration * desired_movement)):unpack()
-- Limit left speed
if new_speed_x < -max_speed_x then
new_speed_x = new_speed_x + acceleration
if new_speed_x > -max_speed_x then -- ease the speed to the intended range if not in the intended range
new_speed_x = -max_speed_x
end
end
-- Limit right speed
if new_speed_x > max_speed_x then
new_speed_x = new_speed_x - acceleration
if new_speed_x < max_speed_x then -- ease the speed to the intended range if not in the intended range
new_speed_x = max_speed_x
end
end
if enemy.equips and enemy.equips.gun and enemy.equips.gun ~= nil then
if enemy.state.scoped_in then
max_speed_y = max_speed_y - enemy.equips.gun.aiming_walk_speed_penalty
end
end
-- Limit up speed
if new_speed_y < -max_speed_y then
new_speed_y = new_speed_y + acceleration
if new_speed_y > -max_speed_y then -- ease the speed to the intended range if not in the intended range
new_speed_y = -max_speed_y
end
end
-- Limit down speed
if new_speed_y > max_speed_y then
new_speed_y = new_speed_y - acceleration
if new_speed_y < max_speed_y then -- ease the speed to the intended range if not in the intended range
new_speed_y = max_speed_y
end
end
enemy.state.speed = vector.new(new_speed_x, new_speed_y)
end
enemy.Decelerate = function (dt)
if enemy.state.speed:dist(ZERO_VECTOR) > 0.1 then
local speed_unit_vector = enemy.state.speed:norm()
local speed_reduction = speed_unit_vector * enemy.stats.acceleration
enemy.state.speed = enemy.state.speed - (speed_reduction*dt)
else
enemy.state.speed = ZERO_VECTOR
end
end
enemy.Movement = function (dt)
enemy.state.position = enemy.state.position+(enemy.state.speed*dt)
end
enemy.DebugRender = function()
end
else
end
return enemy
end