The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
question about graphix programming
Discuss question about graphix programming in the C Programming forum on Dev Shed. question about graphix programming C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

March 24th, 2003, 12:07 PM
|
 |
not a fan of fascism (n00b)
|
|
Join Date: Feb 2003
Location: ct
|
|
|
question about graphix programming
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.
|

March 24th, 2003, 01:17 PM
|
|
Contributing User
|
|
Join Date: Oct 2000
Location: Back in the real world.
|
|
Arkanoid - Breakout ... good old times
Without further influence, AFAIK things bounce off this way:
angle out = 180° - angle in
|

March 24th, 2003, 01:32 PM
|
 |
not a fan of fascism (n00b)
|
|
Join Date: Feb 2003
Location: ct
|
|
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.
|

March 24th, 2003, 01:49 PM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
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?
|

March 24th, 2003, 01:51 PM
|
|
Contributing User
|
|
Join Date: Oct 2000
Location: Back in the real world.
|
|
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?)
|

March 24th, 2003, 02:00 PM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
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.
|

March 24th, 2003, 02:00 PM
|
 |
not a fan of fascism (n00b)
|
|
Join Date: Feb 2003
Location: ct
|
|
|
"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
|

March 24th, 2003, 02:09 PM
|
|
Contributing User
|
|
Join Date: Oct 2000
Location: Back in the real world.
|
|
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
|

March 26th, 2003, 10:50 AM
|
 |
jasondoucette.com
|
|
Join Date: Feb 2003
Location: Canada
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
|

March 26th, 2003, 04:29 PM
|
 |
not a fan of fascism (n00b)
|
|
Join Date: Feb 2003
Location: ct
|
|
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! 
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|