Skip to content

Commit

Permalink
redesign, code cleaning, comments
Browse files Browse the repository at this point in the history
  • Loading branch information
damrem committed Jul 2, 2014
1 parent 583cfaa commit 2c3733c
Show file tree
Hide file tree
Showing 25 changed files with 80 additions and 158 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ bin-release/
# information for Eclipse / Flash Builder.

/obj

Thumbs.db
Binary file added bin/match3.swf
Binary file not shown.
17 changes: 6 additions & 11 deletions src/Main.as
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,18 @@ package
/**
* @author damrem
*/
[SWF(backgroundColor="#000000", frameRate=60, width="755", height="600")]
[SWF(backgroundColor="#000000", frameRate=60, width="400", height="400")]
public class Main extends MovieClip
{
public static var verbose : Boolean;

public static const STAGE_WIDTH:uint = 755;
public static const STAGE_HEIGHT:uint = 600;

/**
* L'objet starling un peu boosté.
* The customized Starling object.
*/
private var starling:CustomStarling;

/**
* Le fond bitmap affiché par la displayList en attendant Starling
* The bitmap background displayed by the flash display list while waiting for Starling.
*/
private var backgroundBitmap:Bitmap;

Expand All @@ -52,7 +49,7 @@ package
}

/**
* Appelé quand le Stage est en place.
* When the flash Stage is ready, we set up Starling.
*/
private function onAddedToStage(event:Event = null):void
{
Expand All @@ -64,22 +61,20 @@ package
this.removeEventListener(Event.ADDED_TO_STAGE, this.onAddedToStage, false);

// setting up Starling
var viewPort:Rectangle = new Rectangle(0, 0, STAGE_WIDTH, STAGE_HEIGHT);
var viewPort:Rectangle = new Rectangle(0, 0, this.stage.stageWidth, this.stage.stageHeight);
this.starling = new CustomStarling(Root, this.stage, viewPort);
this.starling.rootCreated.add(this.onRootCreated);
}

/**
* Appelé quand Starling est en place.
* When Starling is ready, we start it.
*/
private function onRootCreated(root:Root):void
{
if (verbose) trace(this + "onRootCreated(" + arguments);

this.starling.rootCreated.removeAll();



// lancement de Starling
this.starling.start();
}
Expand Down
Binary file modified src/assets/textures/BackGround-topMask.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/textures/BackGround.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/textures/Blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/textures/Green.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/textures/Purple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/textures/Red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/textures/Yellow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 8 additions & 7 deletions src/game/Board.as
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ package game
import starling.display.DisplayObjectContainer;
import starling.display.Quad;
import starling.display.Sprite;

/**
* ...
* The board would be the model in an MVC pattern.
* @author damrem
*/
public class Board extends Sprite
Expand Down Expand Up @@ -160,12 +161,10 @@ package game

public function getLeftPawn(refPawn:Pawn):Pawn
{
//if (verbose) trace(refPawn.index + "%" + WIDTH + "=" + (refPawn.index % WIDTH));
if (refPawn.index % WIDTH == 0)
{
return null;
}
//if (verbose) trace("pawns[" + (refPawn.index - 1) + "]=" + this.pawns[refPawn.index - 1]);
return this.pawns[refPawn.index - 1];
}

Expand Down Expand Up @@ -343,10 +342,12 @@ package game
this.destroyablePawns.push(pawn);
}





/**
* Detects if two specified pawns are neighbors in the grid.
* @param pawn1 1st pawn.
* @param pawn2 2nd pawn.
* @return Whether two specified pawns are neighbors in the grid.
*/
public function arePawnsNeighbors(pawn1:Pawn, pawn2:Pawn):Boolean
{
return (pawn1 == this.getLeftPawn(pawn2) || pawn1 == this.getRightPawn(pawn2) || pawn1 == this.getTopPawn(pawn2) || pawn1 == this.getBottomPawn(pawn2))
Expand Down
1 change: 1 addition & 0 deletions src/game/GameController.as
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package game
import game.states.InputListener;
import game.states.Swapper;
import starling.core.Starling;

/**
* Main controller of the game.
* It handles the transition between the differents states/sub-controllers,
Expand Down
12 changes: 5 additions & 7 deletions src/game/GameScreen.as
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ package game
this.controller.TIME_LEFT_UPDATED.add(this.hud.updateTimeLeft);
this.controller.TIME_S_UP.add(this.GAME_OVER.dispatch);

this.controller.board.x = 324;
this.controller.board.y = 98;
this.controller.board.x = 40;
this.controller.board.y = 40;
this.addChild(this.controller.board);

this.addChild(this.bgMask);
Expand All @@ -70,7 +70,8 @@ package game
private function createHUD():HUD
{
var hud:HUD = new HUD();
hud.y = 416;
hud.x = 40;
hud.y = 360;

return hud;
}
Expand All @@ -83,18 +84,15 @@ package game
{
var bmp:Bitmap = new Embeds.BackgroundTopMask();
var img:Image = Image.fromBitmap(bmp);
img.x = Starling.current.nativeStage.stageWidth - img.width;
//img.x = Starling.current.nativeStage.stageWidth - img.width;
return img;
//this.addChild(new Image(new Embeds.Background()));
}

private function createBg():Image
{
var bmp:Bitmap = new Embeds.Background();
var img:Image = Image.fromBitmap(bmp);
//this.addChild(img);
return img;
//this.addChild(new Image(new Embeds.Background()));
}

public function get score():uint
Expand Down
31 changes: 10 additions & 21 deletions src/game/Pawn.as
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,22 @@ package game

public var debugTf:TextField;

public static const SIZE:int = 45;

/**
* Useful for pivoting.
*/
//public static const HALF_SIZE:int = 22;
public static const SIZE:int = 40;

public static const COLORS:Array = [0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xff00ff];

public function Pawn(/*_index:int*/)
/**
* Does nothing.
* The pawn 'construction' is made by the reset() method for pooling.
*/
public function Pawn()
{
if (verbose) trace(this + "Pawn(" + arguments);

//this.setIndex(_index);

/*
this.type = Random.getInteger(0, 4);
this.drawGem();
Pawn.select(this);
Pawn.unselect();
*/
}

/**
* Replaces the constructor. Useful for pooling.
*/
public function reset():void
{
if(verbose) trace(this + "reset(" + arguments);
Expand All @@ -66,9 +57,7 @@ package game

private function drawGem():void
{
//this.pivotX = this.pivotY = Pawn.HALF_SIZE;
var img:Image = new Image(Embeds.gemTextures[this.type]);
//img.x = img.y = Math.round(- Pawn.SIZE / 2);
this.addChild(img);

}
Expand All @@ -81,7 +70,7 @@ package game
{
this.debugTf = new TextField(SIZE, SIZE/2, "");
this.updateDebug();
//this.addChild(this.debugTf);
if(verbose) this.addChild(this.debugTf);
}

}
Expand Down
8 changes: 6 additions & 2 deletions src/game/states/AbstractState.as
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package game.states
import game.Board;
import utils.abstract;
/**
* ...
* An abstract state, from which other states inherit.
* @author damrem
*/
public class AbstractState
Expand All @@ -15,12 +15,16 @@ package game.states
this.board = board;
}

/**
* When entering the state.
* @param caller An indicator of where the method is called. For debugging purposes only.
*/
public function enter(caller:String="other"):void
{
abstract(this, "enter");
}

public function exit():void
public function exit(caller:String="other"):void
{
abstract(this, "exit");
}
Expand Down
14 changes: 4 additions & 10 deletions src/game/states/Destroyer.as
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package game.states
{
import flash.events.TimerEvent;
import flash.utils.Timer;
import game.Board;
import game.Pawn;
import game.PawnPool;
import org.osflash.signals.Signal;
import starling.animation.Tween;
import starling.core.Starling;
/**
* ...
* Controller which handles pawn-destruction animation.
* @author damrem
*/
public class Destroyer extends AbstractState
Expand All @@ -20,6 +17,8 @@ package game.states

private var nbCompleted:int = 0;
public const ALL_ARE_DESTROYED:Signal = new Signal();

private var tweens:Vector.<Tween>;

public function Destroyer(board:Board)
{
Expand All @@ -43,7 +42,6 @@ package game.states
}
}

private var tweens:Vector.<Tween>;
private function startDestroyingPawn(pawn:Pawn):void
{
if (!this.tweens) this.tweens = new <Tween>[];
Expand Down Expand Up @@ -80,9 +78,6 @@ package game.states

this.nbCompleted ++;

// we register the hole
//this.endDestroyingPawn(pawn);

if (verbose) trace("completed: " + this.nbCompleted+"/"+this.board.destroyablePawns.length);

if (this.nbCompleted == this.board.destroyablePawns.length)
Expand Down Expand Up @@ -112,10 +107,9 @@ package game.states



override public function exit():void
override public function exit(caller:String="other"):void
{
if (verbose) trace(this + "exit(" + arguments);
//if (verbose) trace(this.board.pawns);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/game/states/FallerAndFiller.as
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package game.states
import starling.animation.Transitions;
import starling.animation.Tween;
import starling.core.Starling;

/**
* Controller that handles the fall of gems when there are holes.
* It also generates/recycles gems at the top of the board.
Expand All @@ -16,10 +17,10 @@ package game.states
public class FallerAndFiller extends AbstractState
{
public static var verbose:Boolean;

/**
* Dispatched when the board is filled so that we can set another state (Check).
*/
//public const BOARD_FILLED:Signal = new Signal();
public const FILLED:Signal = new Signal();

public static const FALL_SPEED_PX_PER_SEC:Number = Pawn.SIZE * 12;
Expand Down Expand Up @@ -211,7 +212,7 @@ package game.states
}
}

override public function exit():void
override public function exit(caller:String="other"):void
{
if (verbose) trace(this + "exit(" + arguments);
if (verbose) trace(this.board.pawns);
Expand Down
4 changes: 1 addition & 3 deletions src/game/states/InputListener.as
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,11 @@ package game.states
}
}

override public function exit():void
override public function exit(caller:String="other"):void
{
if (verbose) trace(this + "exit(" + arguments);

this.activateTouchZone(false);

//Pawn.unselect();
}

/**
Expand Down
Loading

0 comments on commit 2c3733c

Please sign in to comment.