Posted: 26th Dec 2008 23:27
hello all
i'm having some problem with collision.
i'm using a Tile Based
// Dark GDK - The Game Creators - www.thegamecreators.com
// the wizard has created a very simple project that uses Dark GDK
// it contains the basic code for a GDK application
// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"
// the main entry point for the application is this function
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
int Tiles[10][10] ={
4,4,4,4,4,4,4,4,4,4,
4,3,3,3,3,3,2,2,2,4,
4,3,3,3,2,2,2,2,2,4,
4,3,3,2,2,2,2,2,2,4,
4,4,4,3,2,2,3,3,2,4,
4,4,2,2,3,3,2,2,2,4,
4,3,2,2,3,3,3,2,2,4,
4,2,2,2,2,2,3,3,4,4,
4,3,3,2,2,3,2,2,2,4,
4,4,4,4,4,4,4,4,4,4};
int TileEndX = 0;
int TileNM = 0;
dbSyncOn ( );
dbSyncRate ( 60 );
dbSetDir("Tiles");
dbCreateAnimatedSprite(200,"soldier.png",3,4,1);
dbLoadImage("sand.jpg",2);
dbLoadImage("bush.jpg",3);
dbLoadImage("trees.jpg",4);
dbSetSpriteFrame(200,1);
dbSprite(200,dbScreenWidth()/2,300,1);
dbSetSpritePriority(200,1);
// our main loop
for (int y = 0; y < 10; y++)
{
TileEndX = 0;
for (int x = 0; x < 10; x++)
{
TileNM++;
dbSprite(TileNM,TileEndX,y*50,Tiles[y][x]);
TileEndX = dbSpriteX(TileNM) + dbSpriteWidth(TileNM);
}
}
while ( LoopGDK ( ) )
{
if (dbRightKey() && dbSpriteImage (dbSpriteCollision(200,0) != 4 ))
dbSprite(200,dbSpriteX(200) + 4,dbSpriteY(200),1);
// update the screen
dbSync ( );
}
for (int i = 0 ; i < 257; i++)
{
dbDeleteSprite(i);
dbDeleteImage(i);
}
// return back to windows
return;
as you can see in the code
i tried all kind of collision but with no succses ..
so eventually , i came up with the idea of
instead finding the Tile number i want the player to colide with
i want the Number of the Image therefor i don't care for what Number is the sprite i'm colliding with i just want its number..
i think i wrote it twice.. but well.. i'm pretty tired.............
so , well this for me dosen't work , but still i think its an awesome idea on how to make collide simple.. when we come to Borders of the tile map , or even when we have an active tile.
if we getting its Image number and not its Tile number(Sprite Number) we can do the same calc and if we want an extra we just add another if or else.. instead of going trough all tiles in a loop to check..
ok i write too much..
pls help with this , i'm not sure its correct but if it is i will be very happy.. for now i go to sleep.
ty for your time.
nadav.