Once you purchase and download Codea for the first time, you immediately have games in the program with example code to to help you out and for you to practice with. It show you how to make a hero character and enemies for a simple game, but my question is how do you create code to get a character to have more than one life and respawn after the character has died without getting a game over message. For example like starting out a game with the parameter displaying Lives: 5 and do not lose the game unless the parameter says Lives: 0. Could someone please show me how to do this. I want to do this when I practice making my first games.
@strotherdw I added code to the example I gave you in another discussion. Drag the sprite over the circle to simulate a hit. The lives will decrement each time. Game over at 0. There already are example programs in Codea for you to practice with. Maybe just not exactly what you want.
displayMode(FULLSCREEN)
function setup()
x=0 -- set x,y to 0
y=0
lives=5
hit=false
end
function draw()
background(40, 40, 50) -- set screen background color
fill(219, 40, 40, 255) -- set color for ellipse
ellipse(WIDTH/2,HEIGHT/2,30) -- draw ellipse at center of screen
sprite("Planet Cute:Character Pink Girl",x,y) -- draw sprite at x,y
checkCollision()
fill(255)
if hit then
text("hit",WIDTH/2,HEIGHT-100)
end
if lives==0 then
text("GAME OVER",WIDTH/2,HEIGHT-140)
elseif sub then
lives=lives-1
sub=false
else
text("Lives left "..lives,WIDTH/2,HEIGHT-140)
end
end
function touched(t)
x=t.x -- set x to touched x value
y=t.y -- set y to touched y value
end
function checkCollision()
v1=vec2(x,y)
d=v1:dist(vec2(WIDTH/2,HEIGHT/2))
if d<50 then
if not hit then
sub=true
end
hit=true
else
hit=false
end
end
Thank You Dave 1707! I’m going to copy and paste this code right away and see what I can learn from it. I’ll let you know how this turns out later, but this good. Thank you very much.