Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / I can't make the simplist game!

Author
Message
soapyfish
21
Years of Service
User Offline
Joined: 24th Oct 2003
Location: Yorkshire, England
Posted: 29th Aug 2004 04:34
Hi again,
Now before we stop the ball from moving off screen we need to understand why it is moving in the first place.

We put the ball at 100,100 then we created variables (ball_x and ball_y) to represent these values. We then added.....



to our code. This is adding 0.75 to the balls x position and 0.75 to the balls y position every loop.

If we want to make our ball change direction we need to change the speed from 0.75 to -0.75, of course, if we want to change it we will need to swap it for a variable, add.....



to the top of your code, then change.....



to



ball_x#=ball_x#+ball_x_speed#, ball_y#=ball_y#+ball_y_speed#

Here we've just done a simple swap of values, we have kept exactly the same co-ordinates as before but we can now change the value associated with the balls direction.

We now need to tell the computer that IF the ball hits the wall we want it to change its direction, so we use an IF command, add......



to your code.

if sprite hit (6,4) then ball_y_speed#=-0.75

We are now saying that IF two sprites (numbers 6 and 4) hit each other, we want to change the ball_y_speed# from 0.75 to -0.75, so we are actually taking away 0.75 from the balls y position, which makes it appear to bounce off the wall.

Your complete code should now look something like this.....



If you run your code you should see the ball bounce off the bottom wall, I'll post again later telling you how to make it bounce off the others, any problems, just say.

Formely code2kill
To tell you the truth, I'm just glad I DON'T enjoy playng The Sims.
the play2kill fan club
soapyfish
21
Years of Service
User Offline
Joined: 24th Oct 2003
Location: Yorkshire, England
Posted: 1st Sep 2004 05:24
Hi,
I've been thinking that your the only one using this tut and it's not really fair if it keeps jumping bakck to the top of the board pushing other posts down. I thought it would be best if I e-mailed you the tut instead, that is ofcourse, if no-one else is using it. So just keep checking your inbox.

Formely code2kill
To tell you the truth, I'm just glad I DON'T enjoy playng The Sims.
the play2kill fan club
The dude guy
20
Years of Service
User Offline
Joined: 3rd Aug 2004
Location: In the streets of sasatuin
Posted: 1st Sep 2004 07:01
Okay!

Andrew Tamalunas
Asternus
20
Years of Service
User Offline
Joined: 11th Aug 2004
Location: N.C. U.S.A
Posted: 3rd Sep 2004 13:12
Hi guys...I'm reading it...
The dude guy
20
Years of Service
User Offline
Joined: 3rd Aug 2004
Location: In the streets of sasatuin
Posted: 3rd Sep 2004 21:39
Glad to know it's helping someone else Not just me.

Andrew Tamalunas
soapyfish
21
Years of Service
User Offline
Joined: 24th Oct 2003
Location: Yorkshire, England
Posted: 5th Sep 2004 05:35 Edited at: 5th Sep 2004 05:49
Ohh, okay, I'll post the next part HERE later tonight.

EDIT:: Right, here we go. To stop your ball from travelling off the screen in all directions we need to add.....



to our code.

if sprite hit (6,3) then ball_y_speed#=0.75
This is practically identical to the code we used to get the ball to bounce off the bottom wall except instead of testing it against sprite 4 we tested it against sprite 3.

IF ball_x#<1 then ball_x_speed#=0.75
This is ALMOST the same as the previous command except instead of changing the y speed of the ball when it hits the horizontal wall, we tell the computer that IF the ball's x co-ordinates are less than 1, reverse its x speed.

IF ball_x#>790 then ball_x_speed#=-0.75
And it's the same with this command, IF the balls x co-ordinates are more than 790 then reverse its x speed to make it move in the opposite direction.

Your code should now look similar to this.



However this code isn't completely bug free and I'l explain how to get it bug free in the next tut, any problems, just ask.

Formely code2kill
To tell you the truth, I'm just glad I DON'T enjoy playng The Sims.
the play2kill fan club
Game Programming Beginner
20
Years of Service
User Offline
Joined: 18th Aug 2004
Location: USA VA
Posted: 5th Sep 2004 12:07
Hey play2kill, Thank you for helping The dude guy and me on learning DBP. I have been been reading this and learning at the some time keep up the great work and thanks

WindowsXP Professional, AMD Athlon 2.500+ GHz CPU, 512 MB of RAM, GEForce2 MX 64mb of RAM. Let the Game's Begin...
The dude guy
20
Years of Service
User Offline
Joined: 3rd Aug 2004
Location: In the streets of sasatuin
Posted: 6th Sep 2004 04:19
What he said THANKS!

Andrew Tamalunas
soapyfish
21
Years of Service
User Offline
Joined: 24th Oct 2003
Location: Yorkshire, England
Posted: 9th Sep 2004 07:54
Hi,
Thanks for letting me know I'm being some help, it's a little late for me to update this thread right now but read it to-morrow and I PROMISE we'll make some big progress with the pong game.

Formely code2kill
To tell you the truth, I'm just glad I DON'T enjoy playng The Sims.
the play2kill fan club
Game Programming Beginner
20
Years of Service
User Offline
Joined: 18th Aug 2004
Location: USA VA
Posted: 9th Sep 2004 16:08
Ok, Thanks play2kill

WindowsXP Professional, AMD Athlon 2.500+ GHz CPU, 512 MB of RAM, GEForce2 MX 64mb of RAM. Let the Game's Begin...
soapyfish
21
Years of Service
User Offline
Joined: 24th Oct 2003
Location: Yorkshire, England
Posted: 10th Sep 2004 06:28
Right,

I said the code wasn't entirely bug free but looking back over it I think I've jumped the gun a little.

If anything strange does happen while your testing the code just say and I'll help out.

Any way, now we know how to get the ball bouncing off the edges of the screen we can edit the code to change what it does at certain point without having to do too much work.

Change........



to.......



IF sprite hit (1,6) then ball_x_speed#=0.75
This may be simpler to understand than the code it replaced, I think it is anyway. Instead of telling the computerIF the balls x co-ordinates are less than 1 make it go in the opposite direction we are saying IF sprite numbers 1(the bat/paddle) and 6(the bal) hit then change the ball x direction.

Your completed code should now look something like this......



In the next tut we'll concentrate on getting the enemy bat to react to whaere the ball is a move accordingly (getting really close to a finished game now) this will use mostly commands that have already beent alked about so fi there's anything you don' understand just ask.

p.s. @Game Programming Beginner
Do you have all the correct sprites or do you want me to e-mail them to you?

Formely code2kill
To tell you the truth, I'm just glad I DON'T enjoy playng The Sims.
the play2kill fan club
Game Programming Beginner
20
Years of Service
User Offline
Joined: 18th Aug 2004
Location: USA VA
Posted: 10th Sep 2004 13:31
I got the sprites that you posted on the first page, right now I'm just reading all of your command reference. This is great I'm learning about why the code lines do the things they do. That to me is aways the frist thing you should learn, why this part of code works and why and how can I make it better. Your explanation of the code looks good to me I can follow it and understand it, but then I'm new at this coding thing that you could be selling me green cheese. But I know your not. If you like to e-mail them to me, go for it

WindowsXP Professional, AMD Athlon 2.500+ GHz CPU, 512 MB of RAM, GEForce2 MX 64mb of RAM. Let the Game's Begin...
RandomSKK
20
Years of Service
User Offline
Joined: 15th Sep 2004
Location: Surrey, UK
Posted: 16th Sep 2004 05:45
Nice!
I've been following this code just now, and it's nice for an example program.
I'm still a new programmer, but I tried a few things to make the enemy bat follow the ball, which work nicely

Except that you can't beat the enemy... ah well


Thanks for taking the time to post this.

Login to post a reply

Server time is: 2024-11-27 11:44:39
Your offset time is: 2024-11-27 11:44:39