Add the rest of the bricks
This commit is contained in:
+101
-26
@@ -38,7 +38,7 @@ const State = struct {
|
|||||||
frame_count: i32,
|
frame_count: i32,
|
||||||
mouse_pos: V2,
|
mouse_pos: V2,
|
||||||
camera: Camera,
|
camera: Camera,
|
||||||
brick: Brick,
|
bricks: [8]Brick,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn pointInsideRect(p: V2, rect_start: V2, rect_size: V2) bool {
|
fn pointInsideRect(p: V2, rect_start: V2, rect_size: V2) bool {
|
||||||
@@ -100,8 +100,8 @@ pub fn updateAndRender(memory: *platform.AppMemory, buffer: platform.OffscreenBu
|
|||||||
if (!memory.initialized) {
|
if (!memory.initialized) {
|
||||||
state.camera.offset = mid;
|
state.camera.offset = mid;
|
||||||
|
|
||||||
state.brick = Brick{
|
state.bricks[0] = Brick{
|
||||||
.pos = V2{ .x = 50, .y = 50},
|
.pos = V2{ .x = 0, .y = 50},
|
||||||
.tiles = [4][4]u32{
|
.tiles = [4][4]u32{
|
||||||
.{1, 1, 1, 1},
|
.{1, 1, 1, 1},
|
||||||
.{1, 0, 0, 0},
|
.{1, 0, 0, 0},
|
||||||
@@ -110,6 +110,77 @@ pub fn updateAndRender(memory: *platform.AppMemory, buffer: platform.OffscreenBu
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
state.bricks[1] = Brick{
|
||||||
|
.pos = V2{ .x = 32, .y = 50},
|
||||||
|
.tiles = [4][4]u32{
|
||||||
|
.{2, 2, 2, 0},
|
||||||
|
.{2, 2, 0, 0},
|
||||||
|
.{0, 0, 0, 0},
|
||||||
|
.{0, 0, 0, 0},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
state.bricks[2] = Brick{
|
||||||
|
.pos = V2{ .x = 64, .y = 50},
|
||||||
|
.tiles = [4][4]u32{
|
||||||
|
.{3, 3, 3, 0},
|
||||||
|
.{0, 0, 3, 3},
|
||||||
|
.{0, 0, 0, 0},
|
||||||
|
.{0, 0, 0, 0},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
state.bricks[3] = Brick{
|
||||||
|
.pos = V2{ .x = 96, .y = 50},
|
||||||
|
.tiles = [4][4]u32{
|
||||||
|
.{4, 0, 0, 0},
|
||||||
|
.{4, 4, 4, 0},
|
||||||
|
.{0, 0, 4, 0},
|
||||||
|
.{0, 0, 0, 0},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
state.bricks[4] = Brick{
|
||||||
|
.pos = V2{ .x = 128, .y = 50},
|
||||||
|
.tiles = [4][4]u32{
|
||||||
|
.{5, 5, 5, 5},
|
||||||
|
.{0, 5, 0, 0},
|
||||||
|
.{0, 0, 0, 0},
|
||||||
|
.{0, 0, 0, 0},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
state.bricks[5] = Brick{
|
||||||
|
.pos = V2{ .x = 160, .y = 50},
|
||||||
|
.tiles = [4][4]u32{
|
||||||
|
.{6, 6, 6, 0},
|
||||||
|
.{6, 0, 0, 0},
|
||||||
|
.{6, 0, 0, 0},
|
||||||
|
.{0, 0, 0, 0},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
state.bricks[6] = Brick{
|
||||||
|
.pos = V2{ .x = 192, .y = 50},
|
||||||
|
.tiles = [4][4]u32{
|
||||||
|
.{7, 7, 7, 0},
|
||||||
|
.{7, 7, 7, 0},
|
||||||
|
.{0, 0, 0, 0},
|
||||||
|
.{0, 0, 0, 0},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
state.bricks[7] = Brick{
|
||||||
|
.pos = V2{ .x = 224, .y = 50},
|
||||||
|
.tiles = [4][4]u32{
|
||||||
|
.{8, 8, 8, 0},
|
||||||
|
.{8, 0, 8, 0},
|
||||||
|
.{0, 0, 0, 0},
|
||||||
|
.{0, 0, 0, 0},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
memory.initialized = true;
|
memory.initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,21 +193,23 @@ pub fn updateAndRender(memory: *platform.AppMemory, buffer: platform.OffscreenBu
|
|||||||
};
|
};
|
||||||
|
|
||||||
var mouse_on_brick = false;
|
var mouse_on_brick = false;
|
||||||
for (state.brick.tiles, 0..) |row, i| {
|
for (&state.bricks) |*brick| {
|
||||||
for (row, 0..) |tile, j| {
|
for (brick.tiles, 0..) |row, i| {
|
||||||
if (tile == 1) {
|
for (row, 0..) |tile, j| {
|
||||||
const tile_pos = V2{
|
if (tile > 0) {
|
||||||
.x = @floatFromInt(j * TILE_SIZE),
|
const tile_pos = V2{
|
||||||
.y = @floatFromInt(i * TILE_SIZE),
|
.x = @floatFromInt(j * TILE_SIZE),
|
||||||
};
|
.y = @floatFromInt(i * TILE_SIZE),
|
||||||
const pos = tile_pos.add(state.brick.pos);
|
};
|
||||||
|
const pos = tile_pos.add(brick.pos);
|
||||||
|
|
||||||
const camera_pos = pos.add(state.camera.pos);
|
const camera_pos = pos.add(state.camera.pos);
|
||||||
if (pointInsideRect(state.mouse_pos, camera_pos, tile_size)) {
|
if (pointInsideRect(state.mouse_pos, camera_pos, tile_size)) {
|
||||||
if (input.mouse_left_down) {
|
if (input.mouse_left_down) {
|
||||||
const diff = mouse_pos.sub(state.mouse_pos);
|
const diff = mouse_pos.sub(state.mouse_pos);
|
||||||
state.brick.pos = state.brick.pos.add(diff);
|
brick.pos = brick.pos.add(diff);
|
||||||
mouse_on_brick = true;
|
mouse_on_brick = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -173,15 +246,17 @@ pub fn updateAndRender(memory: *platform.AppMemory, buffer: platform.OffscreenBu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (state.brick.tiles, 0..) |row, i| {
|
for (state.bricks) |brick| {
|
||||||
for (row, 0..) |tile, j| {
|
for (brick.tiles, 0..) |row, i| {
|
||||||
if (tile == 1) {
|
for (row, 0..) |tile, j| {
|
||||||
const pos = V2{
|
if (tile > 0) {
|
||||||
.x = @floatFromInt(j * TILE_SIZE),
|
const pos = V2{
|
||||||
.y = @floatFromInt(i * TILE_SIZE),
|
.x = @floatFromInt(j * TILE_SIZE),
|
||||||
};
|
.y = @floatFromInt(i * TILE_SIZE),
|
||||||
const camera_pos = state.brick.pos.add(pos).add(state.camera.pos);
|
};
|
||||||
fillSquare(buffer, @intFromFloat(camera_pos.x), @intFromFloat(camera_pos.y), 30, 0xFFFF0000);
|
const camera_pos = brick.pos.add(pos).add(state.camera.pos);
|
||||||
|
fillSquare(buffer, @intFromFloat(camera_pos.x), @intFromFloat(camera_pos.y), 30, 0xFFFF0000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user