diff --git a/res/drawable/HpMed.png b/res/drawable/HpMed.png index 5f7d8af..12b3a58 100644 Binary files a/res/drawable/HpMed.png and b/res/drawable/HpMed.png differ diff --git a/zsrc/game.zig b/zsrc/game.zig index 8edaef0..d77e4e0 100644 --- a/zsrc/game.zig +++ b/zsrc/game.zig @@ -869,9 +869,15 @@ fn slowDownSnake(snake: *pl.Snake, duration: c_int) void { ); ani.lifeSpan = duration; ani.scaled = false; - if (snake.buffs[tps.BUFF_DEFENCE] > 0) { - continue; - } + // r.c. - This line prevents slow downs from tracking with the sprite when + // BUFF_DEFENCE is non-zero. I don't know why this code is like this. But + // I believe the animations should always track alongside the sprite's x,y coords. + // In other words, bindAnimationToSprite should always be ran. + + // if (snake.buffs[tps.BUFF_DEFENCE] > 0) { + // continue; + // } + ren.bindAnimationToSprite(ani, sprite, true); } } @@ -941,7 +947,7 @@ fn attackUpSnake(snake: *pl.Snake, duration: c_int) void { } } -fn takeHpMedcine(snake: *pl.Snake, delta: c_int, extra: bool) void { +fn takeHpMedicine(snake: *pl.Snake, delta: c_int, extra: bool) void { var p = snake.sprites.first; while (p) |node| : (p = node.next) { const sprite: *spr.Sprite = @alignCast(@ptrCast(node.data)); @@ -1422,7 +1428,7 @@ fn makeSnakeCross(snake: *pl.Snake) bool { itemMap[i][j].type == .ITEM_HP_EXTRA_MEDICINE) { aud.playAudio(res.AUDIO_MED); - takeHpMedcine(snake, GAME_HP_MEDICINE_DELTA, itemMap[i][j].type == .ITEM_HP_EXTRA_MEDICINE); + takeHpMedicine(snake, GAME_HP_MEDICINE_DELTA, itemMap[i][j].type == .ITEM_HP_EXTRA_MEDICINE); flasksCount -= @intFromBool(itemMap[i][j].type == .ITEM_HP_MEDICINE); tps.removeAnimationFromLinkList(&ren.animationsList[ren.RENDER_LIST_MAP_ITEMS_ID], ani); diff --git a/zsrc/render.zig b/zsrc/render.zig index b7e8fc4..af292cc 100644 --- a/zsrc/render.zig +++ b/zsrc/render.zig @@ -43,7 +43,7 @@ pub const RENDER_LIST_EFFECT_ID = 5; pub const RENDER_LIST_MAP_FOREWALL = 6; pub const RENDER_LIST_UI_ID = 7; pub const RENDER_BUFFER_SIZE = 1 << 16; -pub const RENDER_HP_BAR_HEIGHT = 2; +pub const RENDER_HP_BAR_HEIGHT = 3; pub const RENDER_HP_BAR_WIDTH = 20; pub const RENDER_COUNTDOWN_BAR_WIDTH = 300; pub const RENDER_COUNTDOWN_BAR_HEIGHT = 10; @@ -220,11 +220,12 @@ fn renderSnakeHp(snake: *pl.Snake) void { const spriteHeight: c_int = sprite.ani.origin.height * SCALE_FACTOR; const bar: c.SDL_Rect = .{ .x = sprite.x - res.UNIT / 2 + (res.UNIT - width) / 2, - .y = sprite.y - spriteHeight - RENDER_HP_BAR_HEIGHT * (@as(c_int, @intCast(i)) + 1), + .y = sprite.y - spriteHeight - RENDER_HP_BAR_HEIGHT * (@as(c_int, @intCast(i)) + 3), .w = @intFromFloat(@as(f64, @floatFromInt(width)) * @min(1.0, percent)), .h = RENDER_HP_BAR_HEIGHT, }; - _ = c.SDL_RenderDrawRect(renderer, &bar); + + _ = c.SDL_RenderFillRect(renderer, &bar); } } } @@ -381,12 +382,6 @@ pub fn clearBindInAnimationsList(sprite: *spr.Sprite, id: c_int) void { } } -pub fn bindAnimationToSprite(ani: *tps.Animation, sprite: *spr.Sprite, isStrong: bool) void { - ani.bind = sprite; - ani.dieWithBind = isStrong; - updateAnimationFromBind(ani); -} - pub fn updateAnimationFromBind(ani: *tps.Animation) void { if (ani.bind) |bnd| { const sprite: *spr.Sprite = @alignCast(@ptrCast(bnd)); @@ -396,6 +391,14 @@ pub fn updateAnimationFromBind(ani: *tps.Animation) void { } } +/// associates an animation to track and render following the sprites x,y position. If isStrong +/// is true, then the animation should be removed should the sprite need to be destroyed, ie: died. +pub fn bindAnimationToSprite(ani: *tps.Animation, sprite: *spr.Sprite, isStrong: bool) void { + ani.bind = sprite; + ani.dieWithBind = isStrong; + updateAnimationFromBind(ani); +} + pub fn renderAnimation(a: ?*tps.Animation) void { if (a == null) return; const ani = a.?; diff --git a/zsrc/res.zig b/zsrc/res.zig index 62d67ca..58b7ae1 100644 --- a/zsrc/res.zig +++ b/zsrc/res.zig @@ -489,7 +489,6 @@ fn loadTileset(path: [:0]const u8, origin: ?*c.SDL_Texture) bool { const p = &textures[texturesCount]; texturesCount += 1; tps.initTexture(p, origin.?, w, h, f); - std.log.debug("{d}). {s}", .{ count, std.mem.sliceTo(&resName, 0) }); var i: usize = 0; while (i < f) : (i += 1) { @@ -499,8 +498,9 @@ fn loadTileset(path: [:0]const u8, origin: ?*c.SDL_Texture) bool { p.crops[i].w = w; } - std.log.debug("Texture Res: {d}). ptr:{*}, x:{d}, y:{d}, w:{d}, h:{d}, f:{d}", .{ + std.log.debug("Texture Res: {d}). name: {s}, ptr:{*}, x:{d}, y:{d}, w:{d}, h:{d}, f:{d}", .{ texturesCount - 1, + std.mem.sliceTo(&resName, 0), p, x, y,