-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaser.script
More file actions
35 lines (31 loc) · 1.03 KB
/
laser.script
File metadata and controls
35 lines (31 loc) · 1.03 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
function init(self)
self.life = 1.5
self.speed = 200
-- Get the bullet's own rotation quaternion
local rotation_quat = go.get_rotation()
-- Rotate a unit vector (1,0,0) using the quaternion
self.direction = vmath.rotate(rotation_quat, vmath.vector3(1, 0, 0))
self.step = vmath.vector3(self.direction.x, self.direction.y, 0)
self.damage = 0
table.insert(_G.lasers, go.get_id()) -- Store this person's ID
end
function update(self, dt)
local pos = go.get_position()
pos = pos + self.step * self.speed * dt
go.set_position(pos)
self.life = self.life - dt
if self.life < 0 then
msg.post("/initfactory#init_spawner", "gone", {r_id = go.get_id(), type="laser"})
go.delete()
end
end
function on_message(self, message_id, message, sender)
if message_id == hash("collision_response") then
msg.post(message.other_id, "hit", {damage = self.damage})
msg.post("/initfactory#init_spawner", "gone", {r_id = go.get_id(), type="laser"})
go.delete()
end
if message_id == hash("damage_amt") then
self.damage = message.damage
end
end