Refactored some code from InWorld into methods in CharacterData
This commit is contained in:
@@ -83,7 +83,7 @@ protected:
|
||||
void SendPlayerUpdate();
|
||||
void RequestDisconnect();
|
||||
void RequestShutdown();
|
||||
//TOOD: more
|
||||
//TODO: more
|
||||
|
||||
//shared parameters
|
||||
ConfigUtility& config;
|
||||
|
||||
+4
-14
@@ -112,14 +112,7 @@ void InWorld::Update(double delta) {
|
||||
|
||||
//update the characters
|
||||
for (auto& it : characterMap) {
|
||||
if (it.second.motion.x && it.second.motion.y) {
|
||||
//TODO: refactor this into a method
|
||||
it.second.position += it.second.motion * delta * CHARACTER_WALKING_MOD;
|
||||
}
|
||||
else if (it.second.motion != 0) {
|
||||
it.second.position += it.second.motion * delta;
|
||||
}
|
||||
//TODO: SPRITE: fix sprite
|
||||
it.second.Update(delta);
|
||||
}
|
||||
//TODO: sort the players and entities by Y position
|
||||
|
||||
@@ -152,8 +145,7 @@ void InWorld::Render(SDL_Surface* const screen) {
|
||||
|
||||
//draw characters
|
||||
for (auto& it : characterMap) {
|
||||
//TODO: refactor this
|
||||
it.second.sprite.DrawTo(screen, it.second.position.x - camera.x, it.second.position.y - camera.y);
|
||||
it.second.DrawTo(screen, camera.x, camera.y);
|
||||
}
|
||||
|
||||
//draw UI
|
||||
@@ -316,8 +308,7 @@ void InWorld::HandleCharacterUpdate(SerialPacket packet) {
|
||||
characterMap[packet.characterInfo.characterIndex].position = packet.characterInfo.position;
|
||||
characterMap[packet.characterInfo.characterIndex].motion = packet.characterInfo.motion;
|
||||
}
|
||||
//TODO: refactor this
|
||||
// characterMap[packet.characterInfo.characterIndex].ResetDirection();
|
||||
characterMap[packet.characterInfo.characterIndex].CorrectSprite();
|
||||
}
|
||||
|
||||
void InWorld::HandleCharacterNew(SerialPacket packet) {
|
||||
@@ -330,8 +321,7 @@ void InWorld::HandleCharacterNew(SerialPacket packet) {
|
||||
characterMap[packet.characterInfo.characterIndex].sprite.LoadSurface(config["dir.sprites"] + packet.characterInfo.avatar, 4, 4);
|
||||
characterMap[packet.characterInfo.characterIndex].position = packet.characterInfo.position;
|
||||
characterMap[packet.characterInfo.characterIndex].motion = packet.characterInfo.motion;
|
||||
//TODO: refactor this
|
||||
// characterMap[packet.characterInfo.characterIndex].ResetDirection();
|
||||
characterMap[packet.characterInfo.characterIndex].CorrectSprite();
|
||||
|
||||
//catch this client's player object
|
||||
if (packet.characterInfo.characterIndex == characterIndex && !localCharacter) {
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "character_data.hpp"
|
||||
|
||||
void CharacterData::Update(double delta) {
|
||||
if (motion.x && motion.y) {
|
||||
position += motion * delta * CHARACTER_WALKING_MOD;
|
||||
}
|
||||
else if (motion != 0) {
|
||||
position += motion * delta;
|
||||
}
|
||||
#ifdef GRAPHICS
|
||||
sprite.Update(delta);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef GRAPHICS
|
||||
|
||||
void CharacterData::DrawTo(SDL_Surface* const dest, int camX, int camY) {
|
||||
sprite.DrawTo(dest, position.x - camX, position.y - camY);
|
||||
}
|
||||
|
||||
void CharacterData::CorrectSprite() {
|
||||
//NOTE: These must correspond to the sprite sheet in use
|
||||
if (motion.y > 0) {
|
||||
sprite.SetYIndex(0);
|
||||
}
|
||||
else if (motion.y < 0) {
|
||||
sprite.SetYIndex(1);
|
||||
}
|
||||
else if (motion.x > 0) {
|
||||
sprite.SetYIndex(3);
|
||||
}
|
||||
else if (motion.x < 0) {
|
||||
sprite.SetYIndex(2);
|
||||
}
|
||||
|
||||
//animation
|
||||
if (motion != 0) {
|
||||
sprite.SetDelay(0.1);
|
||||
}
|
||||
else {
|
||||
sprite.SetDelay(0);
|
||||
sprite.SetXIndex(0);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -59,6 +59,13 @@ struct CharacterData {
|
||||
//TODO: buffs
|
||||
//TODO: debuffs
|
||||
|
||||
//methods
|
||||
void Update(double delta);
|
||||
#ifdef GRAPHICS
|
||||
void DrawTo(SDL_Surface* const, int camX, int camY);
|
||||
void CorrectSprite();
|
||||
#endif
|
||||
|
||||
//active gameplay members
|
||||
//NOTE: these are lost when unloaded
|
||||
#ifdef GRAPHICS
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#config
|
||||
INCLUDES+=.
|
||||
INCLUDES+=. ../utilities ../graphics
|
||||
LIBS+=
|
||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) -DGRAPHICS
|
||||
|
||||
#source
|
||||
CXXSRC=$(wildcard *.cpp)
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
#include "account_data.hpp"
|
||||
#include "character_data.hpp"
|
||||
#include "client_data.hpp"
|
||||
#include "combat_data.hpp"
|
||||
#include "enemy_data.hpp"
|
||||
#include "statistics.hpp"
|
||||
|
||||
/* DOCS: Sanity check, read more
|
||||
* Since most/all of the files in this directory are header files, I've created
|
||||
* this source file as a "sanity check", to ensure that the above header files
|
||||
* are written correctly via make.
|
||||
*
|
||||
* Oddly enough, I'm pretty sure this is the first directory compiled in a
|
||||
* clean build.
|
||||
*/
|
||||
Reference in New Issue
Block a user