diff --git a/client/character_data.cpp b/client/character_data.cpp new file mode 100644 index 0000000..81e4c75 --- /dev/null +++ b/client/character_data.cpp @@ -0,0 +1,61 @@ +/* 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) { + origin += motion * delta * CHARACTER_WALKING_MOD; + } + else if (motion != 0) { + origin += motion * delta; + } + sprite.Update(delta); +} + +void CharacterData::DrawTo(SDL_Surface* const dest, int camX, int camY) { + sprite.DrawTo(dest, origin.x - camX, origin.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); + } +} diff --git a/client/character_data.hpp b/client/character_data.hpp new file mode 100644 index 0000000..ec8f12d --- /dev/null +++ b/client/character_data.hpp @@ -0,0 +1,71 @@ +/* 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. +*/ +#ifndef CHARACTERDATA_HPP_ +#define CHARACTERDATA_HPP_ + +//components +#include "character_defines.hpp" +#include "vector2.hpp" +#include "statistics.hpp" + +//graphics +#include "sprite_sheet.hpp" + +//std namespace +#include +#include + +//TODO: encapsulate this +struct CharacterData { + //metadata + int owner; + std::string handle; + std::string avatar; + + //members + SpriteSheet sprite; + + //world position + int roomIndex = 0; + Vector2 origin = {0.0,0.0}; + Vector2 motion = {0.0,0.0}; + Vector2 bounds = {0.0,0.0}; + + //base statistics + Statistics stats; + + //TODO: gameplay components: equipment, items, buffs, debuffs + + //methods + void Update(double delta); + + void DrawTo(SDL_Surface* const, int camX, int camY); + void CorrectSprite(); + + //active gameplay members + //NOTE: these are lost when unloaded + bool inCombat = false; + int atbGauge = 0; + //TODO: stored command +}; + +#endif diff --git a/client/makefile b/client/makefile index 947b822..9a2a0ca 100644 --- a/client/makefile +++ b/client/makefile @@ -1,7 +1,7 @@ #config INCLUDES+=. ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet ../common/network/serial ../common/ui ../common/utilities LIBS+=../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua -CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) -DGRAPHICS +CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) #source CXXSRC=$(wildcard *.cpp) diff --git a/common/gameplay/character_defines.hpp b/common/gameplay/character_defines.hpp new file mode 100644 index 0000000..76d80c9 --- /dev/null +++ b/common/gameplay/character_defines.hpp @@ -0,0 +1,33 @@ +/* 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. +*/ +#ifndef CHARACTERDEFINES_HPP_ +#define CHARACTERDEFINES_HPP_ + +//the speeds that the characters move +constexpr double CHARACTER_WALKING_SPEED = 140.0; +constexpr double CHARACTER_WALKING_MOD = 1.0/sqrt(2.0); + +//the bounding boxes for the characters +constexpr double CHARACTER_BOUNDS_WIDTH = 32.0; +constexpr double CHARACTER_BOUNDS_HEIGHT = 32.0; + +#endif diff --git a/common/gameplay/sanity_check.cpp b/common/gameplay/combat_defines.hpp similarity index 72% rename from common/gameplay/sanity_check.cpp rename to common/gameplay/combat_defines.hpp index 8669811..0771561 100644 --- a/common/gameplay/sanity_check.cpp +++ b/common/gameplay/combat_defines.hpp @@ -19,13 +19,15 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#include "character_data.hpp" -#include "combat_data.hpp" -#include "enemy_data.hpp" -#include "statistics.hpp" +#ifndef COMBATDEFINES_HPP_ +#define COMBATDEFINES_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. -*/ \ No newline at end of file +#define COMBAT_MAX_CHARACTERS 16 +#define COMBAT_MAX_ENEMIES 16 + +enum class TerrainType { + NONE = 0, + GRASSLANDS, +}; + +#endif diff --git a/common/gameplay/makefile b/common/gameplay/makefile index 3be52be..9013447 100644 --- a/common/gameplay/makefile +++ b/common/gameplay/makefile @@ -1,7 +1,7 @@ #config -INCLUDES+=. ../utilities ../graphics +INCLUDES+=. LIBS+= -CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) -DGRAPHICS +CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) #source CXXSRC=$(wildcard *.cpp) diff --git a/common/network/packet/combat_packet.hpp b/common/network/packet/combat_packet.hpp index ea27e8f..6b068df 100644 --- a/common/network/packet/combat_packet.hpp +++ b/common/network/packet/combat_packet.hpp @@ -24,13 +24,13 @@ #include "serial_packet_base.hpp" -#include "combat_data.hpp" +#include "combat_defines.hpp" struct CombatPacket : SerialPacketBase { //identify the combat instance int combatIndex; int difficulty; - CombatData::Terrain terrainType; + TerrainType terrainType; //combatants int characterArray[COMBAT_MAX_CHARACTERS]; diff --git a/common/network/serial/serial_combat.cpp b/common/network/serial/serial_combat.cpp index 268d580..318779f 100644 --- a/common/network/serial/serial_combat.cpp +++ b/common/network/serial/serial_combat.cpp @@ -29,7 +29,7 @@ void serializeCombat(CombatPacket* packet, void* buffer) { //identify the combat instance SERIALIZE(buffer, &packet->combatIndex, sizeof(int)); SERIALIZE(buffer, &packet->difficulty, sizeof(int)); - SERIALIZE(buffer, &packet->terrainType, sizeof(CombatData::Terrain)); + SERIALIZE(buffer, &packet->terrainType, sizeof(TerrainType)); //combatants SERIALIZE(buffer, &packet->characterArray, sizeof(int) * COMBAT_MAX_CHARACTERS); @@ -49,7 +49,7 @@ void deserializeCombat(CombatPacket* packet, void* buffer) { //identify the combat instance DESERIALIZE(buffer, &packet->combatIndex, sizeof(int)); DESERIALIZE(buffer, &packet->difficulty, sizeof(int)); - DESERIALIZE(buffer, &packet->terrainType, sizeof(CombatData::Terrain)); + DESERIALIZE(buffer, &packet->terrainType, sizeof(TerrainType)); //combatants DESERIALIZE(buffer, &packet->characterArray, sizeof(int) * COMBAT_MAX_CHARACTERS); diff --git a/common/gameplay/character_data.cpp b/server/characters/character_data.cpp similarity index 100% rename from common/gameplay/character_data.cpp rename to server/characters/character_data.cpp diff --git a/common/gameplay/character_data.hpp b/server/characters/character_data.hpp similarity index 100% rename from common/gameplay/character_data.hpp rename to server/characters/character_data.hpp diff --git a/common/gameplay/combat_data.hpp b/server/combat/combat_data.hpp similarity index 84% rename from common/gameplay/combat_data.hpp rename to server/combat/combat_data.hpp index b170e5f..683e66f 100644 --- a/common/gameplay/combat_data.hpp +++ b/server/combat/combat_data.hpp @@ -23,31 +23,18 @@ #define COMBATDATA_HPP_ #include "vector2.hpp" +#include "combat_defines.hpp" //gameplay members #include "character_data.hpp" #include "enemy_data.hpp" -//graphics -#ifdef GRAPHICS - #include "sprite_sheet.hpp" -#endif - //std namespace #include #include #include -#define COMBAT_MAX_CHARACTERS 12 -#define COMBAT_MAX_ENEMIES 12 - struct CombatData { - enum class Terrain { - //TODO: types of combat terrains - NONE = 0, - GRASSLANDS, - }; - typedef std::chrono::steady_clock Clock; std::array characterArray; @@ -60,11 +47,6 @@ struct CombatData { //time interval Clock::time_point lastTick = Clock::now(); - - //graphics -#ifdef GRAPHICS - SpriteSheet sprite; -#endif }; #endif diff --git a/common/gameplay/enemy_data.hpp b/server/enemies/enemy_data.hpp similarity index 88% rename from common/gameplay/enemy_data.hpp rename to server/enemies/enemy_data.hpp index 533add6..ab1ef89 100644 --- a/common/gameplay/enemy_data.hpp +++ b/server/enemies/enemy_data.hpp @@ -25,11 +25,6 @@ #include "vector2.hpp" #include "statistics.hpp" -//graphics -#ifdef GRAPHICS - #include "sprite_sheet.hpp" -#endif - //std namespace #include @@ -45,11 +40,6 @@ struct EnemyData { //active gameplay members //NOTE: these are lost when unloaded -#ifdef GRAPHICS - SpriteSheet sprite; - Vector2 origin = {0.0,0.0}; - Vector2 bounds = {0.0,0.0}; -#endif int tableIndex; int atbGauge = 0; };