diff --git a/LibDQt/LibDQt.pro b/LibDQt/LibDQt.pro index b998845..acdf8a4 100644 --- a/LibDQt/LibDQt.pro +++ b/LibDQt/LibDQt.pro @@ -54,7 +54,8 @@ HEADERS += ../src/Actor/Player.h \ ../src/TMXParser/base64.h \ ../src/Collision/TileCollision.h \ ../src/Actor/NPC.h \ - ../src/Sound/SoundEffect.h + ../src/Sound/SoundEffect.h \ + ../src/Actor/Actor.h SOURCES += ../src/Actor/Player.cpp \ ../src/Collision/AABB.cpp \ ../src/Global/Globals.cpp \ @@ -85,5 +86,6 @@ SOURCES += ../src/Actor/Player.cpp \ ../src/TMXParser/TmxImage.cpp \ ../src/TMXParser/base64.cpp \ ../src/Actor/NPC.cpp \ - ../src/Sound/SoundEffect.cpp + ../src/Sound/SoundEffect.cpp \ + ../src/Actor/Actor.cpp OTHER_FILES += diff --git a/src/Actor/Actor.cpp b/src/Actor/Actor.cpp new file mode 100644 index 0000000..c5467e9 --- /dev/null +++ b/src/Actor/Actor.cpp @@ -0,0 +1,21 @@ +#include "Actor.h" + +Actor::Actor(void) : VELOCITY(10.0f) { + +} + +Actor::~Actor(void) { + +} + +void Actor::LoadSprite(const char* filename, float w, float h) { + +} + +void Actor::Update(void) { + +} + +void Actor::Render(void) { + _actor->Draw(); +} diff --git a/src/Actor/Actor.h b/src/Actor/Actor.h new file mode 100644 index 0000000..7c0b82b --- /dev/null +++ b/src/Actor/Actor.h @@ -0,0 +1,53 @@ +#pragma once +#include "../Sprite/Sprite.h" + +class Actor { +public: + enum State { + WALKING, + RUNNING, + ATTACKING, + }; + + enum Facing { + FRONT, + BACK, + LEFT, + RIGHT + }; + + Actor(void); + ~Actor(void); + + void LoadSprite(const char* filename, float w, float h); + void Update(void); + void Render(void); + + float GetX(void) { return x; } + float GetY(void) { return y; } + float GetWidth(void) { return w; } + float GetHeight(void) { return h; } + + void SetXY(float xArg, float yArg) { x = xArg; y = yArg; } + + int GetDirection(void) { return _direction; } + void SetDirection(int direction) { _direction = direction; } + +protected: + const float VELOCITY; + + int _direction; + + static const int ANIM_LEFT_FOOT = 0; + static const int ANIM_NO_FOOT = 1; + static const int ANIM_RIGHT_FOOT = 2; + static const int ANIM_ATTACK = 3; + +private: + float x; + float y; + float w; + float h; + + Sprite* _actor; +}; diff --git a/src/Actor/Player.cpp b/src/Actor/Player.cpp index be9e269..e4692be 100644 --- a/src/Actor/Player.cpp +++ b/src/Actor/Player.cpp @@ -33,19 +33,19 @@ void Player::Render(void) { void Player::ProcessEvents(void) { float oldX = x = _player->GetX(); float oldY = y = _player->GetY(); - if(KeyStillDown(SDLK_w)) { + if(KeyStillDown(SDLK_w) || KeyStillDown(SDLK_UP)) { y -= PLAYER_SPEED; _player->SetY(y); } - if(KeyStillDown(SDLK_s)) { + if(KeyStillDown(SDLK_s) || KeyStillDown(SDLK_DOWN)) { y += PLAYER_SPEED; _player->SetY(y); } - if(KeyStillDown(SDLK_a)) { + if(KeyStillDown(SDLK_a) || KeyStillDown(SDLK_LEFT)) { x -= PLAYER_SPEED; _player->SetX(x); } - if(KeyStillDown(SDLK_d)) { + if(KeyStillDown(SDLK_d) || KeyStillDown(SDLK_RIGHT)) { x += PLAYER_SPEED; _player->SetX(x); } diff --git a/src/Actor/Player.h b/src/Actor/Player.h index 6b86ba0..0054e4e 100644 --- a/src/Actor/Player.h +++ b/src/Actor/Player.h @@ -10,21 +10,6 @@ class SoundEffect; // We will derive from an Actor class at some point. class Player { public: - // Facing enum controls which spritr to render. - enum Facing { - LEFT, - RIGHT, - NONE - }; - - // Control the current state the character is in. - enum Status { - STANDING = 0, - WALKING, - HURT, - DEAD, - }; - Player(void); ~Player(void); @@ -47,8 +32,6 @@ private: Sprite* _player; float _rotationAngle; - Facing _preventMovement; - SoundEffect* _stepSFX[4]; int _lastStepSFXPlayed; };