Implemented Rogue-style room generation... badly.
10,000 ways not to make a lightbulb, I guess.
This commit is contained in:
62
assets/scripts/tilemap/rendernode.toy
Normal file
62
assets/scripts/tilemap/rendernode.toy
Normal file
@@ -0,0 +1,62 @@
|
||||
//constants for generating maps
|
||||
var ROOM_MIN_WIDTH: int const = 4; //minimum safe value 4
|
||||
var ROOM_MIN_HEIGHT: int const = 4;
|
||||
|
||||
var ROOM_MAX_WIDTH: int const = 12;
|
||||
var ROOM_MAX_HEIGHT: int const = 12;
|
||||
|
||||
var CELL_WIDTH: int const = 16; //minimum safe value ROOM_MAX_* + 4
|
||||
var CELL_HEIGHT: int const = 16;
|
||||
|
||||
var CELL_COUNT_X: int const = 3;
|
||||
var CELL_COUNT_Y: int const = 3;
|
||||
|
||||
var tilemap: [int] = null;
|
||||
|
||||
fn setTilemap(node: opaque, t: [int]) {
|
||||
tilemap = t;
|
||||
}
|
||||
|
||||
//lifecycle functions
|
||||
fn onLoad(node: opaque) {
|
||||
node.loadNodeTexture("sprites:/tileset.png");
|
||||
|
||||
node.setNodeScaleX(CAMERA_SCALE_X);
|
||||
node.setNodeScaleY(CAMERA_SCALE_Y);
|
||||
}
|
||||
|
||||
fn onDraw(node: opaque) {
|
||||
assert tilemap, "tilemap is null";
|
||||
|
||||
var posX: int const = node.getNodeWorldPositionX();
|
||||
var posY: int const = node.getNodeWorldPositionY();
|
||||
|
||||
//draw everything at twice the original size
|
||||
var scaleX: float const = node.getNodeWorldScaleX();
|
||||
var scaleY: float const = node.getNodeWorldScaleY();
|
||||
|
||||
//draw the tilemap
|
||||
for (var j = 0; j < CELL_HEIGHT * CELL_COUNT_Y; j++) {
|
||||
for (var i = 0; i < CELL_WIDTH * CELL_COUNT_X; i++) {
|
||||
//don't render empty tiles
|
||||
if (tilemap[j * CELL_WIDTH * CELL_COUNT_X * 3 + i * 3] < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//set the rect of the node on the tilesheet - the "tilemap" var is a single blob of data
|
||||
node.setNodeRect(
|
||||
tilemap[j * CELL_WIDTH * CELL_COUNT_X * 3 + i * 3] * TILE_PIXEL_WIDTH,
|
||||
tilemap[j * CELL_WIDTH * CELL_COUNT_X * 3 + i * 3 + 1] * TILE_PIXEL_HEIGHT,
|
||||
TILE_PIXEL_WIDTH, TILE_PIXEL_HEIGHT
|
||||
);
|
||||
|
||||
//draw to the screen
|
||||
node.drawNode(
|
||||
floor((i * TILE_PIXEL_WIDTH + posX) * scaleX) + globalCameraX,
|
||||
floor((j * TILE_PIXEL_HEIGHT + posY) * scaleY) + globalCameraY,
|
||||
floor(TILE_PIXEL_WIDTH * scaleX),
|
||||
floor(TILE_PIXEL_HEIGHT * scaleY)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user