forked from flipperdevices/flipperzero-firmware
-
-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
1,266 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 @@ | ||
dist/ | ||
.vscode/ | ||
.clang-format | ||
.editorconfig | ||
.env | ||
.ufbt |
Large diffs are not rendered by default.
Oops, something went wrong.
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,44 @@ | ||
# Paper Plane | ||
|
||
Port of [this game](https://ticalc.org/archives/files/fileinfo/341/34139.html) to the Flipper Zero. | ||
|
||
## Gameplay | ||
|
||
![plane flying down](./img/gameplay2.png) | ||
|
||
Your goal is to fly a paper plane through obstacles and get to the bottom of the map. | ||
|
||
Your score is dictated by how far down the level you get. | ||
|
||
![plane flying left](./img/gameplay1.png) | ||
|
||
## Building | ||
|
||
This game can be built with the [ufbt](https://github.com/flipperdevices/flipperzero-ufbt) toolkit. | ||
|
||
Install: | ||
|
||
```bash | ||
python3 -m pip install --upgrade ufbt | ||
``` | ||
|
||
Build: | ||
|
||
```bash | ||
ufbt update # update ufbt to the latest version | ||
ufbt # builds the application | ||
``` | ||
|
||
Run: | ||
|
||
```bash | ||
ufbt launch # be sure your flipper is plugged in and detected | ||
``` | ||
|
||
## Credits | ||
|
||
This game is a port of [Paper Plane](https://ticalc.org/archives/files/fileinfo/341/34139.html) from the TI-83+/84+ series of graphing calculators, which itself is a port of a minigame from Wario Ware Inc. on the GBA. | ||
|
||
The art and map are direct conversions from the calculator version. | ||
|
||
Most of the Flipper Zero specific code comes from [this project](https://github.com/Rrycbarm/t-rex-runner), which was a huge help in figuring how things work. |
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,17 @@ | ||
App( | ||
appid="paper_plane", | ||
name="Paper Plane", | ||
apptype=FlipperAppType.EXTERNAL, | ||
entry_point="paperplane_app", | ||
cdefines=["APP_PAPERPLANE"], | ||
requires=["gui"], | ||
stack_size=8 * 1024, | ||
fap_category="Games", | ||
fap_icon="paperplane_icon.png", | ||
fap_icon_assets="assets", | ||
order=36, | ||
fap_author="@Larry-the-Pig", | ||
fap_weburl="https://github.com/Larry-the-Pig/flipper-plane", | ||
fap_version="1.3", | ||
fap_description="Guide a paper plane through obstacles to get the highest score.", | ||
) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,52 @@ | ||
#include <furi.h> | ||
#include <stdlib.h> | ||
#include "game_state.h" | ||
#include "paper.h" | ||
#include "map.h" | ||
|
||
void game_state_init(GameState* const game_state) { | ||
game_state->last_tick = furi_get_tick(); | ||
game_state->crash_flag = 0; | ||
game_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal); | ||
|
||
Paper* paper = malloc(sizeof(Paper)); | ||
paper_init(paper); | ||
|
||
uint16_t* map = malloc(sizeof(uint16_t) * MAP_HEIGHT); | ||
init_map(map); | ||
|
||
game_state->paper = paper; | ||
game_state->map = map; | ||
} | ||
|
||
void game_state_reinit(GameState* const game_state) { | ||
game_state->last_tick = furi_get_tick(); | ||
game_state->crash_flag = 0; | ||
|
||
paper_init(game_state->paper); | ||
} | ||
|
||
void check_collision(GameState* const game_state) { | ||
/* | ||
to make collision detection easier, | ||
convert the u_int16_t to an array of | ||
u_int8_t's | ||
*/ | ||
u_int8_t currentRow[sizeof(uint16_t) * 8]; | ||
u_int16_t mapCopy = game_state->map[(int)game_state->paper->y + 3]; | ||
for(unsigned int j = 0; j < sizeof(uint16_t) * 8; j++) { | ||
if(mapCopy & 0x8000) { | ||
currentRow[j] = 1; | ||
} else { | ||
currentRow[j] = 0; | ||
} | ||
|
||
mapCopy <<= 1; | ||
} | ||
|
||
// TODO: this collision code barely works, needs a refactor | ||
if(currentRow[(unsigned int)(game_state->paper->x + 0.375)] || | ||
currentRow[(unsigned int)(game_state->paper->x + 0.625)]) { | ||
game_state->crash_flag = 1; | ||
} | ||
} |
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,25 @@ | ||
#ifndef GAME_STATE_H | ||
#define GAME_STATE_H | ||
|
||
#include <furi.h> | ||
#include <stdlib.h> | ||
#include "game_state.h" | ||
#include "paper.h" | ||
#include "map.h" | ||
|
||
typedef struct GameState { | ||
Paper* paper; | ||
FuriTimer* timer; | ||
uint32_t last_tick; | ||
FuriMutex* mutex; | ||
uint16_t* map; | ||
int crash_flag; | ||
} GameState; | ||
|
||
void game_state_init(GameState* const game_state); | ||
|
||
void game_state_reinit(GameState* const game_state); | ||
|
||
void check_collision(GameState* const game_state); | ||
|
||
#endif |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,131 @@ | ||
#include <stdint.h> | ||
#include "map.h" | ||
|
||
void init_map(uint16_t* map) { | ||
/* | ||
this is all the map data same as | ||
the map from https://ticalc.org/archives/files/fileinfo/341/34139.html | ||
1: 8x8 tile exists on an 8x8 grid | ||
0: no 8x8 tile | ||
*/ | ||
|
||
map[0] = 0b1111111001111111; | ||
map[1] = 0b1111110000111111; | ||
map[2] = 0b1111000000001111; | ||
map[3] = 0b0000000000000000; | ||
map[4] = 0b0000000000000000; | ||
map[5] = 0b0000000000011111; | ||
map[6] = 0b0000000000000000; | ||
map[7] = 0b0000000000000000; | ||
map[8] = 0b1111111100000000; | ||
map[9] = 0b0000000000000000; | ||
map[10] = 0b0000000000000000; | ||
map[11] = 0b0000000000000000; | ||
map[12] = 0b1111000000111111; | ||
map[13] = 0b0000000000000000; | ||
map[14] = 0b0000000000000000; | ||
map[15] = 0b0000000011110000; | ||
map[16] = 0b0000000000000000; | ||
map[17] = 0b0000000000110000; | ||
map[18] = 0b0000000000000000; | ||
map[19] = 0b0000000000000000; | ||
map[20] = 0b1111111110000000; | ||
map[21] = 0b0000000000000111; | ||
map[22] = 0b1111000000000000; | ||
map[23] = 0b0000000000000000; | ||
map[24] = 0b0000000000000000; | ||
map[25] = 0b0000000000000000; | ||
map[26] = 0b0000000011110000; | ||
map[27] = 0b0000000000000000; | ||
map[28] = 0b0000000000110000; | ||
map[29] = 0b0000000000000000; | ||
map[30] = 0b1111110000000111; | ||
map[31] = 0b0000000000000000; | ||
map[32] = 0b0000000011111111; | ||
map[33] = 0b0000000000000000; | ||
map[34] = 0b0000000000000000; | ||
map[35] = 0b0000000111110000; | ||
map[36] = 0b0000000000000000; | ||
map[37] = 0b0000000000000000; | ||
map[38] = 0b0000000011000000; | ||
map[39] = 0b1110000000000111; | ||
map[40] = 0b1110000000000111; | ||
map[41] = 0b0000000000000000; | ||
map[42] = 0b1111111111000000; | ||
map[43] = 0b0000000000000000; | ||
map[44] = 0b1111100000000000; | ||
map[45] = 0b0000000000111111; | ||
map[46] = 0b0000000000000000; | ||
map[47] = 0b0000001111110000; | ||
map[48] = 0b0000000000000000; | ||
map[49] = 0b0000000000000000; | ||
map[50] = 0b0000000000000000; | ||
map[51] = 0b0000000000000000; | ||
map[52] = 0b0001111100001111; | ||
map[53] = 0b0000000000000000; | ||
map[54] = 0b0000000000000000; | ||
map[55] = 0b0000001111110000; | ||
map[56] = 0b0000000000000000; | ||
map[57] = 0b0000000000000000; | ||
map[58] = 0b1111110000000000; | ||
map[59] = 0b0000000000001111; | ||
map[60] = 0b0000000000000000; | ||
map[61] = 0b0000011110000000; | ||
map[62] = 0b0000000000000000; | ||
map[63] = 0b0000000001110000; | ||
map[64] = 0b0000000000000000; | ||
map[65] = 0b0000111111000000; | ||
map[66] = 0b0000000000000000; | ||
map[67] = 0b0000000001111111; | ||
map[68] = 0b0000000000000000; | ||
map[69] = 0b0000011000000000; | ||
map[70] = 0b0000000000000000; | ||
map[71] = 0b0000001111000000; | ||
map[72] = 0b0000000000000000; | ||
map[73] = 0b0000000000110000; | ||
map[74] = 0b0000111100000000; | ||
map[75] = 0b0000000000000000; | ||
map[76] = 0b0001100000111111; | ||
map[77] = 0b0000000000000000; | ||
map[78] = 0b0000000000000000; | ||
map[79] = 0b1111111111000000; | ||
map[80] = 0b0000000000000000; | ||
map[81] = 0b0000000011110000; | ||
map[82] = 0b0000000000000000; | ||
map[83] = 0b0001111001100000; | ||
map[84] = 0b0000000000000000; | ||
map[85] = 0b0000000000000000; | ||
map[86] = 0b0000110011000111; | ||
map[87] = 0b0000000000011111; | ||
map[88] = 0b0000000000000000; | ||
map[89] = 0b1111000000001111; | ||
map[90] = 0b0000000001100000; | ||
map[91] = 0b1111000000000000; | ||
map[92] = 0b0000000110000000; | ||
map[93] = 0b0000110000110000; | ||
map[94] = 0b0000000000000000; | ||
map[95] = 0b0000011111110000; | ||
map[96] = 0b0000000000000000; | ||
map[97] = 0b0000111000000000; | ||
map[98] = 0b0000000001110000; | ||
map[99] = 0b1111000000000111; | ||
map[100] = 0b0000000000000000; | ||
map[101] = 0b0000001110110000; | ||
map[102] = 0b1110000000000111; | ||
map[103] = 0b0000011110000000; | ||
map[104] = 0b0000000000111111; | ||
map[105] = 0b0001110000000000; | ||
map[106] = 0b0000000001100000; | ||
map[107] = 0b0000011111110000; | ||
map[108] = 0b0000000000000000; | ||
map[109] = 0b0001100000011111; | ||
map[110] = 0b0000000000000000; | ||
map[111] = 0b1111111110000000; | ||
map[112] = 0b0000000000001111; | ||
map[113] = 0b0000000001110000; | ||
map[114] = 0b1111110000000000; | ||
map[115] = 0b0000000000000000; | ||
map[116] = 0b1111000000000111; | ||
map[117] = 0b1111111100111111; | ||
map[118] = 0b0001111111111000; | ||
} |
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,10 @@ | ||
#ifndef MAP_H | ||
#define MAP_H | ||
#include <stdint.h> | ||
|
||
#define MAP_WIDTH 16 | ||
#define MAP_HEIGHT 119 | ||
|
||
void init_map(uint16_t* map); | ||
|
||
#endif |
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,60 @@ | ||
#include "paper.h" | ||
#include "paper_plane_icons.h" | ||
|
||
void update_sprite_rotation(Paper* dest) { | ||
switch(dest->rotation) { | ||
case -3: | ||
dest->icon = &I_PaperLeft3; | ||
break; | ||
case -2: | ||
dest->icon = &I_PaperLeft2; | ||
break; | ||
case -1: | ||
dest->icon = &I_PaperLeft1; | ||
break; | ||
case 0: | ||
dest->icon = &I_PaperDown; | ||
break; | ||
case 1: | ||
dest->icon = &I_PaperRight1; | ||
break; | ||
case 2: | ||
dest->icon = &I_PaperRight2; | ||
break; | ||
case 3: | ||
dest->icon = &I_PaperRight3; | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
} | ||
|
||
void rotate_left(Paper* dest) { | ||
if(dest->rotation > PAPER_MIN_ROTATION) dest->rotation--; | ||
|
||
update_sprite_rotation(dest); | ||
} | ||
|
||
void rotate_right(Paper* dest) { | ||
if(dest->rotation < PAPER_MAX_ROTATION) dest->rotation++; | ||
|
||
update_sprite_rotation(dest); | ||
} | ||
|
||
void paper_init(Paper* dest) { | ||
dest->x = PAPER_START_X; | ||
dest->rotation = 0; | ||
dest->y = 0; | ||
|
||
update_sprite_rotation(dest); | ||
} | ||
|
||
int get_gravity_from_rotation(int rotation) { | ||
return -abs(rotation) + BASE_GRAVITY; | ||
} | ||
|
||
void update_position(Paper* dest, int delta_time_ms) { | ||
dest->x += (float)dest->rotation * ROTATION_MULTIPLIER * delta_time_ms / 1000; | ||
dest->y += (float)get_gravity_from_rotation(dest->rotation) * delta_time_ms / 1000; | ||
} |
Oops, something went wrong.