[FL-1427] Dolphin: new assets and engine rework (#546)

This commit is contained in:
its your bedtime
2021-08-05 23:49:04 +03:00
committed by GitHub
parent 5741ed2bd5
commit 9c38efd4ef
118 changed files with 1055 additions and 419 deletions

View File

@@ -1,15 +1,12 @@
#pragma once
static const char* emotes_list[] = {
"(O_o)", "(!_?)", "(^_^)", "(*__*)", "(@_@)", "(X_x)", "(>_<)", "(^ ^)", "(^_^)",
"(-_-)", "(~_~)", "(#^.^#)", "(^ ^)", "(^.^)", "(-.-)", "zZzZ", "(^_-)", "(^_-)",
"(+_+)", "(+o+)", "(' ')", "('-')", "('.')", "('_')", "(* > *)", "(o o)", "(^_^)",
"(^O^)", "(^o^)", "(^o^)", "(._.)", "(_^_)", "('_')", "('_;)", "(T_T)", "(;_;)",
"(ー_ー)", "(-.-)", "(^o^)", "(-_-)", "(=_=)", "(=^ ^=)", "(. .)", "(._.)", "( ^m^)",
"(?_?)", "(*^_^*)", "(^<^)", "(^.^)", "(^·^)", "(^.^)", "(^_^.)", "(^_^)", "(^^)",
"(^J^)", "(*^.^*)", "(#^.^#)", "(~o~)", "(^o^)", "(-o-)", "(^. ^)", "(^o^)", "(*^0^*)",
"(*_*)", "(~ o ~)", "(~_~)", "(p_-)", "d[-_-]b", "(^0_0^)", "- ^ -"};
static const char* dialogues_list[] = {
"Let's hack!\n\nbla bla bla\nbla bla..",
// temp
const char* console_emotes[] = {
"Run it, m8",
"Lets GOOOO",
"Click it, buddy",
"I wanna play",
"Wtf is this?",
"Just do it",
"JUST DO IT!",
};

View File

@@ -1,49 +1,38 @@
#include <gui/elements.h>
#include "applications.h"
#include "items_i.h"
#include "emotes.h"
#include <gui/icon_i.h>
const Item TV = {
.layer = 7,
.timeout = 10,
.x = 160,
.y = 34,
.icon = &I_TV_20x24,
.action_name = "Use",
.draw = draw_tv,
.callback = smash_tv};
const Item Painting = {
.layer = 3,
.timeout = 20,
.x = 160,
.y = 10,
.icon = &I_Home_painting_17x20,
.action_name = "Inspect",
.draw = NULL,
.callback = inspect_painting};
const Item Sofa = {
const Item Food = {
.layer = 4,
.timeout = 100,
.x = 250,
.y = 34,
.icon = &I_Sofa_40x13,
.action_name = "Sit",
.draw = NULL,
.callback = sofa_sit};
.pos =
{
.x = 0,
.y = 90,
},
.width = 60,
.height = 50,
.draw = food_redraw,
.callback = food_callback};
const Item PC = {
const Item Console = {
.layer = 4,
.timeout = 100,
.x = 400,
.y = 10,
.icon = &I_PC_22x29,
.action_name = "Use",
.draw = NULL,
.callback = pc_callback};
.pos =
{
.x = 357,
.y = 190,
},
.width = 40,
.height = 20,
.draw = console_redraw,
.callback = console_callback};
const Item* Home[ITEMS_NUM] = {&TV, &Sofa, &Painting, &PC};
const Item** Scenes[1] = {*&Home};
const Item* Home[] = {&Food, &Console};
const Item** Scenes[] = {Home};
const Item** get_scene(SceneState* state) {
return Scenes[state->scene_id];
@@ -64,6 +53,37 @@ static void dolphin_scene_start_app(SceneState* state, const FlipperApplication*
furi_thread_start(state->scene_app_thread);
}
uint16_t roll_new(uint16_t prev, uint16_t max) {
uint16_t val = 999;
while(val != prev) {
val = random() % max;
break;
}
return val;
}
static void dolphin_scene_type_text(
Canvas* canvas,
SceneState* state,
uint8_t x,
uint8_t y,
const char* text) {
char dialog_str[64];
char buf[64];
strcpy(dialog_str, (char*)text);
if(state->dialog_progress <= strlen(dialog_str)) {
if(HAL_GetTick() / 10 % 2 == 0) state->dialog_progress++;
dialog_str[state->dialog_progress] = '\0';
snprintf(buf, state->dialog_progress, dialog_str);
} else {
snprintf(buf, 64, dialog_str);
}
canvas_draw_str_aligned(canvas, x, y, AlignCenter, AlignCenter, buf);
}
const void scene_activate_item_callback(SceneState* state, Canvas* canvas) {
furi_assert(state);
furi_assert(canvas);
@@ -78,16 +98,32 @@ const void scene_activate_item_callback(SceneState* state, Canvas* canvas) {
}
}
const Vec2 item_get_pos(SceneState* state, ItemsEnum item) {
const Item** current = get_scene(state);
Vec2 rel_pos = {0, 0};
rel_pos.x = DOLPHIN_WIDTH / 2 + (current[item]->pos.x * PARALLAX(current[item]->layer));
rel_pos.y = DOLPHIN_WIDTH / 4 + (current[item]->pos.y * PARALLAX(current[item]->layer));
return rel_pos;
}
const Item* is_nearby(SceneState* state) {
furi_assert(state);
uint8_t item = 0;
bool found = false;
const Item** current = get_scene(state);
while(item < ITEMS_NUM) {
int32_t rel =
while(item < ItemsEnumTotal) {
int32_t rel_x =
(DOLPHIN_CENTER + DOLPHIN_WIDTH / 2 -
(current[item]->x - state->player_global.x) * PARALLAX(current[item]->layer));
if(abs(rel) <= DOLPHIN_WIDTH / 2) {
(current[item]->pos.x - state->player_global.x) * PARALLAX(current[item]->layer));
uint8_t item_height = current[item]->height;
uint8_t item_width = current[item]->width;
int32_t rel_y = current[item]->pos.y - state->player_global.y;
if(abs(rel_x) <= item_width && abs(rel_y) <= item_height) {
found = !found;
break;
}
@@ -96,50 +132,102 @@ const Item* is_nearby(SceneState* state) {
return found ? current[item] : NULL;
}
void draw_tv(Canvas* canvas, void* state) {
furi_assert(state);
SceneState* s = state;
canvas_set_color(canvas, ColorWhite);
canvas_draw_box(
canvas, (TV.x + 3 - s->player_global.x) * PARALLAX(TV.layer), TV.y + 4, 16, 20);
canvas_set_color(canvas, ColorBlack);
canvas_set_bitmap_mode(canvas, true);
}
void food_redraw(Canvas* canvas, void* s) {
furi_assert(s);
SceneState* state = s;
const Icon* food_frames[] = {
&I_food1_61x98,
&I_food2_61x98,
&I_food3_61x98,
&I_food4_61x98,
&I_food5_61x98,
&I_food6_61x98,
&I_food7_61x98,
&I_food8_61x98,
&I_food9_61x98,
&I_food10_61x98,
&I_food11_61x98,
&I_food12_61x98,
};
uint8_t frame = ((HAL_GetTick() / 200) % SIZEOF_ARRAY(food_frames));
if(is_nearby(state) && (state->player_global.y > Food.pos.y)) {
dolphin_scene_type_text(
canvas,
state,
(Food.pos.x - state->player_global.x) * PARALLAX(Food.layer) + 90,
state->screen.y + 8,
console_emotes[state->emote_id]);
} else {
state->dialog_progress = 0;
state->emote_id = roll_new(state->previous_emote, SIZEOF_ARRAY(console_emotes));
}
void smash_tv(Canvas* canvas, void* state) {
furi_assert(state);
SceneState* s = state;
s->player_flipped = true;
canvas_set_bitmap_mode(canvas, true);
canvas_draw_icon(
canvas, ((TV.x - 5) - s->player_global.x) * PARALLAX(TV.layer), TV.y - 2, &I_FX_Bang_32x6);
canvas_set_bitmap_mode(canvas, false);
if(s->action_timeout < TV.timeout - 2) {
elements_multiline_text_framed(canvas, 80, 24, "Bang!");
canvas,
(Food.pos.x - state->player_global.x) * PARALLAX(Food.layer),
Food.pos.y - state->player_global.y,
food_frames[frame]);
canvas_set_bitmap_mode(canvas, true);
}
void food_callback(Canvas* canvas, void* s) {
furi_assert(s);
SceneState* state = s;
if(state->use_pending) {
dolphin_scene_start_app(state, &FLIPPER_SCENE_APPS[1]);
}
}
void sofa_sit(Canvas* canvas, void* state) {
furi_assert(state);
SceneState* s = state;
// temp fix pos
s->player_global.x = 154;
s->dolphin_gfx = &A_FX_Sitting_40x27;
s->dolphin_gfx_b = &I_FX_SittingB_40x27;
}
void console_redraw(Canvas* canvas, void* s) {
furi_assert(s);
SceneState* state = s;
void inspect_painting(Canvas* canvas, void* state) {
furi_assert(state);
SceneState* s = state;
if(s->use_pending) {
dolphin_scene_start_app(s, &FLIPPER_SCENE_APPS[0]);
const Icon* console[] = {
&I_Console_74x67_0,
&I_Console_74x67_1,
&I_Console_74x67_2,
&I_Console_74x67_3,
&I_Console_74x67_4,
&I_Console_74x67_5,
&I_Console_74x67_6,
&I_Console_74x67_7,
&I_Console_74x67_8,
};
uint8_t frame = ((HAL_GetTick() / 100) % SIZEOF_ARRAY(console));
canvas_draw_icon(
canvas,
(Console.pos.x - state->player_global.x) * PARALLAX(Console.layer),
Console.pos.y - state->player_global.y,
console[frame]);
canvas_set_bitmap_mode(canvas, true);
if(is_nearby(state)) {
dolphin_scene_type_text(
canvas,
state,
(Console.pos.x - state->player_global.x) * PARALLAX(Console.layer) - 25,
Console.pos.y - state->player_global.y + 14,
console_emotes[state->emote_id]);
} else {
state->dialog_progress = 0;
state->emote_id = roll_new(state->previous_emote, SIZEOF_ARRAY(console_emotes));
}
}
void pc_callback(Canvas* canvas, void* state) {
furi_assert(state);
SceneState* s = state;
if(s->use_pending) {
dolphin_scene_start_app(s, &FLIPPER_SCENE_APPS[1]);
void console_callback(Canvas* canvas, void* s) {
furi_assert(s);
SceneState* state = s;
if(state->use_pending) {
dolphin_scene_start_app(state, &FLIPPER_SCENE_APPS[1]);
}
}

View File

@@ -1,8 +1,14 @@
#pragma once
#include "dolphin/scenes/scene.h"
#define ITEMS_NUM 4
typedef enum {
ItemsFood,
ItemsConsole,
ItemsEnumTotal,
} ItemsEnum;
uint16_t roll_new(uint16_t prev, uint16_t max);
const Vec2 item_get_pos(SceneState* state, ItemsEnum item);
const Item* is_nearby(SceneState* state);
const Item** get_scene(SceneState* state);
const void scene_activate_item_callback(SceneState* state, Canvas* canvas);

View File

@@ -1,8 +1,8 @@
#pragma once
#include "items.h"
void smash_tv(Canvas* canvas, void* state);
void draw_tv(Canvas* canvas, void* state);
void sofa_sit(Canvas* canvas, void* state);
void inspect_painting(Canvas* canvas, void* state);
void pc_callback(Canvas* canvas, void* state);
void food_redraw(Canvas* canvas, void* state);
void food_callback(Canvas* canvas, void* state);
void console_redraw(Canvas* canvas, void* state);
void console_callback(Canvas* canvas, void* state);

View File

@@ -0,0 +1,276 @@
#pragma once
#include "dolphin/scenes/scene.h"
const DolphinFrame up = {
.frames =
{
{
.f = &I_up1_73x61,
.b = &I_black_up1_73x61,
},
{
.f = &I_up2_73x61,
.b = &I_black_up2_73x61,
},
},
.total = 2,
};
const DolphinFrame up_down = {
.frames =
{
{
.f = &I_updown1_73x61,
.b = &I_black_updown1_73x61,
},
{
.f = &I_updown2_73x61,
.b = &I_black_updown2_73x61,
},
{
.f = &I_updown3_73x61,
.b = &I_black_updown3_73x61,
},
},
.total = 3,
};
const DolphinFrame up_right = {
.frames =
{
{
.f = &I_upright1_73x61,
.b = &I_black_upright1_73x61,
},
{
.f = &I_upright2_73x61,
.b = &I_black_upright2_73x61,
},
},
.total = 2,
};
const DolphinFrame up_left = {
.frames =
{
{
.f = &I_upleft1_73x61,
.b = &I_black_upleft1_73x61,
},
{
.f = &I_upleft2_73x61,
.b = &I_black_upleft2_73x61,
},
},
.total = 2,
};
const DolphinFrame right = {
.frames =
{
{
.f = &I_right1_73x61,
.b = &I_black_right1_73x61,
},
{
.f = &I_right2_73x61,
.b = &I_black_right2_73x61,
},
{
.f = &I_right3_73x61,
.b = &I_black_right3_73x61,
},
},
.total = 3,
};
const DolphinFrame right_up = {
.frames =
{
{
.f = &I_rightup1_73x61,
.b = &I_black_rightup1_73x61,
},
{
.f = &I_rightup2_73x61,
.b = &I_black_rightup2_73x61,
},
},
.total = 2,
};
const DolphinFrame right_down = {
.frames =
{
{
.f = &I_rightdown1_73x61,
.b = &I_black_rightdown1_73x61,
},
{
.f = &I_rightdown2_73x61,
.b = &I_black_rightdown2_73x61,
},
},
.total = 2,
};
const DolphinFrame right_left = {
.frames =
{
{
.f = &I_rightleft1_73x61,
.b = &I_black_rightleft1_73x61,
},
{
.f = &I_rightleft2_73x61,
.b = &I_black_rightleft2_73x61,
},
},
.total = 2,
};
const DolphinFrame down = {
.frames =
{
{
.f = &I_down1_73x61,
.b = &I_black_down1_73x61,
},
{
.f = &I_down2_73x61,
.b = &I_black_down2_73x61,
},
},
.total = 2,
};
const DolphinFrame down_up = {
.frames =
{
{
.f = &I_downup1_73x61,
.b = &I_black_downup1_73x61,
},
{
.f = &I_downup2_73x61,
.b = &I_black_downup2_73x61,
},
{
.f = &I_downup3_73x61,
.b = &I_black_downup3_73x61,
},
},
.total = 3,
};
const DolphinFrame down_left = {
.frames =
{
{
.f = &I_downleft1_73x61,
.b = &I_black_downleft1_73x61,
},
{
.f = &I_downleft2_73x61,
.b = &I_black_downleft2_73x61,
},
{
.f = &I_downleft3_73x61,
.b = &I_black_downleft3_73x61,
},
},
.total = 3,
};
const DolphinFrame down_right = {
.frames =
{
{
.f = &I_downright1_73x61,
.b = &I_black_downright1_73x61,
},
{
.f = &I_downright2_73x61,
.b = &I_black_downright2_73x61,
},
{
.f = &I_downright3_73x61,
.b = &I_black_downright3_73x61,
},
},
.total = 3,
};
const DolphinFrame left = {
.frames =
{
{
.f = &I_left1_73x61,
.b = &I_black_left1_73x61,
},
{
.f = &I_left2_73x61,
.b = &I_black_left2_73x61,
},
{
.f = &I_left3_73x61,
.b = &I_black_left3_73x61,
},
},
.total = 3,
};
const DolphinFrame left_up = {
.frames =
{
{
.f = &I_leftup1_73x61,
.b = &I_black_leftup1_73x61,
},
{
.f = &I_leftup2_73x61,
.b = &I_black_leftup2_73x61,
},
},
.total = 2,
};
const DolphinFrame left_down = {
.frames =
{
{
.f = &I_leftdown1_73x61,
.b = &I_black_leftdown1_73x61,
},
{
.f = &I_leftdown2_73x61,
.b = &I_black_leftdown2_73x61,
},
},
.total = 2,
};
const DolphinFrame left_right = {
.frames =
{
{
.f = &I_rightleft1_73x61,
.b = &I_black_rightleft1_73x61,
},
{
.f = &I_rightleft2_73x61,
.b = &I_black_rightleft2_73x61,
},
},
.total = 2,
};
const DolphinFrame* frames[4][4] = {
[DirUp] = {[DirUp] = &up, [DirRight] = &up_right, [DirDown] = &up_down, [DirLeft] = &up_left},
[DirRight] =
{[DirUp] = &right_up, [DirRight] = &right, [DirDown] = &right_down, [DirLeft] = &right_left},
[DirDown] =
{[DirUp] = &down_up, [DirRight] = &down_right, [DirDown] = &down, [DirLeft] = &down_left},
[DirLeft] =
{[DirUp] = &left_up, [DirRight] = &left_right, [DirDown] = &left_down, [DirLeft] = &left},
};