blades-engine parse terrain and floor height
This commit is contained in:
@@ -14,6 +14,7 @@ import flash.display.BitmapData;
|
||||
import kiss.Prelude;
|
||||
import data.blades.ScenData;
|
||||
import data.blades.Scenario;
|
||||
import data.blades.TileMap;
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
class BladesMapState extends FlxState {}
|
||||
|
@@ -12,27 +12,30 @@
|
||||
(Scenario.test)
|
||||
|
||||
(let [valleydy (Scenario.fromBasFile "Blades of Avernum Scenarios/Valley of Dying Things/valleydy.bas")]
|
||||
~valleydy)
|
||||
|
||||
(addFloorLayer (groups (collect (range 255)) 32 Keep))
|
||||
(addTerrainLayer (groups (concat
|
||||
(for _ (range 255) -1)
|
||||
(collect (range 512)))
|
||||
32 Keep)))
|
||||
(addSprites
|
||||
// 2D nth >:)
|
||||
(nth valleydy.outdoorSections 0 0))))
|
||||
|
||||
(var SELECTED_COLOR FlxColor.LIME)
|
||||
(var NORMAL_COLOR FlxColor.WHITE)
|
||||
(var CLIFF_HEIGHT 22)
|
||||
|
||||
(method :Void addFloorLayer [:Array<Array<Int>> tiles]
|
||||
(method :Void addSprites [:TileMap map]
|
||||
(let [&mut rowStartX 0
|
||||
&mut rowStartY 0]
|
||||
(doFor row tiles
|
||||
(doFor tileY (range map.height)
|
||||
(let [&mut x rowStartX
|
||||
&mut y rowStartY]
|
||||
(doFor tile row
|
||||
(let [tileSprite (data.floorSprite tile)]
|
||||
(doFor tileX (range map.width)
|
||||
(let [height (nth map.floorHeights tileX tileY)
|
||||
floor (nth map.floorCodes tileX tileY)
|
||||
terrain (nth map.terrainCodes tileX tileY)
|
||||
yOffset (* CLIFF_HEIGHT height)]
|
||||
// First add the floor
|
||||
(let [tileSprite (data.floorSprite floor)]
|
||||
// TODO add cliffs if it's higher than the one in front of it
|
||||
(set tileSprite.x x)
|
||||
(set tileSprite.y y)
|
||||
(set tileSprite.y (- y yOffset))
|
||||
(FlxMouseEventManager.add tileSprite
|
||||
// handle click on floor:
|
||||
->downTS {}
|
||||
@@ -40,23 +43,15 @@
|
||||
->overTS (set overTS.color SELECTED_COLOR)
|
||||
->outTS (set outTS.color NORMAL_COLOR))
|
||||
(add tileSprite))
|
||||
(+= x (/ FLOOR_WIDTH 2))
|
||||
(+= y (/ FLOOR_HEIGHT 2))))
|
||||
(-= rowStartX (/ FLOOR_WIDTH 2))
|
||||
(+= rowStartY (/ FLOOR_HEIGHT 2)))))
|
||||
|
||||
// TODO creatures and items need to be added when their floor and terrain tiles are
|
||||
// added, to preserve Z order
|
||||
(method :Void addTerrainLayer [: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 (data.terrainSprite tile)]
|
||||
// TODO add any items
|
||||
|
||||
// TODO add any characters
|
||||
|
||||
// TODO the wall sprites will be from different sheets defined by town/outdoor section
|
||||
(let [tileSprite (data.terrainSprite terrain)]
|
||||
(set tileSprite.x x)
|
||||
(set tileSprite.y y)
|
||||
(set tileSprite.y (- y yOffset))
|
||||
(when (> tileSprite.height SPRITE_HEIGHT)
|
||||
(-= tileSprite.y SPRITE_HEIGHT))
|
||||
(FlxMouseEventManager.add tileSprite
|
||||
@@ -65,7 +60,7 @@
|
||||
->upTS {}
|
||||
->overTS (set overTS.color SELECTED_COLOR)
|
||||
->outTS (set outTS.color NORMAL_COLOR))
|
||||
(add tileSprite))
|
||||
(add tileSprite)))
|
||||
(+= x (/ FLOOR_WIDTH 2))
|
||||
(+= y (/ FLOOR_HEIGHT 2))))
|
||||
(-= rowStartX (/ FLOOR_WIDTH 2))
|
||||
|
@@ -61,6 +61,8 @@ class ScenData {
|
||||
}
|
||||
|
||||
public function floorSprite(floorId:Int) {
|
||||
if (!(floorId >= 0 && floorId < 256))
|
||||
throw 'floor $floorId is out of range';
|
||||
if (!floorData.exists(floorId)) {
|
||||
return emptySprite();
|
||||
}
|
||||
@@ -81,6 +83,8 @@ class ScenData {
|
||||
}
|
||||
|
||||
public function terrainSprite(terrainId:Int) {
|
||||
if (!(terrainId >= 0 && terrainId < 512))
|
||||
throw 'terrain $terrainId is out of range';
|
||||
if (!terrainData.exists(terrainId)) {
|
||||
var s = new FlxSprite(0, 0);
|
||||
s.makeGraphic(46, 55, FlxColor.TRANSPARENT);
|
||||
|
@@ -108,18 +108,28 @@ class Scenario {
|
||||
var sec = new TileMap(outdoorWidth, outdoorHeight, stream.readCString(19));
|
||||
trace(sec.name);
|
||||
|
||||
for (y in 0...outdoorHeight) {
|
||||
for (x in 0...outdoorWidth) {
|
||||
for (y in 0...outdoorHeight) {
|
||||
sec.setFloor(x, y, stream.readByte());
|
||||
}
|
||||
}
|
||||
|
||||
// floor heights
|
||||
for (y in 0...outdoorHeight) {
|
||||
for (x in 0...outdoorWidth) {
|
||||
for (y in 0...outdoorHeight) {
|
||||
sec.setFloorHeight(x, y, stream.readByte());
|
||||
}
|
||||
}
|
||||
|
||||
// 1 byte of padding to align the int16s
|
||||
// terrain
|
||||
for (x in 0...outdoorWidth) {
|
||||
for (y in 0...outdoorHeight) {
|
||||
// these are big-endian
|
||||
sec.setTerrain(x, y, 256 * stream.readByte() + stream.readByte());
|
||||
}
|
||||
}
|
||||
|
||||
stream.tracePosition();
|
||||
// TODO all the other outdoor section stuff
|
||||
|
||||
|
@@ -6,10 +6,10 @@ class TileMap {
|
||||
// TODO might need encapsulation
|
||||
public var floorCodes:TileArray<Int>;
|
||||
public var floorHeights:TileArray<Int>;
|
||||
private var terrainCodes:TileArray<Int>;
|
||||
public var terrainCodes:TileArray<Int>;
|
||||
|
||||
private var width = 0;
|
||||
private var height = 0;
|
||||
public var width = 0;
|
||||
public var height = 0;
|
||||
|
||||
public var name = "";
|
||||
|
||||
|
Reference in New Issue
Block a user