Add charged hits
parent
ce54c5dec3
commit
3432efe823
|
@ -0,0 +1,4 @@
|
||||||
|
plugins/recharge/recharge.so: plugins/recharge/recharge.c plugins/recharge/recharge.h plugins/game/game.h
|
||||||
|
cc -g -shared -fpic -o plugins/recharge/recharge.so plugins/recharge/recharge.c
|
||||||
|
|
||||||
|
PLUGINS := ${PLUGINS} plugins/recharge/recharge.so
|
|
@ -0,0 +1 @@
|
||||||
|
game
|
|
@ -0,0 +1,72 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "recharge.h"
|
||||||
|
#include "../game/game.h"
|
||||||
|
|
||||||
|
static double recharge_full_timer = 0.0;
|
||||||
|
static double recharge_timer = 0.0;
|
||||||
|
|
||||||
|
static const char *recharge_icon;
|
||||||
|
|
||||||
|
bool is_charged()
|
||||||
|
{
|
||||||
|
return recharge_timer <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void recharge(double timer, const char *icon)
|
||||||
|
{
|
||||||
|
recharge_full_timer = recharge_timer = timer;
|
||||||
|
recharge_icon = icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void render_recharge_meter(struct winsize ws)
|
||||||
|
{
|
||||||
|
int y = ws.ws_row - 1;
|
||||||
|
int x = ws.ws_col - 14;
|
||||||
|
|
||||||
|
if (recharge_timer <= 0.0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
double frac = (recharge_full_timer - recharge_timer) / recharge_full_timer;
|
||||||
|
|
||||||
|
printf("\e[%d;%dH", y, x);
|
||||||
|
|
||||||
|
printf("%s[", recharge_icon);
|
||||||
|
|
||||||
|
struct color color = {
|
||||||
|
(1.0 - frac) * 255,
|
||||||
|
frac * 255,
|
||||||
|
0,
|
||||||
|
};
|
||||||
|
|
||||||
|
set_color(color, true);
|
||||||
|
|
||||||
|
char bar[11];
|
||||||
|
sprintf(bar, "%9d%%", (int) (frac * 100));
|
||||||
|
|
||||||
|
int bars = frac * 10;
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
if (i == bars)
|
||||||
|
set_color(black, true);
|
||||||
|
printf("%c", bar[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
set_color(black, true);
|
||||||
|
|
||||||
|
printf("]");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void recharge_globalstep(double dtime)
|
||||||
|
{
|
||||||
|
if (recharge_timer > 0.0)
|
||||||
|
recharge_timer -= dtime;
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__ ((constructor)) static void init()
|
||||||
|
{
|
||||||
|
register_render_component(&render_recharge_meter);
|
||||||
|
register_globalstep((struct globalstep) {
|
||||||
|
.run_if_dead = false,
|
||||||
|
.callback = &recharge_globalstep,
|
||||||
|
});
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
#ifndef _RECHARGE_H_
|
||||||
|
#define _RECHARGE_H_
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
bool is_charged();
|
||||||
|
void recharge(double timer, const char *icon);
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,4 +1,4 @@
|
||||||
plugins/sword/sword.so: plugins/sword/sword.c plugins/game/game.h plugins/movement/movement.h plugins/inventory/inventory.h
|
plugins/sword/sword.so: plugins/sword/sword.c plugins/game/game.h plugins/movement/movement.h plugins/inventory/inventory.h plugins/recharge/recharge.h
|
||||||
cc -g -shared -fpic -o plugins/sword/sword.so plugins/sword/sword.c
|
cc -g -shared -fpic -o plugins/sword/sword.so plugins/sword/sword.c
|
||||||
|
|
||||||
PLUGINS := ${PLUGINS} plugins/sword/sword.so
|
PLUGINS := ${PLUGINS} plugins/sword/sword.so
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
game
|
game
|
||||||
movement
|
movement
|
||||||
inventory
|
inventory
|
||||||
|
recharge
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "../game/game.h"
|
#include "../game/game.h"
|
||||||
#include "../movement/movement.h"
|
#include "../movement/movement.h"
|
||||||
#include "../inventory/inventory.h"
|
#include "../inventory/inventory.h"
|
||||||
|
#include "../recharge/recharge.h"
|
||||||
|
|
||||||
static bool use_broken_sword(struct itemstack *stack)
|
static bool use_broken_sword(struct itemstack *stack)
|
||||||
{
|
{
|
||||||
|
@ -22,6 +23,9 @@ static struct item broken_sword = {
|
||||||
|
|
||||||
static bool use_sword(struct itemstack *stack)
|
static bool use_sword(struct itemstack *stack)
|
||||||
{
|
{
|
||||||
|
if (! is_charged())
|
||||||
|
return false;
|
||||||
|
|
||||||
int x, y;
|
int x, y;
|
||||||
x = player.x;
|
x = player.x;
|
||||||
y = player.y;
|
y = player.y;
|
||||||
|
@ -35,6 +39,8 @@ static bool use_sword(struct itemstack *stack)
|
||||||
|
|
||||||
if (rand() % 100 == 0)
|
if (rand() % 100 == 0)
|
||||||
stack->item = &broken_sword;
|
stack->item = &broken_sword;
|
||||||
|
|
||||||
|
recharge(1.0, "⚔ ");
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue