Implemented sprite & added player animation.

This commit is contained in:
2016-11-30 00:34:36 +02:00
parent d2c335bfa5
commit bcd0a359fc
26 changed files with 843 additions and 86 deletions

View File

@@ -38,13 +38,13 @@ void GuiController::initialize(GameState* gameState)
// Add a text element
auto text = new gui::widgets::TextArea();
text->setText("Hello world!\nMy name is Tibi!\nThis is a really really long long long, even the longest ever, line.\nThis is a very loooooooooooooooooong word.");
text->setSize(200, 200);
text->setText("Hello world!");
text->setSize(50, 5);
text->setPosition(100, 10);
text->setColor(0, 1, 0);
text->setBackColor(0.5f, 0, 0, 0.5f);
text->setTextSize(11);
text->setHorizontalWrap(gui::widgets::TextHorizontalWrapping::Wrap);
text->setHorizontalWrap(gui::widgets::TextHorizontalWrapping::Ellipsis);
text->setVerticalWrap(gui::widgets::TextVerticalWrapping::Trim);
text->setAlignment(gui::widgets::TextAlign::BottomRight);
m_canvas.addChild(text);

View File

@@ -7,13 +7,10 @@
#include <GameState.h>
#include <controller/PlayerController.h>
#include <utils/Assert.h>
#include <cassert>
namespace farmlands
{
namespace controller
{
namespace farmlands {
namespace controller {
PlayerController::PlayerController()
: m_gameState(nullptr)
@@ -26,7 +23,8 @@ PlayerController::~PlayerController()
void PlayerController::initialize(GameState* gameState)
{
assert(gameState != nullptr);
Assert(gameState != nullptr, "Game state must not be NULL!");
m_gameState = gameState;
}
@@ -71,6 +69,9 @@ void PlayerController::updateLogic()
{
m_gameState->player.posX = newX;
m_gameState->player.posY = newY;
m_gameState->player.lastDeltaX = deltaX * deltaMultiplier;
m_gameState->player.lastDeltaY = deltaY * deltaMultiplier;
setDirection(deltaX, deltaY);
m_gameState->camera.posX = m_gameState->player.posX;
m_gameState->camera.posY = m_gameState->player.posY - 1;
@@ -83,5 +84,21 @@ bool PlayerController::canMove(float x, float y)
return true;
}
static const model::Direction directions[3][3] =
{
{ model::Direction::NorthWest, model::Direction::West, model::Direction::SouthWest },
{ model::Direction::North, model::Direction::South, model::Direction::South },
{ model::Direction::NorthEast, model::Direction::East, model::Direction::SouthEast },
};
void PlayerController::setDirection(float dx, float dy)
{
int xx = (0 < dx) - (dx < 0);
int yy = (0 < dy) - (dy < 0);
if (xx != 0 || yy != 0)
m_gameState->player.direction = directions[xx + 1][yy + 1];
}
} /* namespace controller */
} /* namespace farmlands */

View File

@@ -42,6 +42,7 @@ namespace controller {
private:
bool canMove(float x, float y);
void setDirection(float dx, float dy);
GameState* m_gameState;
};