# \[MX\]beggining tile based movement

**URL:** <https://forum.kirupa.com/t/mx-beggining-tile-based-movement/26904>\
**Category:** flash\
**Created:** [July 28, 2003, 4:17am UTC](https://forum.kirupa.com/t/mx-beggining-tile-based-movement/26904 "2003-07-28T04:17:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mythmon](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@Mythmon](https://forum.kirupa.com/u/Mythmon)\
**Post date:** [July 28, 2003, 4:17am UTC](https://forum.kirupa.com/t/mx-beggining-tile-based-movement/26904/1 "2003-07-28T04:17:00Z")

</div>

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

[AS]  
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;
}

```

}  
[/AS]

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?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 28, 2003, 5:15am UTC](https://forum.kirupa.com/t/mx-beggining-tile-based-movement/26904/2 "2003-07-28T05:15:19Z")

</div>

> 

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?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 28, 2003, 6:20am UTC](https://forum.kirupa.com/t/mx-beggining-tile-based-movement/26904/3 "2003-07-28T06:20:49Z")

</div>

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/](http://outsideofsociety.idz.net/)

hope it helps.  
:beam:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 28, 2003, 2:19pm UTC](https://forum.kirupa.com/t/mx-beggining-tile-based-movement/26904/4 "2003-07-28T14:19:55Z")

</div>

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
