diff --git a/Toy b/Toy index 6698087..76ddd57 160000 --- a/Toy +++ b/Toy @@ -1 +1 @@ -Subproject commit 669808730e3b881c0995408b8331e2e29d5943cc +Subproject commit 76ddd5703e73cc7435595f7b38c8d8a1c63a80d0 diff --git a/assets/scripts/gameplay/tilemap.toy b/assets/scripts/gameplay/tilemap.toy index 2dfffeb..427faa2 100644 --- a/assets/scripts/gameplay/tilemap.toy +++ b/assets/scripts/gameplay/tilemap.toy @@ -2,14 +2,39 @@ import standard; import node; //consts -var ROOM_WIDTH: int const = 5; -var ROOM_HEIGHT: int const = 5; +var ROOM_WIDTH: int const = 8; +var ROOM_HEIGHT: int const = 8; -var TILE_WIDTH: int const = 128; -var TILE_HEIGHT: int const = 128; +var TILE_WIDTH: int const = 64; +var TILE_HEIGHT: int const = 64; + +//map between the identity and position on the sprite sheet +var tilemap: [[string]] = null; + +var tileset: [string : [int]] = [ + "pillar": [0, 0], + + "floor-0": [0, 1], + "floor-1": [1, 1], + "floor-2": [2, 1], + "floor-3": [3, 1], + + "wall-t": [0, 2], + "wall-b": [1, 2], + "wall-l": [2, 2], + "wall-r": [3, 2], + + "corner-tl": [0, 3], + "corner-tr": [1, 3], + "corner-bl": [2, 3], + "corner-br": [3, 3], + + "edge-tl": [0, 4], + "edge-tr": [1, 4], + "edge-bl": [2, 4], + "edge-br": [3, 4] +]; -//vars -var tilemap: [[int]] = null; //debug vars var camX = 0; @@ -18,17 +43,12 @@ var camW = 1080; var camH = 720; - //lifecycle functions fn onInit(node: opaque) { - tilemap = generateBlankMap(ROOM_WIDTH, ROOM_HEIGHT); + tilemap = generateMap(ROOM_WIDTH, ROOM_HEIGHT); node.loadTexture("sprites:/tileset.png"); - node.setNodeRect(0, 0, 32, 32); - //debug - print tilemap; - tilemap[1][1] = 1; print tilemap; } @@ -49,7 +69,10 @@ fn onDraw(node: opaque) { //draw the tilemap for (var j = lowerY; j < upperY; j++) { for (var i = lowerX; i < upperX; i++) { - node.setCurrentNodeFrame(tilemap[i][j]); + + var pos = tileset[tilemap[i][j]]; + node.setNodeRect(pos[0] * 16, pos[1] * 16, 16, 16); + node.drawNode(i * TILE_WIDTH, j * TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT); } } @@ -57,19 +80,32 @@ fn onDraw(node: opaque) { //utils functions -fn generateBlankMap(width: int, height: int) { - //generate the row template - var row: [int] = []; +fn generateMap(width: int, height: int) { + import random; + var rng: opaque = createRandomGenerator(clock().hash()); + + //generate an empty grid + var result: [[string]] = []; + var row: [string] = []; for (var j: int = 0; j < height; j++) { - row.push(0); + row.push("pillar"); } - var result: [[int]] = []; - //generate the game map proper for (var i: int = 0; i < width; i++) { result.push(row); } + //generate the contents of the grid + for (var j: int = 0; j < height; j++) { + for (var i: int = 0; i < width; i++) { + //select a random floor tile + var x: int = rng.generateRandomNumber() % 4; + var t: string = "floor-" + string x; + + result[i][j] = t; + } + } + return result; } diff --git a/assets/sprites/tileset.png b/assets/sprites/tileset.png index b50809a..57e3535 100644 Binary files a/assets/sprites/tileset.png and b/assets/sprites/tileset.png differ