Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 935219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:07:21+00:00 2026-05-15T21:07:21+00:00

Original code: (can be seen working here: http://sandbox.hokuten.net/jqrpg/ ) /* google.setOnLoadCallback(function() { */ $(function()

  • 0

Original code: (can be seen working here: http://sandbox.hokuten.net/jqrpg/)

/* google.setOnLoadCallback(function() { */
$(function() {

jqr = new Object();
jqr.settings = new Object();
jqr.settings.sprite_width = 16;
jqr.settings.sprite_height = 16;
jqr.settings.space = false;

jqr.p = new Object();
function jqrpgResetPlayer() {
    jqr.p.face = 'd';
    jqr.p.x = 3;
    jqr.p.y = 3;
    jqr.p.state = 'map';
}

jqr.map = new Object();
jqr.map.height  = 16;
jqr.map.width   = 16;
jqr.map.terrain = [
 '01','02','03','11','11','11','11','11','11','11','11','11','11','11','11','11',
 '01','01','00','00','11','00','00','11','11','00','00','00','00','00','00','00',
 '01','00','00','00','11','00','00','00','00','11','00','00','00','00','00','00',
 '01','00','00','00','00','00','00','11','00','11','00','00','00','00','00','00',
 '01','00','00','00','00','00','00','11','00','11','11','11','11','00','00','00',
 '00','00','00','00','00','11','11','00','00','00','00','00','11','00','00','00',
 '00','00','00','00','00','00','00','00','00','11','00','00','00','00','00','00',
 '00','00','00','00','00','00','00','00','00','00','00','00','00','00','00','00',
 '00','00','00','00','00','00','00','00','00','11','00','00','00','00','00','00',
 '00','00','00','00','00','00','00','00','00','00','00','00','11','00','00','00',
 '00','00','00','00','00','00','00','00','00','11','00','00','00','00','00','00',
 '00','00','00','00','00','00','00','00','00','11','00','00','00','00','00','00',
 '00','00','00','00','00','00','00','00','00','11','00','00','11','01','01','01',
 '00','00','00','00','00','00','00','00','00','11','11','11','00','00','00','01',
 '00','00','00','00','00','00','00','00','00','00','00','00','00','00','00','00',
 '00','00','00','00','00','00','00','00','00','00','00','00','00','00','00','00',
];
jqr.map.terrain_walkable = [
 '00','01','02',
];

jqr.battle = new Object();

jqrpgBuildMapHtml();
jqrpgUpdateMapClasses();
jqrpgResetPlayer();
jqrpgSetPlayerFace(jqr.p.face);
jqrpgSetPlayer(jqr.p.x, jqr.p.y);
jqrpgBindKeys();

/**
 * only call this once
 */
function jqrpgBuildInterface() {
    $('#jqrpg_wrapper').width($('#jqrpg_screen').width());
}
function jqrpgBuildMapHtml() {
    $('#jqrpg_screen, #jqrpg_wrapper').height(jqr.map.height * jqr.settings.sprite_height)
     .width(jqr.map.width * jqr.settings.sprite_width);
    m = $('#jqrpg_map');
    m.empty();
    for (y = 0; y < jqr.map.height; y++) {
        for (x = 0; x < jqr.map.width; x++) {
            // cti = y * x; // current_tile_index
            // <![CDATA[
            m.append('<span>.</span>');
            // ]]>
        }
    }
}

/**
 * call this whenever enter a new screen
 */
function jqrpgUpdateMapClasses() {
    for (y = 0; y < jqr.map.height; y++) {
        for (x = 0; x < jqr.map.width; x++) {
            cti = y * jqr.map.height + x; // current_tile_index
            ct = $('#jqrpg_map span').eq(cti);
            ct.removeClass()
             .addClass('tile')
             .addClass('tile_x' + x + 'y'+ y)
             .addClass('tile_' + jqr.map.terrain[cti]);
            if (y && x == 0) ct.addClass('tile_row');
        }
    }
    $('#jqrpg_map').fadeIn('slow');
}
function jqrpgSetPlayerFace(new_face) {
    $('#jqrpg_player').removeClass().addClass('face_' + new_face);
}
function jqrpgSetPlayer(new_x, new_y) {
    $('#jqrpg_player').css({
     'left' : new_x * jqr.settings.sprite_width,
     'top' : new_y * jqr.settings.sprite_height
    });
}

/**
 * key binding
 */
function jqrpgBindKeys() {
    $(document).bind('keydown', 'up', function() {
        if (jqr.p.state != 'map') return false;
        jqrpgSetPlayerFace('u');
        return jqrpgMovePlayer(0, -1);
    })
    .bind('keydown', 'Down', function() {
        if (jqr.p.state != 'map') return false;
        jqrpgSetPlayerFace('d');
        return jqrpgMovePlayer(0, 1);
    })
    .bind('keydown', 'Left', function() {
        if (jqr.p.state != 'map') return false;
        jqrpgSetPlayerFace('l');
        return jqrpgMovePlayer(-1, 0);
    })
    .bind('keydown', 'Right', function() {
        if (jqr.p.state != 'map') return false;
        jqrpgSetPlayerFace('r');
        return jqrpgMovePlayer(1, 0);
    })
    .bind('keypress', 'Space', function() {
        // if (console) console.log('space');
        if (jqr.p.state == 'map') return false;
        jqr.settings.space = true;
        if (jqr.p.state == 'battle') jqrpgBattle();
        return true;
    });
}

/**
 * movement
 */
function jqrpgMovePlayer(new_x, new_y) {
    // if (console) console.log('x: ' + jqr.p.x + '  y: ' + jqr.p.y);
    if (jqr.p.x + new_x + 1 > jqr.map.width
     || jqr.p.y + new_y + 1 > jqr.map.height
     || jqr.p.x + new_x + 1 == 0
     || jqr.p.y + new_y + 1 == 0
     || !jqrpgIsTileWalkable(jqr.p.x + new_x, jqr.p.y + new_y)
    ) return;
    jqr.p.x += new_x;   jqr.p.y += new_y;

    $('#jqrpg_player').dequeue().animate({
     left: jqr.p.x * jqr.settings.sprite_width,
     top: jqr.p.y * jqr.settings.sprite_height
    },
    250,
    function() {
        jqrpgGetRandomBattle();
    });
    return true;
}
function jqrpgIsTileWalkable(x, y) {
    return jQuery.inArray(jqr.map.terrain[(y) * 16 + x], jqr.map.terrain_walkable) > -1;
}
/**
 * battle
 */
function jqrpgGetRandomBattle() {
    var likelihood = Math.floor(Math.random() * 6) + 1;
    if (likelihood == 1) {
        jqrpgBattleInit();
    }
}
function jqrpgBattleInit() {
    jqr.p.state = 'battle';
    m = $('#jqrpg_menu');
    m.show();
    // <![CDATA[
    m.html('<p>Random battle! Press [space] to continue.</p>');
    // ]]>
    $('#jqrpg_wrapper').css({'border-color' : '#a00'});
}
function jqrpgBattle() {
    if (jqr.settings.space) {
        jqr.settings.space = false;
        jqrpgBattleEnd();
    }
}
function jqrpgBattleEnd() {
    jqr.p.state = 'map';
    $('#jqrpg_wrapper').css({'border-color' : '#000'});
    m.fadeOut('fast');
}

});

My code: (Can be seen working here: http://project-vanquish.co.cc/jQRPG/)

$(function() {

jqr = new Object();
jqr.settings = new Object();
jqr.settings.sprite_width = 16;
jqr.settings.sprite_height = 16;
jqr.settings.space = false;

jqr.p = new Object();
function jqrpgResetPlayer() {
    jqr.p.face = 'd';
    jqr.p.x = 3;
    jqr.p.y = 3;
    jqr.p.state = 'map';
}

jqr.map = new Object();
jqr.map.height  = 16;
jqr.map.width   = 16;
jqr.map.terrain = [
 '01','02','03','11','11','11','11','11','11','11','11','11','11','11','11','11',
 '01','01','00','00','11','00','00','11','11','00','00','00','00','00','00','00',
 '01','00','00','00','11','00','00','00','00','11','00','00','00','00','00','00',
 '01','00','00','00','00','00','00','11','00','11','00','00','00','00','00','00',
 '01','00','00','00','00','00','00','11','00','11','11','11','11','00','00','00',
 '00','00','00','00','00','11','11','00','00','00','00','00','11','00','00','00',
 '00','00','00','00','00','00','00','00','00','11','00','00','00','00','00','00',
 '00','00','00','00','00','00','00','00','00','00','00','00','00','00','00','00',
 '00','00','00','00','00','00','00','00','00','11','00','00','00','00','00','00',
 '00','00','00','00','00','00','00','00','00','00','00','00','11','00','00','00',
 '00','00','00','00','00','00','00','00','00','11','00','00','00','00','00','00',
 '00','00','00','00','00','00','00','00','00','11','00','00','00','00','00','00',
 '00','00','00','00','00','00','00','00','00','11','00','00','11','01','01','01',
 '00','00','00','00','00','00','00','00','00','11','11','11','00','00','00','01',
 '00','00','00','00','00','00','00','00','00','00','00','00','00','00','00','00',
 '00','00','00','00','00','00','00','00','00','00','00','00','00','00','00','00',
];
jqr.map.terrain_walkable = [
 '00','01','02',
];

jqr.battle = new Object();

jqrpgBuildMapHtml();
jqrpgUpdateMapClasses();
jqrpgResetPlayer();
jqrpgSetPlayerFace(jqr.p.face);
jqrpgSetPlayer(jqr.p.x, jqr.p.y);
jqrpgBindKeys();

/**
 * only call this once
 */
function jqrpgBuildInterface() {
    $('#jqrpg_wrapper').width($('#jqrpg_screen').width());
}
function jqrpgBuildMapHtml() {
    $('#jqrpg_screen, #jqrpg_wrapper').height(jqr.map.height * jqr.settings.sprite_height)
     .width(jqr.map.width * jqr.settings.sprite_width);
    m = $('#jqrpg_map');
    m.empty();
    for (y = 0; y < jqr.map.height; y++) {
        for (x = 0; x < jqr.map.width; x++) {
            // cti = y * x; // current_tile_index
            // <![CDATA[
            m.append('<span>.</span>');
            // ]]>
        }
    }
}

/**
 * call this whenever enter a new screen
 */
function jqrpgUpdateMapClasses() {
    for (y = 0; y < jqr.map.height; y++) {
        for (x = 0; x < jqr.map.width; x++) {
            cti = y * jqr.map.height + x; // current_tile_index
            ct = $('#jqrpg_map span').eq(cti);
            ct.removeClass()
             .addClass('tile')
             .addClass('tile_x' + x + 'y'+ y)
             .addClass('tile_' + jqr.map.terrain[cti]);
            if (y && x == 0) ct.addClass('tile_row');
        }
    }
    $('#jqrpg_map').fadeIn('slow');
}
function jqrpgSetPlayerFace(new_face) {
    $('#jqrpg_player').removeClass().addClass('face_' + new_face);
}
function jqrpgSetPlayer(new_x, new_y) {
    $('#jqrpg_player').css({
     'left' : new_x * jqr.settings.sprite_width,
     'top' : new_y * jqr.settings.sprite_height
    });
}

/**
 * key binding
 */
function jqrpgBindKeys() {
    $(document).bind('keydown', 'up', function() {
        if (jqr.p.state != 'map') return false;
        jqrpgSetPlayerFace('u');
        return jqrpgMovePlayer(0, -1);
    })
    .bind('keydown', 'Down', function() {
        if (jqr.p.state != 'map') return false;
        jqrpgSetPlayerFace('d');
        return jqrpgMovePlayer(0, 1);
    })
    .bind('keydown', 'Left', function() {
        if (jqr.p.state != 'map') return false;
        jqrpgSetPlayerFace('l');
        return jqrpgMovePlayer(-1, 0);
    })
    .bind('keydown', 'Right', function() {
        if (jqr.p.state != 'map') return false;
        jqrpgSetPlayerFace('r');
        return jqrpgMovePlayer(1, 0);
    })
    .bind('keypress', 'Space', function() {
        // if (console) console.log('space');
        if (jqr.p.state == 'map') return false;
        jqr.settings.space = true;
        if (jqr.p.state == 'battle') jqrpgBattle();
        return true;
    });
}

/**
 * movement
 */
function jqrpgMovePlayer(new_x, new_y) {
    // if (console) console.log('x: ' + jqr.p.x + '  y: ' + jqr.p.y);
    if (jqr.p.x + new_x + 1 > jqr.map.width
     || jqr.p.y + new_y + 1 > jqr.map.height
     || jqr.p.x + new_x + 1 == 0
     || jqr.p.y + new_y + 1 == 0
     || !jqrpgIsTileWalkable(jqr.p.x + new_x, jqr.p.y + new_y)
    ) return;
    jqr.p.x += new_x;   jqr.p.y += new_y;

    $('#jqrpg_player').dequeue().animate({
     left: jqr.p.x * jqr.settings.sprite_width,
     top: jqr.p.y * jqr.settings.sprite_height
    },
    250,
    function() {
        jqrpgGetRandomBattle();
    });
    return true;
}
function jqrpgIsTileWalkable(x, y) {
    return jQuery.inArray(jqr.map.terrain[(y) * 16 + x], jqr.map.terrain_walkable) > -1;
}
/**
 * battle
 */
function jqrpgGetRandomBattle() {
    var likelihood = Math.floor(Math.random() * 6) + 1;
    if (likelihood == 1) {
        jqrpgBattleInit();
    }
}
function jqrpgBattleInit() {
    jqr.p.state = 'battle';
    m = $('#jqrpg_menu');
    m.show();
    // <![CDATA[
    m.html('<p>Random battle! Press [space] to continue.</p>');
    // ]]>
    $('#jqrpg_wrapper').css({'border-color' : '#a00'});
}
function jqrpgBattle() {
    if (jqr.settings.space) {
        jqr.settings.space = false;
        jqrpgBattleEnd();
    }
}
function jqrpgBattleEnd() {
    jqr.p.state = 'map';
    $('#jqrpg_wrapper').css({'border-color' : '#000'});
    m.fadeOut('fast');
}

});

So, the problem I have is that my player movement executes more than once (seems to be 3 times).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:07:22+00:00Added an answer on May 15, 2026 at 9:07 pm

    The problem is in how they’re doing the bindings, with the 1.4.2 event model re-write that approach just doesn’t work anymore, but you can write it to work with 1.4.2, like this:

    function jqrpgBindKeys() {
        $(document).bind('keydown', function(e) {
            if (jqr.p.state != 'map' && e.which != 32) return false;
            switch(e.which) {
              case 38: //up
                jqrpgSetPlayerFace('u');
                return jqrpgMovePlayer(0, -1);
              case 40: //down
                jqrpgSetPlayerFace('d');
                return jqrpgMovePlayer(0, 1);
              case 37: //left
                jqrpgSetPlayerFace('l');
                return jqrpgMovePlayer(-1, 0);
              case 39: //right
                jqrpgSetPlayerFace('r');
                return jqrpgMovePlayer(1, 0);
              case 32: //space bar
                if (jqr.p.state == 'map') return false;
                jqr.settings.space = true;
                if (jqr.p.state == 'battle') jqrpgBattle();
                return true;
            }
        });
    }
    

    You can give it a try (using jQuery 1.4.2) here. You could also do this via an object map, etc…but this is the quick change version to make it work with 1.4.2.


    Separate issue:
    The problem is in your webhost, well…screwing with your page. If you look at the source on http://www.project-vanquish.co.cc/jQRPG/ you’ll see this at the end (modified to remove real domains):

    </body> 
    </html> 
    <!-- www.removedToProtectTheGuilty.com Analytics Code --> 
    <script type="text/javascript" src="http://analytics.example.com/count.php"></script> 
    <noscript><a href="http://www.example.com/"><img src="http://analytics.example.com/count.php" alt="web hosting" /></a></noscript> 
    <!-- End Of Analytics Code --> 
    

    That script executing after </html> causes all sorts of craziness around document.ready and will just give problems in general…if at all possible get rid of it, or try and get it inside <body></body>. Some webhosts look for a tag to stick it in, e.g.:

     <div id="analyticsCodeHere"></div>
    

    I’d see if you have that option 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 487k
  • Answers 487k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Not sure what you are trying to do but the… May 16, 2026 at 8:29 am
  • Editorial Team
    Editorial Team added an answer https://stackoverflow.com/questions/162144/what-is-a-good-ruby-on-rails-hosting-service/265646#265646 I'm not interested in learning how to configure Apache,… May 16, 2026 at 8:29 am
  • Editorial Team
    Editorial Team added an answer Yes, the result in example (1) could easily overflow if,… May 16, 2026 at 8:29 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.