Debian Codegraph @

scripts/frigate_shooting.lua

raw symbols SCIP
1 local blueprints = require 'blueprints'
2
3 local missile_speed = 1
4 local shot_cooldown_time = 6
5 local shot_capacity = 8
6 local shot_reload_rate = 1.2 / 60
7
8 local shots = 0
9 local cooldown = 0
10
11 function is_empty()
12 return shots < 1
13 end
14
15 function is_reloaded()
16 return shots == shot_capacity
17 end
18
19 function is_cooled_down()
20 return cooldown == 0
21 end
22
23 function is_ready_to_shoot()
24 return is_cooled_down() and is_reloaded()
25 end
26
27 function update()
28 cooldown = math.max(0, cooldown - 1)
29 shots = math.min(shots + shot_reload_rate, shot_capacity)
30 end
31
32 function shoot()
33 if cooldown == 0 and shots >= 1 then
34 shots = shots - 1
35 cooldown = shot_cooldown_time
36 local start_vel = missile_speed * self.transform.facing + self.ship.velocity
37 game.actors.new(blueprints.missile,
38 {'transform', pos=self.transform.pos},
39 {'ship', velocity=start_vel, player=self.ship.player})
40 end
41 end