creating a game - lost a life

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
star0629
Posts: 22
Joined: Thu Nov 28, 2013 9:04 pm

creating a game - lost a life

Post by star0629 » Thu Nov 28, 2013 9:13 pm

Basically so far i got the background moving with gaps in between which the character has to jump over(if that makes sense)... What I am planning is if the character bumps into an object e.g flying bird or something... the character should lose a life. trouble is i am unsure how to code for the character to lose their second life if they bump into another object. so far i have something like this...

on openCard
put "life1" into lives[1]
put "life2" into lives[2]
put "life3" into lives[3]
end openCard

on startGame
activateScreenUpdates
put true into sGameRunning
end startGame

on detectCollisions
put 0 into liveslost
if intersect (button "box", image "horse") then
put liveslost + 1 into lives[liveslost]

// next line is wrong and not sure how to code it
set the visible of button lives[liveslost]["liveslost"] to false

end if
end detectCollisions

so if it bumps into the object it loses a life and in turn an empty heart shape image is in its place.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: creating a game - lost a life

Post by Simon » Thu Nov 28, 2013 11:07 pm

Hi star0629,
Welcome to the forums :)

I'm going to make an assumption that you are a beginner, if not forget I wrote anything.
You've started off using arrays and that's not a bad thing just a bigger leap then is needed (at least for 3 "lives").

Code: Select all

local tLiveslost
on detectCollisions
   if tLiveslost >= 3 then gameOver --this is your 3 lives
   if intersect (button "box", image "horse") then
      add 1 to tLiveslost -- count down the remaining lives
      set the icon of button "box" to "emptyHeart" --Change the image of the Runner button to something else
end if
end detectCollisions

on gameOver
   put 0 into tLiveslost
   --do your new game stuff here
end gameOver
emptyHeart is just an imported image.
One thing strange about the line
set the icon of button "box" to "emptyHeart"
is I thought it would be
set the icon of button "box" to image "emptyHeart"
But it's not.

I hope this gets you started, if not just keep asking questions.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

star0629
Posts: 22
Joined: Thu Nov 28, 2013 9:04 pm

Re: creating a game - lost a life

Post by star0629 » Fri Nov 29, 2013 11:19 pm

thanks for the help I understand better where i am going with this now..but still struggling to code the bit where the character loses their second life in the game..so if they bump into the object for the second time is should delete the second heart

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: creating a game - lost a life

Post by Simon » Sat Nov 30, 2013 12:09 am

hmm... possibly

Code: Select all

add 1 to tLiveslost
You follow?

Simon
Edit: Sorry, I see you are using a "heart" as a count down thingy as well as the "death" button.
After the 5th line in my code above, what will tLiveslost contain after the second time through the code?
Can you work out what to do now?
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

star0629
Posts: 22
Joined: Thu Nov 28, 2013 9:04 pm

Re: creating a game - lost a life

Post by star0629 » Sat Nov 30, 2013 11:12 am

Sorry i dont think i am making myself clear enough :( ...
Okay so forget the box that was just something to start me of the box is in fact a bird which i going across the screen.
At the top of the game screen i have images of 3 hearts named "life1 "life2" "life3" those are visible at the start of the game.
When the "horse" interacts with the "bird"
"Life1" disappears and a image of a empty heart appears in its place named "lostlife1"

I am finding it hard to code for "life2" to disappear when the "horse" interacts with the "bird"

Hence the arrays at the beginning of the code, so when i add 1 to lostlives the counter will understand somehow i am talking about "life1" to disappear into another image. When lostlives = 2 (second interaction with the bird) "life2" disappears into another image "lostlife2"

And when lostlives >=3 then
//game will end and got to card x

Livecode is soo not for me but i enjoy every bit of it and i am determined to solve it somehow.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: creating a game - lost a life

Post by Simon » Sat Nov 30, 2013 12:28 pm

Hi star0629,
Well you have started really well!
it's great that you named the "hearts" numerically, but you are going to have to do a little more work.
Lets just talk about 1 location and two images (full heart/empty heart), they are one on top of the other. Lets call them "life1" and "empty1"

Again with the code I posted above;

Code: Select all

...
add 1 to tLiveslost
hide image "life" & tLiveslost --this concatenates to "life1" on the first run through
show image "empty" & tLiveslost --this concatenates to "empty1" errr... adds them together
...
Can you see how "life2" will follow?

Really no need for arrays yet.
In your pre/openCard script you will have to hide all of the "empties" and show all the "hearts" but that is not hard.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: creating a game - lost a life

Post by Klaus » Sat Nov 30, 2013 12:58 pm

To avoid headaches:
...
hide image ("life" & tLiveslost)
show image ("empty" & tLiveslost)
...
8)

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: creating a game - lost a life

Post by Simon » Sat Nov 30, 2013 10:44 pm

Hi Klaus,
I had finished writing that post and said to myself "I must add the parenthesis like Klaus says"...
Well there must have been something shiny and I got distracted, because obviously I forgot. :oops:

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: creating a game - lost a life

Post by Klaus » Sat Nov 30, 2013 11:00 pm

Thou shalt be forgiven! 8)

:D

star0629
Posts: 22
Joined: Thu Nov 28, 2013 9:04 pm

Re: creating a game - lost a life

Post by star0629 » Thu Dec 05, 2013 5:28 pm

thank you soo much for helping me out ive finally got the scores, lives, and leaderboard sorted :)

Post Reply