From de6bd2d39557fe6ed3177c2f56dcee755fcb514d Mon Sep 17 00:00:00 2001 From: Rtch90 <ritchie.cunningham@protonmail.com> Date: Thu, 12 Apr 2012 18:55:13 +0100 Subject: [PATCH 1/3] [Add] Initial actor base class. --- LibDQt/LibDQt.pro | 6 ++++-- src/Actor/Actor.cpp | 9 +++++++++ src/Actor/Actor.h | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 src/Actor/Actor.cpp create mode 100644 src/Actor/Actor.h 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..e5b79b5 --- /dev/null +++ b/src/Actor/Actor.cpp @@ -0,0 +1,9 @@ +#include "Actor.h" + +Actor::Actor(void) : VELOCITY(10.0f) { + +} + +Actor::~Actor(void) { + +} diff --git a/src/Actor/Actor.h b/src/Actor/Actor.h new file mode 100644 index 0000000..30bc2e9 --- /dev/null +++ b/src/Actor/Actor.h @@ -0,0 +1,34 @@ +#pragma once + +class Actor { +public: + enum State { + WALKING, + RUNNING, + ATTACKING, + }; + + enum Facing { + FRONT, + BACK, + LEFT, + RIGHT + }; + + Actor(void); + ~Actor(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; } + +private: + const float VELOCITY; + float x; + float y; + float w; + float h; +}; From 1997e82ee14565b22d52dfd27653cd5fe03493d9 Mon Sep 17 00:00:00 2001 From: Rtch90 <ritchie.cunningham@protonmail.com> Date: Thu, 12 Apr 2012 19:14:47 +0100 Subject: [PATCH 2/3] [Add] Adding some more method declarations to Actor.* --- src/Actor/Actor.cpp | 12 ++++++++++++ src/Actor/Actor.h | 21 ++++++++++++++++++++- src/Actor/Player.h | 17 ----------------- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/Actor/Actor.cpp b/src/Actor/Actor.cpp index e5b79b5..c5467e9 100644 --- a/src/Actor/Actor.cpp +++ b/src/Actor/Actor.cpp @@ -7,3 +7,15 @@ 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 index 30bc2e9..7c0b82b 100644 --- a/src/Actor/Actor.h +++ b/src/Actor/Actor.h @@ -1,4 +1,5 @@ #pragma once +#include "../Sprite/Sprite.h" class Actor { public: @@ -18,6 +19,10 @@ public: 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; } @@ -25,10 +30,24 @@ public: void SetXY(float xArg, float yArg) { x = xArg; y = yArg; } -private: + 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.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; }; From b2731c4cf5b7994b173db05f8f92dcff6fe988ef Mon Sep 17 00:00:00 2001 From: Rtch90 <ritchie.cunningham@protonmail.com> Date: Thu, 12 Apr 2012 19:18:29 +0100 Subject: [PATCH 3/3] [Add] Added arrow key movement, for those less capable of using wasd. --- src/Actor/Player.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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); }