Code: Select all
function enemy_player_collide()
for i,v in ipairs(enemy) do
for ia, va in ipairs(player) do
if va.x == v.x and
va.y == v.y then
va.x = 0
end
end
end
end
Code: Select all
function enemy_player_collide()
for i,v in ipairs(enemy) do
for ia, va in ipairs(player) do
if va.x == v.x and
va.y == v.y then
va.x = 0
end
end
end
end
Code: Select all
local players = {
{x = 5, y = 5}
}
local enemies = {
[1] = {x = 5, y = 5, enabled = true},
[2] = {x = 6, y = 6, enabled = true},
[3] = {x = 3, y = 3, enabled = true}
}
function collide()
for _,player_value in pairs(players) do
for enemy_key, enemy_value in pairs(enemies) do
if player_value.x == enemy_value.x and player_value.y == enemy_value.y then
-- kill the enemy?
enemies[enemy_key].enabled = false
print("Killed the enemy "..enemy_key)
print("There are "..count_enabled().." enemies left to defeat.")
end
end
end
end
function count_enabled()
local counter = 0 -- count how many enemies have the flag set to true
for enemy_key, enemy_value in pairs(enemies) do
if enemies[enemy_key].enabled == true then
counter = counter + 1
end
end
return counter
end
collide()
Users browsing this forum: Ahrefs [Bot] and 5 guests