Skip to content

Commit

Permalink
Create an additonal little splosion for the player also.
Browse files Browse the repository at this point in the history
  • Loading branch information
djcsdy committed Aug 23, 2010
1 parent a6b7d2e commit 89152b3
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 14 deletions.
Expand Up @@ -6,10 +6,12 @@ package net.noiseinstitute.ld18

import org.flixel.*;

public class Splosion extends ThingThatScores
public class AlienSplosion extends ThingThatScores
{
private static const START_RADIUS:Number = 16;
private static const END_RADIUS:Number = 32;
private static const WIDTH:Number = 32;
private static const HEIGHT:Number = 32;
private static const START_RADIUS:Number = 12;
private static const END_RADIUS:Number = 24;
private static const COLOUR:uint = 0xffffff;
private static const START_ALPHA:Number = 0.5
private static const ANIMATION_LENGTH:uint = 30;
Expand All @@ -18,11 +20,11 @@ package net.noiseinstitute.ld18

private var _pointValue :Number;

public function Splosion(x:Number=0, y:Number=0)
public function AlienSplosion(x:Number=0, y:Number=0)
{
super(x, y);
width = START_RADIUS*2;
height = START_RADIUS*2;
width = WIDTH;
height = HEIGHT;
centreX = x;
centreY = y;
_pointValue = 0;
Expand All @@ -32,7 +34,6 @@ package net.noiseinstitute.ld18
}

override public function update():void {
--angle;
++frame;
super.update();
}
Expand Down
4 changes: 2 additions & 2 deletions src/net/noiseinstitute/ld18/LD18Sprite.as
Expand Up @@ -5,9 +5,9 @@ package net.noiseinstitute.ld18

public class LD18Sprite extends FlxSprite
{
public function LD18Sprite(X:Number=0, Y:Number=0, SimpleGraphic:Class=null)
public function LD18Sprite(x:Number=0, y:Number=0, SimpleGraphic:Class=null)
{
super(X, Y, SimpleGraphic);
super(x, y, SimpleGraphic);
}

public function get centreX():Number {
Expand Down
23 changes: 18 additions & 5 deletions src/net/noiseinstitute/ld18/PlayState.as
Expand Up @@ -29,6 +29,7 @@ package net.noiseinstitute.ld18
// Sprites
private var arena:Arena;
private var ship:Ship;
private var playerGroup:FlxGroup;
protected var aliens:FlxGroup;
public var bullets:FlxGroup;
private var collidables:FlxGroup;
Expand Down Expand Up @@ -74,9 +75,11 @@ package net.noiseinstitute.ld18
// Create group to contain splosions, but don't add it yet.
splosions = new FlxGroup();

// Create the ship
// Create the ship and group to contain it and related guff
ship = new Ship();
add(ship);
playerGroup = new FlxGroup();
playerGroup.add(ship);
add(playerGroup);

// Add splosions group second-last, so it appears above other sprites
add(splosions);
Expand Down Expand Up @@ -271,6 +274,7 @@ package net.noiseinstitute.ld18
}

protected function overlapped(obj1:LD18Sprite, obj2:LD18Sprite):void {
var timer:Timer;
if (obj2 is AlienDeathBall) {
var alien:AlienDeathBall = AlienDeathBall(obj2);
if(obj1 is Ship && !obj1.dead) {
Expand All @@ -280,6 +284,15 @@ package net.noiseinstitute.ld18
ship.kill();
gameEndTick = tick;

// Make asplode
var splosion:PlayerSplosion = new PlayerSplosion(ship.centreX, ship.centreY);
playerGroup.add(splosion);
timer = new Timer(REMOVE_SPLOSION_TIME, 1);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, function ():void {
playerGroup.remove(splosion);
});
timer.start();

// Penalize the point value of the alien
alien.penalize();
}
Expand Down Expand Up @@ -307,16 +320,16 @@ package net.noiseinstitute.ld18
FlxG.score += pointValue;

// For each, place a splosion that can trigger chain reactions
var splosion1:Splosion = new Splosion(alien.centreX, alien.centreY);
var splosion2:Splosion = new Splosion(obj1.centreX, obj1.centreY);
var splosion1:AlienSplosion = new AlienSplosion(alien.centreX, alien.centreY);
var splosion2:AlienSplosion = new AlienSplosion(obj1.centreX, obj1.centreY);
splosion1.chainMultiplier = thingThatScores.chainMultiplier + 1;
splosion2.chainMultiplier = thingThatScores.chainMultiplier + 1;
splosion1.pointValue = pointValue;
splosion2.pointValue = pointValue;
aliens.add(splosion1);
aliens.add(splosion2);

var timer:Timer = new Timer(CHAIN_REACTION_TIME, 1);
timer = new Timer(CHAIN_REACTION_TIME, 1);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, function ():void {
splosion1.dead = true;
splosion2.dead = true;
Expand Down
53 changes: 53 additions & 0 deletions src/net/noiseinstitute/ld18/PlayerSplosion.as
@@ -0,0 +1,53 @@
package net.noiseinstitute.ld18
{
import flash.display.BlendMode;
import flash.display.Graphics;
import flash.display.Sprite;

import org.flixel.*;

public class PlayerSplosion extends LD18Sprite
{
private static const START_RADIUS:Number = 8;
private static const END_RADIUS:Number = 16;
private static const COLOUR:uint = 0xffffff;
private static const START_ALPHA:Number = 0.5
private static const ANIMATION_LENGTH:uint = 30;

private var drawSprite:Sprite;

private var _pointValue :Number;

public function PlayerSplosion(x:Number=0, y:Number=0) {
super(x, y);
width = START_RADIUS*2;
height = START_RADIUS*2;
centreX = x;
centreY = y;
_pointValue = 0;

drawSprite = new Sprite();
frame = 0;
}

override public function update():void {
++frame;
super.update();
}

override public function render():void {
var graphics:Graphics = drawSprite.graphics;
graphics.clear();
graphics.beginFill(COLOUR, START_ALPHA - (frame * START_ALPHA / ANIMATION_LENGTH));
graphics.drawCircle(0, 0, END_RADIUS + (START_RADIUS-END_RADIUS) * (ANIMATION_LENGTH-frame)/ANIMATION_LENGTH);

getScreenXY(_point);
_mtx.identity();
if(angle != 0) {
_mtx.rotate(Math.PI * 2 * (angle / 360));
}
_mtx.translate(_point.x+START_RADIUS,_point.y+START_RADIUS);
FlxG.buffer.draw(drawSprite, _mtx, null, BlendMode.ADD);
}
}
}

0 comments on commit 89152b3

Please sign in to comment.