Skip to content

Commit

Permalink
Merge pull request #68 from AEFeinstein/origin/lumberjack
Browse files Browse the repository at this point in the history
Origin/lumberjack
  • Loading branch information
AEFeinstein authored Sep 15, 2023
2 parents ce9723d + 99c23b2 commit c58ca09
Show file tree
Hide file tree
Showing 119 changed files with 1,986 additions and 3 deletions.
Binary file removed assets/fonts/radiostars.font.png
Binary file not shown.
Binary file added assets/lumbers/alert.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/lumbers/bottom_floor1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/lumbers/bottom_floor10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/lumbers/bottom_floor2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/lumbers/bottom_floor3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/lumbers/bottom_floor4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/lumbers/bottom_floor5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/lumbers/bottom_floor6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/lumbers/bottom_floor7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/lumbers/bottom_floor8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/lumbers/bottom_floor9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/lumbers/enemy_a1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/lumbers/enemy_a2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/lumbers/enemy_a3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/lumbers/enemy_a4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/lumbers/enemy_a5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/lumbers/enemy_a6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/lumbers/enemy_a7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/lumbers/enemy_b1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/lumbers/enemy_b2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/lumbers/enemy_b3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/lumbers/enemy_b4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/lumbers/enemy_b5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/lumbers/enemy_b6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/lumbers/enemy_b7.png
Binary file added assets/lumbers/enemy_c1.png
Binary file added assets/lumbers/enemy_c2.png
Binary file added assets/lumbers/enemy_c3.png
Binary file added assets/lumbers/enemy_c4.png
Binary file added assets/lumbers/enemy_c5.png
Binary file added assets/lumbers/enemy_c6.png
Binary file added assets/lumbers/enemy_c7.png
Binary file added assets/lumbers/enemy_d1.png
Binary file added assets/lumbers/enemy_d2.png
Binary file added assets/lumbers/lumbers_green_1.png
Binary file added assets/lumbers/lumbers_green_10.png
Binary file added assets/lumbers/lumbers_green_11.png
Binary file added assets/lumbers/lumbers_green_12.png
Binary file added assets/lumbers/lumbers_green_13.png
Binary file added assets/lumbers/lumbers_green_14.png
Binary file added assets/lumbers/lumbers_green_15.png
Binary file added assets/lumbers/lumbers_green_16.png
Binary file added assets/lumbers/lumbers_green_17.png
Binary file added assets/lumbers/lumbers_green_18.png
Binary file added assets/lumbers/lumbers_green_19.png
Binary file added assets/lumbers/lumbers_green_2.png
Binary file added assets/lumbers/lumbers_green_20.png
Binary file added assets/lumbers/lumbers_green_21.png
Binary file added assets/lumbers/lumbers_green_3.png
Binary file added assets/lumbers/lumbers_green_4.png
Binary file added assets/lumbers/lumbers_green_5.png
Binary file added assets/lumbers/lumbers_green_6.png
Binary file added assets/lumbers/lumbers_green_7.png
Binary file added assets/lumbers/lumbers_green_8.png
Binary file added assets/lumbers/lumbers_green_9.png
Binary file added assets/lumbers/lumbers_red_1.png
Binary file added assets/lumbers/lumbers_red_10.png
Binary file added assets/lumbers/lumbers_red_11.png
Binary file added assets/lumbers/lumbers_red_12.png
Binary file added assets/lumbers/lumbers_red_13.png
Binary file added assets/lumbers/lumbers_red_14.png
Binary file added assets/lumbers/lumbers_red_15.png
Binary file added assets/lumbers/lumbers_red_16.png
Binary file added assets/lumbers/lumbers_red_17.png
Binary file added assets/lumbers/lumbers_red_2.png
Binary file added assets/lumbers/lumbers_red_3.png
Binary file added assets/lumbers/lumbers_red_4.png
Binary file added assets/lumbers/lumbers_red_5.png
Binary file added assets/lumbers/lumbers_red_6.png
Binary file added assets/lumbers/lumbers_red_7.png
Binary file added assets/lumbers/lumbers_red_8.png
Binary file added assets/lumbers/lumbers_red_9.png
Binary file added assets/lumbers/secret_swadgeland_1.png
Binary file added assets/lumbers/secret_swadgeland_10.png
Binary file added assets/lumbers/secret_swadgeland_11.png
Binary file added assets/lumbers/secret_swadgeland_12.png
Binary file added assets/lumbers/secret_swadgeland_13.png
Binary file added assets/lumbers/secret_swadgeland_14.png
Binary file added assets/lumbers/secret_swadgeland_15.png
Binary file added assets/lumbers/secret_swadgeland_16.png
Binary file added assets/lumbers/secret_swadgeland_17.png
Binary file added assets/lumbers/secret_swadgeland_18.png
Binary file added assets/lumbers/secret_swadgeland_19.png
Binary file added assets/lumbers/secret_swadgeland_2.png
Binary file added assets/lumbers/secret_swadgeland_20.png
Binary file added assets/lumbers/secret_swadgeland_21.png
Binary file added assets/lumbers/secret_swadgeland_22.png
Binary file added assets/lumbers/secret_swadgeland_3.png
Binary file added assets/lumbers/secret_swadgeland_4.png
Binary file added assets/lumbers/secret_swadgeland_5.png
Binary file added assets/lumbers/secret_swadgeland_6.png
Binary file added assets/lumbers/secret_swadgeland_7.png
Binary file added assets/lumbers/secret_swadgeland_8.png
Binary file added assets/lumbers/secret_swadgeland_9.png
Binary file added assets/lumbers/water_floor0.png
Binary file added assets/lumbers/water_floor1.png
Binary file added assets/lumbers/water_floor2.png
Binary file added assets/lumbers/water_floor3.png
Binary file added assets/lumbers/water_floor4.png
Binary file added assets/lumbers/water_floor_b1.png
Binary file added assets/lumbers/water_floor_b2.png
Binary file added assets/lumbers/water_floor_b3.png
Binary file added assets/lumbers/water_floor_b4.png
2 changes: 2 additions & 0 deletions emulator/src/extensions/modes/ext_modes.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "jukebox.h"
#include "mainMenu.h"
#include "pong.h"
#include "lumberjack.h"
#include "touchTest.h"
#include "tunernome.h"

Expand Down Expand Up @@ -58,6 +59,7 @@ static swadgeMode_t* allSwadgeModes[] = {
&jukeboxMode,
&mainMenuMode,
&pongMode,
&lumberjackMode,
&touchTestMode,
&tunernomeMode,
};
Expand Down
2 changes: 1 addition & 1 deletion emulator/src/idf/esp_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ void esp_log_write(esp_log_level_t level, const char* tag, const char* format, .
vsnprintf(dbgStr, sizeof(dbgStr), format, args);
va_end(args);

printf("%c| %s\n", levelChars[level], dbgStr);
printf("%c|%s| %s\n", levelChars[level], tag, dbgStr);
}
}
5 changes: 5 additions & 0 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ idf_component_register(SRCS "swadge2024.c"
"modes/dance/dance.c"
"modes/dance/portableDance.c"
"modes/demo/demoMode.c"
"modes/lumberjack/lumberjack.c"
"modes/lumberjack/lumberjackGame.c"
"modes/lumberjack/lumberjackEntity.c"
"modes/lumberjack/lumberjackPlayer.c"
"modes/jukebox/jukebox.c"
"modes/mainMenu/mainMenu.c"
"modes/pushy/pushy.c"
Expand Down Expand Up @@ -67,6 +71,7 @@ idf_component_register(SRCS "swadge2024.c"
"./modes/pong"
"./modes/tunernome"
"./modes/mainMenu"
"./modes/lumberjack"
"./modes/demo"
"./modes/quickSettings")

Expand Down
347 changes: 347 additions & 0 deletions main/modes/lumberjack/lumberjack.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,347 @@
//==============================================================================
// Includes
//==============================================================================

#include <stdlib.h>
#include <esp_log.h>

#include "menu.h"

// For lumberjack
#include "lumberjack.h"
#include "lumberjackGame.h"

static void lumberjackEnterMode(void);
static void lumberjackExitMode(void);
static void lumberjackMainLoop(int64_t elapsedUs);
static void lumberjackMenuLoop(int64_t elapsedUs);
static void lumberjackAudioCallback(uint16_t* samples, uint32_t sampleCnt);
static void lumberjackBackgroundDrawCallback(int16_t x, int16_t y, int16_t w, int16_t h, int16_t up, int16_t upNum);
static void lumberjackEspNowRecvCb(const esp_now_recv_info_t* esp_now_info, const uint8_t* data, uint8_t len,
int8_t rssi);
static void lumberjackEspNowSendCb(const uint8_t* mac_addr, esp_now_send_status_t status);

static void lumberjackConCb(p2pInfo* p2p, connectionEvt_t evt);
static void lumberjackMsgRxCb(p2pInfo* p2p, const uint8_t* payload, uint8_t len);
static void lumberjackMsgTxCbFn(p2pInfo* p2p, messageStatus_t status, const uint8_t* data, uint8_t len);

static void lumberjackMenuCb(const char*, bool selected, uint32_t settingVal);

static void lumberjackJoinGame(void);

static const char lumberjackName[] = "Lumberjack";
static const char lumberjackPanic[] = "Panic";
static const char lumberjackAttack[] = "Attack";
static const char lumberjackBack[] = "Back";

// static const char lumberjackNone[] = "None";
static const char lumberjackRedCharacter[] = "Character: Red";
static const char lumberjackGreen[] = "Character: Green";
static const char lumberjackSpecialCharacter[] = "Character: Special";

static const char lumberjackMenuSinglePlayer[] = "Single Player";
static const char lumberjackMenuMultiPlayerHost[] = "Multi-Player";
static const char lumberjackMenuMultiPlayerClient[] = "Multi-Player Join";

const char* LUM_TAG = "LUM";

swadgeMode_t lumberjackMode = {
.modeName = lumberjackName,
.wifiMode = ESP_NOW_IMMEDIATE,
.overrideUsb = false,
.usesAccelerometer = false,
.usesThermometer = false,
.fnEnterMode = lumberjackEnterMode,
.fnExitMode = lumberjackExitMode,
.fnMainLoop = lumberjackMainLoop,
.fnAudioCallback = lumberjackAudioCallback,
.fnBackgroundDrawCallback = lumberjackBackgroundDrawCallback,
.fnEspNowRecvCb = lumberjackEspNowRecvCb,
.fnEspNowSendCb = lumberjackEspNowSendCb,
.fnAdvancedUSB = NULL,
};

lumberjack_t* lumberjack = NULL;

static void lumberjackEnterMode(void)
{
ESP_LOGI(LUM_TAG, "Lumber!");
// Allocate and clear all memory for the menu mode.
lumberjack = calloc(1, sizeof(lumberjack_t));

loadFont("ibm_vga8.font", &lumberjack->ibm, false);
loadFont("logbook.font", &lumberjack->logbook, false);

lumberjack->menu = initMenu(lumberjackName, lumberjackMenuCb);
lumberjack->menuLogbookRenderer = initMenuLogbookRenderer(&lumberjack->logbook);

lumberjack->gameMode = LUMBERJACK_MODE_NONE;
lumberjack->networked = false;
lumberjack->host = false;

lumberjack->menu = startSubMenu(lumberjack->menu, lumberjackPanic);
addSingleItemToMenu(lumberjack->menu, lumberjackMenuSinglePlayer);
addSingleItemToMenu(lumberjack->menu, lumberjackMenuMultiPlayerHost);
addSingleItemToMenu(lumberjack->menu, lumberjackMenuMultiPlayerClient);
lumberjack->menu = endSubMenu(lumberjack->menu);

addSingleItemToMenu(lumberjack->menu, lumberjackAttack);

if (true) // Ignore this line
{
static const char* defaultCharacters[] = {lumberjackRedCharacter, lumberjackGreen};

addMultiItemToMenu(lumberjack->menu, defaultCharacters, ARRAY_SIZE(defaultCharacters), 0);
}
else
{
static const char* defaultCharacterswUnlocks[]
= {lumberjackRedCharacter, lumberjackGreen, lumberjackSpecialCharacter};

addMultiItemToMenu(lumberjack->menu, defaultCharacterswUnlocks, ARRAY_SIZE(defaultCharacterswUnlocks), 0);
}

lumberjack->screen = LUMBERJACK_MENU;

// Lumberjack. Game 19
// Init menu :(

bzrStop(); // Stop the buzzer?

// High score stuff?
// Unlockables ? Save data?
}

static void lumberjackJoinGame(void)
{
if (lumberjack->gameMode == LUMBERJACK_MODE_PANIC)
{
lumberjack->screen = LUMBERJACK_A;
lumberjackStartGameMode(lumberjack, lumberjack->selected);
return;
}

if (lumberjack->gameMode == LUMBERJACK_MODE_ATTACK)
{
lumberjack->screen = LUMBERJACK_B;
lumberjackStartGameMode(lumberjack, lumberjack->selected);
return;
}

lumberjack->screen = LUMBERJACK_MENU;
}

static void lumberjackExitMode(void)
{
lumberjackExitGameMode();

p2pDeinit(&lumberjack->p2p);
freeFont(&lumberjack->ibm);
freeFont(&lumberjack->logbook);
deinitMenu(lumberjack->menu);
free(lumberjack);
}

static void lumberjackMainLoop(int64_t elapsedUs)
{
switch (lumberjack->screen)
{
case LUMBERJACK_MENU:
{
lumberjackMenuLoop(elapsedUs);
break;
}
case LUMBERJACK_A:
case LUMBERJACK_B:
{
lumberjackGameLoop(elapsedUs);
break;
}
}
}

static void lumberjackMenuLoop(int64_t elapsedUs)
{
buttonEvt_t evt = {0};
while (checkButtonQueueWrapper(&evt))
{
lumberjack->menu = menuButton(lumberjack->menu, evt);
}

drawMenuLogbook(lumberjack->menu, lumberjack->menuLogbookRenderer, elapsedUs);
}

static void lumberjackAudioCallback(uint16_t* samples, uint32_t sampleCnt)
{
}

static void lumberjackBackgroundDrawCallback(int16_t x, int16_t y, int16_t w, int16_t h, int16_t up, int16_t upNum)
{
fillDisplayArea(x, y, x + w, y + h, c145);

// Are we drawing the game here?
}

//==============================================================================
// ESP_NOW
//==============================================================================
static void lumberjackEspNowRecvCb(const esp_now_recv_info_t* esp_now_info, const uint8_t* data, uint8_t len,
int8_t rssi)
{
// ESP_LOGI(LUM_TAG, "Getting: %d", (uint8_t)&data);
p2pRecvCb(&lumberjack->p2p, esp_now_info->src_addr, data, len, rssi);
}

static void lumberjackEspNowSendCb(const uint8_t* mac_addr, esp_now_send_status_t status)
{
p2pSendCb(&lumberjack->p2p, mac_addr, status);
}

static void lumberjackConCb(p2pInfo* p2p, connectionEvt_t evt)
{
// Do anything
if (evt == CON_ESTABLISHED)
{
ESP_LOGI(LUM_TAG, "LumberJack.Net ready! %d", (int)p2pGetPlayOrder(p2p));

if (GOING_FIRST == p2pGetPlayOrder(p2p))
{
ESP_LOGI(LUM_TAG, "HOST?");
const uint8_t testMsg[] = {0x01, 0x02, 0x03, 0x04};

p2pSendMsg(&lumberjack->p2p, testMsg, ARRAY_SIZE(testMsg), lumberjackMsgTxCbFn);
}
}

if (evt == CON_LOST)
{
// Do we attempt to get it back?
ESP_LOGW(LUM_TAG, "We lost connection!");
}

lumberjack->conStatus = evt;
}

static void lumberjackMsgRxCb(p2pInfo* p2p, const uint8_t* payload, uint8_t len)
{
// Do anything

if (len > 1)
{
if (payload[0] == 0x19)
{
int locX = (int)payload[1] << 0 | (uint32_t)payload[2] << 8;
int locY = (int)payload[3] << 0 | (uint32_t)payload[4] << 8;
uint8_t frame = (uint8_t)payload[5];
printf("Got %d,%d %d|", locX, locY, frame);

lumberjackUpdateRemote(locX, locY, frame);
}
}

printf("Received %d %d!\n", *payload, len);
}

void lumberjackSendAttack(int number)
{
const uint8_t testMsg[] = {0x13};
p2pSendMsg(&lumberjack->p2p, testMsg, ARRAY_SIZE(testMsg), lumberjackMsgTxCbFn);
}

void lumberjackUpdateLocation(int ghostX, int ghostY, int frame)
{
const uint8_t locationMessage[6]
= {0x19, (uint8_t)(ghostX >> 0), (uint8_t)(ghostX >> 8), (uint8_t)(ghostY >> 0), (uint8_t)(ghostY >> 8), frame};
p2pSendMsg(&lumberjack->p2p, locationMessage, ARRAY_SIZE(locationMessage), lumberjackMsgTxCbFn);
}

/**
* @brief TODO use this somewhere
*
* @param p2p
* @param status
* @param data
* @param len
*/
static void lumberjackMsgTxCbFn(p2pInfo* p2p, messageStatus_t status, const uint8_t* data, uint8_t len)
{
}

static void lumberjackMenuCb(const char* label, bool selected, uint32_t settingVal)
{
ESP_LOGI(LUM_TAG, "Info ");
if (selected)
{
if (label == lumberjackPanic)
{
ESP_LOGI(LUM_TAG, "Panic");
lumberjack->gameMode = LUMBERJACK_MODE_PANIC;
// lumberjack->screen = LUMBERJACK_A;
// lumberjackStartGameMode(LUMBERJACK_MODE_PANIC, lumberjack->selected);
}
else if (label == lumberjackAttack)
{
ESP_LOGI(LUM_TAG, "Attack");
lumberjack->gameMode = LUMBERJACK_MODE_ATTACK;

// lumberjack->screen = LUMBERJACK_B;
// lumberjackStartGameMode(LUMBERJACK_MODE_ATTACK, lumberjack->selected);
}

if (label == lumberjackMenuMultiPlayerHost)
{
p2pInitialize(&lumberjack->p2p, 0x13, lumberjackConCb, lumberjackMsgRxCb, -70);
p2pStartConnection(&lumberjack->p2p);
lumberjack->networked = true;
lumberjack->host = true;
lumberjackJoinGame();
}
else if (label == lumberjackMenuMultiPlayerClient)
{
p2pInitialize(&lumberjack->p2p, 0x13, lumberjackConCb, lumberjackMsgRxCb, -70);
p2pStartConnection(&lumberjack->p2p);
lumberjack->networked = true;
lumberjack->host = false;
lumberjackJoinGame();
}
else if (label == lumberjackMenuSinglePlayer)
{
lumberjack->networked = false;
lumberjack->host = false;
lumberjackJoinGame();
}

if (label == lumberjackRedCharacter)
{
lumberjack->selected = 0;
}
else if (label == lumberjackGreen)
{
lumberjack->selected = 1;
}
else if (label == lumberjackSpecialCharacter)
{
lumberjack->selected = 2;
}

if (label == lumberjackBack)
{
//.switchToSwadgeMode(&mainMenuMode);
}
}
else
{
if (label == lumberjackRedCharacter)
{
lumberjack->selected = 0;
}
else if (label == lumberjackGreen)
{
lumberjack->selected = 1;
}
else if (label == lumberjackSpecialCharacter)
{
lumberjack->selected = 2;
}
}
}
Loading

0 comments on commit c58ca09

Please sign in to comment.