• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

This topic is now archived and is closed to further replies.

Slayer-X

Bouncing algorithm

8 posts in this topic

I wish I had a scanned of it because it's pretty goofy. I just found out about a year ago. If you could find an Atari manual for Pong or Breakout or probably even Combat they break it down.

They basically use a complety arbitrary system where it cycles thorough eight hits and depending on which hit it is and where on the paddle it hits, it shoots out at a predefined angle. I guess it's set up that way to keep things interesting. I always used to think that how fast I spun the controller determined how the ball bounced.

What really cracked me up is that they told you how the ball bounced in the instructions, as if by the time you're on the eighth level in Break-Out you're actually saying "this is the sixth step in the pattern, so I want to hit the ball here" Maybe they wanted to keep people from thinking the computer was cheating.

There are a few internet sites that might have scanned atari manuals, or if not, there's always flea markets.

0

Share this post


Link to post
Share on other sites
It's all pretty easy actually.. I won't give you all the details but here is a start.

First you have to have a structure for the ball with :

velx, vely, angle, speed..etc..

when the ball hits the paddle then you :

velx -= velx;
vely -= vely;
angle -= angle;

etc..

I'm tired and I may just be babbling, so if you still don't find someone to explain it to you better, then I could send you real a code example.

william_reiach@hotmail.com

0

Share this post


Link to post
Share on other sites
Ok,
A couple of the ways i have seen it done is to change the angle depending on were it is hit, so if it hits the center it bounces straight up, and the further left it goes the more to the left it bounces and the more to the right the further right it bounces. you could also add a tiny bit of randomness.
0

Share this post


Link to post
Share on other sites
Well, before I checked to see if I got any replies on it I came up with a way to do the bouncing. It's just like the Atari Pong game works. The closer to the center you get, the larger the reflection angle...and if you hit the center it bounces straight up. So far I just need to get the score displayed, the round number, the computer AI, the 2nd player controls and display, and the bouncing in. It's kind of a lot left...but I already have about 500 lines done...and that's about 3/4 of the way done. Thanx for your help.
0

Share this post


Link to post
Share on other sites
If u want to base your game on real physics then u should use Gromits way , and may be if u want the edges of your paddle to be rounded ( which makes the game more interesting I guess ) you can use the angle between the speed vector of the ball and the tangent at the point of collision .
To make it more interesting its better to use floats for the position and speed of the ball and the paddles ( you can cast them to integers when you want the Pixel coordinates ) this way you can make the game much more real and also much more interesting .
0

Share this post


Link to post
Share on other sites
I'll probably rewrite the ball moving section of the game when I can actually get the ball moving, lol. For some reason I'm having problems getting the ball moving much. I probably screwed up on my math, today wasn't a good day to be doing the math for the ball, I wasn't thinking very mathematically. Here's the code I'm using the move the ball. ball_x is the ball's x position, ball_y is the ball's y position, brd_x is the player's board's x position, cmp_brd_x is the computer's board's x position, ball_move_x is how much to move the ball's x position, ball_move_y is how much to move the ball's y position, and g_score is the player's score. The game field is: upper left: (9, 80), upper right: (600, 80), lower left: (9, 440), lower right: (600, 440). I would really appreciate any help anyone could post about this. Here's the code:

** beginning of code **
void move_ball(int ball_x, int ball_y)
{
// check to see if the ball hits a side barrier
// if so bounce ball

if (ball_x > 600)
{
ball_move_x = - 10;
sound(1000);
}
else if (ball_x < 9)
{
ball_move_x + 10;
sound(1000);
}

// check to see if the ball has passed a paddle
// if so add or subtract points, and change round

else if ((ball_x > brd_x + 63 | | ball_x < brd_x) && ball_y > 440)
g_score[0] = g_score[0] - 20;
else if ((ball_x < cmp_brd_x + 63 | | ball_x < cmp_brd_x) && ball_y < 80)
g_score[0] = g_score[0] + 50;

// do paddle bouncing

// Player 1

// Left 22.5 degree

else if (ball_x > brd_x && ball_x < (brd_x + 9)
&& ball_y < 442)
{
ball_move_x = - 2.5;
ball_move_y = - 1;
sound(800);
}
// Left 45 degree
else if (ball_x > (brd_x + 9) && ball_x < (brd_x + 18)
&& ball_y < 442)
{
ball_move_x = -1;
ball_move_y = -1;
sound(800);
}
// Left 67.5 degree
else if (ball_x > (brd_x + 18) && ball_x < (brd_x + 27)
&& ball_y < 442)
{
ball_move_x = -.4;
ball_move_y = -1;
sound(800);
}
// Center 90 degree
else if (ball_x > (brd_x + 27) && ball_x < (brd_x + 34)
&& ball_y < 442)
{
ball_move_x = 0;
ball_move_y = -1;
sound(800);
}
// Right 67.5 degree
else if (ball_x > (brd_x + 34) && ball_x < (brd_x + 45)
&& ball_y < 442)
{
ball_move_x = .4;
ball_move_y = -1;
sound(800);
}
// Right 45 degree
else if (ball_x > (brd_x + 45) && ball_x < (brd_x + 54)
&& ball_y < 442)
{
ball_move_x = 1;
ball_move_y = -1;
sound(800);
}
// Right 22.5 degree
else if (ball_x > (brd_x + 54) && ball_x < (brd_x + 63)
&& ball_y < 442)
{
ball_move_x = 2.5;
ball_move_y = -1;
sound(800);
}

// Computer

// Left 22.5 degree

else if (ball_x > cmp_brd_x && ball_x < (cmp_brd_x + 9)
&& ball_y < 82)
{
ball_move_x = -2.5;
ball_move_y = 1;
sound(400);
}
// Left 45 degree
else if (ball_x > (cmp_brd_x + 9) && ball_x < (cmp_brd_x + 18) && ball_y < 82)
{
ball_move_x = -1;
ball_move_y = 1;
sound(400);
}
// Left 67.5 degree
else if (ball_x > (cmp_brd_x + 18) && ball_x < (cmp_brd_x + 27) && ball_y < 82)
{
ball_move_x = -.4;
ball_move_y = 1;
sound(400);
}
// Center 90 degree
else if (ball_x > (cmp_brd_x + 27) && ball_x < (cmp_brd_x + 34) && ball_y < 82)
{
ball_move_x = 0;
ball_move_y = 1;
sound(400);
}
// Right 67.5 degree
else if (ball_x > (cmp_brd_x + 34) && ball_x < (cmp_brd_x + 45) && ball_y < 82)
{
ball_move_x = .4;
ball_move_y = 1;
sound(400);
}
// Right 45 degree
else if (ball_x > (cmp_brd_x + 45) && ball_x < (cmp_brd_x + 54) && ball_y < 82)
{
ball_move_x = 1;
ball_move_y = 1;
sound(400);
}
// Right 22.5 degree
else if (ball_x > (cmp_brd_x + 54) && ball_x < (cmp_brd_x + 63) && ball_y < 82)
{
ball_move_x = 2.5;
ball_move_y = 1;
sound(400);
}
else
{
ball_x = ball_x + ball_move_x;
ball_y = ball_y + ball_move_y;
}

// Show score

outtextxy(61, 0, &score[0]);

// Stop bounce sound

nosound();

// Move ball

ball_x = ball_x + ball_move_x;
ball_y = ball_y + ball_move_y;

circle(ball_x, ball_y, ball_radius);
}
** end of code **
Thanx for any help.

0

Share this post


Link to post
Share on other sites
And I could use some help on my computer AI. I did this at the same time so it is probably all screwed up too. comp_board_x is the computer's board x position, cmp_brd_x is the global x position, comp_board_y is the computer's board y position, and cmp_brd_y is the global y position. Here it is:

** beginning of code **
comp_board_x = cmp_brd_x; // assign local to global comp board x
comp_board_y = cmp_brd_y; // assign local to global comp board y
int direction = 0; // the comp board direction

switch(rand()%1)
{
case 0: // don't change direction
break;

case 1: // change direction
{
switch(direction)
{
case 0: // move computer board left
{
comp_board_x = comp_board_x + 10;
} break;

case 1: // move computer board right
{
comp_board_x = comp_board_x - 10;
} break;

case 2: // keep board still
{
comp_board_x = comp_board_x;
} break;

default:break;
}
}
default:break;
}
if (comp_board_x < 5)
comp_board_x = comp_board_x + 1;
else if ((comp_board_x + 60) > 600)
comp_board_x = comp_board_x - 1;

line(comp_board_x, comp_board_y, (comp_board_x + 60), comp_board_y);

cmp_brd_x = comp_board_x; // change the computer's board x
cmp_brd_y = comp_board_y; // change the computer's board y

** end of code **

Sorry about the screwed up looking code, the lines got long and were wrapped in this window.

0

Share this post


Link to post
Share on other sites
I know this probably sounds stupid, but I'm making a pong game as my first game using graphics. I like thinking about things and figuring them out, but I just need this thing done. I was wondering if anyone knew how to do the algorithm that bounces the ball off of the paddle and bounce at different angles without using a random angle or just plain angle reflection.
0

Share this post


Link to post
Share on other sites
Nevermind the screwed up code thing....I just noticed it didn't wrap it.
0

Share this post


Link to post
Share on other sites