Draw a test character to start experimenting.

This commit is contained in:
King_DuckZ 2016-11-09 01:46:10 +01:00
parent 4c105fc3df
commit e65c2341c2
5 changed files with 82 additions and 0 deletions

View file

@ -65,6 +65,7 @@ add_executable(${PROJECT_NAME}
src/tileiterator.cpp
src/texture.cpp
src/movingobject.cpp
src/character.cpp
)
target_include_directories(${PROJECT_NAME} SYSTEM

BIN
LPC_Sara_Preview.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

46
src/character.cpp Normal file
View file

@ -0,0 +1,46 @@
#include "character.hpp"
namespace curry {
Character::Character() :
m_position(0.0f)
{
}
void Character::load (const char* parTexturePath, cloonel::SDLMain& parSDLMain) {
m_texture.load(parTexturePath, parSDLMain);
}
void Character::unload() {
m_texture.unload();
}
void Character::set_position (const vec2f& parPos) {
m_position = parPos;
}
const vec2f& Character::position() const {
return m_position;
}
vec2us Character::width_height() const {
return m_texture.width_height();
}
Texture& Character::texture() {
return m_texture;
}
Rect<float> Character::destination_rect (const vec2f& parWorldPos) const {
return Rect<float>(
m_position - parWorldPos,
m_position - parWorldPos + vector_cast<vec2f>(width_height())
);
}
Rect<float> Character::source_rect() const {
return Rect<float>(
vec2f(0.0f),
vector_cast<vec2f>(width_height())
);
}
} //namespace curry

29
src/character.hpp Normal file
View file

@ -0,0 +1,29 @@
#pragma once
#include "texture.hpp"
#include "vector.hpp"
#include "rect.hpp"
namespace cloonel {
class SDLMain;
} //namespace cloonel
namespace curry {
class Character {
public:
Character();
void load (const char* parTexturePath, cloonel::SDLMain& parSDLMain);
void unload();
const vec2f& position() const;
void set_position (const vec2f& parPos);
vec2us width_height() const;
Texture& texture();
Rect<float> destination_rect (const vec2f& parWorldPos) const;
Rect<float> source_rect() const;
private:
Texture m_texture;
vec2f m_position;
};
} //namespace curry

View file

@ -8,6 +8,7 @@
#include "worldviewport.hpp"
#include "texture.hpp"
#include "rect.hpp"
#include "character.hpp"
#include "csvloader.hpp"
#include <SDL2/SDL.h>
#include <algorithm>
@ -39,6 +40,7 @@ namespace curry {
WorldViewport viewport;
Texture worldtiles;
MovingObject player;
Character character;
};
IngameScene::IngameScene (cloonel::SDLMain* parSDLMain) :
@ -71,6 +73,7 @@ namespace curry {
#endif
m_local_data->viewport.allow_overscan(false);
m_local_data->character.load(RESOURCES_PATH "LPC_Sara_Preview.png", *this->sdl_main());
}
void IngameScene::on_update (float parDeltaT) {
@ -92,6 +95,7 @@ namespace curry {
if (cloonel::IsPressed(input_bag(), ActionDown))
offset.y() += speed;
viewport.set_position(viewport.position() + offset);
m_local_data->character.set_position(m_local_data->character.position() + offset);
const auto tilesize(static_cast<vec2f>(world.tile_size()));
const auto tilecount(m_local_data->worldtiles.width_height() / world.tile_size());
@ -108,9 +112,11 @@ namespace curry {
this->draw_clipped(m_local_data->worldtiles, src_rect, dst_rect);
}
}
this->draw_clipped(m_local_data->character.texture(), m_local_data->character.source_rect(), m_local_data->character.destination_rect(viewport.position()));
}
void IngameScene::on_destroy() noexcept {
m_local_data->worldtiles.unload();
m_local_data->character.unload();
}
} //namespace curry