// The game gravity
var gravity = 0.8;
// The floor position (y)
var floor = 300;
// Add the hero MovieClip
var hero = new Hero();
// Set the x position
hero.x = 550 / 2;
// Set the y position on the floor
hero.y = floor;
// Set the hero state to "stand"
hero.gotoAndStop("stand");
// Add hero on the display list
addChild(hero);
// Create and set the speedY property to 0
hero.speedY = 0;
// Create and set the jump impulsion to 10
hero.impulsion = 10;
// Add an enter frame event
hero.addEventListener(Event.ENTER_FRAME, heroEnterFrame);
function heroEnterFrame(pEvent)
{
// On each frames...
// Set the world gravity
hero.speedY += gravity;
// Move the hero with his speedY
hero.y += hero.speedY;
// If the y property is larger than the floor position
if (hero.y > floor)
{
// Set the hero on the floor
hero.y = floor;
// Cancel the current speed
hero.speedY = 0;
// Change the state to stand
hero.gotoAndStop("stand");
}
}
// Add a mouse event on the stage
stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
function mouseDown(pEvent)
{
// When the user click on the stage...
// If the hero is standing
if (hero.currentLabel == "stand")
{
// Set the new speedY with the hero impulsion
hero.speedY = - hero.impulsion;
// And change the state to jump
hero.gotoAndStop("jump");
}
}
WHAT'S NEW?
Loading...
Gravity mc
- Judul : Gravity mc
- Penulis : PF studio
- Kategori : Archive
-
Rating : 100% based on 10 ratings. 5 user reviews.
Item Reviewed: Gravity mc
9 out of 10 based on 10 ratings. 9 user reviews.
facebook
twitter
google+
fb share