/* * Character.as - the player class for the platform game moving platform tutorial * Author: Stephen Harris, Kaiparasoft Ltd * */ class Character extends MovieClip { // velocity var vx = 0; var vy = 0; // is the player touching the ground currently var onGround:Boolean = true; // a reference to one of the game platforms if the player is on one, or null if the player isn't touching any platforms var myMovPlat:MovieClip = null; // reference to the main game object var mainApp:PlatformGame; // constructor - empty function Character(){ } // update function called from the game object every frame function Update(){ // simulate gravity if(!onGround){ vy += 0.5; myMovPlat = null; } else{ if(mainApp.jump == false){ vy = 0; } } // update the position based on the velocities _x += vx // if the moving platform reference is not null, update the players position to match the movement of the platform if(myMovPlat != null){ _x += myMovPlat.linearSpeed*myMovPlat.dirn; } _y += vy; } }