2021-04-13 18:06:25 +00:00
|
|
|
#include <furi.h>
|
2021-04-26 12:19:14 +00:00
|
|
|
#include "scene.h"
|
|
|
|
#include "assets/items.h"
|
2021-08-05 20:49:04 +00:00
|
|
|
#include "assets/meta.h"
|
2021-04-13 18:06:25 +00:00
|
|
|
#include <gui/elements.h>
|
|
|
|
|
2021-08-05 20:49:04 +00:00
|
|
|
void dolphin_scene_transition_handler(SceneState* state) {
|
|
|
|
uint8_t speed_mod = (state->player_v.x || state->player_v.y || state->transition) ? 6 : 10;
|
|
|
|
|
|
|
|
if(state->player_v.x < 0) {
|
|
|
|
state->frame_pending = DirLeft;
|
|
|
|
} else if(state->player_v.x > 0) {
|
|
|
|
state->frame_pending = DirRight;
|
|
|
|
} else if(state->player_v.y < 0) {
|
|
|
|
state->frame_pending = DirUp;
|
|
|
|
} else if(state->player_v.y > 0) {
|
|
|
|
state->frame_pending = DirDown;
|
2021-04-13 18:06:25 +00:00
|
|
|
}
|
2021-08-05 20:49:04 +00:00
|
|
|
state->transition_pending = state->frame_group != state->frame_pending;
|
2021-04-13 18:06:25 +00:00
|
|
|
|
2021-08-05 20:49:04 +00:00
|
|
|
if(*&frames[state->frame_group][state->frame_type]->frames[state->frame_idx].f) {
|
|
|
|
state->current_frame = *&frames[state->frame_group][state->frame_type];
|
2021-04-13 18:06:25 +00:00
|
|
|
}
|
|
|
|
|
2021-08-05 20:49:04 +00:00
|
|
|
uint8_t total = state->current_frame->frames[2].f == NULL ? 2 : 3;
|
2021-04-13 18:06:25 +00:00
|
|
|
|
2021-08-05 20:49:04 +00:00
|
|
|
if(state->transition_pending && !state->frame_idx) {
|
|
|
|
state->transition_pending = false;
|
|
|
|
state->transition = true;
|
2021-04-13 18:06:25 +00:00
|
|
|
}
|
|
|
|
|
2021-08-05 20:49:04 +00:00
|
|
|
if(state->transition) {
|
|
|
|
state->frame_type = state->frame_pending;
|
|
|
|
state->frame_group = state->last_group;
|
|
|
|
state->transition = !(state->frame_idx == total - 1);
|
|
|
|
} else {
|
|
|
|
state->frame_group = state->frame_type;
|
2021-04-13 18:06:25 +00:00
|
|
|
}
|
2021-05-18 18:54:56 +00:00
|
|
|
|
2021-08-05 20:49:04 +00:00
|
|
|
state->player_anim++;
|
2021-05-18 18:54:56 +00:00
|
|
|
|
2021-08-05 20:49:04 +00:00
|
|
|
if(!(state->player_anim % speed_mod)) {
|
|
|
|
state->frame_idx = (state->frame_idx + 1) % total;
|
2021-05-18 18:54:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-26 12:19:14 +00:00
|
|
|
void dolphin_scene_render_dolphin(SceneState* state, Canvas* canvas) {
|
2021-04-13 18:06:25 +00:00
|
|
|
furi_assert(state);
|
|
|
|
furi_assert(canvas);
|
|
|
|
|
2021-08-05 20:49:04 +00:00
|
|
|
dolphin_scene_transition_handler(state);
|
2021-04-26 12:19:14 +00:00
|
|
|
|
|
|
|
canvas_set_bitmap_mode(canvas, true);
|
|
|
|
canvas_set_color(canvas, ColorWhite);
|
2021-08-05 20:49:04 +00:00
|
|
|
canvas_draw_icon(
|
|
|
|
canvas, state->player.x, state->player.y, state->current_frame->frames[state->frame_idx].b);
|
2021-04-26 12:19:14 +00:00
|
|
|
canvas_set_color(canvas, ColorBlack);
|
2021-08-05 20:49:04 +00:00
|
|
|
canvas_draw_icon(
|
|
|
|
canvas, state->player.x, state->player.y, state->current_frame->frames[state->frame_idx].f);
|
2021-04-26 12:19:14 +00:00
|
|
|
canvas_set_bitmap_mode(canvas, false);
|
|
|
|
}
|
|
|
|
|
2021-08-05 20:49:04 +00:00
|
|
|
static bool item_screen_bounds_x(int32_t pos) {
|
2021-04-26 12:19:14 +00:00
|
|
|
return pos > -SCREEN_WIDTH && pos < (SCREEN_WIDTH * 2);
|
2021-04-13 18:06:25 +00:00
|
|
|
}
|
2021-08-05 20:49:04 +00:00
|
|
|
static bool item_screen_bounds_y(int32_t pos) {
|
|
|
|
return pos > -SCREEN_HEIGHT * 2 && pos < (SCREEN_HEIGHT * 2);
|
|
|
|
}
|
2021-04-13 18:06:25 +00:00
|
|
|
|
|
|
|
void dolphin_scene_render(SceneState* state, Canvas* canvas, uint32_t t) {
|
|
|
|
furi_assert(state);
|
|
|
|
furi_assert(canvas);
|
|
|
|
|
|
|
|
canvas_set_font(canvas, FontSecondary);
|
|
|
|
canvas_set_color(canvas, ColorBlack);
|
|
|
|
const Item** current_scene = get_scene(state);
|
|
|
|
|
|
|
|
for(uint8_t l = 0; l < LAYERS; l++) {
|
2021-08-05 20:49:04 +00:00
|
|
|
for(uint8_t i = 0; i < ItemsEnumTotal; i++) {
|
|
|
|
int32_t item_pos_X = (current_scene[i]->pos.x - state->player_global.x);
|
|
|
|
int32_t item_pos_Y = (current_scene[i]->pos.y - state->player_global.y);
|
|
|
|
|
|
|
|
if(item_screen_bounds_x(item_pos_X) && item_screen_bounds_y(item_pos_Y)) {
|
|
|
|
if(l == current_scene[i]->layer) {
|
|
|
|
if(current_scene[i]->draw) {
|
|
|
|
current_scene[i]->draw(canvas, state);
|
2021-04-13 18:06:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(l == DOLPHIN_LAYER) dolphin_scene_render_dolphin(state, canvas);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-26 12:19:14 +00:00
|
|
|
void dolphin_scene_render_state(SceneState* state, Canvas* canvas) {
|
2021-04-13 18:06:25 +00:00
|
|
|
furi_assert(state);
|
|
|
|
furi_assert(canvas);
|
|
|
|
|
|
|
|
char buf[64];
|
|
|
|
|
|
|
|
canvas_set_font(canvas, FontSecondary);
|
|
|
|
canvas_set_color(canvas, ColorBlack);
|
|
|
|
|
|
|
|
// dolphin_scene_debug
|
|
|
|
if(state->debug) {
|
|
|
|
sprintf(
|
|
|
|
buf,
|
2021-08-05 20:49:04 +00:00
|
|
|
"%d:%d %d/%dP%dL%d T%d-%d",
|
|
|
|
state->frame_idx,
|
|
|
|
state->current_frame->frames[2].f == NULL ? 2 : 3,
|
|
|
|
state->frame_group,
|
|
|
|
state->frame_type,
|
|
|
|
state->frame_pending,
|
|
|
|
state->last_group,
|
|
|
|
state->transition_pending,
|
|
|
|
state->transition);
|
2021-04-13 18:06:25 +00:00
|
|
|
canvas_draw_str(canvas, 0, 13, buf);
|
|
|
|
}
|
2021-08-05 20:49:04 +00:00
|
|
|
if(state->action == INTERACT) scene_activate_item_callback(state, canvas);
|
2021-04-13 18:06:25 +00:00
|
|
|
}
|