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.

Dark GDK / Move ball ?

Author
Message
The Real Abaddon
16
Years of Service
User Offline
Joined: 26th Jun 2008
Location:
Posted: 25th Sep 2008 17:45
I`m tring to create a 2d pong game, i know how to do almost everything but i don't have a clue how to make the ball move. I searched for scraps of code but couldn't help me, i`ve found some code for dbpro but i can't understand it very well. Can anyone show me a code made in dark gdk on how to make a ball move ?

Thanks.

http://drainwrath.blogspot.com Drain Wrath Action/Adventure development blog.
yerrel
21
Years of Service
User Offline
Joined: 9th Sep 2003
Location: Planet Earth.. :-)
Posted: 25th Sep 2008 21:33
Yo!

This is also a pong movement type, but this is in 3D.
But the code for moving is the same for the 2D version, so you may examine and experiment with it.

I hope that it will help you out.. if not post another message or try my site.



MSI K8T NEO-2 F2.0, 8XAGP, 2x512Mb Dual Channel... Dark GDK..... http://www.binary-coder.com
AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 26th Sep 2008 00:22
We're gonna need a little more info. First of all, are you using sprites?? Assuming you are, then it's as simple as using dbRotateSprite( ) to rotate the ball then dbMoveSprite( ) to move it in that direction. Of course you have to specify what sprite you're moving.

90% of statistics are completely inaccurate.
The Real Abaddon
16
Years of Service
User Offline
Joined: 26th Jun 2008
Location:
Posted: 26th Sep 2008 20:27
Thank you both, but i still have a problem figuring on how to work with dbRotateSprite and dbMoveSprite, i know it's a simple math problem here i`m stuck but i just can't figure it out on how to make the ball move endlessly. Tried some stuff but the ball just moves once and stops.
Can i get a little more info ?

Thanks.

P.S i am using sprites.

http://drainwrath.blogspot.com Drain Wrath Action/Adventure development blog.
The Real Abaddon
16
Years of Service
User Offline
Joined: 26th Jun 2008
Location:
Posted: 26th Sep 2008 21:12
As i can see i need a function which will give me the current distance it moved so i can add it with 1.0 let's say and pass it as a argument to dbMoveSprite().
Tried but with no luck! any help very much appreciated.

http://drainwrath.blogspot.com Drain Wrath Action/Adventure development blog.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 26th Sep 2008 21:34
Um, wouldn't dbMoveSprite be a little more complicated to use and keep track of?

Just use dbSprite to reposition it at intervals.

Windows Vista Home Premium Intel Pentium Dual-Core 1.6 Ghz 1GB DDR2 RAM GeForce 8600GT Twin Turbo
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 26th Sep 2008 22:26
Keep a float value for the x and y position and the same for the x and y displacement. You'll also need a value for the speed.


Assuming you have the position and speed set



On each iteration of the loop



You'll probably want to do an additional scaling based on your frame rate if dbSync () doesn't keep things smooth enough. This should be enough to get things started

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
The Real Abaddon
16
Years of Service
User Offline
Joined: 26th Jun 2008
Location:
Posted: 29th Sep 2008 18:12
Thanks alot Lilith it worked

http://drainwrath.blogspot.com Drain Wrath Action/Adventure development blog.
The Real Abaddon
16
Years of Service
User Offline
Joined: 26th Jun 2008
Location:
Posted: 30th Sep 2008 13:40
I still have a problem figuring out how to do when the ball hits a wall to change it's direction.

Here is the code

and i`ve made an If:

but works only for the top and bottom wall on the left and right wall it goes straight 0 angle, and doesn't come back. How can i solve this ?

http://drainwrath.blogspot.com Drain Wrath Action/Adventure development blog.
Aura Art
16
Years of Service
User Offline
Joined: 29th Sep 2008
Location:
Posted: 30th Sep 2008 17:00
I think you want the condition to multiply speed by ( -1 ) when the ball hits the sides of the screen.

Try it out.
Swift
16
Years of Service
User Offline
Joined: 17th Aug 2008
Location:
Posted: 30th Sep 2008 18:14
this is the code i used for bouncing the ball in my pong game

collision check function

the function requires you to input two paramaters which are pointers to the class IdInfo. I use IdInfo class to contain the generic variables in my programs. The input to the functions must address an object from the class IdInfo. All objects of class IdInfo have variables x,y (current position on screen), width,length(of the sprite). this are used to determine if the two objets are colliding. Or you could use the inbuilt GDK function.





this is the basis code for my ball bouncing off paddles and walls.
I removed some of the code to make it easier to understand. Hope it helps. Also i did this a while ago and the calcs for bouncing are fair confusing, but they do work.

Login to post a reply

Server time is: 2024-11-25 03:57:26
Your offset time is: 2024-11-25 03:57:26