Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

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