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,11 +44,10 @@ 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
|
||||
|
@ -63,6 +64,7 @@ pub fn renderBag(self: *Self, game: Game) void {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn renderHeld(self: *Self, game: Game) void {
|
||||
const pos_x = self.grid_pos_x - (5 * self.grid_cell_size);
|
||||
|
@ -76,11 +78,10 @@ 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
|
||||
|
@ -96,6 +97,7 @@ pub fn renderHeld(self: *Self, game: Game) void {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render(self: *Self, game: Game) void {
|
||||
renderGrid(self, game.grid);
|
||||
|
@ -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);
|
||||
|
||||
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