-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrocket.script
More file actions
60 lines (53 loc) · 1.82 KB
/
rocket.script
File metadata and controls
60 lines (53 loc) · 1.82 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
function init(self)
self.life = 1.5
self.speed = 200
local rotation_quat = go.get_rotation()
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
self.design = nil
table.insert(_G.rockets, 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="rocket"})
go.delete()
end
if self.design == "arrows" then
msg.post("#sprite", "play_animation", {id = hash("arrow")})
elseif self.design == "stone" then
msg.post("#sprite", "play_animation", {id = hash("pebble")})
else
msg.post("#sprite", "play_animation", {id = hash("rocket")})
end
end
function on_message(self, message_id, message, sender)
if message_id == hash("collision_response") then
msg.post("/initfactory#init_spawner", "gone", {r_id = go.get_id(), type="rocket"})
msg.post(message.other_id, "hit", {damage = self.damage})
go.delete()
end
if message_id == hash("info") then
self.damage = message.damage
self.life = message.life
self.design = message.design
if message.design == "arrows" then
local rotation_quat = go.get_rotation()
local angle = math.rad(-45)
local new_rotation = vmath.quat_rotation_z(angle) * rotation_quat
go.set_rotation(new_rotation)
local new_scale = go.get_scale() * 0.02
go.set_scale(new_scale)
elseif message.design == "stone" then
local angle = math.rad(math.random(-180,180))
local new_rotation = vmath.quat_rotation_z(angle)
go.set_rotation(new_rotation)
local new_scale = go.get_scale() * 0.01
go.set_scale(new_scale)
end
end
end