Function question
Posted: Tue Apr 24, 2012 8:21 pm
Hi, this might be a noob question but I have't actually needed it until now. For my game I am doing some collision detection in combination with movement of the character. Looks something like
love.update(dt)
if key.isDown (direction) then
check coordinates
if coordinates are ok then
change playerX, playerY
But this is good for my character, I would like to make the enemies to move on the same pattern and since to make the check for each enemy in the update function is too long I though to put the above in a function and just to call it whenever I want some movement/collision detection to take place. The new function should look something like movementDirection (objectX, objectY, speed). I have attached the code for it. The problem is I haven't actulaly needed to call outer function so far, and don't know how exactly to do it. Any advice would be nice.
love.update(dt)
if key.isDown (direction) then
check coordinates
if coordinates are ok then
change playerX, playerY
But this is good for my character, I would like to make the enemies to move on the same pattern and since to make the check for each enemy in the update function is too long I though to put the above in a function and just to call it whenever I want some movement/collision detection to take place. The new function should look something like movementDirection (objectX, objectY, speed). I have attached the code for it. The problem is I haven't actulaly needed to call outer function so far, and don't know how exactly to do it. Any advice would be nice.