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 / My 2D Pong game

Author
Message
Lost Kid
20
Years of Service
User Offline
Joined: 16th Feb 2005
Location: Usa
Posted: 20th Feb 2005 13:40
I'm one of the noobs that thought makin' a pong game whould be pie, but i was wrong(sigh), while i was in the process of making it it was easy until i had to make the bats move by the keyboard(I just can't seem to get it down) and im asking, How Do I Make The Keyboard Move The Images?
Foxy
20
Years of Service
User Offline
Joined: 4th Jan 2005
Location: The Dale, South Australia
Posted: 20th Feb 2005 20:15 Edited at: 20th Feb 2005 20:31
What you need to do is use keystate() command that'll check to see which key is pressed, look it up in the help files. If you need to find which value you need to check for you can use a program like this:



That program will print the code for the current key that is pressed using the scancode() feature. The scancode() feature stores the value of the key that is pressed, if any are pressed in.

To move your sprite you need to have variables for their x and y positions or in the case of pong, just one of these (depending on which way you are playing). For your prog, you'll probably use a code block similar to this:



The writing in the ( and ) need to be replaced with a number eg.



Hope I helped.

If there is anything wrong with the code lemme know and I'll fix it up (DB on other computer, it's late at night etc etc).

P.S. 3D is much easier than 2D esp in DBC.

[McEdit]: Fixed code - me spud.

If I were you and you were me, then you'd be yourself 'cos you are me and I am you.
Nuggets
20
Years of Service
User Offline
Joined: 27th Dec 2004
Location:
Posted: 4th Mar 2005 06:17
You can place inkey()="letter" and that makes it easter than keystate more useful info
Underworld 1020
21
Years of Service
User Offline
Joined: 2nd Mar 2004
Location: NY, USA
Posted: 4th Mar 2005 22:04 Edited at: 5th Mar 2005 07:24
First you need to make a Paddle image, which you've probably already created in the paint program, but if you want you can make a paddle image in DarkBasic

Here's How:


You can make it look a lot better, but if you want to keep it simple that should do for the paddle image.

However, you can just make a paddle in paint and then load it into DarkBasic.

Here's How:


That's all you got to do, but just make sure you put the real name of your Paddle that you created in the quotes.

So, pick whatever one you want to do either creating the image in Paint or DarkBasic, and put the code at the top of your program.

Then, write this below that for your main loop:


Once you've done all that you'll have a simple paddle sprite moving at the bottom of the screen by pressing the right and left keys .
It might not look like much, but you got to start somewhere. And after you get the paddle moving like I posted above, you can make it move even better and if you want I can show you how, but make sure you understand what I already posted first and if you don't just ask.

Hope I've helped

Underworld 1020
21
Years of Service
User Offline
Joined: 2nd Mar 2004
Location: NY, USA
Posted: 4th Mar 2005 22:22
I fixed the code above,so If you tried running it and it didn't work, try running the new code above.

Lost Kid
20
Years of Service
User Offline
Joined: 16th Feb 2005
Location: Usa
Posted: 5th Mar 2005 08:08 Edited at: 5th Mar 2005 08:16
Thanks Everyone but i somehow figgered it out myself
now im stuck on trying to make the ball and collision and stuff
Dont Download i had to edit this post i dont think that download works

Attachments

Login to view attachments
Lost Kid
20
Years of Service
User Offline
Joined: 16th Feb 2005
Location: Usa
Posted: 5th Mar 2005 08:17
Heres The Code

Login to post a reply

Server time is: 2025-05-23 18:50:43
Your offset time is: 2025-05-23 18:50:43