Hello im trying to crate a game using tilemaps i have my tilemap laid out fine
i have my sprites working fine....
but i cant figure out how to check if a sprite is on a certain tile
for example : if Sprite was on a water tile i want it to play a water sound
here is my code
#include "DarkGDK.h"
const int RR=60;
const int grass=1;
const int rock=2;
const int water=3;
const int skull=4;
const int boat=5;
const int gator=6;
const int gator1=7;
const int TW=64;
const int TH=48;
const int TR=10;
const int TC=10;
int x;
int y;
int gatorx=600;
int gatory=600;
void setup();
void display(int[][TC],int);
void duck(int &,int &);
void ali();
void map();
void DarkGDK()
{
setup();
while(!dbEscapeKey())
{
map();
duck(x,y);
ali();
dbSync();
}
}
void setup()
{ dbSyncOn();
dbSyncRate(RR);
dbLoadImage("water.bmp",water);
dbLoadImage("grass.bmp",grass);
dbLoadImage("skull.bmp",skull);
dbLoadImage("boat.bmp",boat);
dbLoadImage("rock.bmp",rock);
dbCreateAnimatedSprite(gator,"gator.bmp",5,1,gator);
dbCreateAnimatedSprite(gator1,"gator1.bmp",5,1,gator1);
dbSetImageColorKey(0,0,0);
}
void display(int map[][TC],int rows)
{
int x=0,y=0;
for ( int r=0;r<rows;r++)
{
x=0;
for (int c=0;c<TC;c++)
{
dbPasteImage(map[r][c],x,y);
x+= TW;
}
y+=TH;
}
}
void map()
{
int TM[TR][TC]=
{
{grass,rock,grass,grass,grass,grass,grass,grass,grass,grass},
{grass,grass,grass,grass,rock,grass,grass,rock,grass,grass},
{water,water,water,water,grass,grass,grass,grass,grass,grass},
{water,grass,grass,water,grass,grass,grass,grass,grass,grass},
{water,grass,grass,water,grass,grass,grass,grass,grass,grass},
{water,grass,grass,water,water,water,water,water,grass,grass},
{water,water,water,water,grass,rock,grass,water,water,grass},
{grass,grass,grass,water,grass,grass,grass,grass,water,grass},
{rock,grass,grass,water,grass,grass,grass,rock,water,water},
{grass,grass,grass,skull,grass,grass,grass,rock,grass,grass}
};
display(TM,TR);
}
void duck(int &x,int &y)
{
dbOffsetSprite(boat,+dbSpriteWidth(boat)/2,+dbSpriteHeight(boat)/2);
dbSprite(boat,x,y,boat);// call sprite
if(dbMouseClick())
{
x=dbMouseX();
y=dbMouseY();
}
if (dbSpriteCollision(boat,0))
{dbHideSprite(boat);}
else{dbShowSprite(boat);}
}
void ali()
{ if(gator!=water)
{
if (gatorx<x)
gatorx++;
if (gatory<y)
gatory++;
if (gatorx>x)
gatorx--;
if (gatory>y)
gatory--;
}
if (gatorx<x )
dbShowSprite(gator1);
else dbHideSprite(gator1);
if(gatorx>x)
dbShowSprite(gator);
else
dbHideSprite(gator);
dbPlaySprite(gator,1,5,200);
dbSprite(gator,gatorx,gatory,gator);
dbOffsetSprite(gator,dbSpriteWidth(gator)/2,dbSpriteHeight(gator1)/2);
dbPlaySprite(gator1,1,5,200);
dbSprite(gator1,gatorx,gatory,gator1);
dbOffsetSprite(gator1,dbSpriteWidth(gator1)/2,dbSpriteHeight(gator1)/2);
}
as you can see im using mouse to move my sprite but i dont want to be able to leave the water....
could someone maybe edit or give an example in the simplest way im just learning how to use arrays so go easy =)