Skip to content

Commit

Permalink
Move direction to chirp
Browse files Browse the repository at this point in the history
  • Loading branch information
kraxarn committed May 19, 2024
1 parent b23348e commit 596a680
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 40 deletions.
9 changes: 5 additions & 4 deletions src/engine/animatedsprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ void ce::animated_sprite::rotate(float value)
void ce::animated_sprite::flip()
{
tileset->flip_horizontal();
dir = dir == direction::left
? direction::right
: direction::left;

dir = dir == chirp::direction::left
? chirp::direction::right
: chirp::direction::left;
}

auto ce::animated_sprite::width() const -> int
Expand Down Expand Up @@ -80,7 +81,7 @@ void ce::animated_sprite::resume()
running = true;
}

auto ce::animated_sprite::get_dir() const -> direction
auto ce::animated_sprite::get_dir() const -> chirp::direction
{
return dir;
}
Expand Down
6 changes: 3 additions & 3 deletions src/engine/animatedsprite.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once

#include "engine/movable.hpp"
#include "enum/direction.hpp"

#include <chirp/asset.hpp>
#include <chirp/direction.hpp>
#include <chirp/tileset.hpp>

#include "raylib.h"
Expand All @@ -26,7 +26,7 @@ namespace ce
void rotate(float value);

void flip();
auto get_dir() const -> direction;
auto get_dir() const -> chirp::direction;

auto width() const -> int;
auto height() const -> int;
Expand Down Expand Up @@ -64,6 +64,6 @@ namespace ce

chirp::asset<chirp::tileset> tileset;

direction dir = direction::left;
chirp::direction dir = chirp::direction::left;
};
}
20 changes: 10 additions & 10 deletions src/entity/boss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ void entity::boss::update(bool is_paused)
auto speed = get_speed();

auto x = dist.x() < static_cast<float>(width())
? 0.F : eq(dir, direction::left)
? 0.F : eq(dir, chirp::direction::left)
? -speed : speed;
auto y = lock_y || dist.y() < static_cast<float>(height())
? 0.F : eq(dir, direction::up)
? 0.F : eq(dir, chirp::direction::up)
? -speed : speed;
move(x, y);

// Flip if needed
if (x < 0 && get_dir() == direction::right
|| x > 0 && get_dir() == direction::left)
if (x < 0 && get_dir() == chirp::direction::right
|| x > 0 && get_dir() == chirp::direction::left)
{
flip();
}
Expand All @@ -46,18 +46,18 @@ void entity::boss::update(bool is_paused)
#endif
}

auto entity::boss::get_player_dirs() const -> direction
auto entity::boss::get_player_dirs() const -> chirp::direction
{
return static_cast<direction>(static_cast<unsigned short>(player.get_x() > get_x()
? direction::right : direction::left)
return static_cast<chirp::direction>(static_cast<unsigned short>(player.get_x() > get_x()
? chirp::direction::right : chirp::direction::left)
| static_cast<unsigned char>(player.get_y() > get_y()
? direction::down : direction::up));
? chirp::direction::down : chirp::direction::up));
}

auto entity::boss::eq(const direction &dir1, const direction &dir2) -> bool
auto entity::boss::eq(const chirp::direction &dir1, const chirp::direction &dir2) -> bool
{
return (static_cast<unsigned short>(dir1) & static_cast<unsigned short>(dir2))
!= static_cast<unsigned short>(direction::none);
!= static_cast<unsigned short>(chirp::direction::none);
}

auto entity::boss::get_player_dist() const -> chirp::vector2f
Expand Down
4 changes: 2 additions & 2 deletions src/entity/boss.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace entity
bool lock_y = false;

/** Get in what directions player is */
auto get_player_dirs() const -> direction;
auto get_player_dirs() const -> chirp::direction;

/** Get distance to player, always positive */
auto get_player_dist() const -> chirp::vector2f;
Expand All @@ -56,6 +56,6 @@ namespace entity

auto get_speed() const -> float;

static auto eq(const direction &dir1, const direction &dir2) -> bool;
static auto eq(const chirp::direction &dir1, const chirp::direction &dir2) -> bool;
};
}
6 changes: 3 additions & 3 deletions src/entity/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,16 @@ auto entity::player::is_grounded() const -> bool
return velocity.y() == 0;
}

auto entity::player::get_player_dir() const -> direction
auto entity::player::get_player_dir() const -> chirp::direction
{
if (velocity.x() < 0)
{
return direction::left;
return chirp::direction::left;
}

if (velocity.x() > 0)
{
return direction::right;
return chirp::direction::right;
}

return get_dir();
Expand Down
4 changes: 2 additions & 2 deletions src/entity/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#include "engine/animatedsprite.hpp"

#include "entity/hud.hpp"
#include "enum/direction.hpp"
#include "physics/collision.hpp"

#include <chirp/assets.hpp>
#include <chirp/direction.hpp>

namespace entity
{
Expand Down Expand Up @@ -45,6 +45,6 @@ namespace entity
chirp::asset<chirp::sound> snd_fall;

void update_collision(ce::level &level);
auto get_player_dir() const -> direction;
auto get_player_dir() const -> chirp::direction;
};
}
10 changes: 0 additions & 10 deletions src/enum/direction.hpp

This file was deleted.

8 changes: 4 additions & 4 deletions src/scene/scenemenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ scene_menu::scene_menu(const chirp::assets &assets)
// Arrow position
spr_arrow.set_x(76);
set_current(0);
arrow_dir = direction::right;
arrow_dir = chirp::direction::right;

// Menu sprite
reset_demo_position();
Expand Down Expand Up @@ -103,7 +103,7 @@ void scene_menu::render()
// Update arrow position
auto arrow_offset = std::abs(static_cast<float>(spr_arrow.get_x()) - 82.F);

if (arrow_dir == direction::left)
if (arrow_dir == chirp::direction::left)
{
spr_arrow.move(-0.5F - (arrow_offset / 10.F), 0);
}
Expand All @@ -114,11 +114,11 @@ void scene_menu::render()

if (spr_arrow.get_x() <= 64)
{
arrow_dir = direction::right;
arrow_dir = chirp::direction::right;
}
else if (spr_arrow.get_x() >= 82)
{
arrow_dir = direction::left;
arrow_dir = chirp::direction::left;
}

// Draw arrow
Expand Down
4 changes: 2 additions & 2 deletions src/scene/scenemenu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include "engine/animatedsprite.hpp"
#include "engine/scene.hpp"
#include "engine/sprite.hpp"
#include "enum/direction.hpp"

#include <chirp/direction.hpp>
#include <chirp/font.hpp>
#include <chirp/text.hpp>

Expand All @@ -26,7 +26,7 @@ class scene_menu: public ce::scene
#endif

ce::sprite spr_arrow;
direction arrow_dir;
chirp::direction arrow_dir;
int current = 0;

ce::animated_sprite spr_demo;
Expand Down

0 comments on commit 596a680

Please sign in to comment.