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.
It's built, no errors in VSCode, no errors with uFBT, but still crashes.
- Loading branch information
1 parent
e1fa614
commit 3cca0c7
Showing
19 changed files
with
804 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
dist/* | ||
.vscode | ||
.clang-format | ||
.editorconfig | ||
.env | ||
.ufbt |
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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
# Flipper-Zero-Laser-Tag | ||
Laser Tag game for Flipper Zero | ||
|
||
Laser Tag game for Flipper Zero. ---> Not working yet, so please help! | ||
|
||
![rocketgod_logo](https://github.com/RocketGod-git/shodanbot/assets/57732082/7929b554-0fba-4c2b-b22d-6772d23c4a18) |
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,20 @@ | ||
App( | ||
appid="laser_tag", | ||
name="Laser Tag", | ||
apptype=FlipperAppType.EXTERNAL, | ||
entry_point="laser_tag_app", | ||
cdefines=["APP_LASER_TAG"], | ||
fap_category="Games", | ||
fap_author="@RocketGod-git", | ||
fap_version="0.1", | ||
fap_description="Laser Tag game for Flipper Zero", | ||
fap_icon="icons/laser_tag_10px.png", | ||
fap_libs=["assets"], | ||
fap_weburl="https://github.com/RocketGod-Git/Flipper-Zero-Laser-Tag", | ||
requires=[ | ||
"gui", | ||
"infrared", | ||
], | ||
stack_size=2 * 1024, | ||
order=10, | ||
) |
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,3 @@ | ||
## v1.0 | ||
|
||
- Initial release. |
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,3 @@ | ||
# Flipper Zero - Laser Tag | ||
|
||
Not working, yet. |
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,99 @@ | ||
#include "game_state.h" | ||
#include <furi.h> | ||
|
||
struct GameState { | ||
LaserTagTeam team; | ||
uint8_t health; | ||
uint16_t score; | ||
uint16_t ammo; | ||
uint32_t game_time; | ||
bool game_over; | ||
}; | ||
|
||
GameState* game_state_alloc() { | ||
GameState* state = malloc(sizeof(GameState)); | ||
state->team = TeamRed; | ||
state->health = 100; | ||
state->score = 0; | ||
state->ammo = 100; | ||
state->game_time = 0; | ||
state->game_over = false; | ||
return state; | ||
} | ||
|
||
void game_state_free(GameState* state) { | ||
free(state); | ||
} | ||
|
||
void game_state_reset(GameState* state) { | ||
state->health = 100; | ||
state->score = 0; | ||
state->ammo = 100; | ||
state->game_time = 0; | ||
state->game_over = false; | ||
} | ||
|
||
void game_state_set_team(GameState* state, LaserTagTeam team) { | ||
state->team = team; | ||
} | ||
|
||
LaserTagTeam game_state_get_team(GameState* state) { | ||
return state->team; | ||
} | ||
|
||
void game_state_decrease_health(GameState* state, uint8_t amount) { | ||
if(state->health > amount) { | ||
state->health -= amount; | ||
} else { | ||
state->health = 0; | ||
state->game_over = true; | ||
} | ||
} | ||
|
||
void game_state_increase_health(GameState* state, uint8_t amount) { | ||
state->health = (state->health + amount > 100) ? 100 : state->health + amount; | ||
} | ||
|
||
uint8_t game_state_get_health(GameState* state) { | ||
return state->health; | ||
} | ||
|
||
void game_state_increase_score(GameState* state, uint16_t points) { | ||
state->score += points; | ||
} | ||
|
||
uint16_t game_state_get_score(GameState* state) { | ||
return state->score; | ||
} | ||
|
||
void game_state_decrease_ammo(GameState* state, uint16_t amount) { | ||
if(state->ammo > amount) { | ||
state->ammo -= amount; | ||
} else { | ||
state->ammo = 0; | ||
} | ||
} | ||
|
||
void game_state_increase_ammo(GameState* state, uint16_t amount) { | ||
state->ammo += amount; | ||
} | ||
|
||
uint16_t game_state_get_ammo(GameState* state) { | ||
return state->ammo; | ||
} | ||
|
||
void game_state_update_time(GameState* state, uint32_t delta_time) { | ||
state->game_time += delta_time; | ||
} | ||
|
||
uint32_t game_state_get_time(GameState* state) { | ||
return state->game_time; | ||
} | ||
|
||
bool game_state_is_game_over(GameState* state) { | ||
return state->game_over; | ||
} | ||
|
||
void game_state_set_game_over(GameState* state, bool game_over) { | ||
state->game_over = game_over; | ||
} |
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 @@ | ||
#pragma once | ||
|
||
#include <stdint.h> | ||
#include <stdbool.h> | ||
|
||
typedef enum { | ||
TeamRed, | ||
TeamBlue | ||
} LaserTagTeam; | ||
|
||
typedef enum { | ||
LaserTagStateTeamSelect, | ||
LaserTagStateGame, | ||
} LaserTagState; | ||
|
||
typedef struct GameState GameState; | ||
|
||
GameState* game_state_alloc(); | ||
void game_state_free(GameState* state); | ||
void game_state_reset(GameState* state); | ||
|
||
void game_state_set_team(GameState* state, LaserTagTeam team); | ||
LaserTagTeam game_state_get_team(GameState* state); | ||
|
||
void game_state_decrease_health(GameState* state, uint8_t amount); | ||
void game_state_increase_health(GameState* state, uint8_t amount); | ||
uint8_t game_state_get_health(GameState* state); | ||
|
||
void game_state_increase_score(GameState* state, uint16_t points); | ||
uint16_t game_state_get_score(GameState* state); | ||
|
||
void game_state_decrease_ammo(GameState* state, uint16_t amount); | ||
void game_state_increase_ammo(GameState* state, uint16_t amount); | ||
uint16_t game_state_get_ammo(GameState* state); | ||
|
||
void game_state_update_time(GameState* state, uint32_t delta_time); | ||
uint32_t game_state_get_time(GameState* state); | ||
|
||
bool game_state_is_game_over(GameState* state); | ||
void game_state_set_game_over(GameState* state, bool game_over); | ||
|
||
#define INITIAL_HEALTH 100 | ||
#define INITIAL_AMMO 100 | ||
#define MAX_HEALTH 100 |
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,112 @@ | ||
#include "infrared_controller.h" | ||
#include <furi.h> | ||
#include <furi_hal.h> | ||
#include <infrared.h> | ||
#include <infrared_worker.h> | ||
#include <stdlib.h> | ||
|
||
#define TAG "LaserTagInfrared" | ||
|
||
#define IR_COMMAND_RED_TEAM 0xA1 | ||
#define IR_COMMAND_BLUE_TEAM 0xB2 | ||
|
||
struct InfraredController { | ||
LaserTagTeam team; | ||
InfraredWorker* worker; | ||
FuriThread* rx_thread; | ||
volatile bool rx_running; | ||
volatile bool hit_received; | ||
}; | ||
|
||
static void infrared_rx_callback(void* context, InfraredWorkerSignal* received_signal) { | ||
InfraredController* controller = (InfraredController*)context; | ||
|
||
const InfraredMessage* message = infrared_worker_get_decoded_signal(received_signal); | ||
if (message != NULL) { | ||
uint32_t received_command = message->address; | ||
if((controller->team == TeamRed && received_command == IR_COMMAND_BLUE_TEAM) || | ||
(controller->team == TeamBlue && received_command == IR_COMMAND_RED_TEAM)) { | ||
controller->hit_received = true; | ||
} | ||
} | ||
} | ||
|
||
static int32_t infrared_rx_thread(void* context) { | ||
InfraredController* controller = (InfraredController*)context; | ||
|
||
while(controller->rx_running) { | ||
infrared_worker_rx_start(controller->worker); | ||
furi_thread_flags_wait(0, FuriFlagWaitAny, 10); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
InfraredController* infrared_controller_alloc() { | ||
InfraredController* controller = malloc(sizeof(InfraredController)); | ||
controller->team = TeamRed; | ||
controller->worker = infrared_worker_alloc(); | ||
controller->rx_running = true; | ||
controller->hit_received = false; | ||
|
||
infrared_worker_rx_set_received_signal_callback(controller->worker, infrared_rx_callback, controller); | ||
|
||
controller->rx_thread = furi_thread_alloc(); | ||
furi_thread_set_name(controller->rx_thread, "IR_Rx_Thread"); | ||
furi_thread_set_stack_size(controller->rx_thread, 1024); | ||
furi_thread_set_context(controller->rx_thread, controller); | ||
furi_thread_set_callback(controller->rx_thread, infrared_rx_thread); | ||
furi_thread_start(controller->rx_thread); | ||
|
||
infrared_worker_rx_start(controller->worker); | ||
|
||
return controller; | ||
} | ||
|
||
void infrared_controller_free(InfraredController* controller) { | ||
furi_assert(controller); | ||
|
||
controller->rx_running = false; | ||
furi_thread_join(controller->rx_thread); | ||
furi_thread_free(controller->rx_thread); | ||
|
||
infrared_worker_rx_stop(controller->worker); | ||
infrared_worker_free(controller->worker); | ||
free(controller); | ||
} | ||
|
||
void infrared_controller_set_team(InfraredController* controller, LaserTagTeam team) { | ||
furi_assert(controller); | ||
controller->team = team; | ||
} | ||
|
||
void infrared_controller_send(InfraredController* controller) { | ||
furi_assert(controller); | ||
uint32_t command = (controller->team == TeamRed) ? IR_COMMAND_RED_TEAM : IR_COMMAND_BLUE_TEAM; | ||
InfraredMessage message = { | ||
.protocol = InfraredProtocolNEC, | ||
.address = 0x00, | ||
.command = command, | ||
.repeat = false | ||
}; | ||
|
||
infrared_worker_set_decoded_signal(controller->worker, &message); | ||
|
||
infrared_worker_tx_set_get_signal_callback( | ||
controller->worker, | ||
infrared_worker_tx_get_signal_steady_callback, | ||
NULL); | ||
|
||
infrared_worker_tx_start(controller->worker); | ||
|
||
furi_delay_ms(250); // Delay to ensure the signal is sent | ||
|
||
infrared_worker_tx_stop(controller->worker); | ||
} | ||
|
||
bool infrared_controller_receive(InfraredController* controller) { | ||
furi_assert(controller); | ||
bool hit = controller->hit_received; | ||
controller->hit_received = false; | ||
return hit; | ||
} |
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,42 @@ | ||
#pragma once | ||
|
||
#include <stdbool.h> | ||
#include "game_state.h" // For LaserTagTeam enum | ||
|
||
typedef struct InfraredController InfraredController; | ||
|
||
/** | ||
* Allocate and initialize an InfraredController. | ||
* @return Pointer to the newly allocated InfraredController. | ||
*/ | ||
InfraredController* infrared_controller_alloc(); | ||
|
||
/** | ||
* Free an InfraredController and its resources. | ||
* @param controller Pointer to the InfraredController to free. | ||
*/ | ||
void infrared_controller_free(InfraredController* controller); | ||
|
||
/** | ||
* Set the team for the InfraredController. | ||
* @param controller Pointer to the InfraredController. | ||
* @param team The team to set (TeamRed or TeamBlue). | ||
*/ | ||
void infrared_controller_set_team(InfraredController* controller, LaserTagTeam team); | ||
|
||
/** | ||
* Send an infrared signal corresponding to the controller's team. | ||
* @param controller Pointer to the InfraredController. | ||
*/ | ||
void infrared_controller_send(InfraredController* controller); | ||
|
||
/** | ||
* Check if a hit has been received from the opposite team. | ||
* @param controller Pointer to the InfraredController. | ||
* @return true if a hit was received, false otherwise. | ||
*/ | ||
bool infrared_controller_receive(InfraredController* controller); | ||
|
||
// IR command definitions | ||
#define IR_COMMAND_RED_TEAM 0xA1 | ||
#define IR_COMMAND_BLUE_TEAM 0xB2 |
Oops, something went wrong.