Fix texture rendering for free cells
This commit is contained in:
parent
0a94c68195
commit
8fbcc7e915
|
@ -14,6 +14,7 @@ renderer: *Renderer,
|
|||
grid_cell_size: i32,
|
||||
grid_pos_x: i32,
|
||||
grid_pos_y: i32,
|
||||
cell_texture: Renderer.Texture,
|
||||
|
||||
pub fn init(renderer: *Renderer) Self {
|
||||
var wsize = renderer.getOutputSize();
|
||||
|
@ -26,6 +27,7 @@ pub fn init(renderer: *Renderer) Self {
|
|||
.grid_pos_x = grid_pos_x,
|
||||
.grid_pos_y = grid_pos_y,
|
||||
.grid_cell_size = grid_cell_size,
|
||||
.cell_texture = Renderer.Texture.init("res/cell.png"),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -42,22 +44,22 @@ pub fn renderBag(self: *Self, game: Game) void {
|
|||
const new_x = pos_x + @as(i32, @intCast(x)) * self.grid_cell_size;
|
||||
const new_y = pos_y + (@as(i32, @intCast(y)) + @as(i32, @intCast(i * piece.structure.len))) * self.grid_cell_size;
|
||||
|
||||
var alpha: u8 = 50;
|
||||
|
||||
if (piece.structure[y][x]) {
|
||||
alpha = 255;
|
||||
self.cell_texture.drawTo(new_x, new_y, self.grid_cell_size, self.grid_cell_size, piece.color);
|
||||
} else {
|
||||
const alpha = 50;
|
||||
|
||||
self.renderer.setColor([_]u8{
|
||||
piece.color[0] -| 30, // r
|
||||
piece.color[1] -| 30, // g
|
||||
piece.color[2] -| 30, // b
|
||||
alpha,
|
||||
});
|
||||
self.renderer.fillRectangle(new_x, new_y, self.grid_cell_size, self.grid_cell_size);
|
||||
|
||||
self.renderer.setColor(.{ piece.color[0], piece.color[1], piece.color[2], alpha });
|
||||
self.renderer.fillRectangle(new_x + 1, new_y + 1, self.grid_cell_size - 2, self.grid_cell_size - 2);
|
||||
}
|
||||
|
||||
self.renderer.setColor([_]u8{
|
||||
piece.color[0] -| 30, // r
|
||||
piece.color[1] -| 30, // g
|
||||
piece.color[2] -| 30, // b
|
||||
alpha,
|
||||
});
|
||||
self.renderer.fillRectangle(new_x, new_y, self.grid_cell_size, self.grid_cell_size);
|
||||
|
||||
self.renderer.setColor(.{ piece.color[0], piece.color[1], piece.color[2], alpha });
|
||||
self.renderer.fillRectangle(new_x + 1, new_y + 1, self.grid_cell_size - 2, self.grid_cell_size - 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -76,22 +78,22 @@ pub fn renderHeld(self: *Self, game: Game) void {
|
|||
const new_x = pos_x + @as(i32, @intCast(x)) * self.grid_cell_size;
|
||||
const new_y = pos_y + @as(i32, @intCast(y)) * self.grid_cell_size;
|
||||
|
||||
var alpha: u8 = 50;
|
||||
|
||||
if (held.structure[y][x]) {
|
||||
alpha = 255;
|
||||
self.cell_texture.drawTo(new_x, new_y, self.grid_cell_size, self.grid_cell_size, held.color);
|
||||
} else {
|
||||
const alpha = 50;
|
||||
|
||||
self.renderer.setColor([_]u8{
|
||||
held.color[0] -| 30, // r
|
||||
held.color[1] -| 30, // g
|
||||
held.color[2] -| 30, // b
|
||||
alpha,
|
||||
});
|
||||
self.renderer.fillRectangle(new_x, new_y, self.grid_cell_size, self.grid_cell_size);
|
||||
|
||||
self.renderer.setColor(.{ held.color[0], held.color[1], held.color[2], alpha });
|
||||
self.renderer.fillRectangle(new_x + 1, new_y + 1, self.grid_cell_size - 2, self.grid_cell_size - 2);
|
||||
}
|
||||
|
||||
self.renderer.setColor([_]u8{
|
||||
held.color[0] -| 30, // r
|
||||
held.color[1] -| 30, // g
|
||||
held.color[2] -| 30, // b
|
||||
alpha,
|
||||
});
|
||||
self.renderer.fillRectangle(new_x, new_y, self.grid_cell_size, self.grid_cell_size);
|
||||
|
||||
self.renderer.setColor(.{ held.color[0], held.color[1], held.color[2], alpha });
|
||||
self.renderer.fillRectangle(new_x + 1, new_y + 1, self.grid_cell_size - 2, self.grid_cell_size - 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -119,15 +121,7 @@ pub fn renderPiece(self: *Self, piece: Piece) void {
|
|||
const new_x = pos_x + (@as(i32, @intCast(x)) + piece.col) * self.grid_cell_size;
|
||||
const new_y = pos_y + (@as(i32, @intCast(y)) + piece.row) * self.grid_cell_size;
|
||||
|
||||
self.renderer.setColor(.{
|
||||
piece.color[0] -| 30,
|
||||
piece.color[1] -| 30,
|
||||
piece.color[2] -| 30,
|
||||
piece.color[3],
|
||||
});
|
||||
self.renderer.fillRectangle(new_x, new_y, self.grid_cell_size, self.grid_cell_size);
|
||||
self.renderer.setColor(piece.color);
|
||||
self.renderer.fillRectangle(new_x + 1, new_y + 1, self.grid_cell_size - 2, self.grid_cell_size - 2);
|
||||
self.cell_texture.drawTo(new_x, new_y, self.grid_cell_size, self.grid_cell_size, piece.color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -142,10 +136,18 @@ pub fn renderGrid(self: *Self, grid: Grid) void {
|
|||
const new_x = pos_x + @as(i32, @intCast(x)) * self.grid_cell_size;
|
||||
const new_y = pos_y + (@as(i32, @intCast(y)) + Grid.buffer) * self.grid_cell_size;
|
||||
|
||||
// Background
|
||||
self.renderer.setColor(color.light_grey);
|
||||
self.renderer.fillRectangle(new_x, new_y, self.grid_cell_size, self.grid_cell_size);
|
||||
self.renderer.setColor(visible[y][x].color);
|
||||
self.renderer.fillRectangle(new_x + 1, new_y + 1, self.grid_cell_size - 2, self.grid_cell_size - 2);
|
||||
|
||||
if (visible[y][x].free) {
|
||||
// Not dropped
|
||||
self.renderer.setColor(visible[y][x].color);
|
||||
self.renderer.fillRectangle(new_x + 1, new_y + 1, self.grid_cell_size - 2, self.grid_cell_size - 2);
|
||||
} else {
|
||||
// Dropped
|
||||
self.cell_texture.drawTo(new_x, new_y, self.grid_cell_size, self.grid_cell_size, visible[y][x].color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue