Files
kubeinvaders/main/bullet.script
2021-01-02 18:35:13 +01:00

45 lines
1.8 KiB
Plaintext

local COLLISION_RESPONSE = hash("collision_response")
function refresh_pods()
http.request(endpoint .. "/api/v1/namespaces/" .. namespace .. "/pods", "GET", pod_api.http_pod_result,headers)
end
function init(self)
msg.post(".", "acquire_input_focus")
headers = {
["Authorization"] = "Bearer " .. token ,
["Accept"] = "application/json",
["Content-Type"] = "application/json"
}
end
function on_message(self, message_id, message, sender)
print "[on_message] bullet object received a message"
if message_id == COLLISION_RESPONSE then
print "[on_message] collision detected"
if bullet_collision_action == "delete_pod" then
msg.post(message["other_id"], "play_animation", {id = hash("delete")})
for i,value in ipairs(current_pods) do
print("[on_message] pod of collision is " .. value["color"] .. " " .. "id is " .. message["other_id"] )
if value["color"] == "white" and value["id"] == message["other_id"] then
old_pos = go.get_position(value["id"])
print ("on_message] position of pod to be deleted is " .. old_pos)
current_pods[i] = { id = value["id"] , color = "red", collision = true, old_position = old_pos, pod_name = value["pod_name"] }
go.delete(value["id"])
end
end
elseif bullet_collision_action == "kubelinter" then
for i,value in ipairs(current_pods) do
print("[on_message] pod of collision is " .. value["color"] .. " " .. "id is " .. message["other_id"] )
if value["color"] == "white" and value["id"] == message["other_id"] then
pod_name = value["pod_name"]
end
end
print("start kubelinter analysis of " .. message["other_id"] .. " pod = " .. pod_name)
msg.post(message["other_id"], "play_animation", {id = hash("view")})
kubelinter_pod = pod_name
end
go.delete()
end
print "[on_message] end of on_message function"
end