PUSHRIGHT
/**
* Copyright Albert ( http://wonderfl.net/user/Albert )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/90yq
*/
package {
import org.flixel.*;
[SWF(width="640", height="480", backgroundColor="#f0f0f0")]
public class Main extends FlxGame
{
public function Main():void
{
super(480, 480, PlayState, 1);
}
}
}
import flash.display.Graphics;
import org.flixel.*;
class PlayState extends FlxState
{
private var SoundExplosionShip:Class;
private var SoundExplosionAlien:Class;
private var _ship: Ship;
private var _aliens: FlxGroup;
private var _scoreText: FlxText;
private var _gameOverText: FlxText;
private var _spawnTimer: Number;
private var _spawnInterval: Number = 0.01;
override public function create():void
{
FlxG.score = 0;
FlxG.bgColor = 0xFFF0F0B0;
_ship = new Ship();
add(_ship);
_aliens = new FlxGroup();
add(_aliens);
var reflection:FlxSprite = new FlxSprite;
reflection.makeGraphic(FlxG.width/3, FlxG.height, 0xD0ffaa55);
reflection.x = FlxG.width/3*2;
reflection.scrollFactor.x = 0;
reflection.scrollFactor.y = 0;
add(reflection);
_scoreText = new FlxText(10, 8, 200, "0");
_scoreText.setFormat(null, 32, 0x404040, "left");
add(_scoreText);
resetSpawnTimer();
super.create();
}
override public function update():void
{
//FlxG.collide(_aliens, _ship, overlapAlienShip);
FlxG.collide(_aliens, _ship);
if(FlxG.keys.justPressed("SPACE") && _ship.alive)
{
//spawnBullet(_ship.getBulletSpawnPosition());
}
if(FlxG.keys.ENTER && !_ship.alive)
{
FlxG.switchState(new PlayState());
}
_spawnTimer -= FlxG.elapsed;
if(_spawnTimer < 0)
{
spawnAlien();
resetSpawnTimer();
}
if (_ship.alive && _ship.x>FlxG.width/3*2)
{
FlxG.score += 1;
_scoreText.text = FlxG.score.toString();
}
super.update();
}
private function spawnAlien():void
{
var x: Number = FlxG.width;
var y: Number = Math.random() * (FlxG.height - 100) + 50;
_aliens.add(new Alien(x, y));
}
private function resetSpawnTimer():void
{
_spawnTimer = _spawnInterval;
_spawnInterval *= 0.95;
if(_spawnInterval < 0.1)
{
_spawnInterval = 0.1;
}
}
private function overlapAlienShip(alien: Alien, ship: Ship):void
{
var emitter:FlxEmitter = createEmitter();
emitter.at(ship);
ship.kill();
alien.kill();
FlxG.shake(0.02);
FlxG.play(SoundExplosionShip);
_gameOverText = new FlxText(0, FlxG.height / 2, FlxG.width, "GAME OVER\nPRESS ENTER TO PLAY AGAIN");
_gameOverText.setFormat(null, 16, 0xFF597137, "center");
add(_gameOverText);
}
private function createEmitter():FlxEmitter
{
var emitter:FlxEmitter = new FlxEmitter();
//emitter.delay = 1;
emitter.gravity = 0;
emitter.maxRotation = 0;
emitter.setXSpeed(-500, 500);
emitter.setYSpeed(-500, 500);
var particles: int = 100;
for(var i: int = 0; i < particles; i++)
{
var particle:FlxParticle = new FlxParticle();
particle.makeGraphic(2, 2, 0xFF597137);
particle.exists = false;
emitter.add(particle);
}
emitter.start();
add(emitter);
return emitter;
}
}
//import flash.display.BitmapData;
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
class Alien extends FlxSprite
{
public function Alien(x: Number, y: Number):void
{
super(x, y, null);
velocity.x = -200;
/*var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
loader.load(new URLRequest("http://assets.wonderfl.net/images/related_images/3/32/32c3/32c3229c715c4e15e3541fd1e587dff9a13dacb7"), new LoaderContext(true));
*/
//Graphics.drawCircle(10,10,10);
}
override public function update():void
{
velocity.y = Math.cos(x / 50) * 50;
velocity.x = -200;
super.update();
}
}
class Ship extends FlxSprite
{
public function Ship():void
{
super(50, 50, null);
scale.x=2;
scale.y=2;
/*var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
loader.load(new URLRequest("http://assets.wonderfl.net/images/related_images/9/92/929d/929d78524407f32a5687e3a4aa8fd2c6a91ba433"), new LoaderContext(true));
*/
}
override public function update():void
{
velocity.x = 0;
velocity.y = 0;
if(FlxG.keys.LEFT)
{
velocity.x = -50;
}
else if(FlxG.keys.RIGHT)
{
velocity.x = 50;
}
if(FlxG.keys.UP)
{
velocity.y = -50;
}
else if(FlxG.keys.DOWN)
{
velocity.y = 50;
}
super.update();
if(x > FlxG.width-width-16)
{
x = FlxG.width-width-16;
}
else if(x < 16)
{
x = 16;
}
if(y > FlxG.height-height-16)
{
y = FlxG.height-height-16;
}
else if(y < 16)
{
y = 16;
}
}
}