Initial Commit

* Adds Menu
* Adds Level Manager - LevelBase
* Adds Sample level
* Basic player movement
This commit is contained in:
Indrajith K L
2022-04-28 03:27:44 +05:30
commit ad2056876e
24 changed files with 717 additions and 0 deletions

4
source/AssetPaths.hx Normal file
View File

@@ -0,0 +1,4 @@
package;
@:build(flixel.system.FlxAssets.buildFileReferences("assets", true))
class AssetPaths {}

19
source/Main.hx Normal file
View File

@@ -0,0 +1,19 @@
package;
import djFlixel.D;
import flixel.FlxGame;
import openfl.display.Sprite;
class Main extends Sprite
{
public function new()
{
super();
D.init({
name: "RAW" + D.DJFLX_VER,
debug_keys: true, // Automatic asset reload on [F12]
smoothing: false,
});
addChild(new FlxGame(0, 0, PlayState, 2));
}
}

19
source/PlayState.hx Normal file
View File

@@ -0,0 +1,19 @@
package;
import flixel.FlxG;
import flixel.FlxState;
import scenes.MenuState;
class PlayState extends FlxState
{
override public function create()
{
super.create();
FlxG.switchState(new MenuState());
}
override public function update(elapsed:Float)
{
super.update(elapsed);
}
}

56
source/core/LevelBase.hx Normal file
View File

@@ -0,0 +1,56 @@
package core;
import core.Types.LevelConfig;
import entities.Player;
import flixel.FlxG;
import flixel.FlxState;
import flixel.addons.editors.ogmo.FlxOgmo3Loader;
import flixel.tile.FlxTilemap;
import scenes.GameOver;
class LevelBase extends FlxState
{
var map:FlxOgmo3Loader;
var bg:FlxTilemap;
var walls:FlxTilemap;
var _player:Player;
public function new(levelConfig:LevelConfig)
{
super();
map = new FlxOgmo3Loader(levelConfig.ogmoLevel, levelConfig.levelJson);
bg = map.loadTilemap(levelConfig.bgTileSheet, "bg");
walls = map.loadTilemap(levelConfig.wallTilesheet, "walls");
bg.scrollFactor.set(.33, .33);
}
override public function create()
{
super.create();
add(bg);
add(walls);
map.loadEntities(loadPlayer, 'player_layer');
FlxG.camera.setScrollBoundsRect(0, 0, walls.width, walls.height, true);
}
override public function update(elapsed:Float)
{
super.update(elapsed);
FlxG.collide(_player, walls);
if (_player.y > walls.height)
{
openSubState(new GameOver());
}
}
function loadPlayer(entity:EntityData)
{
if (entity.name == "player")
{
_player = new Player(entity.x, entity.y);
add(_player);
FlxG.camera.follow(_player, NO_DEAD_ZONE);
}
}
}

9
source/core/Types.hx Normal file
View File

@@ -0,0 +1,9 @@
package core;
typedef LevelConfig =
{
var ogmoLevel:String;
var levelJson:String;
var wallTilesheet:String;
var bgTileSheet:String;
}

75
source/entities/Player.hx Normal file
View File

@@ -0,0 +1,75 @@
package entities;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.input.actions.FlxAction.FlxActionDigital;
import flixel.input.actions.FlxActionManager;
import flixel.util.FlxColor;
class Player extends FlxSprite
{
var actionsManager:FlxActionManager;
var _left:FlxActionDigital;
var _right:FlxActionDigital;
var _jump:FlxActionDigital;
var _jumpPower:Int = 200;
public function new(x:Int, y:Int)
{
super(x, y);
makeGraphic(16, 16, FlxColor.BLUE);
var runSpeed:Int = 80;
drag.x = runSpeed * 8;
acceleration.y = 420;
maxVelocity.set(runSpeed, _jumpPower);
_left = new FlxActionDigital().addKey(LEFT, PRESSED);
_right = new FlxActionDigital().addKey(RIGHT, PRESSED);
_jump = new FlxActionDigital().addKey(X, JUST_PRESSED);
if (actionsManager == null)
{
actionsManager = FlxG.inputs.add(new FlxActionManager());
}
actionsManager.addActions([_left, _right, _jump]);
}
override public function update(elapsed:Float):Void
{
acceleration.x = 0;
updateInputs();
super.update(elapsed);
}
function updateInputs()
{
if (_left.triggered)
moveLeft();
else if (_right.triggered)
moveRight();
if (_jump.triggered)
jump();
// if (_shoot.triggered)
// shoot();
}
function moveLeft()
{
acceleration.x -= drag.x;
}
function moveRight()
{
acceleration.x += drag.x;
}
function jump()
{
if (velocity.y == 0)
{
velocity.y = -_jumpPower;
}
}
}

16
source/scenes/Credits.hx Normal file
View File

@@ -0,0 +1,16 @@
package scenes;
import flixel.FlxState;
class Credits extends FlxState
{
override public function create()
{
super.create();
}
override public function update(elapsed:Float)
{
super.update(elapsed);
}
}

73
source/scenes/GameOver.hx Normal file
View File

@@ -0,0 +1,73 @@
package scenes;
import djFlixel.gfx.pal.Pal_DB32;
import djFlixel.ui.FlxMenu;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxSubState;
import flixel.math.FlxPoint;
import flixel.util.FlxColor;
import flixel.util.FlxSpriteUtil;
class GameOver extends FlxSubState
{
var bgWidth:Int = 126;
var bgHeight:Int = 116;
var menuWidth:Int = 90;
var bgMenuSpace:Int = 16;
var bgRectDiff:Int = 2;
var menuFontSize:Int = 20;
public function new()
{
super(0x33000000);
}
override public function create()
{
super.create();
var bg:FlxSprite = new FlxSprite();
bg.makeGraphic(menuWidth + (bgMenuSpace * 2) + (bgRectDiff * 2), bgHeight, FlxColor.TRANSPARENT);
FlxSpriteUtil.drawRoundRect(bg, 0, 0, (bgWidth - (bgRectDiff * 2)), bgHeight, 10, 10, FlxColor.BLACK);
var _menu = new FlxMenu(FlxG.width / 2 - (menuWidth / 2 - menuFontSize), FlxG.height / 2, menuWidth);
bg.setPosition((_menu.x - bgMenuSpace), (_menu.y) - (bgMenuSpace * 2));
_menu.stI.text = {
f: AssetPaths.MrPixel__otf,
s: menuFontSize,
bt: 1,
so: [1, 1]
};
_menu.PARAMS.enable_mouse = false;
_menu.stI.col_t = {
idle: Pal_DB32.COL[21],
focus: Pal_DB32.COL[28],
accent: Pal_DB32.COL[29],
dis: Pal_DB32.COL[25], // Disabled
dis_f: Pal_DB32.COL[23], // Disabled focused
};
_menu.stI.col_b = {
idle: Pal_DB32.COL[1],
focus: Pal_DB32.COL[0]
};
_menu.stHeader = {
f: AssetPaths.MrPixel__otf,
s: 16,
bt: 2,
bs: 1,
c: Pal_DB32.COL[8],
bc: Pal_DB32.COL[27]
};
_menu.PARAMS.header_CPS = 30;
_menu.PARAMS.page_anim_parallel = true;
_menu.createPage('main', "GAME OVER").addM(['Restart |link|restart', 'Home |link|home', 'Exit |link|exit']);
_menu.onItemEvent = (a, b) -> {};
add(bg);
add(_menu);
_menu.goto('main');
FlxG.camera.follow(null);
FlxG.camera.focusOn(new FlxPoint(0, 0));
}
}

27
source/scenes/Level1.hx Normal file
View File

@@ -0,0 +1,27 @@
package scenes;
import core.LevelBase;
import flixel.FlxState;
class Level1 extends LevelBase
{
public function new()
{
super({
ogmoLevel: AssetPaths.maps__ogmo,
bgTileSheet: AssetPaths.bg__png,
wallTilesheet: AssetPaths.sci_fi_tileset__png,
levelJson: AssetPaths.level1__json
});
}
override public function create()
{
super.create();
}
override public function update(elapsed:Float)
{
super.update(elapsed);
}
}

View File

@@ -0,0 +1,81 @@
package scenes;
import djFlixel.gfx.StarfieldSimple;
import djFlixel.gfx.pal.Pal_DB32;
import djFlixel.ui.FlxMenu;
import flixel.FlxG;
import flixel.FlxState;
import openfl.system.System;
class MenuState extends FlxState
{
override public function create()
{
super.create();
this.generateStarField();
this.createMenu();
}
private function generateStarField()
{
var stars = new StarfieldSimple();
stars.WIDE_PIXEL = false;
stars.STAR_SPEED = 1.9;
add(stars);
}
private function createMenu()
{
var _menu = new FlxMenu(FlxG.width / 2 - (70 - 20), FlxG.height / 2 + 40, 140);
_menu.stI.text = {
f: AssetPaths.MrPixel__otf,
s: 20,
bt: 1,
so: [1, 1]
};
_menu.PARAMS.enable_mouse = false;
_menu.stI.col_t = {
idle: Pal_DB32.COL[21],
focus: Pal_DB32.COL[28],
accent: Pal_DB32.COL[29],
dis: Pal_DB32.COL[25], // Disabled
dis_f: Pal_DB32.COL[23], // Disabled focused
};
_menu.stI.col_b = {
idle: Pal_DB32.COL[1],
focus: Pal_DB32.COL[0]
};
_menu.stHeader = {
f: AssetPaths.MrPixel__otf,
s: 16,
bt: 2,
bs: 1,
c: Pal_DB32.COL[8],
bc: Pal_DB32.COL[27]
};
_menu.PARAMS.header_CPS = 30;
_menu.PARAMS.page_anim_parallel = true;
_menu.createPage('main').addM(['Start |link|gamestart', 'Credits |link|credits', 'Exit |link|exit']);
_menu.onItemEvent = (a, b) ->
{
if (a == fire)
{
switch (b.ID)
{
case 'gamestart': this.switchState(new Level1());
case 'credits': this.switchState(new Credits());
case 'exit': System.exit(0);
}
}
};
add(_menu);
_menu.goto('main');
}
private function switchState(state)
{
FlxG.switchState(state);
}
}