Online Pong Tutorial

Non-platform specific questions.

Postby Just4Fun » Wed Jan 21, 2004 5:59 pm

#$%:
I hate scripting!...But I love this tutorial. While all of you have been making great things happen here, I've spent hours trying to figure out how to apply jazz-e-bob's xrange example to a yrange boundary for the paddle (upper and lower y paddle limits ). Now I have to go to the dentist. It must be my lucky day.

Anyway, would someone please save my head another wall bashing incident and show me how to set these boundries. I know I'm close to the solution, but I just can't seem to get all the way there. Sigh. :cry: TIA ....Rachel
I've learned that I still have a lot to learn.

** Makslane == Genious **
Just4Fun
 
Posts: 524
Joined: Tue Jul 01, 2003 5:19 am
Location: USA: Washington State; West Coast
Score: 6 Give a positive score

Postby trajecto » Wed Jan 21, 2004 6:26 pm

Take a close look at how I added "a little play" into the paddle, this just says if its vertical position is greater than a certain value make it that value, if it's less than a certain value make it that value, this locks it into a range:

if (y > 165)
y = 165;
if (y < 130)
y = 130;

I am just hard-coding my range here, you could do this for the x axis also. I found it seems to work fine just leaving x alone though.

Also remember to change the Follow Mouse property of the paddle to both axis.


This is nice because you can get a little extra power out of the paddle because you can move it up and down a little. Makslane's physical properties takes the extra speed into effect and the puck is hit harder or softer, however you hit it.
User avatar
trajecto
 
Posts: 86
Joined: Fri Jan 16, 2004 3:12 pm
Location: Michigan, US
Score: 6 Give a positive score

Postby Just4Fun » Wed Jan 21, 2004 7:32 pm

*After another head bashing incident, Just4Fun comments with embarrassment:

Cheeeeze trajecto,
I forgot to set the 'follow mouse co-ordinates' to "Both". :roll: Everything is now working! Thank you.
I've learned that I still have a lot to learn.

** Makslane == Genious **
Just4Fun
 
Posts: 524
Joined: Tue Jul 01, 2003 5:19 am
Location: USA: Washington State; West Coast
Score: 6 Give a positive score

Postby makslane » Wed Jan 21, 2004 10:07 pm

Reading and writing a single integer to a file.
Reading and writing a list of integers to a file.
Reading and writing text to a file.
Reading and writing a list of texts to a file.



The next version will have a nice way to make this :)
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby jazz_e_bob » Wed Jan 21, 2004 10:14 pm

Brilliant.

That's what Game Editor is all about! :D

Taking the fiddly annoying bits about programming and making a neat little Event/Action to take care of it.

( Poor Makslane has to do the ugly bits and we get to have all the fun. )
Controlling complexity is the essence of computer programming.
User avatar
jazz_e_bob
 
Posts: 742
Joined: Tue Jul 01, 2003 9:38 pm
Location: Bloke from Cockatoo Creek Australia
Score: 14 Give a positive score

Postby trajecto » Thu Jan 22, 2004 3:12 pm

I figured out the "Game Over" screen. It's all in Makslane's samples and tutorials.

jazz_e_bob found how to code it in fact in the Asteroids demo:


At time of death:

if(lives == 0)
{
DestroyActor("Event Actor");
CreateActor("gameover", "text", "no parent", "no path", -117, -12, true);
}
else
{
if(lives==3) DestroyActor("liveActor3");
else if(lives == 2) DestroyActor("liveActor2");
else if(lives == 1) DestroyActor("liveActor1");
lives--;
}


Note the CreateActor command, it is creating a text actor called "gameover" and putting it on the screen. This is all you need to do when the game ends.

To create a complete text actor that allows you to type anything, you need an entire game font.

For this example I will use the font BlazingStar2


To get that font try here:

http://www.zone38.net/font/#bitmap
Hit the link:
"Download codeman38's Bitmap Font Writer collection!"

If you want to make a font yourself try this:
Bitmap Font Writer
http://www.stefan-pettersson.nu/site/bmpfont/

There is also a gamefont in the Asteroids demo as Makslane mentioned earlier.



All you need to do to create a text actor that says anything you want is:


Add Actor
Name it
In Actor Control select "Text"

Text: Game Over
File: your gamefont file
Initial font char: the first character of the file (BlazingStar2 is a ! just enter an exclamation mark)
Number of Font Chars: 63 (for BlazingStar2)
Hit Ok and you will see your text


NOTE 1: BlazingStar2 has little white pixels in the upper left of each font cell, I think this is affecting transparency so you may want to paint those out. I didn't try it yet.

NOTE 2: I believe also you can edit the text actors text property at runtime if you want some info that changes to display (like our score counter).
User avatar
trajecto
 
Posts: 86
Joined: Fri Jan 16, 2004 3:12 pm
Location: Michigan, US
Score: 6 Give a positive score

Postby Just4Fun » Thu Jan 22, 2004 5:15 pm

trajecto,
I tried to work the "lives" script out yesterday, but as yet, I can't seem to figure it out. For some reason none of the Demos will work in the game play mode on either of my machines. Does anyone else have this problem?
I have some other things that I have to do today, but I will keep working and post my questions. Now that you have added a little more information, I will try again.
Also, thank you for the links: Most Excellent! :lol:

* One question that I do have, "Where should I define my "lives" variable? I am currently using "Create Actor" script for the ball (puck). I made it global. It seems like that is what is recommended in this thread, but maybe I'm not getting it. TIA
I've learned that I still have a lot to learn.

** Makslane == Genious **
Just4Fun
 
Posts: 524
Joined: Tue Jul 01, 2003 5:19 am
Location: USA: Washington State; West Coast
Score: 6 Give a positive score

Postby jazz_e_bob » Thu Jan 22, 2004 5:27 pm

trajecto

Bitmap fonts resources link. Brilliant! :)
Controlling complexity is the essence of computer programming.
User avatar
jazz_e_bob
 
Posts: 742
Joined: Tue Jul 01, 2003 9:38 pm
Location: Bloke from Cockatoo Creek Australia
Score: 14 Give a positive score

Postby trajecto » Thu Jan 22, 2004 7:02 pm

All the demos seem to work fine on my system, no problems!

Just4Fun
Normally in C programming you define a variable then initialize it with a value. There are different types of variables for different types of data such as whole numbers, chars, floating point numbers, etc. A good book for you would be Absolute Beginners Guide to C by Sams Publishing. I've used it for some things here.


Add a global variable as an integer:
lifenum

Then add global code:
lifenum = 5;


As far as I can tell this defines it and initializes it in Game Editor.


In C you can define and initialize a variable at the same time like this:
int lifenum = 5;
That type of code usually goes near the beginning of your program. I am guessing Global Code in GE is like this, like startup code.


An integer is just a whole number between -32768 and 32767
If you want outside of that rane you use a long integer, I'm not sure if Game Editor has that. We are ok for this game within that range anyways.

Is this too much info about C? :shock: Sorry, you need to learn it to get the real potential out of GE! :D
User avatar
trajecto
 
Posts: 86
Joined: Fri Jan 16, 2004 3:12 pm
Location: Michigan, US
Score: 6 Give a positive score

Postby trajecto » Fri Jan 23, 2004 2:33 am

I have edited the white pixels out of BlazingStar2 font and resized it for Pocket PC:

http://www.trajectorylabs.com/BlazingStar2.png

It looks like fonts work the same way as images, The transparency color is the color of the first pixel at the very upper left of your image. It looks much better now.

Remember for this one to use:

Initial font char: !
Number of font chars: 63
User avatar
trajecto
 
Posts: 86
Joined: Fri Jan 16, 2004 3:12 pm
Location: Michigan, US
Score: 6 Give a positive score

BASIC FINAL STEPS

Postby trajecto » Fri Jan 23, 2004 5:20 am

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!
User avatar
trajecto
 
Posts: 86
Joined: Fri Jan 16, 2004 3:12 pm
Location: Michigan, US
Score: 6 Give a positive score

Postby jazz_e_bob » Fri Jan 23, 2004 7:07 am

trajecto

Very well done. I want to play it!

Could you please post a link to a copy of the project. (I am far too lazy to make my own. :wink: )

Also. You can save scripts to a standard "c" file which can be read in text editor. Cut, copied pasted etc...

Image

Just testing image posting... I am building an extension to my house. This is where the new roof will join up with the old one. :)
Controlling complexity is the essence of computer programming.
User avatar
jazz_e_bob
 
Posts: 742
Joined: Tue Jul 01, 2003 9:38 pm
Location: Bloke from Cockatoo Creek Australia
Score: 14 Give a positive score

Postby Just4Fun » Fri Jan 23, 2004 3:07 pm

trajecto
Unfortunately, physical life has intercepted my virtual journey with GE. I am hoping to work through the rest of your tutorial this weekend. This tutorial has been a lot of fun. I finally see how GE works. I'd just about given up trying.

I'm looking forward to more of your tutorials in the future. How about a board game tutorial next? (the Chechers demo is WAY over my head). Hint, Hint :wink:
I've learned that I still have a lot to learn.

** Makslane == Genious **
Just4Fun
 
Posts: 524
Joined: Tue Jul 01, 2003 5:19 am
Location: USA: Washington State; West Coast
Score: 6 Give a positive score

Postby Just4Fun » Fri Jan 23, 2004 3:24 pm

Jazz-e-bob,

Two things:
I. Thanks for the great web site area that you created on the 'C' language. I was trying to figure out how add a remark statement in the Pong script area and I found it right away on your site.
2. I doubt that you are too "lazy" to type in the Pong code. My guess is, rather, you are "too busy". Building an extension to the house yourself is a MAJOR project. :wink:


*trajecto,
I second the request for a link to the finished tutorial. I really need to see how the script is preformed to count the "lives". TIA

*Makslane: It would be nice to have an "off topic other" area in the forum area.
I've learned that I still have a lot to learn.

** Makslane == Genious **
Just4Fun
 
Posts: 524
Joined: Tue Jul 01, 2003 5:19 am
Location: USA: Washington State; West Coast
Score: 6 Give a positive score

Postby Just4Fun » Sat Jan 24, 2004 12:15 am

jazz-e-bob,

Is there some reason that diretional_velocity is mispelled? Why isn't it directional-velosity used instead? :?:
I've learned that I still have a lot to learn.

** Makslane == Genious **
Just4Fun
 
Posts: 524
Joined: Tue Jul 01, 2003 5:19 am
Location: USA: Washington State; West Coast
Score: 6 Give a positive score

PreviousNext

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron