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.


Results 1 to 4 of 4

Thread: [MX]beggining tile based movement

  1. #1

    [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. #2

    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. #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. #4
    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012