Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
March 24th, 2003, 01:07 PM
 infamous41md
not a fan of fascism (n00b)

Join Date: Feb 2003
Location: ct
Posts: 2,756
Time spent in forums: 2 Days 11 h 4 m 29 sec
Reputation Power: 94

ok, does everyone remember that game Arkanoid in the arcades from a loooooooong time ago? it was teh one where u have a small paddle on the bottom of the screen and the objective is to bounce the ball against the blocks on the top of the screen to knock them all off? My question is, when u have the ball bouncing off the walls and paddle and blocks, how do u calculate the angle that it bounces back? Im assuming there must be some algorithms that already exist b/c i cant even fathom how to write one!! Anyone know or have an y useful links? i already googled and came up with no results.

#2
March 24th, 2003, 02:17 PM
 M.Hirsch
Contributing User

Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,966
Time spent in forums: 1 Month 2 Days 52 m 24 sec
Reputation Power: 190
Arkanoid - Breakout ... good old times

Without further influence, AFAIK things bounce off this way:

angle out = 180° - angle in
__________________
--
Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more.

#3
March 24th, 2003, 02:32 PM
 infamous41md
not a fan of fascism (n00b)

Join Date: Feb 2003
Location: ct
Posts: 2,756
Time spent in forums: 2 Days 11 h 4 m 29 sec
Reputation Power: 94
ahhh, now i remember that from the good ol Algebra II days... how may i ask does one find the trajectory/entry angle of the ball? is there a class in MFC or something that contains methods like this? all my searches on google result in greedy bastards wanting \$\$\$ for this info . and Arkanoid was one of the best games ever!! i've been looking for an old arcade machine to buy but they are so ridicuosly xpensive on eBay.

#4
March 24th, 2003, 02:49 PM
 dwise1_aol
Contributing User

Join Date: Jan 2003
Location: USA
Posts: 6,855
Time spent in forums: 3 Months 1 Day 4 h 11 m 54 sec
Reputation Power: 2199
Quote:
 Originally posted by infamous41md ahhh, now i remember that from the good ol Algebra II days... how may i ask does one find the trajectory/entry angle of the ball? is there a class in MFC or something that contains methods like this? all my searches on google result in greedy bastards wanting \$\$\$ for this info . and Arkanoid was one of the best games ever!! i've been looking for an old arcade machine to buy but they are so ridicuosly xpensive on eBay.

Sounds like what I knew as "Breakout". That might help widen your search.

As for the entry angle, couldn't you just define an acceptable range of angle values and then pick one randomly?

#5
March 24th, 2003, 02:51 PM
 M.Hirsch
Contributing User

Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,966
Time spent in forums: 1 Month 2 Days 52 m 24 sec
Reputation Power: 190
Someone wants \$\$ for that info? You can read it in any algebra or physics book!

In general, you remember:
sin(alpha)=b/c
cos(alpha)=a/c
and tan(alpha)=b/a
in a triangle with (my words, too lazy to look up a translation service ) close side a, far side b and hypothenuse c.

but depending on the way you are storing your ballŽs current state, it can be more complicated to calculate that.

How does the code for that look like right now? (how do you store angle / position / velocity of your ball?)

#6
March 24th, 2003, 03:00 PM
 Scorpions4ever
Banned ;)

Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,535
Time spent in forums: 2 Months 3 Days 5 h 32 m 8 sec
Reputation Power: 4106
Heck, I always used code like this:
Code:
```int dx = 5, dy=5;
while (playing) {
x += dx;
y += dy;

if (x < 10 || x > max_width-10)
dx = -dx;

if (y < 10 || x > max_height-10)
dy = -dy;
}```

Simple and efficient. If it hits an edge, bat, brick etc., simply reverse the value of dx or dy.

#7
March 24th, 2003, 03:00 PM
 infamous41md
not a fan of fascism (n00b)

Join Date: Feb 2003
Location: ct
Posts: 2,756
Time spent in forums: 2 Days 11 h 4 m 29 sec
Reputation Power: 94
"but depending on the way you are storing your ballŽs current state, it can be more complicated to calculate that.

How does the code for that look like right now? (how do you store angle / position / velocity of your ball?) "

-well, this is kind of what i was asking.i havent yet started coding anything. i wanted to have a firm grasp on how i would go about this b4 i got myself into something i couldnt complete. i just made my first game ever in C++, and that was a tic tac toe game, so, anything that involves motion is a HUGE step for me. not sure if it's a step i can even take, that's why i was curious how one would go about setting up something like this. i was hoping someone had a good link to a site for beginners tutorials on game programming in C++. all the searches i do just turn up crap or want a "subscription fee", but i guess i'll go back and try to change up my search terms and maybe i'll stumble across something good....i'm sure it's out there somewhere

#8
March 24th, 2003, 03:09 PM
 M.Hirsch
Contributing User

Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,966
Time spent in forums: 1 Month 2 Days 52 m 24 sec
Reputation Power: 190
Scorpions4Ever gave you the answer if you used dx and dy in independent variables (probably best choice for 2D gaming - dx and dy being the movement speed for x and y in pixels per tick - "delta X and delta Y"). For a simple "180-angle in" calculation, this does the trick. If you want to add "spin" to your ball, youŽll need some more calculation though...

HereŽs a cool site for games programming that youŽll have to read for months to get all their cool ideas and tricks (I didnŽt get thru half of them yet although I know it for over one year already - but my free time is rare... ):

www.gamedev.net

#9
March 26th, 2003, 11:50 AM
 Jason Doucette
jasondoucette.com

Join Date: Feb 2003
Posts: 378
Time spent in forums: 7 h 23 m 8 sec
Reputation Power: 11
I made an arkanoid clone for 360x360 mode X, but never finished it as a game. The one thing that I did proper was proper collision detection, which none of any of the breakout/arkanoid clones (or originals) did properly. Every version of this game only sees the ball hitting bricks at either a flat surface, or a 45 degree angle for the corners. If this is all you are looking for, then the explanations in this thread are fine. If you wish to do it properly, then you have to start thinking about how physics work with real life objects. The calculations are pretty difficult, and cannot be answered in a simple post.

I wish to someday release my version as a commercial product at some point in the future, but have no time for it now. My demo is here: Arkanoid '97 please note: it runs in 360x360 mode-x, so don't blame me if your monitor is not 100% VGA compatible and cannot handle the mode

#10
March 26th, 2003, 05:29 PM
 infamous41md
not a fan of fascism (n00b)

Join Date: Feb 2003
Location: ct
Posts: 2,756
Time spent in forums: 2 Days 11 h 4 m 29 sec
Reputation Power: 94
M.Hirsch << damn that website is awesome... so much stuff on there and so many cool links. i found this one site that had tons and tons of video games with indepth articles about the AI and graphix in them. thnx

jason<< i wasnt able to run that program, but i did read about that and a bunch of other stuff on ur site. good stuff!

 Viewing: Dev Shed Forums > Programming Languages > C Programming > question about graphix programming