mercredi 19 avril 2017

Action Script Character jump and falls

I am trying to make a minion game. I want to make it jump, and fall back down. At the moment it jumps, but no matter what I do it doesn't fall back down. What am I doing wrong?

import flash.display.MovieClip;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.events.Event;


stage.addEventListener(KeyboardEvent.KEY_DOWN, moveMinionLeft);

function moveMinionLeft (e:KeyboardEvent):void{
    if (e.keyCode == Keyboard.LEFT){
    sideMinion.x -=10; 
        sideMinion.left();

    } 

    if (e.keyCode == Keyboard.RIGHT){
    sideMinion.x +=10;
        sideMinion.right();
} 

}
var gravity:Number = 1.5;
var jump:Number = 10;
var ySpeed:Number = 0;
var falling:Boolean=false;

stage.addEventListener(KeyboardEvent.KEY_UP, jumpMinion);

function jumpMinion(e:KeyboardEvent):void{

    if(e.keyCode == Keyboard.SPACE){
        ySpeed=-jump;
        sideMinion.y=ySpeed;
        if(falling){
        ySpeed+=gravity;
        trace("jump");
         }
        }
}

Aucun commentaire:

Enregistrer un commentaire