Randomized Mob Spawning spamming mobs
Posted: Fri Jan 18, 2013 9:47 pm
For some reason, my randomized mob spawning(randomizes the mob's X and Y coordinates) keeps spamming the mob, not just spawning it once. How can I fix this?
main
entity
spawn
main
Code: Select all
require "core/player"
require "core/physics"
require "core/font"
require "core/entity"
function love.load()
player_create() --Creates the player
entity_mob() --Spawns the entity "mob"
love.graphics.setBackgroundColor(104, 136, 248)
end
function love.update(dt)
player_move(dt)
end
function love.draw()
player_draw()
entity_mobDraw()
end
function love.mousepressed(x, y, button)
end
Code: Select all
require "core/spawn"
entity = {}
entity_limit = false
function entity_spawn(entity)
end
function entity_mob()
entity.mob = {}
entity.mob.body = love.physics.newBody(world, entX, entY, "dynamic")
entity.mob.shape = love.physics.newRectangleShape(15, 20)
entity.mob.fixture = love.physics.newFixture(entity.mob.body, entity.mob.shape, 1)
end
function entity_mobDraw()
spawn_random()
love.graphics.setColor(166, 166, 50)
love.graphics.rectangle("fill", entX, entY, 15, 20)
entity_limit = true
end
function entity_limit()
end
Code: Select all
local width = love.graphics.getWidth()
local height = love.graphics.getHeight()
function spawn_random()
x = math.random(1, width)
y = math.random(1, height)
entX = x
entY = y
if x - 10 < objects.player.body:getX() then
entX = x
elseif y - 10 < objects.player.body:getY() then
entY = y
end
end