Skip to content

Commit

Permalink
[battle] [viewer] uniform sprite-sheets directions.
Browse files Browse the repository at this point in the history
  • Loading branch information
vagra committed Mar 27, 2023
1 parent 4d70743 commit a079969
Show file tree
Hide file tree
Showing 14 changed files with 9 additions and 37 deletions.
Binary file modified assets/heros/hero0.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 modified assets/heros/hero1.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 modified assets/heros/hero2.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 modified assets/heros/hero3.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 modified assets/heros/hero4.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 modified assets/heros/hero5.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 modified assets/heros/hero6.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 modified assets/heros/hero7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 1 addition & 15 deletions battle/Hero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void Hero::play(sf::Time elapsed) {
}

void Hero::step() {
const int direction = getScreenDirection(getDirection());
const int direction = getDirection();

m_frame.x = getStartFrame() + getCurrentFrame();
m_frame.y = direction;
Expand All @@ -89,7 +89,6 @@ void Hero::step() {
m_text->setString(to_string(m_fsm.context().hp));
}


int Hero::getStartFrame() const {
return m_action_set->getAction(m_fsm.context().action)->start;
}
Expand Down Expand Up @@ -349,17 +348,4 @@ sf::Vector2f Hero::genPosition() {

int Hero::genHit() noexcept {
return rand() % (MAX_HIT - MIN_HIT) + MIN_HIT;
}


// ---------------------------------------------
// private static methods
// ---------------------------------------------

constexpr int Hero::getScreenDirection(int direction) noexcept {
return (DIRECTIONS + INIT_DIRECTION - direction) % DIRECTIONS;
}

constexpr int Hero::getTextureDirection(int direction) noexcept {
return (DIRECTIONS + INIT_DIRECTION - direction) % DIRECTIONS;
}
5 changes: 0 additions & 5 deletions battle/Hero.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ class Hero : public Actor
sf::Vector2f genPosition();
int genHit() noexcept;

/* private static methods */

static constexpr int getScreenDirection(int direction) noexcept;
static constexpr int getTextureDirection(int direction) noexcept;

/* private members */

Hero* m_enemy = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion battle/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ constexpr int ACTOR_TYPES = 8;
constexpr int ACTIONS = 12;
constexpr int ROW_ACTIONS = ACTIONS;

constexpr int INIT_DIRECTION = 6;
constexpr int INIT_DIRECTION = 0;

constexpr int FRAME_WIDTH = 80;
constexpr int FRAME_HEIGHT = 80;
Expand Down
16 changes: 4 additions & 12 deletions viewer/Hero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ void Hero::play(sf::Time elapsed) {

m_frame_timer += elapsed.asMilliseconds();

if (m_frame_timer >= DURATION || g_change_action) {
m_frame_timer = m_frame_timer % DURATION;
if (m_frame_timer >= FRAME_CYCLE || g_change_action) {
m_frame_timer = m_frame_timer % FRAME_CYCLE;
g_change_action = false;
step();
}
Expand Down Expand Up @@ -56,7 +56,7 @@ void Hero::move(bool move) noexcept {
}

void Hero::turn(int direction) {
g_direction = getTextureDirection(direction);
g_direction = direction;
}

void Hero::changeActor() {
Expand All @@ -82,18 +82,10 @@ int Hero::getCurrentFrame() const noexcept {
}

int Hero::getDirection() const {
return getScreenDirection(g_direction);
return g_direction;
}

sf::Vector2f Hero::getOffset() const {
const int direction = getDirection();
return VECTORS.at(direction) * SPEED;
}

constexpr int Hero::getScreenDirection(int direction) {
return (DIRECTIONS + INIT_DIRECTION - direction) % DIRECTIONS;
}

constexpr int Hero::getTextureDirection(int direction) {
return (DIRECTIONS + INIT_DIRECTION - direction) % DIRECTIONS;
}
5 changes: 1 addition & 4 deletions viewer/Hero.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
#include "../common/ActionManager.h"
#include "../common/ActorManager.h"

constexpr int INIT_DIRECTION = 6;
constexpr int FRAME_CYCLE = 100;
constexpr float SPEED = 2.0f;
constexpr int DURATION = 100;

class Hero : public Actor
{
Expand All @@ -31,8 +30,6 @@ class Hero : public Actor
sf::Vector2f getOffset() const override;

private:
static constexpr int getScreenDirection(int direction);
static constexpr int getTextureDirection(int direction);

static inline sf::Vector2f g_position = sf::Vector2f(INIT_WIDTH / 2, INIT_HEIGHT / 2);
static inline int g_frame_step = 0;
Expand Down
2 changes: 2 additions & 0 deletions viewer/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ constexpr int ACTOR_TYPES = 8;
constexpr int ACTIONS = 12;
constexpr int ROW_ACTIONS = ACTIONS;

constexpr int INIT_DIRECTION = 0;

constexpr int FRAME_WIDTH = 80;
constexpr int FRAME_HEIGHT = 80;
constexpr int ORIGIN_X = 39;
Expand Down

0 comments on commit a079969

Please sign in to comment.