blades-engine render one tile

This commit is contained in:
2022-05-06 16:44:08 -04:00
parent d876911929
commit 3cfb9fdc86
14 changed files with 251 additions and 0 deletions

2
projects/blades-engine/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
export/
Data/

View File

@@ -0,0 +1,6 @@
{
"recommendations": [
"openfl.lime-vscode-extension",
"redhat.vscode-xml"
]
}

View File

@@ -0,0 +1,21 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Build + Debug",
"type": "lime",
"request": "launch"
},
{
"name": "Debug",
"type": "lime",
"request": "launch",
"preLaunchTask": null
},
{
"name": "Macro",
"type": "haxe-eval",
"request": "launch"
}
]
}

View File

@@ -0,0 +1,13 @@
{
"search.exclude": {
"export/**/*.hx": true
},
"[haxe]": {
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"editor.codeActionsOnSave": {
"source.sortImports": true
}
},
"haxe.enableExtendedIndentation": true
}

View File

@@ -0,0 +1,13 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "lime",
"command": "test",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}

View File

@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<project xsi:schemaLocation="http://lime.software/project/1.0.2 http://lime.software/xsd/project-1.0.2.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://lime.software/project/1.0.2">
<!-- _________________________ Application Settings _________________________ -->
<app version="0.0.1" title="blades-engine" main="Main" file="blades-engine" company="NQNStudios"/>
<!--The flixel preloader is not accurate in Chrome. You can use it regularly if you embed the swf into a html fileor you can set the actual size of your file manually at "FlxPreloaderBase-onUpdate-bytesTotal"-->
<app preloader="flixel.system.FlxPreloader"/>
<!--Minimum without FLX_NO_GAMEPAD: 11.8, without FLX_NO_NATIVE_CURSOR: 11.2-->
<set value="11.8" name="SWF_VERSION"/>
<!-- ____________________________ Window Settings ___________________________ -->
<!--These window settings apply to all targets-->
<window width="1280" vsync="false" height="720" hardware="true" fps="60" background="#000000"/>
<!--HTML5-specific-->
<window resizable="false" if="html5"/>
<!--Desktop-specific-->
<window resizable="true" orientation="landscape" if="desktop" fullscreen="false"/>
<!--Mobile-specific-->
<window width="0" orientation="landscape" if="mobile" height="0" fullscreen="true"/>
<!-- _____________________________ Path Settings ____________________________ -->
<set value="export" name="BUILD_DIR"/>
<source path="source"/>
<assets path="assets"/>
<assets path="Data"/>
<!-- _______________________________ Libraries ______________________________ -->
<haxelib name="flixel"/>
<haxelib name="kiss"/>
<haxelib name="kiss-flixel"/>
<!--In case you want to use the addons package-->
<!--<haxelib name="flixel-addons" />-->
<!--In case you want to use the ui package-->
<!--<haxelib name="flixel-ui" />-->
<!--In case you want to use nape with flixel-->
<!--<haxelib name="nape-haxe4" />-->
<!-- ______________________________ Haxedefines _____________________________ -->
<!--Enable the Flixel core recording system-->
<!--<haxedef name="FLX_RECORD" />-->
<!--Disable the right and middle mouse buttons-->
<!--<haxedef name="FLX_NO_MOUSE_ADVANCED" />-->
<!--Disable the native cursor API on Flash-->
<!--<haxedef name="FLX_NO_NATIVE_CURSOR" />-->
<!--Optimise inputs, be careful you will get null errors if you don't use conditionals in your game-->
<haxedef name="FLX_NO_MOUSE" if="mobile"/>
<haxedef name="FLX_NO_KEYBOARD" if="mobile"/>
<haxedef name="FLX_NO_TOUCH" if="desktop"/>
<!--<haxedef name="FLX_NO_GAMEPAD" />-->
<!--Disable the Flixel core sound tray-->
<!--<haxedef name="FLX_NO_SOUND_TRAY" />-->
<!--Disable the Flixel sound management code-->
<!--<haxedef name="FLX_NO_SOUND_SYSTEM" />-->
<!--Disable the Flixel core focus lost screen-->
<!--<haxedef name="FLX_NO_FOCUS_LOST_SCREEN" />-->
<!--Disable the Flixel core debugger. Automatically gets set whenever you compile in release mode!-->
<haxedef unless="debug" name="FLX_NO_DEBUG"/>
<!--Enable this for Nape release builds for a serious peformance improvement-->
<haxedef unless="debug" name="NAPE_RELEASE_BUILD"/>
<!-- _________________________________ Custom _______________________________ -->
<!--Place custom nodes like icons here (higher priority to override the HaxeFlixel icon)-->
</project>

View File

@@ -0,0 +1,15 @@
{
"lineEnds": {
"leftCurly": "both",
"rightCurly": "both",
"objectLiteralCurly": {
"leftCurly": "after"
}
},
"sameLine": {
"ifElse": "next",
"doWhile": "next",
"tryBody": "next",
"tryCatch": "next"
}
}

View File

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

View File

@@ -0,0 +1,16 @@
package;
import flixel.FlxState;
import flixel.FlxSprite;
import flixel.util.FlxColor;
import flixel.math.FlxRect;
import flixel.math.FlxVector;
import flixel.graphics.FlxGraphic;
import flixel.FlxG;
import flash.display.BitmapData;
import kiss.Prelude;
@:build(kiss.Kiss.build())
class IsometricMapState extends FlxState {}

View File

@@ -0,0 +1,62 @@
// TODO make these variables
(var FLOOR_WIDTH 46)
(var FLOOR_HEIGHT 32)
(var SPRITE_HEIGHT 55)
(var SPRITE_PADDING 1)
(prop :Array<FlxSprite> floorTiles [])
(method &override :Void create []
(super.create)
// TODO load from a more accessible path
(let [bitmapData (BitmapData.fromFile "Data/Terrain Graphics/G796.png")
spriteSheet (.loadGraphic (new FlxSprite) (FlxGraphic.fromBitmapData bitmapData))]
(spriteSheet.replaceColor FlxColor.WHITE FlxColor.TRANSPARENT)
(let [sheetWidth (/ (- spriteSheet.frameWidth SPRITE_PADDING) (+ SPRITE_PADDING FLOOR_WIDTH))
sheetHeight (/ (- spriteSheet.frameHeight SPRITE_PADDING) (+ SPRITE_PADDING SPRITE_HEIGHT))]
(doFor row (range sheetHeight)
(doFor col (range sheetWidth)
(floorTiles.push (let [tile (spriteSheet.clone)]
(set tile.clipRect (new FlxRect
(+ SPRITE_PADDING (* col (+ SPRITE_PADDING FLOOR_WIDTH)))
(+ SPRITE_PADDING (* col (+ SPRITE_PADDING SPRITE_HEIGHT)))
FLOOR_WIDTH
SPRITE_HEIGHT))
tile))))))
(addSpriteLayer ~(for row (range 5) (collect (range 5)))))
(method :Void addSpriteLayer [:Array<Array<Int>> tiles]
(let [&mut rowStartX 0
&mut rowStartY 0]
(doFor row tiles
(let [&mut x rowStartX
&mut y rowStartY]
(doFor tile row
(let [tileSprite (.clone ~(nth floorTiles tile))]
(set tileSprite.x x)
(set tileSprite.y y)
(add tileSprite))
(+= x (/ FLOOR_WIDTH 2))
(+= y (/ FLOOR_HEIGHT 2))))
(-= rowStartX (/ FLOOR_WIDTH 2))
(+= rowStartY (/ FLOOR_HEIGHT 2)))))
(var CAMERA_SPEED 100)
(method &override :Void update [:Float elapsed]
(super.update elapsed)
(let [&mut cameraMovement (new FlxVector 0 0)]
(when (= 0 FlxG.mouse.screenX)
(set cameraMovement.x -1))
(when (= 0 FlxG.mouse.screenY)
(set cameraMovement.y -1))
(when (= (- FlxG.width 1) FlxG.mouse.screenX)
(set cameraMovement.x 1))
(when (= (- FlxG.height 1) FlxG.mouse.screenY)
(set cameraMovement.y 1))
(set cameraMovement (cameraMovement.truncate 1))
(set cameraMovement (cameraMovement.scale (* elapsed CAMERA_SPEED)))
(set FlxG.camera.scroll (FlxG.camera.scroll.add cameraMovement.x cameraMovement.y))))

View File

@@ -0,0 +1,13 @@
package;
import flixel.FlxGame;
import openfl.display.Sprite;
class Main extends Sprite
{
public function new()
{
super();
addChild(new FlxGame(0, 0, IsometricMapState));
}
}