function player::onLevelLoaded(%this, %scenegraph) { // Set the players name to the instance $pSprite = %this; moveMap.bindCmd(keyboard, "a", "pSpriteLeft();", "pSpriteLeftStop();"); moveMap.bindCmd(keyboard, "d", "pSpriteRight();", "pSpriteRightStop();"); moveMap.bindCmd(keyboard, "w", "pSpriteJump();", ""); moveMap.bindCmd(keyboard, "g", "playGuitar();", ""); moveMap.bindCmd(keyboard, "lshift", "pSpriteRun;", "pSpriteUnRun();"); %this.setTimerOn(100); %this.standStill = 0; %this.ani = "stand"; %this.run = false; %this.jumping = false; } function playGuitar() { $pSprite.ani = "guitar"; $pSprite.guitarFrame = 0; } function player::walk(%this) { if (%this.walkFrame > 7) { %this.walkFrame = 1; } %this.setFrame(110 + (%this.walkFrame % 7)); %this.walkFrame++; } function player::playGuitar(%this) { if (%this.guitarFrame < 40) { %this.setFrame(70 + (%this.guitarFrame % 4)); %this.guitarFrame++; } else { %this.setFrame(0); %this.ani = "stand"; } } function player::footTap(%this) { if (%this.tapFrame > 3) { %this.tapFrame = 1; } %this.setFrame(10 + (%this.tapFrame % 3)); %this.tapFrame++; } function player::onTimer(%this) { %this.standStill++; switch$ (%this.ani) { case "stand": %this.setFrame(0); case "walk": %this.standStill = 0; %this.walk(); case "guitar": %this.standStill = 0; %this.playGuitar(); case "foottap": %this.footTap(); case "pocket": %this.setFrame(30); default: %this.setFrame(0); } if (%this.standStill > 50) { // If the player hasn't moved in 5 seconds %this.ani = "pocket"; } if (%this.standStill > 100) { // If player hasn't moved in 10 seconds %this.ani = "foottap"; } } function player::onCollision(%this, %srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts) { %this.jumping = false; %this.jump = false; } function player::updateMovement(%this) { %this.ani = "walk"; %this.walkFrame = 0; if (%this.moveLeft) { %this.direction = 0; %this.setLinearVelocityX( -%this.hSpeed ); } if (%this.moveRight) { %this.direction = 1; %this.setLinearVelocityX( %this.hSpeed ); } if (%this.jump && !%this.jumping) { echo("Jumping with " @ %this.jumpPower @ " power."); %this.setLinearVelocityY( -%this.jumpPower ); echo ("Linear Velocity: " @ %this.getLinearVelocityY()); %this.jumping = true; } if (%this.direction == 0) { %this.setFlip(true, false); } else { %this.setFlip(false, false); } if (!%this.moveLeft && !%this.moveRight) { %this.ani = "stand"; %this.setFrame(0); %this.setLinearVelocityX( 0 ); } } function pSpriteLeft() { $pSprite.moveLeft = true; $pSprite.updateMovement(); } function pSpriteRight() { $pSprite.moveRight = true; $pSprite.updateMovement(); } function pSpriteLeftStop() { $pSprite.moveLeft = false; $pSprite.updateMovement(); } function pSpriteRightStop() { $pSprite.moveRight = false; $pSprite.updateMovement(); } function pSpriteJump(){ $pSprite.jump = true; $pSprite.updateMovement(); }