Talking about Pacco game, Actionscript 3, Flash and Game development.
I always loved one-button games. First, they can be played with just one button. Second, in the mobile game era, it’s easy to port an on-button concept to an one-tap concept.
Almost five years ago (ages!!) I showed a strange way to move the player with Flash made with AS2, and I find it interesting to port it to AS3, to be ported again in other languages.
Since you can find the complete theory in the original post, I will just post the AS3 source code:
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
public class Main extends Sprite {
private var ball:Ball=new Ball();
private var directionArrow:DirectionArrow=new DirectionArrow();
private var powerText:TextField = new TextField();
private var rotate:Boolean=true;
private var power:Number=0;
private var xSpeed:Number=0;
private var ySpeed:Number=0;
private var friction:Number=0.975;
private var rotationSpeed:Number=5;
public function Main() {
addChild(ball);
ball.x=320;
ball.y=240;
ball.addChild(directionArrow);
powerText.textColor = 0xffffff;
powerText.y=-10;
powerText.x=-5;
powerText.visible=false;
ball.addChild(powerText);
addEventListener(Event.ENTER_FRAME,update);
stage.addEventListener(MouseEvent.MOUSE_DOWN,prepareLaunch);
stage.addEventListener(MouseEvent.MOUSE_UP,launch);
}
private function prepareLaunch(e:MouseEvent):void {
powerText.visible=true
rotate=false;
}
private function launch(e:MouseEvent):void {
if (! rotate) {
powerText.visible=false;
rotate=true;
xSpeed+=power*Math.cos((directionArrow.rotation-90)*0.0174532925)/10;
ySpeed+=power*Math.sin((directionArrow.rotation-90)*0.0174532925)/10;
power=0;
rotationSpeed*=-1;
}
}
private function update(e:Event):void {
if (rotate) {
directionArrow.rotation+=rotationSpeed;
}
else {
power++;
power=Math.min(power,50);
powerText.text=power.toString();
}
ball.x+=xSpeed;
ball.y+=ySpeed;
xSpeed*=friction;
ySpeed*=friction;
}
}
}
and this is the result:
Press and keep the mouse pressed to move the ball with a given direction and speed
During next days I’ll port this prototype into the most famous formats.
Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.