You are on page 1of 1

stop(); //stop from going to next frame. var g=0.

4; //Variable for gravity var


f=0.8; //Variable for friction //We use player before each variable below, to
assign the variables to the player object. player._x=Stage.width/2; //Players,
x (horizontal location). player.vx=0; //Velocity X player.vy=0; //Velocity y
player.power=10; //Power used to increase the vx for moving. player.jump=-130;
//What vy will be set to when jumping. player.jumping=false; //If the player is
jumping player.health=50; //The players health //Below we use enemy before th
e variables to assign the variables to the enemy object. enemy.vx=0; //Enemys v
x enemy.vy=0; //Enemys vy enemy.power=0.5; //Enemys power enemy.jump=-20; //
Enemys jump enemy.jumping=false; //if the enemy is jumping this.onEnterFrame=f
unction(){ //On every frame run this code brain(enemy,player); //Run the br
ain function with the "enemy" as the ob value, and "player" as the tr value.
player.vx*=f; //Multiply the playres vx value by f which will decrease it slow
ing the player down. player.vy+=g; //Add gravity to the players vy value.
player._y+=player.vy; //Move the players x position based off its vy. h
ealthbar.gotoAndStop(player.health); //Set the healthbars frame to player.heath
if(player.health<=0){ //if the players heath goes below 0 ie Dead.
cleanup(); //Run our cleanup function }// Close the if statement if(p
layer._x>(Stage.width/2)-20 && player._x<(Stage.width/2)+20){ //if the
players x is within 40 pixels of stage center. ground._x-=player.vx; //
move the ground instead of the player in the opposite direction. enemy.
_x-=player.vx; //move the enemy away also }else{ //else meaning if the abov
e condition is not true then do the following player._x+=player.vx; //m
ove the player because they are out of the center }//close the else. u
pdater(enemy); //run the update function using "enemy" as the ob value. if(
Key.isDown(Key.LEFT)&& !_root.ground.hitTest(pla

You might also like