PDA

View Full Version : [MX]beggining tile based movement



Mythmon
July 28th, 2003, 12:17 AM
im staring into tile based coding and im trying to make a 8x8 grid with 3 kinds of terrain
0 = empty
1 = blocked
2 = swamp

now i have this code


speed = 4;

function walk (dir) {
// check dir
if ( dir == null ) {
return;
}
// where are our edges?
var downY = Math.floor( ( _y + (_height/2) ) /_parent.tileH );
var upY = Math.floor( ( _y - (_height/2) ) /_parent.tileH );
var leftX = Math.floor( ( _x - (_width/2) ) /_parent.tileW );
var rightX = Math.floor( ( _x + (_width/2) ) / _parent.tileW );
var centerX = Math.floor( _x / _parent.tileW );
var centerY = Math.floor( _y / _parent.tileH );

if ( dir == "up" && _parent.myMap[upY][centerX] == 2 ) {
speed = 2
} else {
speed = 4
}
if ( dir == "down" && _parent.myMap[downY][centerX] == 2 ) {
speed = 2
} else {
speed = 4
}
if ( dir == "left" && _parent.myMap[centerY][leftX] == 2 ) {
speed = 2
} else {
speed = 4
}
if ( dir == "right" && _parent.myMap[centerY][rightX] == 2 ) {
speed = 2
} else {
speed = 4
}

if ( dir == "up" && _parent.myMap[upY][centerX] != 1 ) {
_y -= speed;
}
if ( dir == "down" && _parent.myMap[downY][centerX] != 1 ) {
_y += speed;
}
if ( dir == "left" && _parent.myMap[centerY][leftX] != 1 ) {
_x -= speed;
}
if ( dir == "right" && _parent.myMap[centerY][rightX] != 1 ) {
_x += speed;
}
}


which, if i right reduce speed t 2 if going through swamp and increase to 4 if not, but it will only work if i go right (this is not all my script but its all thats important.)

can any one help me?

blah-de-blah
July 28th, 2003, 01:15 AM
which, if i right reduce speed t 2 if going through swamp and increase to 4 if not,


what do you mean by this part?? And is this like a game thing you're trying to make, like making a guy walk?

.:®:.
July 28th, 2003, 02:20 AM
hey there,

If you want the lowdown of tile based gaming, this guy Klas Kroon has some fantastic knowledge to share.

People may remember him from Jail*****.....

http://outsideofsociety.idz.net/

hope it helps.
:beam:

Mythmon
July 28th, 2003, 10:19 AM
im basically using the jail***** tutorial code all i addded was the code to decrease speed if entering a swamp land but it wont work