-
-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Actual game implementation added as a submodule from https://github.com/100askTeam/lv_lib_100ask.
- Loading branch information
Showing
8 changed files
with
580 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FILE(GLOB app_sources *.c) | ||
target_sources(app PRIVATE ${app_sources}) | ||
set(LV_USE_100ASK_2048 "1") | ||
target_include_directories(app PRIVATE 2048_lib/src/lv_100ask_2048) | ||
target_sources(app PRIVATE 2048_lib/src/lv_100ask_2048/lv_100ask_2048.c) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <2048/game_2048_ui.h> | ||
#include <application_manager.h> | ||
#include <zephyr/kernel.h> | ||
#include <zephyr/init.h> | ||
#include <lv_100ask_2048.h> | ||
|
||
// Functions needed for all applications | ||
static void game_2048_app_start(lv_obj_t *root, lv_group_t *group); | ||
static void game_2048_app_stop(void); | ||
|
||
LV_IMG_DECLARE(icon_2048); | ||
|
||
static application_t app = { | ||
.name = "2048", | ||
.icon = &icon_2048, | ||
.start_func = game_2048_app_start, | ||
.stop_func = game_2048_app_stop | ||
}; | ||
|
||
static void game_2048_app_start(lv_obj_t *root, lv_group_t *group) | ||
{ | ||
game_2048_ui_show(root); | ||
} | ||
|
||
static void game_2048_app_stop(void) | ||
{ | ||
game_2048_ui_remove(); | ||
} | ||
|
||
static int game_2048_app_add(const struct device *arg) | ||
{ | ||
application_manager_add_application(&app); | ||
|
||
return 0; | ||
} | ||
|
||
SYS_INIT(game_2048_app_add, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include <2048/game_2048_ui.h> | ||
#include <lvgl.h> | ||
#include <lv_100ask_2048.h> | ||
|
||
static void game_2048_event_cb(lv_event_t * e); | ||
|
||
static lv_obj_t *root_page = NULL; | ||
|
||
void game_2048_ui_show(lv_obj_t *root) | ||
{ | ||
assert(root_page == NULL); | ||
lv_obj_t* obj_2048; | ||
|
||
// Create the root container | ||
root_page = lv_obj_create(root); | ||
// Remove the default border | ||
lv_obj_set_style_border_width(root_page, 0, LV_PART_MAIN); | ||
// Make root container fill the screen | ||
lv_obj_set_size(root_page, LV_PCT(100), LV_PCT(100)); | ||
// Don't want it to be scollable. Putting anything close the edges | ||
// then LVGL automatically makes the page scrollable and shows a scroll bar. | ||
// Does not look very good on the round display. | ||
lv_obj_set_scrollbar_mode(root_page, LV_SCROLLBAR_MODE_OFF); | ||
|
||
lv_obj_set_style_bg_color(root_page, lv_color_hex(0xb3a397), LV_PART_MAIN); // Match 2048 game background color | ||
|
||
obj_2048 = lv_100ask_2048_create(root_page); | ||
lv_obj_set_size(obj_2048, 200, 200); | ||
lv_obj_center(obj_2048); | ||
lv_obj_set_style_outline_width(obj_2048, 0, LV_STATE_FOCUS_KEY | LV_STATE_DEFAULT); | ||
|
||
// Score | ||
lv_obj_t * label = lv_label_create(root_page); | ||
lv_label_set_recolor(label, true); | ||
lv_label_set_text_fmt(label, "#ff00ff %d #", lv_100ask_2048_get_score(obj_2048)); | ||
lv_obj_align_to(label, obj_2048, LV_ALIGN_OUT_TOP_MID, -20, 0); | ||
lv_obj_add_event_cb(obj_2048, game_2048_event_cb, LV_EVENT_ALL, label); | ||
} | ||
|
||
void game_2048_ui_remove(void) | ||
{ | ||
lv_obj_del(root_page); | ||
root_page = NULL; | ||
} | ||
|
||
static void game_2048_event_cb(lv_event_t * e) | ||
{ | ||
lv_event_code_t code = lv_event_get_code(e); | ||
lv_obj_t * obj_2048 = lv_event_get_target(e); | ||
lv_obj_t * label = lv_event_get_user_data(e); | ||
|
||
if (code == LV_EVENT_VALUE_CHANGED) { | ||
if (lv_100ask_2048_get_best_tile(obj_2048) >= 2048) { | ||
lv_label_set_text(label, "#00b329 YOU WIN! #"); | ||
} else if(lv_100ask_2048_get_status(obj_2048)) { | ||
lv_label_set_text(label, "#ff0000 GAME OVER! #"); | ||
} else { | ||
lv_label_set_text_fmt(label, "#ff00ff %d #", lv_100ask_2048_get_score(obj_2048)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#pragma once | ||
|
||
#include <inttypes.h> | ||
#include <lvgl.h> | ||
|
||
void game_2048_ui_show(lv_obj_t *root); | ||
|
||
void game_2048_ui_remove(void); |
Oops, something went wrong.