Enemy Question
i watched the tutorial for strike and interact and my problem is that the enemys are duplicate unlimited
is this code right?
//init initEnemies = function() enemies = [] for i = 1 to 3 spawnEnemy() end end
spawnEnemy = function() local enemy = object active = true size = 40 end local placed = false while not placed enemy.x = randRange(-175, 175) enemy.y = randRange(-75, 45) if distance(enemy.x ,enemy.y , player.x,edd ddrdwa player.y) > 30 then placed = true end end enemies.push(enemy) end
updateEnemy = function() temp = [] for enemy in enemies if distance(enemy.x,enemy.y,player.sword_x,player.sword_y) < 15 then enemy.active = false end if enemy.active then temp.push(enemy) end end enemies = temp end
drawEnemies = function() for enemy in enemies screen.drawSprite("cookie",enemy.x,enemy.y,50 ,50 ) end end //player screen.setDrawScale(player.facing, 1) screen.drawSprite("maincharakter", player.x, player.y, player.width, player.height)
if map == "flurvorinformatik" then
end
if player.attack_timer > 0 then screen.setDrawAnchor(0.5, 0) screen.drawSprite("stift",player.sword_x,player.sword_y, 32, 12 ) screen.setDrawAnchor(0,0) end screen.setDrawScale(1,1)
//drawfunction draw = function() drawStart() drawPlayer() drawDoor() drawLife() playeranim()
if distance(player.x, player.y, door.x, door.y) < 25 then screen.clear map = "flurvorinformatik" drawFlur()
if map == "flurvorinformatik" then drawFlur()
drawPlayer() spawnEnemy() drawEnemies() end
if game_paused then
drawPauseMenu()
end
end end