diff --git a/main/spaceship.script b/main/spaceship.script index 4f48be6..fe3e342 100644 --- a/main/spaceship.script +++ b/main/spaceship.script @@ -129,24 +129,41 @@ function http_update_pod_result(self, _, response) end function ai() + launch_bullet = false msg.post("ui#gui", "error",{ errormessage = "" }) if automatic == false then return end for i=1,1 do - rand_pod = math.random(100, 1000) + rand_pos = math.random(100, 1100) end pos = go.get_position() pos.y = 220 go.set_position(pos) - pos.x = rand_pod - go.animate(go.get_id(), "position.x", go.PLAYBACK_ONCE_FORWARD, pos.x, go.EASING_INQUAD, 1,0, function() - pos = go.get_position() - bullet = factory.create("/bullet#bulletfactory", pos) - go.animate(bullet, "position.y", go.PLAYBACK_ONCE_FORWARD, 700, go.EASING_INQUAD, 1,0,function() - go.delete(bullet) - end) - end) + pos.x = rand_pos + + for i,value in ipairs(current_pods) do + if value["color"] == "white" then + position_of_pod = go.get_position(value["id"]) + if (pos.x > position_of_pod.x and pos.x - position_of_pod.x < 30) then + launch_bullet = true + elseif (position_of_pod.x > pos.x and position_of_pod.x - pos.x < 30) then + launch_bullet = true + end + end + end + + if launch_bullet == true then + go.animate(go.get_id(), "position.x", go.PLAYBACK_ONCE_FORWARD, pos.x, go.EASING_INQUAD, 1,0, function() + pos = go.get_position() + bullet = factory.create("/bullet#bulletfactory", pos) + go.animate(bullet, "position.y", go.PLAYBACK_ONCE_FORWARD, 700, go.EASING_INQUAD, 1,0,function() + go.delete(bullet) + end) + end) + else + go.animate(go.get_id(), "position.x", go.PLAYBACK_ONCE_FORWARD, pos.x, go.EASING_INQUAD, 1,0) + end end function update_pod() @@ -295,7 +312,7 @@ function init(self) timer.repeat_seconds(0.3, function() update_pod() end) - timer.repeat_seconds(2, function() + timer.repeat_seconds(1, function() ai() end) set_pods()