Let Character store a pointer to the world.
It's going to be needed for collision testing.
This commit is contained in:
parent
2062d50775
commit
ab02e7ef58
4 changed files with 29 additions and 1 deletions
|
@ -20,6 +20,7 @@
|
|||
#include "character.hpp"
|
||||
#include "inputbag.hpp"
|
||||
#include "gameactions.hpp"
|
||||
#include "worldgrid.hpp"
|
||||
#include <ciso646>
|
||||
#include <cassert>
|
||||
|
||||
|
@ -32,9 +33,11 @@ namespace curry {
|
|||
m_position(vec2f(0.0f), vec2f(0.0f), vec2f(0.0f)),
|
||||
m_width_height(0.0f),
|
||||
m_input_bag(parInputBag),
|
||||
m_world(parDeferredRegister.world()),
|
||||
m_speed(1.0f)
|
||||
{
|
||||
assert(m_input_bag);
|
||||
assert(m_world);
|
||||
}
|
||||
|
||||
void Character::load (const char* parTexturePath, cloonel::SDLMain& parSDLMain) {
|
||||
|
@ -95,7 +98,13 @@ namespace curry {
|
|||
offset.y() -= speed;
|
||||
if (cloonel::IsPressed(*m_input_bag, ActionDown))
|
||||
offset.y() += speed;
|
||||
this->set_position(this->position() + offset);
|
||||
|
||||
const auto old_pos = this->position();
|
||||
const auto new_pos = old_pos + offset;
|
||||
|
||||
//if (m_world
|
||||
|
||||
this->set_position(new_pos);
|
||||
}
|
||||
|
||||
void Character::set_speed (float parSpeed) {
|
||||
|
|
|
@ -32,6 +32,8 @@ namespace cloonel {
|
|||
} //namespace cloonel
|
||||
|
||||
namespace curry {
|
||||
class WorldGrid;
|
||||
|
||||
class Character : public WorldSizeNotifiable, public Moveable {
|
||||
public:
|
||||
Character (cloonel::InputBag* parInputBag, const WorldSizeNotifiable::DeferredRegister& parDeferredRegister);
|
||||
|
@ -54,6 +56,7 @@ namespace curry {
|
|||
Texture m_texture;
|
||||
vec2f m_width_height;
|
||||
cloonel::InputBag* m_input_bag;
|
||||
WorldGrid* m_world;
|
||||
float m_speed;
|
||||
};
|
||||
} //namespace curry
|
||||
|
|
|
@ -121,4 +121,18 @@ namespace curry {
|
|||
vec2i world_size_pixel (const WorldGrid& parWorld) {
|
||||
return parWorld.tile_size() * parWorld.world_size();
|
||||
}
|
||||
|
||||
vec2us pixel_to_world_tile (const WorldGrid& parWorld, const vec2i& parPos) {
|
||||
assert(position_is_on_map(parWorld, parPos));
|
||||
return vector_cast<vec2us>(
|
||||
parPos / vector_cast<vec2i>(parWorld.tile_size())
|
||||
);
|
||||
}
|
||||
|
||||
bool position_is_on_map (const WorldGrid& parWorld, const vec2i& parPos) {
|
||||
assert(parWorld.tile_size() > vec2us(0));
|
||||
|
||||
return parPos >= vec2i(0) and
|
||||
parPos / vector_cast<vec2i>(parWorld.tile_size()) < parWorld.world_size();
|
||||
}
|
||||
} //namespace curry
|
||||
|
|
|
@ -57,4 +57,6 @@ namespace curry {
|
|||
};
|
||||
|
||||
vec2i world_size_pixel (const WorldGrid& parWorld);
|
||||
vec2us pixel_to_world_tile (const WorldGrid& parWorld, const vec2i& parPos);
|
||||
bool position_is_on_map (const WorldGrid& parWorld, const vec2i& parPos);
|
||||
} //namespace curry
|
||||
|
|
Loading…
Reference in a new issue