Use the new vector class wherever possible.
This commit is contained in:
parent
e2e932358b
commit
abee07a844
5 changed files with 18 additions and 16 deletions
12
src/game.cpp
12
src/game.cpp
|
@ -10,8 +10,7 @@ namespace cloonel {
|
|||
Game::Game (SDLMain* parSdlMain) :
|
||||
GameBase(parSdlMain),
|
||||
m_character(nullptr),
|
||||
m_posx(0.0f),
|
||||
m_posy(0.0f)
|
||||
m_pos(0.0f)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -35,15 +34,14 @@ namespace cloonel {
|
|||
///------------------------------------------------------------------------
|
||||
///------------------------------------------------------------------------
|
||||
void Game::OnRender() {
|
||||
const int posx = static_cast<int>(m_posx + 0.5f);
|
||||
const int posy = static_cast<int>(m_posy + 0.5f);
|
||||
m_character->Render(posx, posy);
|
||||
const int2 newPos(static_cast<int2>(m_pos + 0.5f));
|
||||
m_character->Render(newPos);
|
||||
}
|
||||
|
||||
///------------------------------------------------------------------------
|
||||
///------------------------------------------------------------------------
|
||||
void Game::OnUpdate (float parDelta) {
|
||||
m_posx += parDelta * 15.0f;
|
||||
m_posy += parDelta * 22.8f;
|
||||
const float2 increase(parDelta * 15.0f, parDelta * 22.8f);
|
||||
m_pos += increase;
|
||||
}
|
||||
} //namespace cloonel
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define id0E85DAFBFF5D497E8B3699AED806840A
|
||||
|
||||
#include "gamebase.hpp"
|
||||
#include "vector.hpp"
|
||||
#include <memory>
|
||||
|
||||
namespace cloonel {
|
||||
|
@ -20,8 +21,7 @@ namespace cloonel {
|
|||
virtual void OnUpdate ( float parDelta );
|
||||
|
||||
std::unique_ptr<Texture> m_character;
|
||||
float m_posx;
|
||||
float m_posy;
|
||||
float2 m_pos;
|
||||
};
|
||||
} //namespace cloonel
|
||||
|
||||
|
|
|
@ -42,15 +42,18 @@ namespace cloonel {
|
|||
|
||||
m_texture = SDL_CreateTextureFromSurface(m_sdlmain->GetRenderer(), surf);
|
||||
SDL_FreeSurface(surf);
|
||||
if (m_texture)
|
||||
SDL_QueryTexture(m_texture, nullptr, nullptr, &m_width, &m_height);
|
||||
if (m_texture) {
|
||||
int width, height;
|
||||
SDL_QueryTexture(m_texture, nullptr, nullptr, &width, &height);
|
||||
m_size = int2(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
///------------------------------------------------------------------------
|
||||
///------------------------------------------------------------------------
|
||||
void Texture::Render (int parX, int parY) {
|
||||
void Texture::Render (const int2& parPos) {
|
||||
assert(IsLoaded());
|
||||
const SDL_Rect dest = { parX, parY, m_width, m_height };
|
||||
const SDL_Rect dest = { parPos.x(), parPos.y(), m_size.x(), m_size.y() };
|
||||
SDL_RenderCopy(m_sdlmain->GetRenderer(), m_texture, nullptr, &dest);
|
||||
}
|
||||
} //namespace cloonel
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef id0F37904CB7274575B7E9419E615DA250
|
||||
#define id0F37904CB7274575B7E9419E615DA250
|
||||
|
||||
#include "vector.hpp"
|
||||
#include <string>
|
||||
|
||||
struct SDL_Texture;
|
||||
|
@ -16,14 +17,13 @@ namespace cloonel {
|
|||
void Reload ( void );
|
||||
void Destroy ( void ) noexcept;
|
||||
bool IsLoaded ( void ) const { return nullptr != m_texture; }
|
||||
void Render ( int parX, int parY );
|
||||
void Render ( const int2& parPos );
|
||||
|
||||
private:
|
||||
const std::string m_path;
|
||||
SDL_Texture* m_texture;
|
||||
SDLMain* const m_sdlmain;
|
||||
int m_width;
|
||||
int m_height;
|
||||
ushort2 m_size;
|
||||
};
|
||||
} //namespace cloonel
|
||||
|
||||
|
|
|
@ -78,6 +78,7 @@ namespace cloonel {
|
|||
|
||||
typedef Vector<float, 2> float2;
|
||||
typedef Vector<uint16_t, 2> ushort2;
|
||||
typedef Vector<int32_t, 2> int2;
|
||||
} //namespace cloonel
|
||||
#include "vector.inl"
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue