//Global variables that will be accessed in the functions below
var TimerWalk; // timer handle for walking
var charStep = 2; // current step, 1=1st foot, 2=stand, 3=2nd foot, 4=stand
var currentKey = false; // records the current key pressed
var lockUp = false; // when lock up, character won't be able to move
var me; // character object
// Settings:
var walkSpeed = 110; //ms, animation speed
var walkLength = 7; //px, move how much px per "walk"
$(document).ready(function() {
obstacles = [
];
me = $('#character');
//add character state class
me.addClass('front-stand');
// iControl System
var $div = $('#character');
// Not Working & Buggy.
$('#ios-left').mousedown(function () {
clearInterval(TimerWalk);
TimerWalk = setInterval(function () {
processWalk('left');
}, 100);
}).mouseup(function () {
$div.stop();
clearInterval(TimerWalk);
}).mouse2touch();
$('#ios-right').mousedown(function () {
clearInterval(TimerWalk);
TimerWalk = setInterval(function () {
processWalk('right');
}, 100);
}).mouseup(function () {
$div.stop();
clearInterval(TimerWalk);
}).mouse2touch();
//Process Character Walk Function
function processWalk(dir) {
//increment the charStep as we will want to use the next stance in the animation
//if the character is at the end of the animation, go back to the beginning
charStep++;
if (charStep == 5)
charStep = 1;
//clear current class
me.removeAttr('class');
//add the new class
switch(charStep) {
case 1:
me.addClass(dir+'-stand');
break;
case 2:
me.addClass(dir+'-right');
break;
case 3:
me.addClass(dir+'-stand');
break;
case 4:
me.addClass(dir+'-left');
break;
}
//move the char
switch(dir) {
case'front':
newX = me.position().left;
newY = me.position().top + walkLength ;
break;
case'back':
newX =...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!