#1
  1. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95

    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.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    191
    Arkanoid - Breakout ... good old times :D

    Without further influence, AFAIK things bounce off this way:

    angle out = 180° - angle in
  4. #3
  5. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    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.
  6. #4
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,255
    Rep Power
    2222
    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?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    191
    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?)
  10. #6
  11. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,648
    Rep Power
    4248
    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.
  12. #7
  13. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    "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
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    191
    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
  16. #9
  17. jasondoucette.com
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Canada
    Posts
    378
    Rep Power
    12
    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
  18. #10
  19. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    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!:cool:

IMN logo majestic logo threadwatch logo seochat tools logo