Skip to content

Commit

Permalink
toast system, and warn no bait
Browse files Browse the repository at this point in the history
  • Loading branch information
city41 committed Nov 30, 2018
1 parent 223391e commit f7c562b
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 36 deletions.
16 changes: 3 additions & 13 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "boat.h"
#include "util.h"
#include "dialogUtils.h"
#include "toast.h"

extern Renderer renderer;
extern Arduboy2Base arduboy;
Expand Down Expand Up @@ -176,14 +177,9 @@ void Game::updatePlay(uint8_t frame) {
for (uint8_t s = 0; s < MAX_SIGNS; ++s) {
if (overlap(player, signs[s].x, signs[s].y, 12, 6)) {
player.undoMove();
currentSignMessage = signs[s].message;
currentSignMessageCount = 150;
Toast::toast(signs[s].message);
}
}

if (currentSignMessageCount > 0) {
currentSignMessageCount -= 1;
}
}

void Game::renderPlay(uint8_t frame) {
Expand Down Expand Up @@ -246,13 +242,7 @@ void Game::renderPlay(uint8_t frame) {
renderer.translateY = 0;
Hud::render(player);

if (currentSignMessageCount > 0) {
renderer.translateX = 0;
renderer.translateY = 0;
renderer.fillRect(0, HEIGHT - 6, WIDTH, 6, BLACK);
renderer.drawString(1, HEIGHT - 5, currentSignMessage);
}

Toast::render();
}

void Game::updateShop(uint8_t frame) {
Expand Down
7 changes: 1 addition & 6 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ class Game {
uint8_t titleCount;
uint8_t seconds; // actual seconds. 1 game hour = SECONDS_PER_HOUR real seconds

const uint8_t* currentSignMessage;
uint8_t currentSignMessageCount;

bool isOnShopDoor();
bool isOnBoat();
bool isTalkingToGirl();
Expand Down Expand Up @@ -68,9 +65,7 @@ class Game {
currentRender(&Game::renderLogo),
nextRender(NULL),
titleCount(0),
seconds(0),
currentSignMessage(NULL),
currentSignMessageCount(0)
seconds(0)
{
State::load();
}
Expand Down
25 changes: 12 additions & 13 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "enumUtils.h"
#include "world.h"
#include "boat.h"
#include "toast.h"

extern Renderer renderer;
extern Arduboy2Base arduboy;
Expand Down Expand Up @@ -72,14 +73,19 @@ void Player::placeCursorBasedOnDir() {
}

void Player::updateWalk(uint8_t frame) {
if (State::gameState.baitCounts[static_cast<int8_t>(currentBait)] > 0 && arduboy.pressed(A_BUTTON)) {
placeCursorBasedOnDir();
if (arduboy.pressed(A_BUTTON)) {
if (State::gameState.baitCounts[static_cast<int8_t>(currentBait)] > 0) {
placeCursorBasedOnDir();

currentUpdate = &Player::updateScanning;
currentRender = &Player::renderScanning;
return;
currentUpdate = &Player::updateScanning;
currentRender = &Player::renderScanning;
return;
} else {
Toast::toast(noBait_string, 50);
}
}


if (arduboy.justPressed(B_BUTTON)) {
areYouSure = false;
menuRow = MenuRow::COLLECTION;
Expand Down Expand Up @@ -130,13 +136,6 @@ void Player::renderWalk(uint8_t frame) {
}

renderer.drawPlusMask(x, y, player_plus_mask, spriteIndex, mirror);

if (saveToastCount > 0) {
saveToastCount -= 1;
renderer.pushTranslate(0, 0);
renderer.fillRect(0, HEIGHT - 5, WIDTH, 5, BLACK);
renderer.drawString(0, HEIGHT - 4, gameSaved_string);
}
}

void Player::updateMenu(uint8_t frame) {
Expand Down Expand Up @@ -171,7 +170,7 @@ void Player::updateMenu(uint8_t frame) {
break;
case MenuRow::SAVE:
State::saveToEEPROM();
saveToastCount = 60;
Toast::toast(gameSaved_string, 90);
currentUpdate = &Player::updateWalk;
currentRender = &Player::renderWalk;
break;
Expand Down
2 changes: 0 additions & 2 deletions src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class Player {
uint8_t reelLevel;
MenuRow menuRow;
bool areYouSure;
uint8_t saveToastCount;
int8_t currentCollectionRow;
CollectionColumn currentCollectionColumn;

Expand All @@ -76,7 +75,6 @@ class Player {
castCount(0),
reelLevel(0),
menuRow(MenuRow::COLLECTION),
saveToastCount(0),
currentCollectionRow(0),
currentCollectionColumn(CollectionColumn::Quantity),
areYouSure(false),
Expand Down
6 changes: 6 additions & 0 deletions src/strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,4 +364,10 @@ const uint8_t lucyWarning_string[27] PROGMEM = {
30, 18, 19, 29, 0, 19, 29, 0, 23, 35, 0, 29, 26, 25, 30, 40, 0, 12, 11, 13, 21, 0, 25, 16, 16, 41, 0xFF
};


// "YOU HAVE NO BAIT!"
const uint8_t noBait_string[18] PROGMEM = {
35, 25, 31, 0, 18, 11, 32, 15, 0, 24, 25, 0, 12, 11, 19, 30, 41, 0xFF
};

#endif
23 changes: 23 additions & 0 deletions src/toast.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "toast.h"
#include "renderer.h"

extern Renderer renderer;

uint8_t Toast::toastCount = 0;
const uint8_t* Toast::msg = NULL;

void Toast::toast(const uint8_t* newMsg, uint8_t count) {
Toast::toastCount = count;
Toast::msg = newMsg;
}

void Toast::render() {
if (toastCount > 0) {
toastCount -= 1;

renderer.translateX = 0;
renderer.translateY = 0;
renderer.fillRect(0, HEIGHT - 5, WIDTH, 5, BLACK);
renderer.drawString(0, HEIGHT - 4, msg);
}
}
12 changes: 12 additions & 0 deletions src/toast.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <Arduino.h>

struct Toast {
static const uint8_t* msg;
static uint8_t toastCount;

static void toast(const uint8_t* msg, uint8_t count = 120);
static void render();
};

4 changes: 2 additions & 2 deletions strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
{ "key": "guyQuest", "value": "BRING ME FOUR BOOTS\nFOR A NEW WAY\nTO FISH" },
{ "key": "guyTurnOnProMode", "value": "SET FISHING MODE\nPRO" },
{ "key": "guyTurnOffProMode", "value": "SET FISHING MODE\nCASUAL" },
{ "key": "lucyWarning", "value": "THIS IS MY SPOT, BACK OFF!" }

{ "key": "lucyWarning", "value": "THIS IS MY SPOT, BACK OFF!" },
{ "key": "noBait", "value": "YOU HAVE NO BAIT!" }
]
}

0 comments on commit f7c562b

Please sign in to comment.