Skip to content

Commit

Permalink
Changed HpMed.png image to be green (healing colors), ensure bindAnim…
Browse files Browse the repository at this point in the history
…ationToSprite always runs for slow down effects of a snake, added comments
  • Loading branch information
deckarep committed Oct 31, 2024
1 parent 0817cd9 commit ac2beb3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
Binary file modified res/drawable/HpMed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 11 additions & 5 deletions zsrc/game.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down
21 changes: 12 additions & 9 deletions zsrc/render.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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));
Expand All @@ -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.?;
Expand Down
4 changes: 2 additions & 2 deletions zsrc/res.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand Down

0 comments on commit ac2beb3

Please sign in to comment.