Skip to content

Commit 3cca0c7

Browse files
committed
Make the Laser Tag game.
It's built, no errors in VSCode, no errors with uFBT, but still crashes.
1 parent e1fa614 commit 3cca0c7

19 files changed

+804
-1
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
dist/*
2+
.vscode
3+
.clang-format
4+
.editorconfig
5+
.env
6+
.ufbt

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# Flipper-Zero-Laser-Tag
2-
Laser Tag game for Flipper Zero
2+
3+
Laser Tag game for Flipper Zero. ---> Not working yet, so please help!
4+
5+
![rocketgod_logo](https://github.com/RocketGod-git/shodanbot/assets/57732082/7929b554-0fba-4c2b-b22d-6772d23c4a18)

application.fam

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
App(
2+
appid="laser_tag",
3+
name="Laser Tag",
4+
apptype=FlipperAppType.EXTERNAL,
5+
entry_point="laser_tag_app",
6+
cdefines=["APP_LASER_TAG"],
7+
fap_category="Games",
8+
fap_author="@RocketGod-git",
9+
fap_version="0.1",
10+
fap_description="Laser Tag game for Flipper Zero",
11+
fap_icon="icons/laser_tag_10px.png",
12+
fap_libs=["assets"],
13+
fap_weburl="https://github.com/RocketGod-Git/Flipper-Zero-Laser-Tag",
14+
requires=[
15+
"gui",
16+
"infrared",
17+
],
18+
stack_size=2 * 1024,
19+
order=10,
20+
)

docs/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## v1.0
2+
3+
- Initial release.

docs/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Flipper Zero - Laser Tag
2+
3+
Not working, yet.

game_state.c

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#include "game_state.h"
2+
#include <furi.h>
3+
4+
struct GameState {
5+
LaserTagTeam team;
6+
uint8_t health;
7+
uint16_t score;
8+
uint16_t ammo;
9+
uint32_t game_time;
10+
bool game_over;
11+
};
12+
13+
GameState* game_state_alloc() {
14+
GameState* state = malloc(sizeof(GameState));
15+
state->team = TeamRed;
16+
state->health = 100;
17+
state->score = 0;
18+
state->ammo = 100;
19+
state->game_time = 0;
20+
state->game_over = false;
21+
return state;
22+
}
23+
24+
void game_state_free(GameState* state) {
25+
free(state);
26+
}
27+
28+
void game_state_reset(GameState* state) {
29+
state->health = 100;
30+
state->score = 0;
31+
state->ammo = 100;
32+
state->game_time = 0;
33+
state->game_over = false;
34+
}
35+
36+
void game_state_set_team(GameState* state, LaserTagTeam team) {
37+
state->team = team;
38+
}
39+
40+
LaserTagTeam game_state_get_team(GameState* state) {
41+
return state->team;
42+
}
43+
44+
void game_state_decrease_health(GameState* state, uint8_t amount) {
45+
if(state->health > amount) {
46+
state->health -= amount;
47+
} else {
48+
state->health = 0;
49+
state->game_over = true;
50+
}
51+
}
52+
53+
void game_state_increase_health(GameState* state, uint8_t amount) {
54+
state->health = (state->health + amount > 100) ? 100 : state->health + amount;
55+
}
56+
57+
uint8_t game_state_get_health(GameState* state) {
58+
return state->health;
59+
}
60+
61+
void game_state_increase_score(GameState* state, uint16_t points) {
62+
state->score += points;
63+
}
64+
65+
uint16_t game_state_get_score(GameState* state) {
66+
return state->score;
67+
}
68+
69+
void game_state_decrease_ammo(GameState* state, uint16_t amount) {
70+
if(state->ammo > amount) {
71+
state->ammo -= amount;
72+
} else {
73+
state->ammo = 0;
74+
}
75+
}
76+
77+
void game_state_increase_ammo(GameState* state, uint16_t amount) {
78+
state->ammo += amount;
79+
}
80+
81+
uint16_t game_state_get_ammo(GameState* state) {
82+
return state->ammo;
83+
}
84+
85+
void game_state_update_time(GameState* state, uint32_t delta_time) {
86+
state->game_time += delta_time;
87+
}
88+
89+
uint32_t game_state_get_time(GameState* state) {
90+
return state->game_time;
91+
}
92+
93+
bool game_state_is_game_over(GameState* state) {
94+
return state->game_over;
95+
}
96+
97+
void game_state_set_game_over(GameState* state, bool game_over) {
98+
state->game_over = game_over;
99+
}

game_state.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#pragma once
2+
3+
#include <stdint.h>
4+
#include <stdbool.h>
5+
6+
typedef enum {
7+
TeamRed,
8+
TeamBlue
9+
} LaserTagTeam;
10+
11+
typedef enum {
12+
LaserTagStateTeamSelect,
13+
LaserTagStateGame,
14+
} LaserTagState;
15+
16+
typedef struct GameState GameState;
17+
18+
GameState* game_state_alloc();
19+
void game_state_free(GameState* state);
20+
void game_state_reset(GameState* state);
21+
22+
void game_state_set_team(GameState* state, LaserTagTeam team);
23+
LaserTagTeam game_state_get_team(GameState* state);
24+
25+
void game_state_decrease_health(GameState* state, uint8_t amount);
26+
void game_state_increase_health(GameState* state, uint8_t amount);
27+
uint8_t game_state_get_health(GameState* state);
28+
29+
void game_state_increase_score(GameState* state, uint16_t points);
30+
uint16_t game_state_get_score(GameState* state);
31+
32+
void game_state_decrease_ammo(GameState* state, uint16_t amount);
33+
void game_state_increase_ammo(GameState* state, uint16_t amount);
34+
uint16_t game_state_get_ammo(GameState* state);
35+
36+
void game_state_update_time(GameState* state, uint32_t delta_time);
37+
uint32_t game_state_get_time(GameState* state);
38+
39+
bool game_state_is_game_over(GameState* state);
40+
void game_state_set_game_over(GameState* state, bool game_over);
41+
42+
#define INITIAL_HEALTH 100
43+
#define INITIAL_AMMO 100
44+
#define MAX_HEALTH 100

icons/laser_tag_10px.png

806 Bytes
Loading

icons/toolkit.png

4.48 KB
Loading

infrared_controller.c

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#include "infrared_controller.h"
2+
#include <furi.h>
3+
#include <furi_hal.h>
4+
#include <infrared.h>
5+
#include <infrared_worker.h>
6+
#include <stdlib.h>
7+
8+
#define TAG "LaserTagInfrared"
9+
10+
#define IR_COMMAND_RED_TEAM 0xA1
11+
#define IR_COMMAND_BLUE_TEAM 0xB2
12+
13+
struct InfraredController {
14+
LaserTagTeam team;
15+
InfraredWorker* worker;
16+
FuriThread* rx_thread;
17+
volatile bool rx_running;
18+
volatile bool hit_received;
19+
};
20+
21+
static void infrared_rx_callback(void* context, InfraredWorkerSignal* received_signal) {
22+
InfraredController* controller = (InfraredController*)context;
23+
24+
const InfraredMessage* message = infrared_worker_get_decoded_signal(received_signal);
25+
if (message != NULL) {
26+
uint32_t received_command = message->address;
27+
if((controller->team == TeamRed && received_command == IR_COMMAND_BLUE_TEAM) ||
28+
(controller->team == TeamBlue && received_command == IR_COMMAND_RED_TEAM)) {
29+
controller->hit_received = true;
30+
}
31+
}
32+
}
33+
34+
static int32_t infrared_rx_thread(void* context) {
35+
InfraredController* controller = (InfraredController*)context;
36+
37+
while(controller->rx_running) {
38+
infrared_worker_rx_start(controller->worker);
39+
furi_thread_flags_wait(0, FuriFlagWaitAny, 10);
40+
}
41+
42+
return 0;
43+
}
44+
45+
InfraredController* infrared_controller_alloc() {
46+
InfraredController* controller = malloc(sizeof(InfraredController));
47+
controller->team = TeamRed;
48+
controller->worker = infrared_worker_alloc();
49+
controller->rx_running = true;
50+
controller->hit_received = false;
51+
52+
infrared_worker_rx_set_received_signal_callback(controller->worker, infrared_rx_callback, controller);
53+
54+
controller->rx_thread = furi_thread_alloc();
55+
furi_thread_set_name(controller->rx_thread, "IR_Rx_Thread");
56+
furi_thread_set_stack_size(controller->rx_thread, 1024);
57+
furi_thread_set_context(controller->rx_thread, controller);
58+
furi_thread_set_callback(controller->rx_thread, infrared_rx_thread);
59+
furi_thread_start(controller->rx_thread);
60+
61+
infrared_worker_rx_start(controller->worker);
62+
63+
return controller;
64+
}
65+
66+
void infrared_controller_free(InfraredController* controller) {
67+
furi_assert(controller);
68+
69+
controller->rx_running = false;
70+
furi_thread_join(controller->rx_thread);
71+
furi_thread_free(controller->rx_thread);
72+
73+
infrared_worker_rx_stop(controller->worker);
74+
infrared_worker_free(controller->worker);
75+
free(controller);
76+
}
77+
78+
void infrared_controller_set_team(InfraredController* controller, LaserTagTeam team) {
79+
furi_assert(controller);
80+
controller->team = team;
81+
}
82+
83+
void infrared_controller_send(InfraredController* controller) {
84+
furi_assert(controller);
85+
uint32_t command = (controller->team == TeamRed) ? IR_COMMAND_RED_TEAM : IR_COMMAND_BLUE_TEAM;
86+
InfraredMessage message = {
87+
.protocol = InfraredProtocolNEC,
88+
.address = 0x00,
89+
.command = command,
90+
.repeat = false
91+
};
92+
93+
infrared_worker_set_decoded_signal(controller->worker, &message);
94+
95+
infrared_worker_tx_set_get_signal_callback(
96+
controller->worker,
97+
infrared_worker_tx_get_signal_steady_callback,
98+
NULL);
99+
100+
infrared_worker_tx_start(controller->worker);
101+
102+
furi_delay_ms(250); // Delay to ensure the signal is sent
103+
104+
infrared_worker_tx_stop(controller->worker);
105+
}
106+
107+
bool infrared_controller_receive(InfraredController* controller) {
108+
furi_assert(controller);
109+
bool hit = controller->hit_received;
110+
controller->hit_received = false;
111+
return hit;
112+
}

0 commit comments

Comments
 (0)