Merge branch 'master' of github.com:Allanis/LibD
This commit is contained in:
commit
0a0dbd18c3
@ -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 +=
|
||||
|
21
src/Actor/Actor.cpp
Normal file
21
src/Actor/Actor.cpp
Normal file
@ -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();
|
||||
}
|
53
src/Actor/Actor.h
Normal file
53
src/Actor/Actor.h
Normal file
@ -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;
|
||||
};
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user