Skip to content

Commit

Permalink
9x9 floor of tiles rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulSB committed Aug 20, 2011
1 parent 5988bc6 commit c41a8f8
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 8 deletions.
Binary file added data/textures/tile_floor.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions src/Main.as
@@ -1,23 +1,24 @@
package
{
import org.flixel.FlxGame;
import states.MenuState;
//import states.MenuState;
import states.PlayState;

// Display properties
[SWF(width = "720", height = "480", backgroundColor = "#000000")]
// Prep preloader
[Frame(factoryClass="Preloader")]

/**
* Ludum Dare 21 -
* @author Paul S Burgess -
* Ludum Dare 21 - Escape
* @author Paul S Burgess - 20/8/2011
*/
public class Main extends FlxGame
{
public function Main()
{
// Entry - invoke FlxGame constructor
super(800, 600, MenuState, 1, 60, 30, true);
super(180, 120, PlayState/*MenuState*/, 4, 60, 30, true);
}
}
}
4 changes: 2 additions & 2 deletions src/Preloader.as
Expand Up @@ -3,8 +3,8 @@ package
import org.flixel.system.FlxPreloader;

/**
* Ludum Dare 21 -
* @author Paul S Burgess -
* Ludum Dare 21 - Escape
* @author Paul S Burgess - 20/8/2011
*/
public class Preloader extends FlxPreloader
{
Expand Down
17 changes: 17 additions & 0 deletions src/game/Player.as
@@ -0,0 +1,17 @@
package game
{
import org.flixel.FlxSprite;

/**
* Ludum Dare 21 - Escape
* @author Paul S Burgess - 20/8/2011
*/
public class Player extends FlxSprite
{

public function Player()
{

}
}
}
31 changes: 29 additions & 2 deletions src/states/MenuState.as
@@ -1,16 +1,43 @@
package states
{
import org.flixel.FlxG;
import org.flixel.FlxState;
import org.flixel.FlxText;

/**
* Ludum Dare 21 -
* @author Paul S Burgess -
* Ludum Dare 21 - Escape
* @author Paul S Burgess - 20/8/2011
*/
public class MenuState extends FlxState
{
//[Embed(source = "../../data/font/Robotaur Condensed.ttf", fontFamily = "Robotaur", embedAsCFF = "false")] private var junk:String;

public function MenuState()
{
// Title text
var tTxt:FlxText;
tTxt = new FlxText(0, FlxG.height / 2 -12, FlxG.width, "ESCAPE");
tTxt.setFormat(null, 16, 0xffffffff, "center");
this.add(tTxt);

// Instruction text
tTxt = new FlxText(0, FlxG.height -12, FlxG.width, "Press SPACE to begin");
tTxt.setFormat(null, 8, 0xffffffff, "center");
this.add(tTxt);
}

override public function update():void
{
if (FlxG.keys.justPressed("SPACE"))
{
FlxG.fade(0xff000000, 0.5, onFade);
}
super.update();
}

private function onFade():void
{
FlxG.switchState( new PlayState() );
}
}
}
30 changes: 30 additions & 0 deletions src/states/PlayState.as
@@ -0,0 +1,30 @@
package states
{
import org.flixel.FlxGroup;
import org.flixel.FlxState;
import world.Level;
import world.LevelManager;

/**
* Ludum Dare 21 - Escape
* @author Paul S Burgess - 20/8/2011
*/
public class PlayState extends FlxState
{
private var m_levelManager:LevelManager;
private var m_currentLevel:Level; // Current room reference

public static var s_layerBackground:FlxGroup;

public function PlayState()
{
m_levelManager = new LevelManager;
m_currentLevel = m_levelManager.getCurrentRoom();

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

add(s_layerBackground);
}
}
}
47 changes: 47 additions & 0 deletions src/world/Level.as
@@ -0,0 +1,47 @@
package world
{
import org.flixel.FlxG;
import org.flixel.FlxGroup;
import org.flixel.FlxSprite;
//import org.flixel.FlxU;

/**
* Ludum Dare 21 - Escape
* @author Paul S Burgess - 20/8/2011
*/
public class Level extends FlxGroup
{
[Embed(source = '../../data/textures/tile_floor.png')] private var imgTileFloor:Class;

private const ROOM_TILE_SIZE:int = 9;
private const ROOM_DRAW_X:int = FlxG.width / 2 - 9;
private const ROOM_DRAW_Y:int = 12;

public function Level()
{
// Create level
var r:Number = (Math.random() * 255.0);
var g:Number = (Math.random() * 255.0);
var b:Number = (Math.random() * 255.0);
var roomColour:uint = 0xff000000 + (r << 16) + (g << 8) + b;

var x:int = ROOM_DRAW_X, y:int = ROOM_DRAW_Y;
for (var j:int = 0; j <= ROOM_TILE_SIZE; ++j)
{
for (var i:int = 0; i < ROOM_TILE_SIZE; ++i)
{
var tile:FlxSprite = new FlxSprite(x,y);
tile.loadGraphic(imgTileFloor);
tile.color = roomColour;
add(tile);

x += tile.width / 2;
y += tile.height / 2;
}

x = ROOM_DRAW_X - j * tile.width / 2;
y = ROOM_DRAW_Y + j * tile.height / 2;
}
}
}
}
30 changes: 30 additions & 0 deletions src/world/LevelManager.as
@@ -0,0 +1,30 @@
package world
{
import world.Level;

/**
* Ludum Dare 21 - Escape
* @author Paul S Burgess - 20/8/2011
*/
public class LevelManager
{
private var m_levels:Array;

private var m_numRooms:int;
private var m_currentRoom:int;

public function LevelManager()
{
m_levels = new Array;
m_levels.push(new Level);
m_numRooms = 1;

m_currentRoom = 0;
}

public function getCurrentRoom():Level
{
return m_levels[m_currentRoom];
}
}
}

0 comments on commit c41a8f8

Please sign in to comment.