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.

DarkBASIC Discussion / need help with pong

Author
Message
Leonard
22
Years of Service
User Offline
Joined: 14th Jan 2003
Location:
Posted: 21st Feb 2003 00:55
hey everyone,
i am trying to write pong but when i hit the upkey the paddle sprite just sits there.
here's my code:

rem setup background
sync on
sync rate 30
ink 100, 50
box 10, 20, 625, 450
load image "yeller.bmp", 1

rem make paddle
sprite 1, 10, 180, 1
size sprite 1, 20, 100

rem make ball
sprite 2, 275, 205, 1
size sprite 2, 50, 50

rem load music and sound
load music "mind trick.mid", 1
play music 1
load sound "getready.wav", 2
play sound 2

rem keyboard input
if upkey()=1 then paste sprite 1, 10, 250
UberTuba
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Brittania
Posted: 21st Feb 2003 01:15
that is because the program ends as soon as it gets to the end of the code. that means that it will only reposition if you are pressing up almost immeadeatly after the prog starts, as it goes throught the prog so quickly.
You need to do a loop. a loop tells the computer, at the end of the loop to go to the start of the loop so it goes round in circles.

THis for instance will only print hello once


but this will print it over and over again



the 'loop' command tells the computer to go back to the do.

so the code you want is:




Life is a terminal disease.
You never survive it.
Smirkenorff
22
Years of Service
User Offline
Joined: 16th Feb 2003
Location: United Kingdom
Posted: 21st Feb 2003 01:44
You'll need to use a variable for the y coordinate of the paddle.



Leonard
22
Years of Service
User Offline
Joined: 14th Jan 2003
Location:
Posted: 3rd Apr 2003 02:16
OK, i have the ball moving like i want it too, i cant get the ball bouncing around. I can get it to move but not to bounce around. what i did is i told the DB to inc both of the ball variables and the i did a if then command saying if the ball collided against one of the edge sprites(i changed to 4 sprites around the edge instead of a box) to dec both of the ball variables(both just before the end of the main loop). the ball moves down the screen but when it hits a sprite it just stops. What im i doing wrong?

Leonard

"Thou hast only to follow the wall far enough and there will de a door in it."
sonecgaimr
22
Years of Service
User Offline
Joined: 25th Mar 2003
Location: United States
Posted: 3rd Apr 2003 02:20
If the ball hits the paddle, reverse its speed.
e.g. y = 5 changes to y = -5

Chessplayer
22
Years of Service
User Offline
Joined: 22nd Dec 2002
Location:
Posted: 3rd Apr 2003 02:23
Shoot! I posted that on my brother's account. (He didn't log off!)

Chess isn't just for old, wise men! (really!)
Leonard
22
Years of Service
User Offline
Joined: 14th Jan 2003
Location:
Posted: 3rd Apr 2003 23:14
chessplaer: is this what you meant?








if so it didnt work.
the ball just kept going.

"Thou hast only to follow the wall far enough and there will de a door in it."
Slick
22
Years of Service
User Offline
Joined: 12th Mar 2003
Location:
Posted: 4th Apr 2003 01:11
if this is your first game go back and do space invaders, i say this becaurse SI will give u an understanding of a full game that loops, points are scored etc.

pong, although innocent is hard for either the newbie or an experienced programmer who is crap at his maths

u need to look at the math functions, for when the ball hits an object you need the angle at which it hit the wall cos() (i think, im crap at maths) then you need to times the value by two and then -180 degrees (assuming its a wall thats straight)

this has probably been no help but hey neither am i

Hamish McHaggis
22
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 4th Apr 2003 21:58
An easier way to do changing direction of a ball is to have an x-movement of the ball and a y-movement of the ball. When the ball hits a wall you subtract the corrisponding movemnet variable from 0 (or times by -1).



SI is much harder due to having to detect collision between all the aliens and the bullet, control shooting and move all the aliens correctly, increasing their speed when their numbers depleat. I'd still recommend it though since it does cover a far wider range of skills than pong does, and it was my first game!

Why the hell'd you ask me for crying out loud!?!
Hamish McHaggis
22
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 4th Apr 2003 22:01
Id also advise you to do it with 2D, non sprite commands as it is much neated and easier, and also the paddles in pong don't generally move from left to right !

Why the hell'd you ask me for crying out loud!?!
Slick
22
Years of Service
User Offline
Joined: 12th Mar 2003
Location:
Posted: 17th Apr 2003 15:54
SI was the first game i ever made, and i didnt do it in basic i did it in borland pascal in a console application using ascii text as characters instead of sprites.

originally i did it in an hour and a half and becaurse my lecturer said it could not be done .

If u have any ideas that u want 2 experiment with quickly, dont bother with sound or graphics (if its 2D ofcourse) try making text games, stuff similar to console programs.

FiShFuN4eVeR
22
Years of Service
User Offline
Joined: 2nd Feb 2003
Location: Netherlands
Posted: 17th Apr 2003 18:31
Hey look in the 20 line challenge, my own made pong stands there, your free to use it

If good programmer()=1 then print "Finaly I get to the top "
k0shi
22
Years of Service
User Offline
Joined: 30th Dec 2002
Location: Cyberspace
Posted: 18th Apr 2003 07:50
ive made 1 2 the controls r 'a' and 'd' for the 1st person
theres AI if the second person doesnt press any of their controls
player 2 uses '4' and '6'

im the only one thats normal in this world.
everyone else is weird.
Leonard
22
Years of Service
User Offline
Joined: 14th Jan 2003
Location:
Posted: 29th Apr 2003 05:32
fishosaurus:

Can you please rem the code or break it down for me?

"Thou hast only to follow the wall far enough and there will de a door in it."

Login to post a reply

Server time is: 2025-05-17 09:38:59
Your offset time is: 2025-05-17 09:38:59