Skip to content

Commit

Permalink
sexy background graphics!
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulSB committed Aug 21, 2011
1 parent 531edfa commit f1c8d08
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 0 deletions.
Binary file added data/textures/orb.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/textures/orb_micro.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/textures/orb_mini.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/states/PlayState.as
Expand Up @@ -13,6 +13,7 @@ package states
import ui.FailOverlay;
import ui.HealthBar;
import ui.WinOverlay;
import world.Background;
import world.Level;
import world.LevelManager;

Expand All @@ -34,6 +35,7 @@ package states

private var m_player:Player;
private var m_enemies:FlxGroup; // Test enemy
private var m_backgroundGFX:Background;

private var m_instructionText:FlxText;
private var m_instructionTarget:FlxSprite = null;
Expand Down Expand Up @@ -65,6 +67,8 @@ package states
{
super.create();

m_backgroundGFX = new Background;

m_levelManager = new LevelManager;
m_currentLevel = m_levelManager.getCurrentRoom();

Expand All @@ -87,6 +91,7 @@ package states
m_muteText.text = s_myMute ? "[M] Unmute" : "[M] Mute";

s_layerBackground = new FlxGroup;
s_layerBackground.add(m_backgroundGFX);
s_layerBackground.add(m_currentLevel.m_floor);

s_layerInScene = new FlxGroup;
Expand Down Expand Up @@ -484,6 +489,7 @@ package states
m_instructionText.visible = false;

m_music.stop(); // The silence is deafening
m_backgroundGFX.visible = false;
}
}
}
Expand Down
75 changes: 75 additions & 0 deletions src/world/Background.as
@@ -0,0 +1,75 @@
package world
{
import org.flixel.FlxG;
import org.flixel.FlxGroup;
import org.flixel.FlxSprite;

/**
* Ludum Dare 21 - Escape
* @author Paul S Burgess - 21/8/2011
*/
public class Background extends FlxGroup
{
[Embed(source = '../../data/textures/orb.png')] private var imgOrb:Class;
[Embed(source = '../../data/textures/orb_mini.png')] private var imgOrbMini:Class;
[Embed(source = '../../data/textures/orb_micro.png')] private var imgOrbMicro:Class;

private const NUM_ORBS:int = 80;
private const ORB_MAX_SPEED:int = 8;

public function Background()
{
for (var orbLoop:int = 0; orbLoop < NUM_ORBS; orbLoop++)
{
var newOrb:FlxSprite = new FlxSprite(Math.random() * FlxG.width, Math.random() * FlxG.height);

var typeRoll:Number = Math.random();
if (typeRoll < 0.4)
newOrb.loadGraphic(imgOrb);
else if (typeRoll < 0.7)
newOrb.loadGraphic(imgOrbMini);
else
newOrb.loadGraphic(imgOrbMicro);
newOrb.blend = "add";
newOrb.alpha = 0.5 + Math.random() * 0.5;

newOrb.x -= newOrb.width / 2;
newOrb.y -= newOrb.height / 2;
newOrb.velocity.x = (Math.random() - 0.5) * ORB_MAX_SPEED * 2;
newOrb.velocity.y = (Math.random() - 0.5) * ORB_MAX_SPEED * 2;

add(newOrb);
}
}

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

for each (var orb:FlxSprite in members)
{
if ( (orb.x < 0 - orb.width) || (orb.x > FlxG.width) || (orb.y < 0 - orb.height) || (orb.y > FlxG.height) )
{
// Recycle orbs:
orb.x = Math.random() * FlxG.width;
orb.y = Math.random() * FlxG.height;

var typeRoll:Number = Math.random();
if (typeRoll < 0.4)
orb.loadGraphic(imgOrb);
else if (typeRoll < 0.7)
orb.loadGraphic(imgOrbMini);
else
orb.loadGraphic(imgOrbMicro);
orb.blend = "add";
orb.alpha = 0.5 + Math.random() * 0.5;

orb.x -= orb.width / 2;
orb.y -= orb.height / 2;
orb.velocity.x = (Math.random() - 0.5) * ORB_MAX_SPEED * 2;
orb.velocity.y = (Math.random() - 0.5) * ORB_MAX_SPEED * 2;
}
}
}
}
}

0 comments on commit f1c8d08

Please sign in to comment.