need help with tile collision detection.....
i have made a reasonable attempt at my own collision detection routine for a tile game. However i have run into a snag. I created a tile that reduces the player's speed by half, however it does not work as i intended it. it slows the player down perfect, however it makes the player jump back and forth when he is on a slowdown tile and against the wall. this makes it near impossible to move through a narrow gap with the slowdown tile there.
It sounds wierd i know, but if you could download my sourcecode and compile it you will understand better!
if anyone could tell me what i am doing wrong, or why i am getting this jumping effect and some idea to get rid of it, i would greatly appreciatte it. And i do check every single tile each time the player moves. But i will fix that later.
Source
Thanks for your time!
Werdy666
Edit:: how do i make a clickable link to my sourcecode??
Edit 2 :: Thanks!
[edited by - werdy666 on January 1, 2003 9:41:02 AM]
[edited by - werdy666 on January 1, 2003 9:48:52 AM]
Like this.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
‹a href="link">Word or sentence to click on‹/a>
EDIT:: np
.lick
[edited by - Pipo DeClown on January 1, 2003 10:14:19 AM]
EDIT:: np
.lick
[edited by - Pipo DeClown on January 1, 2003 10:14:19 AM]
It might be easier if you use a 2D array rather than store all the tiles with their positions, but anyway. . .
I added a function:
and I changed CheckKeyboardInput to this:
and it seems to work fine.
I added a function:
bool IsTileType(double x, double y, int type){ for (int p = 0; p<324;p++) if(tile[p].texture_number == type && fabs(x - tile[p].xpos) < 32 && fabs(y - tile[p].ypos) < 32) return true; return false;}
and I changed CheckKeyboardInput to this:
int CheckKeyboardInput(){ if (keys[VK_ESCAPE]) // Was ESC Pressed? { done=TRUE; // ESC Signalled A Quit } if (keys[VK_F1]) // Is F1 Being Pressed? { keys[VK_F1]=FALSE; // If So Make Key FALSE KillGLWindow(); // Kill Our Current Window fullscreen=!fullscreen; // Toggle Fullscreen / Windowed Mode // Recreate Our OpenGL Window if (!CreateGLWindow("OpenGL Basecode Version 0.40....",SCREENWIDTH,SCREENHEIGHT,BITSPERPIXEL,fullscreen)) { return 0; // Quit If Window Was Not Created } } if (keys[VK_LEFT]) { int speed = IsTileType(plyx, plyy, HALFSPEED) ? playerspeed/2 : playerspeed; if(!IsTileType(plyx-speed, plyy, WALL)) plyx -= speed; } if (keys[VK_RIGHT]) { int speed = IsTileType(plyx, plyy, HALFSPEED) ? playerspeed/2 : playerspeed; if(!IsTileType(plyx+speed, plyy, WALL)) plyx += speed; } if (keys[VK_UP]) { int speed = IsTileType(plyx, plyy, HALFSPEED) ? playerspeed/2 : playerspeed; if(!IsTileType(plyx, plyy-speed, WALL)) plyy -= speed; } if (keys[VK_DOWN]) { int speed = IsTileType(plyx, plyy, HALFSPEED) ? playerspeed/2 : playerspeed; if(!IsTileType(plyx, plyy+speed, WALL)) plyy += speed; }return true;}
and it seems to work fine.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
To create a link you can use either
or
As for the rest... I''m currently looking through your code
Some text to describe link
or
Some text to describe link
As for the rest... I''m currently looking through your code
If you run into a wall in a slowdown tile, you set the player back to his previous position, and, because it''s a slowdown tile, you set his pos another bit (half the movement speed) back. This has the result you are jumping back. smart_idiot already gave you a possible solution, I just wanted to tell you why this has happened.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement