diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..5dc46e6 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +* text=auto eol=lf +*.{cmd,[cC][mM][dD]} text eol=crlf +*.{bat,[bB][aA][tT]} text eol=crlf \ No newline at end of file diff --git a/Project.xml b/Project.xml index b9c56b5..98f3e17 100644 --- a/Project.xml +++ b/Project.xml @@ -16,13 +16,13 @@ - + - + @@ -63,10 +63,10 @@ - + - + @@ -91,6 +91,6 @@ - - + + diff --git a/assets/data/levels/level5.json b/assets/data/levels/level5.json index ffea5eb..768972f 100644 --- a/assets/data/levels/level5.json +++ b/assets/data/levels/level5.json @@ -29,7 +29,7 @@ "gridCellsX": 16, "gridCellsY": 11, "tileset": "DefaultTile", - "data": [9, -1, -1, 7, 8, 10, 14, 14, 14, 14, 15, -1, -1, -1, 7, 8, 9, -1, -1, 7, 10, 15, -1, -1, -1, -1, -1, -1, -1, 1, 17, 8, 16, 2, 2, 17, 9, -1, -1, -1, -1, -1, -1, -1, -1, 7, 8, 8, 14, 14, 14, 11, 9, -1, -1, -1, 1, 2, 2, 3, -1, 7, 8, 8, -1, -1, -1, 7, 9, -1, -1, -1, 7, 8, 8, 9, -1, 7, 8, 8, -1, -1, -1, 13, 12, 5, -1, -1, 13, 14, 11, 9, -1, 7, 8, 8, 2, 3, -1, -1, -1, -1, -1, -1, -1, -1, 7, 9, -1, 7, 10, 14, 8, 9, -1, -1, -1, -1, -1, -1, -1, -1, 13, 15, -1, 13, 15, -1, 8, 16, 2, 2, 2, 3, -1, 1, 3, -1, -1, -1, -1, -1, -1, -1, 8, 8, 8, 8, 8, 16, -1, 17, 9, -1, -1, -1, -1, -1, -1, -1, 8, 8, 8, 8, 8, 8, -1, 8, 16, 2, 2, 2, 2, 2, 2, 2], + "data": [9, -1, -1, 7, 8, 10, 14, 14, 14, 14, 15, -1, -1, -1, 7, 8, 9, -1, -1, 7, 10, 15, -1, -1, -1, -1, -1, -1, -1, 1, 17, 8, 16, 2, 2, 17, 9, -1, -1, -1, -1, -1, -1, -1, -1, 7, 8, 8, 14, 14, 14, 11, 9, -1, -1, -1, -1, 1, 2, 3, -1, 7, 8, 8, -1, -1, -1, 7, 9, -1, -1, -1, 1, 17, 8, 9, -1, 7, 8, 8, -1, -1, -1, 13, 12, 5, -1, -1, 13, 14, 11, 9, -1, 7, 8, 8, 2, 3, -1, -1, -1, -1, -1, -1, -1, -1, 7, 9, -1, 7, 10, 14, 8, 9, -1, -1, -1, -1, -1, -1, -1, -1, 13, 15, -1, 13, 15, -1, 8, 16, 2, 2, 2, 3, -1, 1, 3, -1, -1, -1, -1, -1, -1, -1, 8, 8, 8, 8, 8, 16, -1, 17, 9, -1, -1, -1, -1, -1, -1, -1, 8, 8, 8, 8, 8, 8, -1, 8, 16, 2, 2, 2, 2, 2, 2, 2], "exportMode": 0, "arrayMode": 0 }, diff --git a/assets/data/levels/level7.json b/assets/data/levels/level7.json deleted file mode 100644 index 5b114a2..0000000 --- a/assets/data/levels/level7.json +++ /dev/null @@ -1,79 +0,0 @@ -{ - "ogmoVersion": "3.4.0", - "width": 192, - "height": 132, - "offsetX": 0, - "offsetY": 0, - "layers": [ - { - "name": "TutoLayer", - "_eid": "12402453", - "offsetX": 0, - "offsetY": 0, - "gridCellWidth": 12, - "gridCellHeight": 12, - "gridCellsX": 16, - "gridCellsY": 11, - "tileset": "Tuto", - "data": [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], - "exportMode": 0, - "arrayMode": 0 - }, - { - "name": "Default", - "_eid": "84201617", - "offsetX": 0, - "offsetY": 0, - "gridCellWidth": 12, - "gridCellHeight": 12, - "gridCellsX": 16, - "gridCellsY": 11, - "tileset": "DefaultTile", - "data": [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 4, 6, 5, -1, -1, -1, -1, 4, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], - "exportMode": 0, - "arrayMode": 0 - }, - { - "name": "FakeFloor", - "_eid": "84953096", - "offsetX": 0, - "offsetY": 0, - "gridCellWidth": 12, - "gridCellHeight": 12, - "gridCellsX": 16, - "gridCellsY": 11, - "tileset": "DefaultTile", - "data": [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], - "exportMode": 0, - "arrayMode": 0 - }, - { - "name": "Entities", - "_eid": "84244893", - "offsetX": 0, - "offsetY": 0, - "gridCellWidth": 12, - "gridCellHeight": 12, - "gridCellsX": 16, - "gridCellsY": 11, - "entities": [ - {"name": "BPlayer", "id": 0, "_eid": "62286992", "x": 168, "y": 96, "originX": 0, "originY": 0}, - {"name": "Player", "id": 2, "_eid": "84246472", "x": 12, "y": 96, "originX": 0, "originY": 0} - ] - }, - { - "name": "Environment", - "_eid": "84269171", - "offsetX": 0, - "offsetY": 0, - "gridCellWidth": 12, - "gridCellHeight": 12, - "gridCellsX": 16, - "gridCellsY": 11, - "tileset": "BackTile", - "data": [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], - "exportMode": 0, - "arrayMode": 0 - } - ] -} \ No newline at end of file diff --git a/assets/images/heart.png b/assets/images/heart.png index e3ef6d1..8220d47 100644 Binary files a/assets/images/heart.png and b/assets/images/heart.png differ diff --git a/misc/concepts/heart.aseprite b/misc/concepts/heart.aseprite index 4ed3284..76ca1c9 100644 Binary files a/misc/concepts/heart.aseprite and b/misc/concepts/heart.aseprite differ diff --git a/misc/concepts/mobile.aseprite b/misc/concepts/mobile.aseprite new file mode 100644 index 0000000..17c935d Binary files /dev/null and b/misc/concepts/mobile.aseprite differ diff --git a/secret/images/mobile_left.png b/secret/images/mobile_left.png new file mode 100644 index 0000000..a721757 Binary files /dev/null and b/secret/images/mobile_left.png differ diff --git a/secret/images/mobile_right.png b/secret/images/mobile_right.png new file mode 100644 index 0000000..250a6a0 Binary files /dev/null and b/secret/images/mobile_right.png differ diff --git a/secret/images/mobile_shot.png b/secret/images/mobile_shot.png new file mode 100644 index 0000000..b734717 Binary files /dev/null and b/secret/images/mobile_shot.png differ diff --git a/secret/images/mobile_up.png b/secret/images/mobile_up.png new file mode 100644 index 0000000..25366a2 Binary files /dev/null and b/secret/images/mobile_up.png differ diff --git a/source/Game.hx b/source/Game.hx index c08bd12..144b94c 100644 --- a/source/Game.hx +++ b/source/Game.hx @@ -6,6 +6,8 @@ class Game public static inline var MAP_HEIGHT:Int = 11; public static inline var PIXEL_PERFECT:Bool = true; + public static inline var GAME_X:Int = 24; + public static function getGameWidth():Int { return TILE_WIDTH * MAP_WIDTH; diff --git a/source/Main.hx b/source/Main.hx index 959925d..fa9550f 100644 --- a/source/Main.hx +++ b/source/Main.hx @@ -1,39 +1,25 @@ package; -import flixel.FlxG; import flixel.FlxGame; import flixel.FlxState; -import flixel.system.FlxAssets.FlxShader; +import misc.FPSMem; import misc.Input; -import openfl.Lib; import openfl.display.Sprite; -import openfl.display.StageQuality; -import openfl.filters.ShaderFilter; -import openfl.system.Capabilities; class Main extends Sprite { - var _width:Int = 832; - var _height:Int = 676; + var _width:Int = 240; + var _height:Int = 156; var _initialState:Class = SavanLogo; public function new() { super(); - addChild(new FlxGame(0, 0, _initialState, true)); + addChild(new FlxGame(_width, _height, _initialState, true)); Input.init(); - FlxG.game.setFilters([new ShaderFilter(new FlxShader())]); - FlxG.game.stage.quality = StageQuality.LOW; - FlxG.resizeWindow(_width, _height); - // Center window on screen - var screenWidth = Capabilities.screenResolutionX; - var screenHeight = Capabilities.screenResolutionY; - trace('Width: $screenWidth - Height: $screenHeight'); - - Lib.application.window.x = Std.int((screenWidth / 2) - (_width / 2)); - Lib.application.window.y = Std.int((screenHeight / 2) - (_height / 2)); - - // FlxG.fullscreen = true; + #if debug + addChild(new FPSMem(5, 5, 0xFFFFFF)); + #end } } diff --git a/source/SavanLogo.hx b/source/SavanLogo.hx index d0413b2..016f998 100644 --- a/source/SavanLogo.hx +++ b/source/SavanLogo.hx @@ -1,9 +1,7 @@ import flixel.FlxG; import flixel.FlxSprite; -import flixel.FlxState; import flixel.text.FlxText; import flixel.util.FlxTimer; -import misc.FadeBoy; import misc.Paths; import states.MenuState; @@ -26,6 +24,11 @@ class SavanLogo extends BaseState logoText.y += 20; add(logoText); + #if desktop + FlxG.mouse.visible = false; + FlxG.mouse.enabled = false; + #end + new FlxTimer().start(3, (_) -> FlxG.switchState(new MenuState())); } } diff --git a/source/misc/FPSMem.hx b/source/misc/FPSMem.hx new file mode 100644 index 0000000..42631e2 --- /dev/null +++ b/source/misc/FPSMem.hx @@ -0,0 +1,65 @@ +package misc; + +import haxe.Timer; +import openfl.display.FPS; +import openfl.events.Event; +import openfl.system.System; +import openfl.text.TextField; +import openfl.text.TextFormat; + +/** + + * FPS class extension to display memory usage. + + * @author Kirill Poletaev + + */ +class FPSMem extends TextField +{ + private var times:Array; + + private var memPeak:Float = 0; + + public function new(inX:Float = 10.0, inY:Float = 10.0, inCol:Int = 0x000000) + { + super(); + + x = inX; + + y = inY; + + selectable = false; + + defaultTextFormat = new TextFormat("_sans", 12, inCol); + + text = "FPS: "; + + times = []; + + addEventListener(Event.ENTER_FRAME, onEnter); + + width = 150; + + height = 70; + } + + private function onEnter(_) + { + var now = Timer.stamp(); + + times.push(now); + + while (times[0] < now - 1) + times.shift(); + + var mem:Float = Math.round(System.totalMemory / 1024 / 1024 * 100) / 100; + + if (mem > memPeak) + memPeak = mem; + + if (visible) + { + text = "FPS: " + times.length + "\nMEM: " + mem + " MB\nMEM peak: " + memPeak + " MB"; + } + } +} diff --git a/source/misc/Input.hx b/source/misc/Input.hx index fa0d273..011eab9 100644 --- a/source/misc/Input.hx +++ b/source/misc/Input.hx @@ -1,7 +1,11 @@ package misc; import flixel.FlxG; +#if mobile +import flixel.input.android.FlxAndroidKey; +#else import flixel.input.keyboard.FlxKey; +#end class Input { @@ -14,6 +18,7 @@ class Input public static var SELECT:Bool; public static var BACK:Bool; public static var SHOOT:Bool; + public static var PAUSE:Bool; // Controles alternos public static var UP_ALT:Bool; @@ -24,17 +29,31 @@ class Input public static var SELECT_ALT:Bool; public static var BACK_ALT:Bool; public static var SHOOT_ALT:Bool; + public static var PAUSE_ALT:Bool; // Detección de Gamepad public static var isGamepadConnected:Bool; public static function init() { + #if mobile + FlxG.android.preventDefaultKeys = [FlxAndroidKey.BACK]; + #else + FlxG.sound.volumeDownKeys = [NUMPADMINUS]; + FlxG.sound.volumeUpKeys = [NUMPADPLUS]; + FlxG.sound.muteKeys = [NUMPADZERO]; + #end trace("Input initialized!"); } public static function update() { + #if mobile + var firstTouch = FlxG.touches.getFirst(); + SELECT = firstTouch != null ? firstTouch.justPressed : false; + PAUSE = FlxG.android.justPressed.BACK; + BACK = FlxG.android.justPressed.BACK; + #else UP = FlxG.keys.justPressed.UP; DOWN = FlxG.keys.justPressed.DOWN; LEFT = FlxG.keys.pressed.LEFT; @@ -43,6 +62,8 @@ class Input SELECT = FlxG.keys.justPressed.ENTER; BACK = FlxG.keys.justPressed.ESCAPE; SHOOT = FlxG.keys.justPressed.Z; + PAUSE = FlxG.keys.justPressed.ENTER; + #end #if desktop // Solamente tengo un humilde joystick genérico, así que trataré mostrar lo mejor que pueda los controles. @@ -59,6 +80,7 @@ class Input SELECT_ALT = gamepad.justPressed.A; BACK_ALT = gamepad.justPressed.BACK; // Xbox -> Back | Play -> Select SHOOT_ALT = gamepad.justPressed.B; + PAUSE_ALT = gamepad.justPressed.START; } else isGamepadConnected = false; diff --git a/source/misc/ScanLines.hx b/source/misc/ScanLines.hx index 2730884..12ab921 100644 --- a/source/misc/ScanLines.hx +++ b/source/misc/ScanLines.hx @@ -1,17 +1,36 @@ package misc; +import flixel.FlxG; import flixel.FlxSprite; +import flixel.group.FlxSpriteGroup; import flixel.util.FlxColor; import openfl.display.BitmapData; import openfl.geom.Matrix; import openfl.geom.Rectangle; // From HaxeFlixel examples xD -class ScanLines extends FlxSprite +class ScanLines extends FlxSpriteGroup { public function new(lines:Bool = true) { super(); + var crtView = new FlxSprite(); + crtView.loadGraphic(createCRTEffect(lines)); + crtView.x = Game.GAME_X; + add(crtView); + + var leftRect = new FlxSprite().makeGraphic(Game.GAME_X, Game.getGameHeight(), FlxColor.BLACK); + add(leftRect); + + var rightRect = new FlxSprite(Game.GAME_X + Game.getGameWidth()).makeGraphic(Game.GAME_X, Game.getGameHeight(), FlxColor.BLACK); + add(rightRect); + + var downRect = new FlxSprite(0, Game.getGameHeight()).makeGraphic(FlxG.width, Game.GAME_X, FlxColor.BLACK); + add(downRect); + } + + function createCRTEffect(lines:Bool):BitmapData + { var bitmapdata = new BitmapData(Game.getGameWidth(), Game.getGameHeight(), true, FlxColor.TRANSPARENT); var scanline = new BitmapData(Game.getGameWidth(), 1, true, 0x40000000); @@ -39,6 +58,6 @@ class ScanLines extends FlxSprite bitmapdata.fillRect(new Rectangle(w - cX[i], h - cY[i], cX[i], cY[i]), FlxColor.BLACK); } - loadGraphic(bitmapdata); + return bitmapdata; } } diff --git a/source/mobile/AndroidPad.hx b/source/mobile/AndroidPad.hx new file mode 100644 index 0000000..dfda7ef --- /dev/null +++ b/source/mobile/AndroidPad.hx @@ -0,0 +1,56 @@ +package mobile; + +import flixel.FlxCamera; +import flixel.group.FlxGroup.FlxTypedGroup; +import flixel.ui.FlxButton; +import misc.Input; +import misc.Paths; + +class AndroidPad extends FlxTypedGroup +{ + var btnLeft:FlxButton; + var btnRight:FlxButton; + var btnJump:FlxButton; + var btnShot:FlxButton; + + public function new() + { + super(); + + btnLeft = new FlxButton(12, 120); + btnLeft.onDown.callback = () -> Input.LEFT = true; + btnLeft.onOut.callback = () -> Input.LEFT = false; + btnLeft.loadGraphic(Paths.getImage("mobile_left", true), true, 24, 24); + add(btnLeft); + + btnRight = new FlxButton(48, 120); + btnRight.onDown.callback = () -> Input.RIGHT = true; + btnRight.onOut.callback = () -> Input.RIGHT = false; + btnRight.loadGraphic(Paths.getImage("mobile_right", true), true, 24, 24); + add(btnRight); + + btnJump = new FlxButton(204, 120); + btnJump.onDown.callback = () -> Input.JUMP = true; + btnJump.onOut.callback = () -> Input.JUMP = false; + btnJump.loadGraphic(Paths.getImage("mobile_up", true), true, 24, 24); + add(btnJump); + + btnShot = new FlxButton(80, 16); + btnShot.onDown.callback = () -> Input.SHOOT = true; + btnShot.onOut.callback = () -> Input.SHOOT = false; + btnShot.loadGraphic(Paths.getImage("mobile_shot", true), true, 80, 32); + } + + public function enableShotButton() + { + add(btnShot); + } + + public function setCamera(_camera:FlxCamera) + { + btnLeft.cameras = [_camera]; + btnRight.cameras = [_camera]; + btnJump.cameras = [_camera]; + btnShot.cameras = [_camera]; + } +} diff --git a/source/states/EndingState.hx b/source/states/EndingState.hx index f432491..241de2b 100644 --- a/source/states/EndingState.hx +++ b/source/states/EndingState.hx @@ -32,9 +32,13 @@ class EndingState extends BaseState override public function create() { super.create(); + var gameCamera = new FlxCamera(Game.GAME_X, 0, Game.getGameWidth(), Game.getGameHeight()); + gameCamera.pixelPerfectRender = Game.PIXEL_PERFECT; + FlxG.cameras.reset(gameCamera); + var uiCamera = new FlxCamera(0, 0, FlxG.width, FlxG.height); uiCamera.bgColor = FlxColor.TRANSPARENT; - FlxG.camera.pixelPerfectRender = Game.PIXEL_PERFECT; + uiCamera.pixelPerfectRender = Game.PIXEL_PERFECT; if (ending == 0) { @@ -84,7 +88,8 @@ class EndingState extends BaseState } } - var screen = new ScanLines(false); + var screen = new ScanLines(); + screen.cameras = [uiCamera]; add(screen); uiText = new FlxText(5, 132 + 5, FlxG.width - 10); @@ -92,7 +97,6 @@ class EndingState extends BaseState add(uiText); FlxG.cameras.add(uiCamera, false); - screen.cameras = [uiCamera]; uiText.cameras = [uiCamera]; } @@ -102,7 +106,7 @@ class EndingState extends BaseState new FlxTimer().start(3, (_) -> { uiText.color = FlxColor.RED; - uiText.text = PlayState.POINTS < 6 ? "Maybe... collecting 6 strawberries?" : "Next time... SHOOT HIM!"; + uiText.text = PlayState.POINTS < 6 ? "Maybe... getting 6 of them?" : "Next time... SHOOT HIM!"; new FlxTimer().start(3, (_) -> System.exit(0)); }); animEnding.kill(); diff --git a/source/states/FinishState.hx b/source/states/FinishState.hx index b0b5119..3e4f206 100644 --- a/source/states/FinishState.hx +++ b/source/states/FinishState.hx @@ -1,5 +1,6 @@ package states; +import flixel.FlxCamera; import flixel.FlxG; import flixel.text.FlxText; import flixel.util.FlxColor; @@ -14,18 +15,23 @@ class FinishState extends BaseState "Game made by SavanDev", "Created in HaxeFlixel", "Music made by\nJoshua McLean", - "This game was made for\n#MejorandoAndo of May", - "Thanks for playing!\n\nPress ESCAPE to exit the game" + "Thanks for playing!\nSee you next time ;)" ]; var actualText:Int = 0; override public function create() { super.create(); - FlxG.camera.pixelPerfectRender = Game.PIXEL_PERFECT; + var gameCamera = new FlxCamera(Game.GAME_X, 0, Game.getGameWidth(), Game.getGameHeight()); + FlxG.cameras.reset(gameCamera); + + var uiCamera = new FlxCamera(0, 0, FlxG.width, FlxG.height); + uiCamera.bgColor = FlxColor.TRANSPARENT; + FlxG.cameras.add(uiCamera, false); var finishText = new FlxText(0, 0, 150, texts[actualText]); finishText.alignment = CENTER; + finishText.cameras = [uiCamera]; finishText.screenCenter(); add(finishText); @@ -38,6 +44,8 @@ class FinishState extends BaseState { if (actualText < texts.length - 1) new FlxTimer().start(3, (_) -> fade.fadeOut(FlxColor.BLACK)); + else + new FlxTimer().start(3, (_) -> System.exit(0)); }); fade.setCallbackOut(() -> { diff --git a/source/states/MenuState.hx b/source/states/MenuState.hx index 45cfc0f..1b68fb5 100644 --- a/source/states/MenuState.hx +++ b/source/states/MenuState.hx @@ -1,5 +1,6 @@ package states; +import flixel.FlxCamera; import flixel.FlxG; import flixel.FlxObject; import flixel.FlxSprite; @@ -34,10 +35,16 @@ class MenuState extends BaseState override public function create() { super.create(); - FlxG.camera.pixelPerfectRender = Game.PIXEL_PERFECT; - bgColor = 0xff0163c6; - FlxG.timeScale = 1.03; + var gameCamera = new FlxCamera(Game.GAME_X, 0, Game.getGameWidth(), Game.getGameHeight()); + gameCamera.pixelPerfectRender = Game.PIXEL_PERFECT; + gameCamera.bgColor = 0xff0163c6; + FlxG.cameras.reset(gameCamera); + + var hudCamera = new FlxCamera(0, 0, FlxG.width, FlxG.height); + hudCamera.pixelPerfectRender = Game.PIXEL_PERFECT; + hudCamera.bgColor = FlxColor.TRANSPARENT; + FlxG.cameras.add(hudCamera, false); var map = new FlxOgmo3Loader(Paths.getOgmoData(), 'assets/data/levels/level0.json'); @@ -74,17 +81,24 @@ class MenuState extends BaseState add(glitchSprite); uiName = new FlxText(0, 30, "COLORLESS", 16); + // uiName.cameras = [hudCamera]; uiName.screenCenter(X); + uiName.x -= gameCamera.x; add(uiName); var screen = new ScanLines(); + screen.cameras = [hudCamera]; add(screen); - var uiBorder = new FlxSprite(0, Game.getGameHeight()); - uiBorder.makeGraphic(FlxG.width, FlxG.height - Std.int(uiBorder.y), FlxColor.BLACK); - add(uiBorder); + var startTitle:String; + #if mobile + startTitle = "Touch to start!"; + #else + startTitle = "Press ENTER to start!"; + #end - uiText = new FlxText(5, Game.getGameHeight() + 5, FlxG.width - 10, "Press ENTER to start!"); + uiText = new FlxText(5, Game.getGameHeight() + 5, FlxG.width - 10, startTitle); + uiText.cameras = [hudCamera]; uiText.alignment = CENTER; add(uiText); diff --git a/source/states/PlayState.hx b/source/states/PlayState.hx index 5060618..d692221 100644 --- a/source/states/PlayState.hx +++ b/source/states/PlayState.hx @@ -19,6 +19,7 @@ import lime.system.System; import misc.Input; import misc.Paths; import misc.ScanLines; +import mobile.AndroidPad; import objects.Artefact; import objects.Bullet; import objects.Heart; @@ -123,18 +124,17 @@ class PlayState extends BaseState { super.create(); - if (LEVEL < 0 || LEVEL > 7) - LEVEL = 7; + if (LEVEL < 0 || LEVEL > 6) + LEVEL = 1; - FlxG.camera.pixelPerfectRender = Game.PIXEL_PERFECT; - bgColor = !BSIDE ? 0xff0163c6 : FlxColor.BLACK; + var gameCamera = new FlxCamera(Game.GAME_X, 0, Game.getGameWidth(), Game.getGameHeight()); + gameCamera.bgColor = !BSIDE ? 0xff0163c6 : FlxColor.BLACK; + FlxG.cameras.reset(gameCamera); - persistentDraw = persistentUpdate = true; - - var glitchedEffect = new FlxGlitchEffect(2); - var uiCamera = new FlxCamera(0, 0, FlxG.width, FlxG.height); + var uiCamera = new FlxCamera(); uiCamera.bgColor = FlxColor.TRANSPARENT; - uiCamera.pixelPerfectRender = Game.PIXEL_PERFECT; + + persistentDraw = persistentUpdate = true; var map = new FlxOgmo3Loader(Paths.getOgmoData(), 'assets/data/levels/level$LEVEL.json'); initPos = new FlxPoint(); @@ -150,10 +150,12 @@ class PlayState extends BaseState walls.setTileProperties(1, FlxObject.ANY); add(walls); + #if !mobile var tutoLayer = map.loadTilemap(Paths.getImage("tuto", true), "TutoLayer"); FlxTween.num(tutoLayer.y, tutoLayer.y + 3, 1, {type: PINGPONG}, (v:Float) -> tutoLayer.y = v); if (!BSIDE) add(tutoLayer); + #end if (!BSIDE) { @@ -175,17 +177,18 @@ class PlayState extends BaseState var screen = new ScanLines(); add(screen); - var uiBorder = new FlxSprite(0, Game.getGameHeight()); - uiBorder.makeGraphic(FlxG.width, FlxG.height - Std.int(uiBorder.y), FlxColor.BLACK); - add(uiBorder); - var uiStrawberry = new Heart(5, Game.getGameHeight() + 5); if (!BSIDE) add(uiStrawberry); else { - var uiStrawGlitched = new FlxEffectSprite(uiStrawberry, [glitchedEffect]); + var glitchedHeart = new FlxGlitchEffect(1); + var uiStrawGlitched = new FlxEffectSprite(uiStrawberry, [glitchedHeart]); + #if mobile + uiStrawGlitched.setPosition(6, 6); + #else uiStrawGlitched.setPosition(5, Game.getGameHeight() + 5); + #end uiStrawGlitched.cameras = [uiCamera]; add(uiStrawGlitched); } @@ -193,15 +196,26 @@ class PlayState extends BaseState uiStrawCount = new FlxText(17, Game.getGameHeight() + 5, 0, "x 0"); add(uiStrawCount); - var uiText = new FlxText(5, Game.getGameHeight() + 5, FlxG.width - 10, !BSIDE ? levelText[LEVEL] : bSideText[LEVEL]); + var uiXPos = uiStrawCount.x + uiStrawCount.width; + var uiText = new FlxText(uiXPos, Game.getGameHeight() + 5, FlxG.width - uiXPos - 5, !BSIDE ? levelText[LEVEL] : bSideText[LEVEL]); uiText.alignment = RIGHT; add(uiText); + #if mobile + uiStrawberry.setPosition(6, 6); + uiStrawCount.setPosition(2, 20); + uiText.alignment = CENTER; + uiText.screenCenter(X); + #end + if (BSIDE) { + var glitchedCursed = new FlxGlitchEffect(2); var spriteCursed = new FlxSprite().loadGraphic(Paths.getImage("cursed", true)); - var cursed = new FlxEffectSprite(spriteCursed, [glitchedEffect]); + var cursed = new FlxEffectSprite(spriteCursed, [glitchedCursed]); cursed.visible = false; + cursed.x = Game.GAME_X; + cursed.cameras = [uiCamera]; add(cursed); if (finishPlayer == null) @@ -220,6 +234,7 @@ class PlayState extends BaseState } else { + cursed.alpha = 0; cursed.visible = true; new FlxTimer().start(.1, (_) -> cursed.alpha = Math.max(0, .5 - (player.x / FlxG.width)), 0); } @@ -228,6 +243,14 @@ class PlayState extends BaseState bullet = new Bullet(player); add(bullet); + #if mobile + // Android controls! + var pad = new AndroidPad(); + pad.cameras = [uiCamera]; + pad.setCamera(uiCamera); + add(pad); + #end + // Music if (FlxG.sound.music == null || !FlxG.sound.music.playing) if (!BSIDE) @@ -264,38 +287,27 @@ class PlayState extends BaseState hasGun = () -> { Player.HAS_GUN = true; + #if !mobile add(tutoLayer); + #else + pad.enableShotButton(); + #end }; // HUD FlxG.cameras.add(uiCamera, false); - uiBorder.cameras = [uiCamera]; uiCamera.cameras = [uiCamera]; uiStrawberry.cameras = [uiCamera]; uiText.cameras = [uiCamera]; uiStrawCount.cameras = [uiCamera]; - screen.cameras = [uiCamera]; - // Hacker time? - if (LEVEL == 7) - { - FlxG.sound.music.stop(); - var spriteCursed = new FlxSprite().loadGraphic(Paths.getImage("cursedever")); - new FlxTimer().start(10, (_) -> - { - player.kill(); - add(spriteCursed); - uiText.text = "DIRTY HACKER"; - uiText.color = FlxColor.RED; - new FlxTimer().start(2, (_) -> System.exit(0)); - }); - } + screen.cameras = [uiCamera]; } function playerInteraction() { // Pasar de nivel por derecha e izquierda - if ((player.x > FlxG.width) || (player.x < -player.width)) + if ((player.x > Game.getGameWidth()) || (player.x < -player.width)) { player.kill(); player.visible = false; @@ -312,8 +324,8 @@ class PlayState extends BaseState player.x = 0; // Pared mágica por derecha - if ((BSIDE || player.y <= 0) && player.x > (FlxG.width - player.width)) - player.x = FlxG.width - player.width; + if ((BSIDE || player.y <= 0) && player.x > (Game.getGameWidth() - player.width)) + player.x = Game.getGameWidth() - player.width; // Te caíste bro if (player.y > FlxG.height && !respawn) @@ -426,13 +438,13 @@ class PlayState extends BaseState if (player.alive) playerInteraction(); - if ((Input.BACK || Input.BACK_ALT) && LEVEL != 7) + if (Input.BACK || Input.BACK_ALT) System.exit(0); if (Player.HAS_GUN && (Input.SHOOT || Input.SHOOT_ALT)) bullet.shoot(); - #if debug + #if (debug && desktop) if (FlxG.keys.justPressed.L) { if (BSIDE)