summaryrefslogtreecommitdiff
path: root/Player.cpp
diff options
context:
space:
mode:
authorXaviDCR92 <xavi.dcr@gmail.com>2017-09-09 12:47:17 +0200
committerXaviDCR92 <xavi.dcr@gmail.com>2017-09-09 12:47:17 +0200
commita7dd9781961b5f26d5dca6829e1933dff6209d23 (patch)
tree6e3f1c469e6997fedbaa096f377d67f99a65ae47 /Player.cpp
parent786dccd2bc0946d48b8a2758ef2c607678bc8dd9 (diff)
Simple collision detection between units added. libgamebuino was always updating header files, so targets were always being rebuilt.
Diffstat (limited to 'Player.cpp')
-rw-r--r--Player.cpp84
1 files changed, 55 insertions, 29 deletions
diff --git a/Player.cpp b/Player.cpp
index 634bb9f..b9c05a4 100644
--- a/Player.cpp
+++ b/Player.cpp
@@ -4,6 +4,7 @@
#include "Player.h"
#include "Pad.h"
+#include "Unit.h"
#include <limits.h>
/* **************************************
@@ -131,17 +132,45 @@ void Player::DrawHandler(void)
}
}
- if (bAnyoneSelected == true)
+ if (human == true)
{
- GfxDrawRectangle(PROGRESS_BAR_X, PROGRESS_BAR_Y, PROGRESS_BAR_W, PROGRESS_BAR_H, GFX_BLACK);
-
- if (showActionsMenu_counter != 0)
+ if (bAnyoneSelected == true)
{
- GfxFillRectangle(PROGRESS_BAR_X, PROGRESS_BAR_Y, showActionsMenu_counter << 1, PROGRESS_BAR_H, GFX_BLACK);
+ GfxDrawRectangle(PROGRESS_BAR_X, PROGRESS_BAR_Y, PROGRESS_BAR_W, PROGRESS_BAR_H, GFX_BLACK);
+
+ if (showActionsMenu_counter != 0)
+ {
+ GfxFillRectangle(PROGRESS_BAR_X, PROGRESS_BAR_Y, showActionsMenu_counter << 1, PROGRESS_BAR_H, GFX_BLACK);
+ }
}
+
+ ActionsMenu();
+
+ ShowResources();
}
}
+void Player::ShowResources(void)
+{
+ char str[16];
+
+ gb.display.setColor(GFX_WHITE);
+ gb.display.fillRect(0, 0, X_SCREEN_RESOLUTION, 5);
+
+ snprintf(str, sizeof(str), "W=%d", Resources.Wood);
+
+ GfxPrintTextFont(str, font3x3, 2, 1);
+
+ snprintf(str, sizeof(str), "G=%d", Resources.Gold);
+
+ GfxPrintTextFont(str, font3x3, 22, 1);
+
+ snprintf(str, sizeof(str), "F=%d", Resources.Food);
+
+ GfxPrintTextFont(str, font3x3, 42, 1);
+}
+
+
bool Player::checkNewBuildingPosition(TYPE_COLLISION_BLOCK * cb)
{
uint8_t i;
@@ -293,7 +322,7 @@ void Player::ActionsMenu(void)
const char* str = UnitGetActionString(action);
- GfxPrintText(str, 40, Y_SCREEN_RESOLUTION - 4);
+ GfxPrintTextFont(str, font3x3, 40, Y_SCREEN_RESOLUTION - 4);
break;
}
@@ -311,18 +340,9 @@ void Player::Handler(void)
UnitBuildingSelection();
- for (uint8_t i = 0; i < PLAYER_MAX_UNITS_BUILDINGS; i++)
- {
- TYPE_UNIT* ptrUnit = &units[i];
-
- UnitHandler(ptrUnit);
- }
-
- ActionsMenu();
+ UnitHandler(units, sizeof(units) / sizeof(units[0]));
ButtonHandler();
-
- GfxShowResources(&Resources);
}
void Player::ButtonHandler(void)
@@ -398,18 +418,14 @@ void Player::ButtonAReleased(void)
if (ptrUnit->selected == true)
{
- if (showActionsMenu_index == ACTION_CREATE_UNIT)
+ switch (showActionsMenu_index)
{
- uint8_t w = UnitGetWidthFromID(ptrUnit->id);
- uint8_t h = UnitGetHeightFromID(ptrUnit->id);
- uint8_t new_pos_x = ptrUnit->x + SystemRand(w, w + (w >> 1));
- uint8_t new_pos_y = ptrUnit->y + SystemRand(h, h + (h >> 1));
- TYPE_COLLISION_BLOCK cb = {.x = new_pos_x, .y = new_pos_y};
-
- createUnit(PEASANT, cb);
-
+ case ACTION_CREATE_UNIT:
+ ActionCreateUnit(ptrUnit);
break;
}
+
+ break;
}
}
}
@@ -417,6 +433,20 @@ void Player::ButtonAReleased(void)
showActionsMenu = (showActionsMenu_counter < ACCEPT_UNIT_BUILDING_OPTIONS_FRAMES)? false: true;
}
+void Player::ActionCreateUnit(TYPE_UNIT* ptrUnit)
+{
+ if (showActionsMenu_index == ACTION_CREATE_UNIT)
+ {
+ uint8_t w = UnitGetWidthFromID(ptrUnit->id);
+ uint8_t h = UnitGetHeightFromID(ptrUnit->id);
+ uint8_t new_pos_x = ptrUnit->x + SystemRand(w, w + (w >> 1));
+ uint8_t new_pos_y = ptrUnit->y + SystemRand(h, h + (h >> 1));
+ TYPE_COLLISION_BLOCK cb = {.x = new_pos_x, .y = new_pos_y};
+
+ createUnit(PEASANT, cb);
+ }
+}
+
void Player::ButtonBPressed(void)
{
enum
@@ -496,8 +526,6 @@ void Player::ButtonLeftReleased(void)
// for current unit.
uint8_t availableActions = UnitGetAvailableActions(ptrUnit);
- DEBUG_VAR(availableActions);
-
for (uint8_t j = showActionsMenu_index - 1; j != showActionsMenu_index ; j--)
{
if (j > (sizeof(uint8_t) << 3))
@@ -539,8 +567,6 @@ void Player::IncreaseShowActionsMenuIndex(void)
// for current unit.
uint8_t availableActions = UnitGetAvailableActions(ptrUnit);
- DEBUG_VAR(availableActions);
-
for (uint8_t j = showActionsMenu_index + 1; j != showActionsMenu_index ; j++)
{
if (j >= (sizeof(uint8_t) << 3) )