diff --git a/Assets/PiratePig.bundle/PiratePig.swf b/Assets/PiratePig.bundle/PiratePig.swf new file mode 100644 index 0000000..21b9ba2 Binary files /dev/null and b/Assets/PiratePig.bundle/PiratePig.swf differ diff --git a/Assets/PiratePig.bundle/include.xml b/Assets/PiratePig.bundle/include.xml new file mode 100644 index 0000000..4a66fc9 --- /dev/null +++ b/Assets/PiratePig.bundle/include.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/Assets/PiratePig.fla b/Assets/PiratePig.fla new file mode 100644 index 0000000..7a389f1 Binary files /dev/null and b/Assets/PiratePig.fla differ diff --git a/Assets/fonts/FreebooterUpdated.eot b/Assets/fonts/FreebooterUpdated.eot new file mode 100644 index 0000000..b12397d Binary files /dev/null and b/Assets/fonts/FreebooterUpdated.eot differ diff --git a/Assets/fonts/FreebooterUpdated.svg b/Assets/fonts/FreebooterUpdated.svg new file mode 100644 index 0000000..e69de29 diff --git a/Assets/fonts/FreebooterUpdated.woff b/Assets/fonts/FreebooterUpdated.woff new file mode 100644 index 0000000..70d83a1 Binary files /dev/null and b/Assets/fonts/FreebooterUpdated.woff differ diff --git a/Assets/library.bundle/library.swf b/Assets/library.bundle/library.swf new file mode 100644 index 0000000..1ab57e4 Binary files /dev/null and b/Assets/library.bundle/library.swf differ diff --git a/Assets/library.fla b/Assets/library.fla new file mode 100644 index 0000000..7fe8a4c Binary files /dev/null and b/Assets/library.fla differ diff --git a/Pirate Pig.hxproj b/PiratePig.hxproj similarity index 95% rename from Pirate Pig.hxproj rename to PiratePig.hxproj index 11cb0e8..e0aad67 100644 --- a/Pirate Pig.hxproj +++ b/PiratePig.hxproj @@ -4,7 +4,7 @@ - + diff --git a/Source/com/eclecticdesignstudio/piratepig/PiratePig.hx b/Source/com/eclecticdesignstudio/piratepig/PiratePig.hx deleted file mode 100644 index e4b3bcd..0000000 --- a/Source/com/eclecticdesignstudio/piratepig/PiratePig.hx +++ /dev/null @@ -1,100 +0,0 @@ -package com.eclecticdesignstudio.piratepig; - - -import nme.Assets; -import nme.display.Bitmap; -import nme.display.BitmapData; -import nme.display.Sprite; -import nme.events.Event; -import nme.events.KeyboardEvent; -import nme.Lib; -import nme.system.Capabilities; - - -/** - * @author Joshua Granick - */ -class PiratePig extends Sprite { - - - private var Background:Bitmap; - private var Footer:Bitmap; - private var Game:PiratePigGame; - - - public function new () { - - super (); - - initialize (); - construct (); - - resize (Lib.current.stage.stageWidth, Lib.current.stage.stageHeight); - Lib.current.stage.addEventListener (Event.RESIZE, stage_onResize); - - #if android - Lib.current.stage.addEventListener (KeyboardEvent.KEY_UP, stage_onKeyUp); - #end - - } - - - private function construct ():Void { - - Footer.smoothing = true; - - addChild (Background); - addChild (Footer); - addChild (Game); - - } - - - private function initialize ():Void { - - Background = new Bitmap (Assets.getBitmapData ("images/background_tile.png")); - Footer = new Bitmap (Assets.getBitmapData ("images/center_bottom.png")); - Game = new PiratePigGame (); - - } - - - private function resize (newWidth:Int, newHeight:Int):Void { - - Background.width = newWidth; - Background.height = newHeight; - - Game.resize (newWidth, newHeight); - - Footer.scaleX = Game.currentScale; - Footer.scaleY = Game.currentScale; - Footer.x = newWidth / 2 - Footer.width / 2; - Footer.y = newHeight - Footer.height; - - } - - - private function stage_onKeyUp (event:KeyboardEvent):Void { - - #if android - - if (event.keyCode == 27) { - - event.stopImmediatePropagation (); - Lib.exit (); - - } - - #end - - } - - - private function stage_onResize (event:Event):Void { - - resize (stage.stageWidth, stage.stageHeight); - - } - - -} \ No newline at end of file diff --git a/Source/com/eclecticdesignstudio/piratepig/PiratePigGame.hx b/Source/piratepig/Game.hx similarity index 55% rename from Source/com/eclecticdesignstudio/piratepig/PiratePigGame.hx rename to Source/piratepig/Game.hx index effb71f..c094758 100644 --- a/Source/com/eclecticdesignstudio/piratepig/PiratePigGame.hx +++ b/Source/piratepig/Game.hx @@ -1,70 +1,56 @@ -package com.eclecticdesignstudio.piratepig; +package piratepig; -import com.eclecticdesignstudio.motion.Actuate; -import com.eclecticdesignstudio.motion.easing.Quad; -import nme.display.Bitmap; -import nme.display.Sprite; -import nme.events.Event; -import nme.events.MouseEvent; -import nme.filters.BlurFilter; -import nme.filters.DropShadowFilter; -import nme.geom.Point; -import nme.media.Sound; -import nme.text.TextField; -import nme.text.TextFormat; -import nme.text.TextFormatAlign; -import nme.Assets; -import nme.Lib; +import motion.easing.Quad; +import motion.Actuate; +import openfl.display.MovieClip; +import openfl.display.Sprite; +import openfl.events.Event; +import openfl.events.MouseEvent; +import openfl.geom.Point; +import openfl.text.TextField; +import openfl.Assets; +import piratepig.Tile; /** - * ... * @author Joshua Granick */ -class PiratePigGame extends Sprite { +class Game extends Sprite { - private static var NUM_COLUMNS:Int = 8; - private static var NUM_ROWS:Int = 8; - - private static var tileImages:Array = [ "images/game_bear.png", "images/game_bunny_02.png", "images/game_carrot.png", "images/game_lemon.png", "images/game_panda.png", "images/game_piratePig.png" ]; - - private var Background:Sprite; - private var IntroSound:Sound; - private var Logo:Bitmap; private var Score:TextField; - private var Sound3:Sound; - private var Sound4:Sound; - private var Sound5:Sound; - private var TileContainer:Sprite; - - public var currentScale:Float; - public var currentScore:Int; + private var TileContainer:MovieClip; private var cacheMouse:Point; + private var currentScore:Int; + private var display:PiratePig; private var needToCheckMatches:Bool; + private var numColumns = 8; + private var numRows = 8; private var selectedTile:Tile; - private var tiles:Array >; - private var usedTiles:Array ; + private var tiles:Array>; + private var tileSpacing:Point; + private var usedTiles:Array; + - public function new () { + public function new (display:PiratePig) { super (); + this.display = display; + initialize (); construct (); - - newGame (); - + } private function addTile (row:Int, column:Int, animate:Bool = true):Void { var tile = null; - var type = Math.round (Math.random () * (tileImages.length - 1)); + var type = Type.createEnumIndex (TileType, Math.round (Math.random () * (Type.allEnums (TileType).length - 1))); for (usedTile in usedTiles) { @@ -78,7 +64,7 @@ class PiratePigGame extends Sprite { if (tile == null) { - tile = new Tile (tileImages[type]); + tile = new Tile (type); } @@ -95,16 +81,12 @@ class PiratePigGame extends Sprite { var firstPosition = getPosition (-1, column); - #if !js tile.alpha = 0; - #end tile.x = firstPosition.x; tile.y = firstPosition.y; tile.moveTo (0.15 * (row + 1), position.x, position.y); - #if !js Actuate.tween (tile, 0.3, { alpha: 1 } ).delay (0.15 * (row - 2)).ease (Quad.easeOut); - #end } else { @@ -113,7 +95,7 @@ class PiratePigGame extends Sprite { } - TileContainer.addChild (tile); + addChild (tile); needToCheckMatches = true; } @@ -121,68 +103,47 @@ class PiratePigGame extends Sprite { private function construct ():Void { - Logo.smoothing = true; - addChild (Logo); - - var font = Assets.getFont ("fonts/FreebooterUpdated.ttf"); - var defaultFormat = new TextFormat (font.fontName, 60, 0x000000); - defaultFormat.align = TextFormatAlign.RIGHT; - - #if js - // Right-aligned text is not supported in HTML5 yet - defaultFormat.align = TextFormatAlign.LEFT; - #end - - var contentWidth = 75 * NUM_COLUMNS; - - Score.x = contentWidth - 200; - Score.width = 200; - Score.y = 12; - Score.selectable = false; - Score.defaultTextFormat = defaultFormat; - - #if !js - Score.filters = [ new BlurFilter (1.5, 1.5), new DropShadowFilter (1, 45, 0, 0.2, 5, 5) ]; - #else - Score.y = 0; - Score.x += 90; - #end + for (row in 0...numRows) { + + for (column in 0...numColumns) { + + removeTile (row, column, false); + + } + + } - Score.embedFonts = true; - addChild (Score); + for (row in 0...numRows) { + + for (column in 0...numColumns) { + + addTile (row, column, false); + + } + + } - Background.y = 85; - Background.graphics.beginFill (0xFFFFFF, 0.4); - Background.graphics.drawRect (0, 0, contentWidth, 75 * NUM_ROWS); + resize (); - #if !js - Background.filters = [ new BlurFilter (10, 10) ]; - addChild (Background); - #end + display.addEventListener (MouseEvent.MOUSE_DOWN, display_onMouseDown); + display.addEventListener (MouseEvent.MOUSE_UP, display_onMouseUp); - TileContainer.x = 14; - TileContainer.y = Background.y + 14; - TileContainer.addEventListener (MouseEvent.MOUSE_DOWN, TileContainer_onMouseDown); - Lib.current.stage.addEventListener (MouseEvent.MOUSE_UP, stage_onMouseUp); - addChild (TileContainer); + Assets.getSound ("soundTheme").play (); - IntroSound = Assets.getSound ("soundTheme"); - Sound3 = Assets.getSound ("sound3"); - Sound4 = Assets.getSound ("sound4"); - Sound5 = Assets.getSound ("sound5"); + addEventListener (Event.ENTER_FRAME, this_onEnterFrame); } private function dropTiles ():Void { - for (column in 0...NUM_COLUMNS) { + for (column in 0...numColumns) { var spaces = 0; - for (row in 0...NUM_ROWS) { + for (row in 0...numRows) { - var index = (NUM_ROWS - 1) - row; + var index = (numRows - 1) - row; var tile = tiles[index][column]; if (tile == null) { @@ -220,7 +181,7 @@ class PiratePigGame extends Sprite { } - private function findMatches (byRow:Bool, accumulateScore:Bool = true):Array { + public function findMatches (byRow:Bool, accumulateScore:Bool = true):Array { var matchedTiles = new Array (); @@ -229,13 +190,13 @@ class PiratePigGame extends Sprite { if (byRow) { - max = NUM_ROWS; - secondMax = NUM_COLUMNS; + max = numRows; + secondMax = numColumns; } else { - max = NUM_COLUMNS; - secondMax = NUM_ROWS; + max = numColumns; + secondMax = numRows; } @@ -243,7 +204,7 @@ class PiratePigGame extends Sprite { var matches = 0; var foundTiles = new Array (); - var previousType = -1; + var previousType = null; for (secondIndex in 0...secondMax) { @@ -261,7 +222,7 @@ class PiratePigGame extends Sprite { if (tile != null && !tile.moving) { - if (previousType == -1) { + if (previousType == null) { previousType = tile.type; foundTiles.push (tile); @@ -278,21 +239,21 @@ class PiratePigGame extends Sprite { if (tile == null || tile.moving || tile.type != previousType || secondIndex == secondMax - 1) { - if (matches >= 2 && previousType != -1) { + if (matches >= 2 && previousType != null) { if (accumulateScore) { if (matches > 3) { - Sound5.play (); + Assets.getSound ("sound5").play (); } else if (matches > 2) { - Sound4.play (); + Assets.getSound ("sound4").play (); } else { - Sound3.play (); + Assets.getSound ("sound3").play (); } @@ -310,7 +271,7 @@ class PiratePigGame extends Sprite { if (tile == null || tile.moving) { needToCheckMatches = true; - previousType = -1; + previousType = null; } else { @@ -332,73 +293,44 @@ class PiratePigGame extends Sprite { private function getPosition (row:Int, column:Int):Point { - return new Point (column * (57 + 16), row * (57 + 16)); + return new Point (column * tileSpacing.x, row * tileSpacing.y); } private function initialize ():Void { - currentScale = 1; - currentScore = 0; + Score = display.Score; + TileContainer = display.TileContainer; - tiles = new Array > (); - usedTiles = new Array (); + var tile = TileContainer.getChildByName ("Tile"); + var tile2 = TileContainer.getChildByName ("Tile2"); + var tile3 = TileContainer.getChildByName ("Tile3"); - for (row in 0...NUM_ROWS) { - - tiles[row] = new Array (); - - for (column in 0...NUM_COLUMNS) { - - tiles[row][column] = null; - - } - - } - - Background = new Sprite (); - Logo = new Bitmap (Assets.getBitmapData ("images/logo.png")); - Score = new TextField (); - TileContainer = new Sprite (); - - } - - - public function newGame ():Void { + tileSpacing = new Point (tile2.x - tile.x, tile3.y - tile.y); currentScore = 0; Score.text = "0"; - for (row in 0...NUM_ROWS) { - - for (column in 0...NUM_COLUMNS) { - - removeTile (row, column, false); - - } - - } + tiles = new Array> (); + usedTiles = new Array (); - for (row in 0...NUM_ROWS) { + for (row in 0...numRows) { + + tiles[row] = new Array (); - for (column in 0...NUM_COLUMNS) { + for (column in 0...numColumns) { - addTile (row, column, false); + tiles[row][column] = null; } } - IntroSound.play (); - - removeEventListener (Event.ENTER_FRAME, this_onEnterFrame); - addEventListener (Event.ENTER_FRAME, this_onEnterFrame); - } - public function removeTile (row:Int, column:Int, animate:Bool = true):Void { + private function removeTile (row:Int, column:Int, animate:Bool = true):Void { var tile = tiles[row][column]; @@ -414,57 +346,17 @@ class PiratePigGame extends Sprite { } - public function resize (newWidth:Int, newHeight:Int):Void { - - var maxWidth = newWidth * 0.90; - var maxHeight = newHeight * 0.86; - - currentScale = 1; - scaleX = 1; - scaleY = 1; - - #if js - - // looking up the total width and height is not working, so we'll calculate it ourselves - - var currentWidth = 75 * NUM_COLUMNS; - var currentHeight = 75 * NUM_ROWS + 85; + public function resize ():Void { - #else - - var currentWidth = width; - var currentHeight = height; - - #end - - if (currentWidth > maxWidth || currentHeight > maxHeight) { - - var maxScaleX = maxWidth / currentWidth; - var maxScaleY = maxHeight / currentHeight; - - if (maxScaleX < maxScaleY) { - - currentScale = maxScaleX; - - } else { - - currentScale = maxScaleY; - - } - - scaleX = currentScale; - scaleY = currentScale; - - } - - x = newWidth / 2 - (currentWidth * currentScale) / 2; + x = TileContainer.x; + y = TileContainer.y; } private function swapTile (tile:Tile, targetRow:Int, targetColumn:Int):Void { - if (targetColumn >= 0 && targetColumn < NUM_COLUMNS && targetRow >= 0 && targetRow < NUM_ROWS) { + if (targetColumn >= 0 && targetColumn < numColumns && targetRow >= 0 && targetRow < numRows) { var targetTile = tiles[targetRow][targetColumn]; @@ -508,7 +400,24 @@ class PiratePigGame extends Sprite { - private function stage_onMouseUp (event:MouseEvent):Void { + private function display_onMouseDown (event:MouseEvent):Void { + + if (Std.is (event.target, Tile)) { + + selectedTile = cast event.target; + cacheMouse = new Point (event.stageX, event.stageY); + + } else { + + cacheMouse = null; + selectedTile = null; + + } + + } + + + private function display_onMouseUp (event:MouseEvent):Void { if (cacheMouse != null && selectedTile != null && !selectedTile.moving) { @@ -585,21 +494,4 @@ class PiratePigGame extends Sprite { } - private function TileContainer_onMouseDown (event:MouseEvent):Void { - - if (Std.is (event.target, Tile)) { - - selectedTile = cast event.target; - cacheMouse = new Point (event.stageX, event.stageY); - - } else { - - cacheMouse = null; - selectedTile = null; - - } - - } - - } \ No newline at end of file diff --git a/Source/piratepig/PiratePig.hx b/Source/piratepig/PiratePig.hx new file mode 100644 index 0000000..0d88e58 --- /dev/null +++ b/Source/piratepig/PiratePig.hx @@ -0,0 +1,111 @@ +package piratepig; + + +import layout.LayoutGroup; +import layout.LayoutItem; +import openfl.display.MovieClip; +import openfl.events.Event; +import openfl.text.TextField; + + +/** + * @author Joshua Granick + */ +class PiratePig extends PiratePig_Display { + + + public var Background:MovieClip; + public var Footer:MovieClip; + public var Logo:MovieClip; + public var Score:TextField; + public var TileBackground:MovieClip; + public var TileContainer:MovieClip; + + private var currentGame:Game; + private var layout:LayoutGroup; + + + public function new () { + + super (); + + initialize (); + construct (); + + startGame (); + + } + + + private function construct ():Void { + + layout.minWidth = 600; + layout.minHeight = 800; + + layout.addItem (new LayoutItem (Background, STRETCH, STRETCH, false, false)); + layout.addItem (new LayoutItem (Footer, CENTER, BOTTOM, false)); + layout.addItem (new LayoutItem (Logo, CENTER, TOP)); + layout.addItem (new LayoutItem (Score, CENTER, TOP)); + layout.addItem (new LayoutItem (TileBackground, CENTER, TOP)); + layout.addItem (new LayoutItem (TileContainer, CENTER, TOP)); + + TileContainer.visible = false; + + resize (stage.stageWidth, stage.stageHeight); + stage.addEventListener (Event.RESIZE, stage_onResize); + + } + + + private function initialize ():Void { + + layout = new LayoutGroup (1024, 848); + + Background = cast getChildByName ("Background"); + Footer = cast getChildByName ("Footer"); + Logo = cast getChildByName ("Logo"); + Score = cast getChildByName ("Score"); + TileBackground = cast getChildByName ("TileBackground"); + TileContainer = cast getChildByName ("TileContainer"); + + } + + + public function resize (newWidth:Int, newHeight:Int):Void { + + layout.resize (newWidth, newHeight); + + Background.width = newWidth; + + if (currentGame != null) { + + currentGame.resize (); + + } + + } + + + public function startGame ():Void { + + currentGame = new Game (this); + addChild (currentGame); + + } + + + + + // Event Handlers + + + + + private function stage_onResize (event:Event):Void { + + resize (stage.stageWidth, stage.stageHeight); + + } + + +} \ No newline at end of file diff --git a/Source/com/eclecticdesignstudio/piratepig/Tile.hx b/Source/piratepig/Tile.hx similarity index 64% rename from Source/com/eclecticdesignstudio/piratepig/Tile.hx rename to Source/piratepig/Tile.hx index 623fb2a..0460f43 100644 --- a/Source/com/eclecticdesignstudio/piratepig/Tile.hx +++ b/Source/piratepig/Tile.hx @@ -1,17 +1,14 @@ -package com.eclecticdesignstudio.piratepig; +package piratepig; -import com.eclecticdesignstudio.motion.Actuate; -import com.eclecticdesignstudio.motion.actuators.GenericActuator; -import com.eclecticdesignstudio.motion.easing.Linear; -import com.eclecticdesignstudio.motion.easing.Quad; -import nme.Assets; -import nme.display.Bitmap; -import nme.display.Sprite; +import motion.easing.Quad; +import motion.Actuate; +import openfl.display.Bitmap; +import openfl.display.Sprite; +import openfl.Assets; /** - * ... * @author Joshua Granick */ class Tile extends Sprite { @@ -21,24 +18,28 @@ class Tile extends Sprite { public var moving:Bool; public var removed:Bool; public var row:Int; - public var type:Int; + public var type:TileType; - public function new (imagePath:String) { + public function new (type:TileType) { super (); - var image = new Bitmap (Assets.getBitmapData (imagePath)); - image.smoothing = true; - addChild (image); + switch (type) { + + case BEAR: addChild (new BearTile ()); + case BUNNY: addChild (new BunnyTile ()); + case CARROT: addChild (new CarrotTile ()); + case LEMON: addChild (new LemonTile ()); + case PANDA: addChild (new PandaTile ()); + case PIG: addChild (new PigTile ()); + default: + + } mouseChildren = false; buttonMode = true; - // Currently, MouseEvent listeners are added to each Tile. - // To make them easier to tap, add an empty fill to increase - // the size of the hit area - graphics.beginFill (0x000000, 0); graphics.drawRect (-5, -5, 66, 66); @@ -50,11 +51,12 @@ class Tile extends Sprite { moving = false; removed = false; - #if !js + mouseEnabled = true; + buttonMode = true; + scaleX = 1; scaleY = 1; alpha = 1; - #end } @@ -70,10 +72,6 @@ class Tile extends Sprite { public function remove (animate:Bool = true):Void { - #if js - animate = false; - #end - if (!removed) { if (animate) { @@ -118,4 +116,16 @@ class Tile extends Sprite { } +} + + +enum TileType { + + BEAR; + BUNNY; + CARROT; + LEMON; + PANDA; + PIG; + } \ No newline at end of file diff --git a/project.nmml b/project.xml similarity index 57% rename from project.nmml rename to project.xml index e08fa58..7ef86a5 100644 --- a/project.nmml +++ b/project.xml @@ -1,23 +1,21 @@ - - + + - - + + - - - + + - - + @@ -27,12 +25,13 @@ + - +
@@ -40,6 +39,6 @@
- + -
+ \ No newline at end of file