[Add] Added mutators for the x/y coordinates of a sprite.
[Add] Implemented Input methods and made a moveable entity.
This commit is contained in:
parent
e894dddcb7
commit
6241b32288
@ -1,7 +1,7 @@
|
||||
#include "Player.h"
|
||||
|
||||
Player::Player(void) {
|
||||
|
||||
PLAYER_SPEED = 15;
|
||||
}
|
||||
|
||||
Player::~Player(void) {
|
||||
@ -24,5 +24,22 @@ void Player::Render(void) {
|
||||
}
|
||||
|
||||
void Player::ProcessEvents(void) {
|
||||
|
||||
float x = _player->GetX();
|
||||
float y = _player->GetY();
|
||||
if(KeyStillDown(SDLK_w)) {
|
||||
y -= PLAYER_SPEED;
|
||||
_player->SetY(y);
|
||||
}
|
||||
if(KeyStillDown(SDLK_s)) {
|
||||
y += PLAYER_SPEED;
|
||||
_player->SetY(y);
|
||||
}
|
||||
if(KeyStillDown(SDLK_a)) {
|
||||
x -= PLAYER_SPEED;
|
||||
_player->SetX(x);
|
||||
}
|
||||
if(KeyStillDown(SDLK_d)) {
|
||||
x += PLAYER_SPEED;
|
||||
_player->SetX(x);
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ public:
|
||||
void ProcessEvents(void);
|
||||
|
||||
private:
|
||||
float PLAYER_SPEED;
|
||||
Sprite* _player;
|
||||
Texture* _playerTexture;
|
||||
float _rotationAngle;
|
||||
|
@ -52,6 +52,10 @@ void Game::Shutdown(void) {
|
||||
delete _player;
|
||||
}
|
||||
|
||||
void Game::ProcessEvents(void) {
|
||||
_player->ProcessEvents();
|
||||
}
|
||||
|
||||
void Game::OnResize(int width, int height) {
|
||||
glViewport(0, 0, width, height);
|
||||
|
||||
|
@ -6,16 +6,18 @@ class Sprite;
|
||||
|
||||
class Game {
|
||||
public:
|
||||
Game(void);
|
||||
~Game(void);
|
||||
Game(void);
|
||||
~Game(void);
|
||||
|
||||
bool Init(void);
|
||||
void Prepare(float dt);
|
||||
void Render(void);
|
||||
void Shutdown(void);
|
||||
bool Init(void);
|
||||
void Prepare(float dt);
|
||||
void Render(void);
|
||||
void Shutdown(void);
|
||||
|
||||
void OnResize(int width, int height);
|
||||
void ProcessEvents(void);
|
||||
|
||||
void OnResize(int width, int height);
|
||||
|
||||
private:
|
||||
Player* _player;
|
||||
Player* _player;
|
||||
};
|
||||
|
@ -13,11 +13,13 @@
|
||||
#include <GL/gl.h>
|
||||
#include <time.h>
|
||||
#include "Game.h"
|
||||
#include "../IO/Input.h"
|
||||
#include "../Global/Globals.h"
|
||||
#include "../Global/Constants.h"
|
||||
#include "../System/Debug.h"
|
||||
|
||||
void Destroy(void) {
|
||||
DestroyInput();
|
||||
SDL_FreeSurface(screen);
|
||||
SDL_Quit();
|
||||
}
|
||||
@ -77,12 +79,13 @@ int main(int argc, char** argv) {
|
||||
Debug::logger->message("\n ----- Logic -----");
|
||||
|
||||
game.Init();
|
||||
CreateInput();
|
||||
|
||||
bool isRunning = true;
|
||||
while(isRunning) {
|
||||
|
||||
while(SDL_PollEvent(&event)){
|
||||
if(event.type == SDL_QUIT) {
|
||||
while(SDL_PollEvent(&event)) {
|
||||
if((event.type == SDL_QUIT) || KeyStillDown(SDLK_ESCAPE)) {
|
||||
isRunning = false;
|
||||
break;
|
||||
}
|
||||
@ -93,6 +96,8 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
|
||||
UpdateInput();
|
||||
game.ProcessEvents();
|
||||
game.Render();
|
||||
SDL_GL_SwapBuffers();
|
||||
}
|
||||
|
@ -12,14 +12,18 @@ public:
|
||||
virtual void Update(float dt);
|
||||
virtual void Draw() const;
|
||||
|
||||
const Vec2& GetPosition() const { return position; }
|
||||
const Vec2& GetSize() const { return size; }
|
||||
const Vec2& GetScale() const { return scale; }
|
||||
float GetRotation() const { return rotation; }
|
||||
Texture* GetTexture() { return texture; }
|
||||
const Texture* GetTexture() const { return texture; }
|
||||
const Vec2& GetPosition() const { return position; }
|
||||
float GetX(void) { return position.x; }
|
||||
float GetY(void) { return position.y; }
|
||||
const Vec2& GetSize() const { return size; }
|
||||
const Vec2& GetScale() const { return scale; }
|
||||
float GetRotation() const { return rotation; }
|
||||
Texture* GetTexture() { return texture; }
|
||||
const Texture* GetTexture() const { return texture; }
|
||||
|
||||
void SetPosition(const Vec2& position) { this->position = position; }
|
||||
void SetPosition(const Vec2& position) { this->position = position; }
|
||||
void SetX(float xArg) { this->position.x = xArg; }
|
||||
void SetY(float yArg) { this->position.y = yArg; }
|
||||
void SetScale(const Vec2& scale) { this->scale = scale; }
|
||||
void SetRotation(float rotation) { this->rotation = rotation; }
|
||||
void SetTexture(Texture* texture);
|
||||
|
Loading…
Reference in New Issue
Block a user