Earning extra lives with Star Shooter Help Please

Hi, I’m working on simple Star shooter game project where the ship shoots asteroids and earns points everytime it shoots an asteroid, each asteroid hit is gains 10 points. The player starts out with 3 lives and I want it to make it where when the player reaches over 1000 points that the player earns an extra life for every time the player reaches every thousand like over 1000 for an extra life and over 2000 for an extra life, etc. Can someone help me with this portion of the code? I believe I need to use some sort of loop but don’t know how. Lives is declared as:

local lives = 3 (to start out with 3 lives)
[import]uid: 119394 topic_id: 21863 reply_id: 321863[/import]

In the function where you add to the score you could use an if statement to see whether or not it was equal to 1000, 2000, etc. and then do lives = lives + 1.

There would be a few ways of tackling this logistically but all would likely revolve around a method similar to that.

Does this make sense or do you need something a little more thorough? (It’s OK if you do, when you haven’t done something before it can seem trickier than it is.)

Let me know, always happy to help.

Peach :slight_smile: [import]uid: 52491 topic_id: 21863 reply_id: 86991[/import]

Hi Peach! Thanks for the reply. I tried an IF statement something similar to what you said but the problem is that I earn an extra life ONLY when it reaches 1000, not 1001 etc. What I’m trying to do is make it earn an extra life after points reach after every 1000 or over. , same when it reaches over 2000 for another life and 3000 for another life, etc. There should be some sort of loop I believe where it gives an extra life after every 1000 or over instead of manually typing an IF statement to make it equal to 1000. Hope my question is understandable :slight_smile: [import]uid: 119394 topic_id: 21863 reply_id: 87020[/import]

If you want to do a for loop you could but honestly I think the easiest way of doing it is with a single if statement, it doesn’t have to be = 1000, it could be >= then adjust for 2000, 3000, etc.

Run the below code, plug and play, does what you want;

[lua]display.setStatusBar(display.HiddenStatusBar)

local bg = display.newRect( 0, 0, 320, 480 )

local score = 0
local lives = 3
local nextLife = 1000

local scoreText = display.newText(score, 260, 5, native.systemFont, 16)
scoreText:setTextColor(0, 0, 0)

local livesText = display.newText(lives, 10, 5, native.systemFont, 16)
livesText:setTextColor(0, 0, 0)

local function upScore()
score = score + 12
scoreText.text = score
if score >= nextLife then
lives = lives + 1
livesText.text = lives
nextLife = nextLife + 1000
end
end
timer.performWithDelay(10, upScore, 0)[/lua]

Peach :slight_smile: [import]uid: 52491 topic_id: 21863 reply_id: 87065[/import]