So this might be an odd question to ask. But I'm not really the biggest mathematician out there, and I have a weird habit of writing code. So I'm going to post what I'm working on. I'm doing a self-game jam this weekend which will be 48 hours long, and I've kind of cheated by already starting. The question is -- well what I'm trying to do is create a ease-in / bouncing effect without using a Tween library.
I feel that what I have is suffice, but I don't think it is very efficient and that I'm overcomplicating my code with clutter.
Below is code from my Engine class with comments that should help decipher what I am doing.
package {
import flash.display.MovieClip;
import flash.ui.Mouse;
import flash.display.Stage;
import flash.events.Event;
public class Engine extends MovieClip {
public var spaceShip:Ship = new Ship(stage);
private var logo:IcarusLogo = new IcarusLogo();
//Math, Velocities , Numbers
private var vF : Number = 0.5; // Velocity Forward
private var vX : Number = 0; // Velocity X
private var vY : Number = 0; // Velocity Y
private var iV : Number = 0.2; // Initial Velocity
private var fV : Number = .90; //Friction
private static var pI:Number = 3.14; // pI
public function Engine() {
initGraphics();
runGame();
Mouse.hide();
}
//INIT EVERYTHING
private function initGraphics():void {
initShip();
initLogo();
}
private function initShip():void {
spaceShip.x = stage.stageWidth/2;
spaceShip.y = stage.stageHeight/2;
stage.addChild(spaceShip);
}
private function initLogo():void {
stage.addChild(logo);
logo.x = stage.stageWidth - 1200;
logo.y = 200;
}
//RUN THE GAME
private function runLogoStyles():void {
logo.x += vX;
iV = .025;
vX *= fV + iV;
if (logo.x <= 450) {
logo.x += vX;
vX += fV + iV;
iV = -.2;
}
}
public function runGame():void {
stage.addEventListener(Event.ENTER_FRAME, update);
}
public function update(e:Event):void {
runGame();
runLogoStyles();
}
//TRASH EVERYTHING THATS NOT NEEDED.
//AS3 HAS NO NARC RULE SO JUST REMOVE.CHILD
public function trashCan():void {
//TrashCan is similar to init. Create Sub-Functions // and init everything in here.
}
}
}
Here's a screenshot to give a better understanding : http://f.cl.ly/items/3X3j0L052v0M2b0v2p1b/screen.png