An one-button way to control the player coming from the past
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:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
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.
They can be easily customized to meet the unique requirements of your project.












This post has 6 comments
Georgiou Georgios
Hi Emanuele,
Thanx for the free code. Unfortunatelly does not works on Flash CS4. I hope to produce it for other versions of Flash.
lbineau
Hi,
I’ve done a quick version with Haxe NME
HTML5 : http://dl.dropbox.com/u/5239872/one_button/bin/html5/bin/index.html
AS3 : http://dl.dropbox.com/u/5239872/one_button/bin/flash/bin/onebutton.swf
But you can target Android or iOS with the same source code !(http://dl.dropbox.com/u/5239872/one_button/one_button.zip) :-)
egdcltd
A bit off topic I know, but what plugin are you using to display the code in your posts?
jujuwiwi
@egdcltd : have a look to the source. It’s wp_syntax for wordpress : http://wordpress.org/extend/plugins/wp-syntax/
egdcltd
Thanks jujuwiwi, I did look at the source but I must have missed that.
Jack
So would it be fine if i were to implement this into a game for the iOS platform? Or were you planning on actually using it?