
One Button Vania - Just perfect, I hardly stopped, hard and extremely addicting, nice arts BTW :) #skill #game foe weekend #1 10.0 / 10
e+Games is nucleart.net team favorite games, books movies and more. A lot of oldschool, retro, classic game remakes and the best of new game releases we love. Also practical info on #gamedev #socialmedia and Empire Avenue. We love these games! :)

//Directory where class placedSource:
package
{
//Imported classes
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.media.Sound;
import flash.text.TextField;
import flash.events.MouseEvent;
import flash.utils.Timer;
import flash.events.TimerEvent;
//Class defenition
public class Game extends Sprite
{
//Assets
[Embed(source="resources/vector/background.svg", mimeType="image/svg-xml")]
public var BackgroundMenuAsset:Class;
[Embed(source="resources/vector/hero.svg", mimeType="image/svg-xml")]
public var HeroAsset:Class;
[Embed(source="resources/images/circle.png")]
public var CircleAsset:Class;
[Embed(source="resources/sound/hit.mp3")]
public var HitSoundAsset:Class;
//Variables
public var background:Sprite;
public var hero:Sprite;
public var enemy:Bitmap;
public var hit_sound:Sound;
public var custom_button:Sprite;
public var text_field:TextField;
public var timer:Timer;
//Constructor
public function Game():void
{
//Vector (.svg) background
//Create
background = new BackgroundMenuAsset();
//Place on Screen
addChild(background);
//Vector hero
hero = new HeroAsset();
addChild(hero);
//Set horisontal position
hero.x = 125;
//Bitmap (.png) enemy
enemy = new CircleAsset();
addChild(enemy);
enemy.y = 100;
//Sound (.mp3)
hit_sound = new HitSoundAsset();
hit_sound.play();
//Custom button
custom_button = new Sprite();
//Prommed graphics
custom_button.graphics.lineStyle(3,0x777777);
custom_button.graphics.beginFill(0xFFFFFFF);
custom_button.graphics.drawRect(0,0,100, 20);
custom_button.graphics.endFill();
addChild(custom_button);
//Add responce function to mouse click
custom_button.addEventListener(MouseEvent.CLICK, onClick);
//Create text
text_field = new TextField();
//Disable mouse interaction for text
text_field.mouseEnabled = false;
//Set text
text_field.text = "click";
addChild(text_field);
text_field.x = 20;
//Create timer for animation
timer = new Timer(1000 / 25, 0);
}
public function onClick(e:MouseEvent):void
{
//Testing mouse click responce
trace("onClick");
text_field.text = "clicked";
//Add function to every timer tick once per 1/25 second
timer.addEventListener(TimerEvent.TIMER, mainCicle);
//Start timer
timer.start();
//Move character to initial position
hero.x = 125;
}
public function mainCicle(e:TimerEvent):void
{
trace("mainCycle");
if (hero.x < 600)
{
//Move hero
hero.x += 10;
} else {
text_field.text = "click";
//Stop hero
timer.stop();
//Memory clean up
timer.removeEventListener(TimerEvent.TIMER, mainCicle);
}
}
}
}