Use the new vector class wherever possible.

This commit is contained in:
King_DuckZ 2014-02-10 01:20:16 +01:00
parent e2e932358b
commit abee07a844
5 changed files with 18 additions and 16 deletions

View file

@ -10,8 +10,7 @@ namespace cloonel {
Game::Game (SDLMain* parSdlMain) : Game::Game (SDLMain* parSdlMain) :
GameBase(parSdlMain), GameBase(parSdlMain),
m_character(nullptr), m_character(nullptr),
m_posx(0.0f), m_pos(0.0f)
m_posy(0.0f)
{ {
} }
@ -35,15 +34,14 @@ namespace cloonel {
///------------------------------------------------------------------------ ///------------------------------------------------------------------------
///------------------------------------------------------------------------ ///------------------------------------------------------------------------
void Game::OnRender() { void Game::OnRender() {
const int posx = static_cast<int>(m_posx + 0.5f); const int2 newPos(static_cast<int2>(m_pos + 0.5f));
const int posy = static_cast<int>(m_posy + 0.5f); m_character->Render(newPos);
m_character->Render(posx, posy);
} }
///------------------------------------------------------------------------ ///------------------------------------------------------------------------
///------------------------------------------------------------------------ ///------------------------------------------------------------------------
void Game::OnUpdate (float parDelta) { void Game::OnUpdate (float parDelta) {
m_posx += parDelta * 15.0f; const float2 increase(parDelta * 15.0f, parDelta * 22.8f);
m_posy += parDelta * 22.8f; m_pos += increase;
} }
} //namespace cloonel } //namespace cloonel

View file

@ -2,6 +2,7 @@
#define id0E85DAFBFF5D497E8B3699AED806840A #define id0E85DAFBFF5D497E8B3699AED806840A
#include "gamebase.hpp" #include "gamebase.hpp"
#include "vector.hpp"
#include <memory> #include <memory>
namespace cloonel { namespace cloonel {
@ -20,8 +21,7 @@ namespace cloonel {
virtual void OnUpdate ( float parDelta ); virtual void OnUpdate ( float parDelta );
std::unique_ptr<Texture> m_character; std::unique_ptr<Texture> m_character;
float m_posx; float2 m_pos;
float m_posy;
}; };
} //namespace cloonel } //namespace cloonel

View file

@ -42,15 +42,18 @@ namespace cloonel {
m_texture = SDL_CreateTextureFromSurface(m_sdlmain->GetRenderer(), surf); m_texture = SDL_CreateTextureFromSurface(m_sdlmain->GetRenderer(), surf);
SDL_FreeSurface(surf); SDL_FreeSurface(surf);
if (m_texture) if (m_texture) {
SDL_QueryTexture(m_texture, nullptr, nullptr, &m_width, &m_height); 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()); 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); SDL_RenderCopy(m_sdlmain->GetRenderer(), m_texture, nullptr, &dest);
} }
} //namespace cloonel } //namespace cloonel

View file

@ -1,6 +1,7 @@
#ifndef id0F37904CB7274575B7E9419E615DA250 #ifndef id0F37904CB7274575B7E9419E615DA250
#define id0F37904CB7274575B7E9419E615DA250 #define id0F37904CB7274575B7E9419E615DA250
#include "vector.hpp"
#include <string> #include <string>
struct SDL_Texture; struct SDL_Texture;
@ -16,14 +17,13 @@ namespace cloonel {
void Reload ( void ); void Reload ( void );
void Destroy ( void ) noexcept; void Destroy ( void ) noexcept;
bool IsLoaded ( void ) const { return nullptr != m_texture; } bool IsLoaded ( void ) const { return nullptr != m_texture; }
void Render ( int parX, int parY ); void Render ( const int2& parPos );
private: private:
const std::string m_path; const std::string m_path;
SDL_Texture* m_texture; SDL_Texture* m_texture;
SDLMain* const m_sdlmain; SDLMain* const m_sdlmain;
int m_width; ushort2 m_size;
int m_height;
}; };
} //namespace cloonel } //namespace cloonel

View file

@ -78,6 +78,7 @@ namespace cloonel {
typedef Vector<float, 2> float2; typedef Vector<float, 2> float2;
typedef Vector<uint16_t, 2> ushort2; typedef Vector<uint16_t, 2> ushort2;
typedef Vector<int32_t, 2> int2;
} //namespace cloonel } //namespace cloonel
#include "vector.inl" #include "vector.inl"
#endif #endif