Update snake example, remove some compiler warning
This commit is contained in:
parent
17b81c83cc
commit
6c28dba5dc
|
@ -6,6 +6,7 @@ out/*
|
|||
.idea/*
|
||||
cmake-build-cmake-build-w10-msvc-debug/*
|
||||
cmake-build-debug-wsl/*
|
||||
build/*
|
||||
|
||||
# Compiled source #
|
||||
###################
|
||||
|
|
|
@ -10,7 +10,7 @@ set(SFML_BUILD_GRAPHICS ON)
|
|||
set(SFML_BUILD_WINDOW ON)
|
||||
set(SFML_BUILD_SYSTEM ON)
|
||||
|
||||
find_package(SFML REQUIRED COMPONENTS system main window graphics audio)
|
||||
find_package(SFML 2 COMPONENTS system main window graphics audio REQUIRED)
|
||||
|
||||
# Link sources
|
||||
file(GLOB_RECURSE source_list src/*.cpp)
|
||||
|
@ -20,7 +20,8 @@ add_library(simpleengine STATIC ${source_list})
|
|||
target_include_directories(simpleengine PUBLIC include PRIVATE include/simpleengine)
|
||||
|
||||
# Link dependencies
|
||||
target_link_libraries(simpleengine PUBLIC sfml-system sfml-main sfml-window OpenGL sfml-network sfml-graphics Freetype OpenAL Vorbis FLAC sfml-audio)
|
||||
target_link_libraries(simpleengine PUBLIC sfml-system sfml-main sfml-window sfml-network sfml-graphics sfml-audio OpenGL Freetype OpenAL Vorbis FLAC)
|
||||
#target_link_libraries(simpleengine PUBLIC FLAC OpenAL OpenGL Vorbis)
|
||||
|
||||
# Add examples as a target if the user has them enabled
|
||||
if (BUILD_EXAMPLES)
|
||||
|
|
|
@ -31,10 +31,10 @@ public:
|
|||
texture.loadFromFile("player_sheet.png");
|
||||
texture.setSmooth(true);
|
||||
sprite.setTexture(texture);
|
||||
sprite.setScale(.7, .7);
|
||||
sprite.setScale(0.7f, 0.7f);
|
||||
|
||||
move_anim_component = std::make_shared<simpleengine::SideScrollerMovementAnimationComponent>(*this, sprite,
|
||||
texture, movement_speed, 5, 1.1);
|
||||
texture, movement_speed, 5.f, 1.1f);
|
||||
move_anim_component->SetAnimation(simpleengine::MovementAnimationType::WALK_LEFT, 8, 0, 9,
|
||||
9, 9, 128, 128);
|
||||
move_anim_component->SetAnimation(simpleengine::MovementAnimationType::IDLE_LEFT, 20, 0, 0,
|
||||
|
@ -43,7 +43,7 @@ public:
|
|||
AddComponent(move_anim_component);
|
||||
|
||||
hitbox_component = std::make_shared<simpleengine::HitboxComponent>(*this, sprite,
|
||||
20, 12, sprite.getGlobalBounds().width - 40, sprite.getGlobalBounds().height - 15);
|
||||
20.f, 12.f, sprite.getGlobalBounds().width - 40.f, sprite.getGlobalBounds().height - 15.f);
|
||||
AddComponent(hitbox_component);
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
movement_direction.y = movement_speed;
|
||||
}
|
||||
|
||||
int duration = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - last_movement).count();
|
||||
long long duration = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - last_movement).count();
|
||||
|
||||
if (duration >= 115 && (movement_direction.x != 0 || movement_direction.y != 0)) {
|
||||
owning_entity.Move(delta_time, movement_direction.x, movement_direction.y);
|
||||
|
@ -58,12 +58,15 @@ private:
|
|||
sf::RectangleShape shape;
|
||||
float movement_speed = 15;
|
||||
sf::Vector2u window_size;
|
||||
|
||||
std::shared_ptr<SnakeMovementComponent> movement_component;
|
||||
public:
|
||||
explicit SnakePlayerEntity(sf::Vector2u window_size) : window_size(window_size) {
|
||||
explicit SnakePlayerEntity(sf::Vector2u window_size) : Entity(shape), window_size(window_size) {
|
||||
shape = sf::RectangleShape(sf::Vector2f(15, 15));
|
||||
shape.setFillColor(sf::Color::White);
|
||||
|
||||
AddComponent(std::make_unique<SnakeMovementComponent>(*this, movement_speed));
|
||||
movement_component = std::make_shared<SnakeMovementComponent>(*this, movement_speed);
|
||||
AddComponent(movement_component);
|
||||
}
|
||||
|
||||
~SnakePlayerEntity() override {
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace simpleengine {
|
|||
friend class Game;
|
||||
friend class Event;
|
||||
public:
|
||||
explicit Entity(sf::Sprite& sprite);
|
||||
explicit Entity(sf::Transformable& transformable);
|
||||
virtual ~Entity() = default;
|
||||
Entity(const Entity& entity) = delete;
|
||||
|
||||
|
@ -35,7 +35,7 @@ namespace simpleengine {
|
|||
virtual void Update(const float& delta_time);
|
||||
|
||||
// Called when the entity is about to be destroyed.
|
||||
// Make sure to call this in your extending Entity.
|
||||
// Make sure to implment this in your extending Entity.
|
||||
virtual void Destroying();
|
||||
void DestroyLater(); // In most cases, this will be ran next EntityEvent::Update()
|
||||
const bool& IsGettingDestroyed() const;
|
||||
|
@ -63,9 +63,11 @@ namespace simpleengine {
|
|||
components.push_back(component);
|
||||
}
|
||||
|
||||
sf::Sprite& GetSprite();
|
||||
inline sf::Transformable& GetTransformable() {
|
||||
return transformable;
|
||||
}
|
||||
protected:
|
||||
sf::Sprite& sprite;
|
||||
sf::Transformable& transformable;
|
||||
std::vector<std::shared_ptr<Component>> components;
|
||||
bool destroying = false;
|
||||
};
|
||||
|
|
|
@ -7,20 +7,20 @@
|
|||
#include "entity.h"
|
||||
#include "component.h"
|
||||
|
||||
simpleengine::Entity::Entity(sf::Sprite &sprite) : sprite(sprite) {
|
||||
simpleengine::Entity::Entity(sf::Transformable &transformable) : transformable(transformable) {
|
||||
|
||||
}
|
||||
|
||||
void simpleengine::Entity::Move(const float &delta_time, const float &dir_x, const float &dir_y) {
|
||||
sprite.setPosition(dir_x * delta_time, dir_y * delta_time);
|
||||
transformable.setPosition(dir_x * delta_time, dir_y * delta_time);
|
||||
}
|
||||
|
||||
void simpleengine::Entity::Move(const float &delta_time, const sf::Vector2f &offset) {
|
||||
sprite.move(offset * delta_time);
|
||||
transformable.move(offset * delta_time);
|
||||
}
|
||||
|
||||
void simpleengine::Entity::Move(const sf::Vector2f &offset) {
|
||||
sprite.move(offset);
|
||||
transformable.move(offset);
|
||||
}
|
||||
|
||||
void simpleengine::Entity::Render(sf::RenderTarget *target) {
|
||||
|
@ -60,7 +60,3 @@ void simpleengine::Entity::DestroyLater() {
|
|||
const bool &simpleengine::Entity::IsGettingDestroyed() const {
|
||||
return destroying;
|
||||
}
|
||||
|
||||
sf::Sprite &simpleengine::Entity::GetSprite() {
|
||||
return sprite;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue