commeownder/main/menu_life.c

82 lines
2.2 KiB
C

#include "menu_life.h"
#include "menus.h"
#include "config.h"
#include "state.h"
#include "draw.h"
#include "game.h"
#include "ble.h"
#include "events.h"
static const uint8_t s_icon_life[2][ICON_W] = {
// Heart (life)
{0x00,0x70,0xF8,0xFC,0xFC,0xFC,0xF8,0xF0,0xF0,0xF8,0xFC,0xFC,0xFC,0xF8,0x70,0x00},
{0x00,0x00,0x00,0x01,0x03,0x07,0x0F,0x3F,0x3F,0x0F,0x07,0x03,0x01,0x00,0x00,0x00},
};
static void life_nav_short(int d)
{
int nc = g_ble_enabled ? 0 : g_num_opponents;
if (g_ble_enabled)
for (int i = 0; i < MAX_BLE_PEERS; i++)
if (g_peers[i].active) nc++;
int total = 3 + nc;
g_life_select = (g_life_select + d + total) % total;
}
static void life_lr_delta(int d)
{
if (g_life_select == 0) {
g_life += d;
g_life_delta += d;
restart_life_delta_timer();
check_elimination();
} else if (g_life_select == 1) {
g_counters[COUNTER_STORM] += d;
if (g_counters[COUNTER_STORM] < 0) g_counters[COUNTER_STORM] = 0;
} else if (g_life_select == 2) {
g_counters[COUNTER_POISON] += d;
if (g_counters[COUNTER_POISON] < 0) g_counters[COUNTER_POISON] = 0;
check_elimination();
} else {
int si = g_life_select - 3;
if (g_ble_enabled) {
int found = 0;
for (int i = 0; i < MAX_BLE_PEERS; i++) {
if (g_peers[i].active && found++ == si) {
g_cmdr_damage[i] += d;
if (g_cmdr_damage[i] < 0) g_cmdr_damage[i] = 0;
check_elimination();
break;
}
}
} else if (si < g_num_opponents) {
g_cmdr_damage[si] += d;
if (g_cmdr_damage[si] < 0) g_cmdr_damage[si] = 0;
check_elimination();
}
}
mark_dirty();
}
static void life_draw(void)
{
oled_draw_life();
}
static void life_on_tick(const app_event_t *evt)
{
(void)evt;
if (g_life_delta != 0) {
g_life_delta = 0;
if (g_active_menu == MENU_LIFE) oled_draw_life();
}
}
const menu_vtable_t menu_life_vtable = {
.nav_short = life_nav_short,
.lr_delta = life_lr_delta,
.draw = life_draw,
.on_tick = life_on_tick,
.icon = s_icon_life,
};