Scoring system issues
I was wanting to add a timer and a score onto my project and display them in opposite sides of the screen. They are not working how I want them to however. For the score I want it to add one point every time you touch an enemy. For that I've created a score variable and then added a distance check in the init function to see how close the player is to the enemy.
if distance(player.x, player.y, enemy.x, enemy.y) < 10 then score += 1 end
the issue is that this doesn't seem to actually change the score variable.. My full code is below, but if anyone has any suggestions it would be appreciated.
init = function()
score =0 timer = 10
player = object end player.x = 0 player.y = 0 player.speed = 2
enemy = object end enemy.x = randRange (-160,160) enemy.y = 100 enemy.speed = 1.5 end
update = function()
if keyboard.W then player.y += player.speed end
if keyboard.S then player.y -= player.speed end
if keyboard.A then player.x -= player.speed end
if keyboard.D then player.x += player.speed end
enemy.y -= enemy.speed if enemy.y < -110 then enemy.y = 110 end
if timer > 0 then timer -= 1/60 else if timer < 0 then timer = 10 end end
if distance(player.x, player.y, enemy.x, enemy.y) < 10 then score += 1 end
if distance(player.x, player.y, enemy.x, enemy.y) < 10 then init () end
end
draw = function() screen.clear() screen.setFont("RetroGaming") screen.drawSprite("player", player.x, player.y, 30, 30) screen.drawSprite("enemy",enemy.x, enemy.y, 30, 30) screen.drawText("Time: " + timer, 200, 80, 15, "rgb(250,100, 200)") screen.drawText("Score: " + score,-200, 80, 15, "rgb(250, 100, 200)")
end