add gradient at bottom

This commit is contained in:
Rokas Puzonas 2026-07-19 03:55:21 +03:00
parent 096a082ac7
commit 19e37f507d
2 changed files with 22 additions and 1 deletions

View File

@ -43,6 +43,7 @@ font: Gfx.Font.Id,
idle_animations: AnimationDirections,
walk_animations: AnimationDirections,
death_animations: AnimationDirections,
gradient_sprite: Gfx.Sprite.Id,
terrain_sheet: Tilesheet,
terrain_tiles: []Tile,
@ -473,6 +474,23 @@ pub fn init(self: *App, plt: Platform.Init) !?u8 {
const now = std.Io.Timestamp.now(plt.io, .awake);
var gradient_sprite = Gfx.getNilSprite();
{
var gradient_data = try Gfx.ImageData.init(plt.gpa, 1, 32, .rgba8);
defer gradient_data.deinit(plt.gpa);
for (0..gradient_data.height) |y| {
const percent = @as(f32, @floatFromInt(y)) / @as(f32, @floatFromInt(gradient_data.height));
const pixel = gradient_data.getPixel(0, @intCast(y));
pixel[0] = 0;
pixel[1] = 0;
pixel[2] = 0;
pixel[3] = @intFromFloat(percent*255);
}
gradient_sprite = Gfx.initSprite(.{});
Gfx.setSprite(gradient_sprite, .{ .image = gradient_data });
}
self.* = App{
.gpa = plt.gpa,
.idle_animations = try AnimationDirections.init(plt.arena, idle_sheet, ns_per_s / idle_fps, 2),
@ -486,6 +504,7 @@ pub fn init(self: *App, plt: Platform.Init) !?u8 {
.eternal_flame_id = undefined,
.upgrades = .{},
.shop = undefined,
.gradient_sprite = gradient_sprite,
.terrain_sheet = terrain_sheet,
.terrain_tiles = terrain_tiles,
@ -1848,6 +1867,8 @@ pub fn frame(self: *App, plt: Platform.Frame) !void {
Gfx.drawSprite(tile.sprite, tile_pos.multiply(terrain_tile_size), terrain_tile_size, .white);
}
}
Gfx.drawSprite(self.gradient_sprite, .init(-2500, 64), .init(5000, 96), .white);
}
{

View File

@ -1711,7 +1711,7 @@ pub const ImageData = struct {
}
}
fn getPixel(self: ImageData, x: u32, y: u32) []u8 {
pub fn getPixel(self: ImageData, x: u32, y: u32) []u8 {
const pixel_index = y * self.width + x;
if (self.pixels) |pixels| {
return switch (pixels) {