Tilemap is working, in theory
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
<None Include="assets\scripts\airplane.toy" />
|
||||
<None Include="assets\scripts\gameplay\lejana.toy" />
|
||||
<None Include="assets\scripts\gameplay\scene.toy" />
|
||||
<None Include="assets\scripts\gameplay\tilemap.toy" />
|
||||
<None Include="assets\scripts\init.toy" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
|
||||
2
Toy
2
Toy
Submodule Toy updated: 6e9d42f892...669808730e
@@ -31,7 +31,7 @@ fn faceUp(node: opaque) {
|
||||
}
|
||||
|
||||
fn faceLeft(node: opaque) {
|
||||
node.setNodeRect(32 * 8, 0, SPRITE_WIDTH, SPRITE_HEIGHT);
|
||||
node.setNodeRect(32 * 12, 0, SPRITE_WIDTH, SPRITE_HEIGHT);
|
||||
node.setNodeFrames(4);
|
||||
}
|
||||
|
||||
|
||||
75
assets/scripts/gameplay/tilemap.toy
Normal file
75
assets/scripts/gameplay/tilemap.toy
Normal file
@@ -0,0 +1,75 @@
|
||||
import standard;
|
||||
import node;
|
||||
|
||||
//consts
|
||||
var ROOM_WIDTH: int const = 5;
|
||||
var ROOM_HEIGHT: int const = 5;
|
||||
|
||||
var TILE_WIDTH: int const = 128;
|
||||
var TILE_HEIGHT: int const = 128;
|
||||
|
||||
//vars
|
||||
var tilemap: [[int]] = null;
|
||||
|
||||
//debug vars
|
||||
var camX = 0;
|
||||
var camY = 0;
|
||||
var camW = 1080;
|
||||
var camH = 720;
|
||||
|
||||
|
||||
|
||||
//lifecycle functions
|
||||
fn onInit(node: opaque) {
|
||||
tilemap = generateBlankMap(ROOM_WIDTH, ROOM_HEIGHT);
|
||||
|
||||
node.loadTexture("sprites:/tileset.png");
|
||||
node.setNodeRect(0, 0, 32, 32);
|
||||
|
||||
//debug
|
||||
print tilemap;
|
||||
tilemap[1][1] = 1;
|
||||
print tilemap;
|
||||
}
|
||||
|
||||
fn onDraw(node: opaque) {
|
||||
//calc the region to render
|
||||
var lowerX: int = round((camX - camW/2.0) / TILE_WIDTH);
|
||||
var upperX: int = round((camX - camW*1.5) / TILE_WIDTH);
|
||||
var lowerY: int = round((camY - camH/2.0) / TILE_HEIGHT);
|
||||
var upperY: int = round((camY - camH*1.5) / TILE_HEIGHT);
|
||||
|
||||
//bounds check
|
||||
lowerX = max(0, lowerX);
|
||||
upperX = min(upperX < 0 ? abs(upperX) : 0, ROOM_WIDTH);
|
||||
lowerY = max(0, lowerY);
|
||||
upperY = min(upperY < 0 ? abs(upperY) : 0, ROOM_HEIGHT);
|
||||
|
||||
|
||||
//draw the tilemap
|
||||
for (var j = lowerY; j < upperY; j++) {
|
||||
for (var i = lowerX; i < upperX; i++) {
|
||||
node.setCurrentNodeFrame(tilemap[i][j]);
|
||||
node.drawNode(i * TILE_WIDTH, j * TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//utils functions
|
||||
fn generateBlankMap(width: int, height: int) {
|
||||
//generate the row template
|
||||
var row: [int] = [];
|
||||
for (var j: int = 0; j < height; j++) {
|
||||
row.push(0);
|
||||
}
|
||||
|
||||
var result: [[int]] = [];
|
||||
//generate the game map proper
|
||||
for (var i: int = 0; i < width; i++) {
|
||||
result.push(row);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
initWindow("Skyland", 1080, 720, false);
|
||||
|
||||
//kick off the logic of the scene graph
|
||||
loadRootNode("scripts:/gameplay/lejana.toy");
|
||||
loadRootNode("scripts:/gameplay/tilemap.toy");
|
||||
}
|
||||
|
||||
//Globals go here
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.8 KiB |
BIN
assets/sprites/tileset.png
Normal file
BIN
assets/sprites/tileset.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 227 B |
@@ -432,7 +432,7 @@ void Box_execEngine() {
|
||||
}
|
||||
|
||||
//render the world
|
||||
SDL_SetRenderDrawColor(engine.renderer, 0, 0, 0, 255); //NOTE: This line can be disabled later
|
||||
SDL_SetRenderDrawColor(engine.renderer, 128, 128, 128, 255); //NOTE: This line can be disabled later
|
||||
SDL_RenderClear(engine.renderer); //NOTE: This line can be disabled later
|
||||
|
||||
Box_callRecursiveEngineNode(engine.rootNode, &engine.interpreter, "onDraw", NULL);
|
||||
|
||||
@@ -594,7 +594,7 @@ static int nativeSetCurrentNodeFrame(Toy_Interpreter* interpreter, Toy_LiteralAr
|
||||
//actually set
|
||||
Box_EngineNode* node = (Box_EngineNode*)TOY_AS_OPAQUE(nodeLiteral);
|
||||
|
||||
Box_setFramesEngineNode(node, TOY_AS_INTEGER(currentFrameLiteral));
|
||||
Box_setCurrentFrameEngineNode(node, TOY_AS_INTEGER(currentFrameLiteral));
|
||||
|
||||
//cleanup
|
||||
Toy_freeLiteral(nodeLiteral);
|
||||
|
||||
Reference in New Issue
Block a user