[SOLVED] Collectible Object Spawns On Player Which Increases Score More Than Once
Posted: Tue Jun 07, 2022 11:44 pm
Hello everyone!
The game
I'm working on my first small Love game to learn Lua and Love2d mechanics the game consists of a player who collects apples to increase the score. There is a timer and a high score feature to see how many you can collect in a limited amount of time.
What I want to happen
What I want to happen is that when the apple is spawned on screen it doesn't spawn near the player because if it spawns on the player it causes the score to increase multiple times when the score is just supposed to go up by one. While this
What I have right now
The whole game is complete but this one bug makes the score and high score feature useless as the score can go up dramatically.
What I want help with
What I want help with is how to make the apple spawn in a random position but not near the player so it can't bug out and increase the score by a lot.
To produce the bug
Simply collect apples and when the apple is randomly changed to a new position that is next to the player you should see the score go up for how long you are on that apple.
Bug Area
I believe this is where the bug originates because this is the collision checker that makes the apple change position and increases its score.
The game
I'm working on my first small Love game to learn Lua and Love2d mechanics the game consists of a player who collects apples to increase the score. There is a timer and a high score feature to see how many you can collect in a limited amount of time.
What I want to happen
What I want to happen is that when the apple is spawned on screen it doesn't spawn near the player because if it spawns on the player it causes the score to increase multiple times when the score is just supposed to go up by one. While this
What I have right now
The whole game is complete but this one bug makes the score and high score feature useless as the score can go up dramatically.
What I want help with
What I want help with is how to make the apple spawn in a random position but not near the player so it can't bug out and increase the score by a lot.
To produce the bug
Simply collect apples and when the apple is randomly changed to a new position that is next to the player you should see the score go up for how long you are on that apple.
Bug Area
I believe this is where the bug originates because this is the collision checker that makes the apple change position and increases its score.
Code: Select all
function T:CheckOverlap()
if (P.y + P.h > T.y) and (P.y < T.y + T.h) and (P.x + P.w > T.x) and (P.x < T.x + T.w) then
math.randomseed(os.time())
T.x = math.random(love.graphics:getWidth())
T.y = math.random(love.graphics:getHeight())
Score = Score + 1
end
end