[RESOLVED]how to reduce the number of lives

Non-platform specific questions.

[RESOLVED]how to reduce the number of lives

Postby castnoshadow » Thu Jan 05, 2012 11:13 am

hi to all,

I hope this is the right section for my topic.

I'm working on "Space Invaders" with some little personalizations like animation, score...but there are few things that I have no idea how to solve.

When the gamer's ship is hit by a enemy shot, the gamer's ship is destroyed, how can I make the ship reappear decreasing the numbers of life? ( for example 3 )
How can I stop the game after that all lives where used with a "game over" message. I tryed to find the solution to this questions, but I was not able to find it.


Thanks to all and sorry for my english.
Last edited by castnoshadow on Sun Jan 08, 2012 9:43 am, edited 1 time in total.
castnoshadow
 
Posts: 8
Joined: Tue Jan 03, 2012 4:31 pm
Score: 0 Give a positive score

Re: how to reduce the number of lives

Postby SuperSonic » Thu Jan 05, 2012 6:32 pm

The first step would be to make a variable called "PlayerLives". Then whenever your character dies, you could do this:
Code: Select all
PlayerLives--;//Subtracts one from player lives

Does that help at all? :P
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: how to reduce the number of lives

Postby castnoshadow » Thu Jan 05, 2012 8:11 pm

Hi SuperSonic thank you for your reply.

I'm not a programmer, all the script that I've added to the game where very simple, so I don't know exactly how to use your script :(

I tell you what I tried.

I tried to use the same method used for score point as i saw on a tutorial, but instead of using addition I tried with subtraction ( lives.textnumber = lives.textnumber -1; ) but it not work ( textnumber was 3).

meybe the variable ( in the script ) is the numbers of lives, can you show me step by step how to use your script?

thank you a lot :D
castnoshadow
 
Posts: 8
Joined: Tue Jan 03, 2012 4:31 pm
Score: 0 Give a positive score

Re: how to reduce the number of lives

Postby skydereign » Thu Jan 05, 2012 8:30 pm

Okay, first thing to know, you shouldn't use textNumber like that. I know that is how it is used in the caveman ged, but using it like that has has been known to create problems. So instead you should create your own variable for lives and your own variable for score. To do add the this script to global code (note if your text display actors have the names score and lives you'll need to destroy the actors, or choose different names for the variables). Just to make sure, you can go to global code by clicking the [Global Code] button.
Global Code
Code: Select all
int score; // creates a variable called score
int lives; // creates a variable called lives

When you add that script, give the script a name, and click [Add]. Now you have two variables, one for score and one for lives.

Whenever you want to increase score, you do this (same idea as what you were using before, but it uses a real variable that you can rely on).
Code: Select all
score = score + 1;

And one thing you have to add to actually make the score display is the following.
score_actor -> Draw Actor -> Script Editor
Code: Select all
textNumber = score; // this will display the score


Now for lives it will work exactly the same way. But, since you want to start with a certain number of lives, you can add this to the player's create actor event.
Code: Select all
lives = 3; // this sets the player's life to 3

And just to reiterate, when you want to reduce the player's life, you use this.
Code: Select all
lives = lives-1;

And to have it displayed, use this.
lives_actor -> Draw Actor -> Script Editor
Code: Select all
textNumber=lives;
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: how to reduce the number of lives

Postby SuperSonic » Thu Jan 05, 2012 9:03 pm

@castnoshadow: I was going to explain my code in more detail but sky basically covered it :P
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: how to reduce the number of lives

Postby castnoshadow » Fri Jan 06, 2012 5:31 pm

hi skydereign, thank you for your help,

there is something that I'm doing wrong.

can you tell me where have I to add the script
Code: Select all
int lives; // creates a variable called lives

I can open the global code if I select une actor, click on "add" button and select an option > script editor,but I don't know for this script witch actor to choose and what option to select. I tried different things without result.

Than I tried this:

"Now for lives it will work exactly the same way. But, since you want to start with a certain number of lives, you can add this to the player's create actor event.

Code: Select all
lives = 3; // this sets the player's life to 3"

I selected my actor >add> create actor>script editor and here I added your script.

After this I added this script "lives = lives-1;" to the lives_actor and after this
Code: Select all
textNumber=lives;
here: "score_actor -> Draw Actor -> Script Editor"

I'm doing something wrong, but I don't know what
castnoshadow
 
Posts: 8
Joined: Tue Jan 03, 2012 4:31 pm
Score: 0 Give a positive score

Re: how to reduce the number of lives

Postby skydereign » Fri Jan 06, 2012 6:41 pm

skydereign wrote: Just to make sure, you can go to global code by clicking the [Global Code] button.

When you are in the script editor, you can click the button on the bottom called [Global code]. From there another script editor type window should appear that is called Global Code Editor. In this script area, you type the code I gave. That will declare the two variables globally.

Now your create actor event is right, but chances are you won't put the lives=lives-1 script into the lives_actor. That code is for when your player dies. So in your case in the player's collision event with the bullet (since that is when you want to decrease the number of lives the player has). You'll also be using lives to destroy the actor most likely (when lives equals zero).
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: how to reduce the number of lives

Postby castnoshadow » Sun Jan 08, 2012 9:41 am

It works!!!!!!!!!

I thank you so mutch!!! it is not so easy to understand how the programm works and it's not easy because I don't know nothing about scripts.
castnoshadow
 
Posts: 8
Joined: Tue Jan 03, 2012 4:31 pm
Score: 0 Give a positive score

Re: [RESOLVED]how to reduce the number of lives

Postby castnoshadow » Sun Jan 08, 2012 10:12 am

now that this works, it's better to open another topic to ask hot to stop the game with a game over message? ( i can't believe that there is no tutorial about)
castnoshadow
 
Posts: 8
Joined: Tue Jan 03, 2012 4:31 pm
Score: 0 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest