PDA

View Full Version : Player bigger then tile-size...



Opie-T
January 14th, 2005, 04:02 AM
I've searched high and low, but sadly not found the answer to my problem...

I'm making a game with help of Tonypa's tutorial on tile-based games,
the hero in my game is 30 in width and 70 in height,
my tiles are 40 x 40... how can I make it work...?

Tonypa wrote:


game.clip.attachMovie("char", "char", 10000);
char.clip = game.clip.char;
char.x = (char.xtile * game.tileW)+game.tileW/2;
char.y = (char.ytile * game.tileH)+game.tileH/2;
char.width = char.clip._width/2;
char.height = char.clip._height/2;
char.clip._x = char.x;
char.clip._y = char.y;
And further down he wrote:


Note that you can create your own boundaries, you dont have to use width and height of movie clip. Some heros might have long puffy hair which can collide with walls, then declare your own width and height variables
What do I need to change?
Tried changing:
char.width = char.clip._width/2;
char.height = char.clip._height/2;
to:
char.width = 30;
char.height = 70;
but it didn't help much, as when I jumped, he landed in mid-air... :(

SeiferTim
January 14th, 2005, 12:18 PM
Basically, you need to make the corners of your sprite smaller than they actual image. For example, in a Zelda: Link to the Past style, where the sprite kind of overlaps the walls behind it to give a fake 3d appearence, all you need to say is that he is a few pixels shorter than he looks. LIke this:



game.clip.attachMovie("char", "char", 10000);
char.clip = game.clip.char;
char.x = (char.xtile * game.tileW)+game.tileW/2;
char.y = (char.ytile * game.tileH)+game.tileH/2;
char.width = char.clip._width/2;
char.height = (char.clip._height/2) - 10; //or whatever by however much you want him to overlap...
char.clip._x = char.x;
char.clip._y = char.y;
Now, I think that's correct, but since I'm not seeing all the code, I could be wrong...

Now, if you were using my tutorial, you would simply have to change this:


function checkCoords(x,y,direct){

guyTL = _root["tile_"+Math.floor((x-(_parent._width/2)+1)/_root.tileWdth)+"_"+Math.floor((y-(_parent._height/2)+1)/_root.tileHght)].barrier;
guyTR = _root["tile_"+Math.floor((x+(_parent._width/2)-1)/_root.tileWdth)+"_"+Math.floor((y-(_parent._height/2)+1)/_root.tileHght)].barrier;
guyBR = _root["tile_"+Math.floor((x+(_parent._width/2)-1)/_root.tileWdth)+"_"+Math.floor((y+(_parent._height/2)-1)/_root.tileHght)].barrier;
guyBL = _root["tile_"+Math.floor((x-(_parent._width/2)+1)/_root.tileWdth)+"_"+Math.floor((y+(_parent._height/2)-1)/_root.tileHght)].barrier;

switch(direct) {

case 0:
if (guyTL || guyTR) {

return false;

}
case 1:
if (guyBR || guyBL) {

return false;

}
case 2:
if (guyTR || guyBR) {

return false;

}
case 3:
if (guyTL || guyBL) {

return false;

}

}
return true;
to something like this:


function checkCoords(x,y,direct){

guyTL = _root["tile_"+Math.floor((x-(_parent._width/2)+1)/_root.tileWdth)+"_"+Math.floor((y-(_parent._height/2)-5)/_root.tileHght)].barrier;
guyTR = _root["tile_"+Math.floor((x+(_parent._width/2)-1)/_root.tileWdth)+"_"+Math.floor((y-(_parent._height/2)-5)/_root.tileHght)].barrier;
guyBR = _root["tile_"+Math.floor((x+(_parent._width/2)-1)/_root.tileWdth)+"_"+Math.floor((y+(_parent._height/2)-1)/_root.tileHght)].barrier;
guyBL = _root["tile_"+Math.floor((x-(_parent._width/2)+1)/_root.tileWdth)+"_"+Math.floor((y+(_parent._height/2)-1)/_root.tileHght)].barrier;

switch(direct) {

case 0:
if (guyTL || guyTR) {

return false;

}
case 1:
if (guyBR || guyBL) {

return false;

}
case 2:
if (guyTR || guyBR) {

return false;

}
case 3:
if (guyTL || guyBL) {

return false;

}

}
return true;

Opie-T
January 14th, 2005, 12:26 PM
Thanx! I'll try it out..