Ok guys, here are my basic final steps for a working Pong Hockey game that:
1. Tracks scores
2. Track lives
3. Has a moving block that interferes with play.
4. Ends with a game over screen when lives run out.
We'll just have to save "levels" and "saving scores" for another demo. It's just way too involved for this, plus this is getting too long.
HERE WE GO:
I figured out a MUCH SIMPLER method to track scores and misses. Instead of using the Out of Vision method (you will have to delete this) I use two Region Actors like shown (green rectangles):
http://www.trajectorylabs.com/pongFinal.gif
One is called "goal" and one is called "miss" so the ball just hits it either way and a collision event occurs making the coding alot simpler.
Make sure you have a Global Integer Variable called lifenum
Make sure in global code you initialize lifenum to 5 like this:
lifenum = 5;
Create a Region Actor "goal"
place it above the goal like in the image link above
Right-click
Actor Control
Events Add
Collision Event
Actor puck
Add Action
Script editor
add this code:
Score.textNumber = Score.textNumber + 1;
DestroyActor("puck");
CreateActor("puck", "ball", "no parent", "no path" 0, 0, true);
Add
Immediate Action
Close
Close
Now create the Region Actor "miss"
Follow the steps above but place it below the paddle like shown.
Add this script:
DestroyActor("puck");
if(lifenum == 0)
{
CreateActor("gameover", "text", "no parent", "no path", -60, 0, true);
}
else
{
if(lifenum == 5) DestroyActor("life.4");
else if (lifenum == 4) DestroyActor("life.3");
else if (lifenum == 3) DestroyActor("life.2");
else if (lifenum == 2) DestroyActor("life.1");
else if (lifenum == 1) DestroyActor("life");
CreateActor("puck", "ball", "no parent", "no path", 0, 0, true);
lifenum--;
};
As you can see the "goal" script increments the score counter, destroys the ball and creates a new ball in the middle of the stage.
The "miss" script destroys the ball, shows GAME OVER if that was the last ball and deletes the life counters as lives are lost. It also creates new balls if it was not the last life.
I have only been learning this about 9 days so hope you have enjoyed my demo, I know I am am rookie! Thanks for all of your help!!!
NOTE: I hope my code has no typos, sorry if it does, the Script Editor really needs Cut and Paste!