Online Pong Tutorial

Non-platform specific questions.

Postby trajecto » Tue Jan 20, 2004 5:11 am

How about adding a score counter to the upper right of our Pong game?

Later we will add code - get the ball through the goal and the score goes up.


Lets add a score counter:

Add Actor "Score"

Actor Control
Text
Text = 000000
File = numbers.png http://www.trajectorylabs.com/numbers.png
(resized for Pocket PC scale from Moon Defender tutorial)
Initial font char: 0
Number of font chars: 10
ok
close


Oops "Score" shows behind wall
Fix that by:

Actor Control
Z Depth - slide to the right
Close

Your project should look like this now (that extra block is optional right now):
http://www.trajectorylabs.com/gameEditorScore.gif
Last edited by trajecto on Wed Jan 21, 2004 1:24 am, edited 1 time in total.
User avatar
trajecto
 
Posts: 86
Joined: Fri Jan 16, 2004 3:12 pm
Location: Michigan, US
Score: 6 Give a positive score

Postby Just4Fun » Tue Jan 20, 2004 7:23 pm

OK trajecto,
I'm on it! So far so good. How the heck do you pick this up so fast? :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 trajecto » Wed Jan 21, 2004 1:01 am

It's easy, the tech support here is fantastic!!!


OK so the puck has gone off the screen (Out of Vision) so how can we tell if it went through the goal or past the paddle? And how do we increment the score counter?

Let's just see what it's "Y" position was when it left the screen. Since I am making a Pocket PC game the screen coords are 240X (width) by 320Y (height) and the center 0,0 is at the center of the screen. So if the puck goes off the screen and its Y coordinate is less than -160 we know we made a goal!

So here we go to add this:

Right-click the puck

Events Add
Out of Vision
Add Action
Script Editor


if (puck.yscreen < -160)
{
Score.textNumber = Score.textNumber + 1;
DestroyActor("puck");
};


Add
Immediate Action





This is a simple C 'if" control-flow statement. If the expression is true the statement(s) within the curly brackets will be executed:

if (expression)
{
statement;
};
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 2:53 am

trajecto,
I worked on this "assignment" today. I got to know the "out of vision" event and even figured out how to increment the counter for a goal. That is major progress for me! However, I couldn't figure out
how to test for the negative decrement until I saw how you approached the problem. Now I think I have it:

if (puck.yscreen < 160)
{
Score.textNumber = Score.textNumber - 1;
DestroyActor("puck");
};

* Does the above look right to you? If it is, how do we get the negative number to display in the score text actor display? Right now it shows 1 instead of -1.

I appreciate the time that you are spending on this tutorial. It is fun to finally be able to understand how things are taking place in GE. I am not familiar with the 'C' Programming language so some of the other stuff here is just too advanced for me. You make a good teacher. Thanks Again. :lol:
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 3:06 am

Try "greater than" 160, since the Y value is going up as the puck moves down the screen:

if (puck.yscreen > 160)
{
Score.textNumber = Score.textNumber - 1;
DestroyActor("puck");
};



I'm not sure how to get a negative value to show, I tried that and got funny results too. I think a "-" needs to be defined for the graphics for one thing. I decided to just give the player 3 or 5 balls and not decrement the score.

I would like to know how to do that though, any ideas guys???
User avatar
trajecto
 
Posts: 86
Joined: Fri Jan 16, 2004 3:12 pm
Location: Michigan, US
Score: 6 Give a positive score

Postby makslane » Wed Jan 21, 2004 3:25 am

Yes, look the GameFont1.bmp file in the Asteroids data directory for a complete font definition.

A correction:

xscreen and yscreen are coordinates relatives to Screen. So:

xscreen = 0: left side of view
xscreen = view.width: right side of view

yscreen = 0: top
yscreen = view.height: down


y and x are coordinate relatives to game coordinate system
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby trajecto » Wed Jan 21, 2004 4:25 am

Let's spice things up a bit and add an annoying block moving around in our way, remember that block graphic from the zip file? Add that as Actor "block" to our Pong game.

Then let's create a path for it:

Path
Add

Name: path1
Frames: 300

Draw

Draw a path like shown or however crazy as you like:
http://www.trajectorylabs.com/path.gif

Close
Close

Right-click "block" and for Path select path1


Also the ball and paddle are nicer from the Breakout tutorial, I have resized the paddle:
http://www.trajectorylabs.com/racket.bmp
http://www.trajectorylabs.com/ball.bmp (be sure to adjust horizontal and vertical frames when adding the ball to get the animation effect).

I have also added a little play in the paddle to get more power out of it when hitting the ball, it works great:

On paddle
Actor Control
Events Add
Draw Actor
Script editor

Add this script:

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

Also change the Follow Mouse property to both axis.


Aren't the xscreen and yscreen coordinates the same as shown in the upper right of GE when editing?
User avatar
trajecto
 
Posts: 86
Joined: Fri Jan 16, 2004 3:12 pm
Location: Michigan, US
Score: 6 Give a positive score

Postby trajecto » Wed Jan 21, 2004 4:59 am

Let's give the user 5 lives, when the ball goes through the goal he gets a point and gets to start over with the same ball, when it slips by the paddle he loses a life.

Add an actor "life" and use the ball graphic for it. Clone it 4 times and place the images like this:

http://www.trajectorylabs.com/lives.gif

We end up with:
life.0
life.1
life.2
life.3
life.4



Next we just need to Create a new ball once the current one goes off the stage and turn off the lives as they go...

We'll need a "GAME OVER" graphic to turn on at the end of the game also. It would be nice to save high scores too.

Any ideas guys???
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 » Wed Jan 21, 2004 9:01 am

You've stumped me. :oops:
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 makslane » Wed Jan 21, 2004 12:37 pm

Aren't the xscreen and yscreen coordinates the same as shown in the upper right of GE when editing?


Are the x and y coordinates
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby makslane » Wed Jan 21, 2004 12:42 pm

It would be nice to save high scores too


You must use standard C file functions for that
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 2:56 pm

The asteroids demo uses 3 separate actors (not clones) and a "lives" variable.

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--;
}
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 » Wed Jan 21, 2004 3:09 pm

Thanks! That looks like the trick! If you tracked a "level" variable you could Destroy and Create actors on the stage to create multiple levels also.

In the Moon Defender tutorial glabal variables are added by going through "Car" does it matter how you get to the Script Editor when adding global Variables?

I tried the CreateActor function though (in the Out of View event) right after the DestroyActor function on the puck, but it created a whole bunch of new ones. How do I create just one new actor?
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 » Wed Jan 21, 2004 3:19 pm

I started to look up standard C functions for writing and reading a High Score file but my brain started to hurt. :cry:

Try http://www.accd.edu/sac/math/FACULTY/AL ... Lec%20.htm to see what I mean.

It would be nice to have demos of:

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.

Anyone? Anyone? Bueller?
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 makslane » Wed Jan 21, 2004 4:48 pm

In the Moon Defender tutorial glabal variables are added by going through "Car" does it matter how you get to the Script Editor when adding global Variables?




Local variable:

Extends the Actor struct. So, this variables will be good to put something like lives, energy...

Use like this:

player.lives = player.lives - 1;

Note: lives = lives - 1; means access to "Event Actor" lives var



Global variables:

Can accessed globaly like this:

coins = coin + 1;

Use the "New Variable" button in "Script Editor"




Global code:

More complex variables, like arrays, structs, and new functions can be defined using "Global Code" editor.
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

PreviousNext

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest