The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

# Thread: [MX]beggining tile based movement

1. 50
posts
Registered User

## [MX]beggining tile based movement

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?

2. 1,550
posts
Mickey Mouse

## Re: [MX]beggining tile based movement

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?

3. 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.

4. 50
posts
Registered User
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