![]() |
| | #1 |
| Registered User Join Date: Aug 2009
Posts: 20
| I M MAKING A GAME WHICH IS CALLED "RAMP GAME". THIS GAME CONSIST OF 1) A BALL, 2) A BASKET, 3) SOME LINES ( which can be place anywhere by the user with in the boundary walls). HERE IS TEH LINK.... Ramps Game - Skill Games - GameGecko.com u can see what it looks like.... now what i m here for?....is i dont know how to bounce a ball w.r.t the collision angle..... i don't know how to move lines at run time..... i should no my problems here, so u can understand what i m trying to say... 1) Setting the lines at run time. 2) When ball collides with the lines then it should reflect w.r.t the angle of reflection. ONE MORE THING......there is a restriction that the game should be made on "OPENGL". PLEASE HELP ME OUT WHO KNOWS OPENGL....... |
| ammad is offline |
| | #2 |
| Registered User Join Date: Aug 2009
Posts: 20
| |
| ammad is offline |
| | #3 |
| Registered User Join Date: Aug 2003
Posts: 774
| What are you having trouble with?? |
| Shakti is offline |
| | #4 |
| Super Moderator Join Date: Aug 2001
Posts: 7,472
| Thread re-opened. I closed it b/c it looked like you were just trying to get hits on a site. Now I see that you want to program a game like the one you linked to. I apologize for closing the thread. Threads have been merged and cleaned up. Oh and on a side note please refrain from using all CAPS.
__________________ If you aim at everything you will hit something but you won't know what it is. |
| Bubba is offline |
| | #5 |
| Registered User Join Date: Aug 2009
Posts: 20
| thanks.... now plz help me....I have some code i.e Code: #include <gl/glut.h> // Also included gl.h, glu.h
#include <Math.h> // Needed for sin, cos
#define PI 3.14159265f
// Global variables
char title[] = "Bouncing Ball (2D)"; // Windowed mode's title
int windowWidth = 640; // Windowed mode's width
int windowHeight = 480; // Windowed mode's height
int windowPosX = 50; // Windowed mode's top-left corner x
int windowPosY = 50; // Windowed mode's top-left corner y
GLfloat ballRadius = 0.5f; // Radius of the bouncing ball
GLfloat xPos = 0.0f; // Ball's (x, y) position
GLfloat yPos = 0.0f;
GLfloat xPosMax, xPosMin, yPosMax, yPosMin; // Ball's (x, y) bounds
GLdouble xLeft, xRight, yBottom, yTop; // Projection clipping area
GLfloat xSpeed = 0.02f; // Ball's speed in x and y directions
GLfloat ySpeed = 0.007f;
int refreshMillis = 30; // Refresh period in milliseconds
// Initialize OpenGL Graphics
void initGL() {
glClearColor(0.0, 0.0, 0.0, 1.0); // Set background (clear) color to black
}
// Callback handler for window re-paint event
void display() {
glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer
glLoadIdentity(); // Reset model-view matrix
glTranslatef(xPos, yPos, 0.0f); // Translate to (xPos, yPos)
// Use triangular segments to form a circle
glBegin(GL_TRIANGLE_FAN);
glColor3f(0.0f, 0.0f, 1.0f); // Blue
glVertex2f(0.0f, 0.0f); // Center of circle
int numSegments = 100;
GLfloat angle;
for (int i = 0; i < numSegments; i++) {
angle = i * 2.0f * PI / numSegments; // 360 deg for all segments
glVertex2f(cos(angle) * ballRadius, sin(angle) * ballRadius);
}
glVertex2f(ballRadius, 0.0f); // Last vertex
glEnd();
glutSwapBuffers(); // Swap front and back buffers (of double buffered mode)
// Animation Control - compute the location for the next refresh
xPos += xSpeed;
yPos += ySpeed;
// Check if the ball exceeds the edges
if (xPos > xPosMax) {
xPos = xPosMax;
xSpeed = -xSpeed;
} else if (xPos < xPosMin) {
xPos = xPosMin;
xSpeed = -xSpeed;
}
if (yPos > yPosMax) {
yPos = yPosMax;
ySpeed = -ySpeed;
} else if (yPos < yPosMin) {
yPos = yPosMin;
ySpeed = -ySpeed;
}
}
// Call back when the windows is re-sized.
void reshape(GLsizei weight, GLsizei height) {
if (height == 0) height = 1; // To prevent divide by 0
GLfloat aspect = (GLfloat)weight / height; // Get aspect ratio
// Set the viewport to cover the entire window
glViewport(0, 0, weight, height);
// Adjust the aspect ratio of clipping area to match the viewport
glMatrixMode(GL_PROJECTION); // Select the Projection matrix
glLoadIdentity(); // Reset
if (weight <= height) {
xLeft = -1.0;
xRight = 1.0;
yBottom = -1.0 / aspect;
yTop = 1.0 / aspect;
} else {
xLeft = -1.0 * aspect;
xRight = 1.0 * aspect;
yBottom = -1.0;
yTop = 1.0;
}
gluOrtho2D(xLeft, xRight, yBottom, yTop);
xPosMin = xLeft + ballRadius;
xPosMax = xRight - ballRadius;
yPosMin = yBottom + ballRadius;
yPosMax = yTop - ballRadius;
// Reset the model-view matrix
glMatrixMode(GL_MODELVIEW); // Select the model-view matrix
glLoadIdentity(); // Reset
}
// Animation timer function
void Timer(int value) {
glutPostRedisplay(); // Post a paint request to activate display()
glutTimerFunc(refreshMillis, Timer, 0); // subsequent timer call at milliseconds
}
// main function - GLUT run as a Console Application
int main(int argc, char** argv) {
glutInit(&argc, argv); // Initialize GLUT
glutInitDisplayMode(GLUT_DOUBLE); // Enable double buffered mode
glutInitWindowSize(windowWidth, windowHeight); // Initial window width and height
glutInitWindowPosition(windowPosX, windowPosY); // Initial window top-left corner (x, y)
glutCreateWindow(title); // Create window with given title
glutDisplayFunc(display); // Register callback handler for window re-paint
glutReshapeFunc(reshape); // Register callback handler for window re-shape
glutTimerFunc(0, Timer, 0); // First timer call immediately
initGL(); // Our own OpenGL initialization
glutMainLoop(); // Enter event-processing loop
return 0;
}
and what this code do??? Code: if (weight <= height) {
xLeft = -1.0;
xRight = 1.0;
yBottom = -1.0 / aspect;
yTop = 1.0 / aspect;
} else {
xLeft = -1.0 * aspect;
xRight = 1.0 * aspect;
yBottom = -1.0;
yTop = 1.0;
}
gluOrtho2D(xLeft, xRight, yBottom, yTop);
xPosMin = xLeft + ballRadius;
xPosMax = xRight - ballRadius;
yPosMin = yBottom + ballRadius;
yPosMax = yTop - ballRadius;
|
| ammad is offline |
| | #6 |
| Registered User Join Date: Aug 2009
Posts: 20
| I have solved one of my ball bouncing problem with the help my some online friends... Can anyone tell me the link or something from i can understand the collision detection between the ball and sloped lines/???? |
| ammad is offline |
| | #7 |
| Registered User Join Date: Jan 2008
Posts: 65
| Collision detection is no easy issue. It may be worth your time to look into a 2D physics engine like box2d. |
| Drac is offline |
| | #8 |
| Registered User Join Date: Sep 2009
Posts: 37
| u need to use phytagoras and find the cutting point of the circle around the 2 radian of your object. i can't find my documents yet for collusion detection to give more detaild informations, i will try to find it and post it here... |
| punkywow is offline |
| | #10 |
| Super Moderator Join Date: Aug 2001
Posts: 7,472
| Please do not bump old threads. Closed.
__________________ If you aim at everything you will hit something but you won't know what it is. |
| Bubba is offline |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Open Source / Semi Open source game idea. Help needed | CaptainPatent | Projects and Job Recruitment | 10 | 05-16-2007 10:44 AM |
| game engine advice? | stien | Game Programming | 0 | 01-23-2007 03:46 PM |
| how do the game engine and the api interact? | Shadow12345 | Game Programming | 7 | 06-05-2002 10:06 PM |
| My Maze Game --- A Few Questions | TechWins | Game Programming | 18 | 04-24-2002 11:00 PM |