diff --git a/client/player_character.cpp b/client/player_character.cpp deleted file mode 100644 index 8e20c92..0000000 --- a/client/player_character.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013 - * - * 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 "player_character.hpp" - -#define WALKING_SPEED 140 - -void PlayerCharacter::Update(double delta) { - if (diagonal) { - constexpr double d = 1.0/sqrt(2); - position += motion * delta * d; - } - else { - position += motion * delta; - } - sprite.Update(delta); -} - -void PlayerCharacter::AdjustDirection(Direction direction) { - //shift the movement in this direction - switch(direction) { - case Direction::NORTH: - if (motion.y >= 0) { - motion.y -= WALKING_SPEED; - } - break; - case Direction::SOUTH: - if (motion.y <= 0) { - motion.y += WALKING_SPEED; - } - break; - case Direction::WEST: - if (motion.x >= 0) { - motion.x -= WALKING_SPEED; - } - break; - case Direction::EAST: - if (motion.x <= 0) { - motion.x += WALKING_SPEED; - } - break; - } - //face the correct direction - ResetDirection(); -} - -void PlayerCharacter::FaceDirection(Direction direction) { - //this function depends on the format of the sprite sheets - switch(direction) { - case Direction::NORTH: - sprite.SetYIndex(1); - break; - case Direction::SOUTH: - sprite.SetYIndex(0); - break; - case Direction::WEST: - sprite.SetYIndex(2); - break; - case Direction::EAST: - sprite.SetYIndex(3); - break; - } -} - -void PlayerCharacter::ResetDirection() { - //base the direction on the character's movement - if (motion.y > 0) { - FaceDirection(Direction::SOUTH); - } - else if (motion.y < 0) { - FaceDirection(Direction::NORTH); - } - else if (motion.x > 0) { - FaceDirection(Direction::EAST); - } - else if (motion.x < 0) { - FaceDirection(Direction::WEST); - } - ResetSpeed(); -} - -void PlayerCharacter::ResetSpeed() { - //diagonal - if (motion.x != 0 && motion.y != 0) { - sprite.SetDelay(0.1); - diagonal = true; - } - //cardinal - else if (motion != 0) { - sprite.SetDelay(0.1); - diagonal = false; - } - //not moving - else { - sprite.SetDelay(0); - sprite.SetXIndex(0); - diagonal = false; - } -} diff --git a/client/player_character.hpp b/client/player_character.hpp deleted file mode 100644 index 9dde742..0000000 --- a/client/player_character.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013 - * - * 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 PLAYERCHARACTER_HPP_ -#define PLAYERCHARACTER_HPP_ - -#include "vector2.hpp" -#include "sprite_sheet.hpp" - -//TODO: correct the PlayerCharacter class and it's movement system -class PlayerCharacter { -public: - enum class Direction { - NORTH, SOUTH, EAST, WEST - }; - - PlayerCharacter() = default; - ~PlayerCharacter() = default; - - void Update(double delta); - - void DrawTo(SDL_Surface* const dest, int camX, int camY) { sprite.DrawTo(dest, position.x - camX, position.y - camY); } - - //clunky code results in smooth movement and controls - void AdjustDirection(Direction); - void FaceDirection(Direction); - void ResetDirection(); - void ResetSpeed(); - - //accessors and mutators - Vector2 SetPosition(Vector2 v) { return position = v; } - Vector2 ShiftPosition(Vector2 v) { return position += v; } - Vector2 GetPosition() { return position; } - - Vector2 SetMotion(Vector2 v) { return motion = v; } - Vector2 ShiftMotion(Vector2 v) { return motion += v; } - Vector2 GetMotion() { return motion; } - - SpriteSheet* GetSprite() { return &sprite; } -private: - Vector2 position; - Vector2 motion; - SpriteSheet sprite; - - //for moving diagonally - bool diagonal = false; -}; - -#endif diff --git a/client/scenes/in_world.hpp b/client/scenes/in_world.hpp index 74fb233..d0c7047 100644 --- a/client/scenes/in_world.hpp +++ b/client/scenes/in_world.hpp @@ -44,7 +44,6 @@ //client #include "base_scene.hpp" -#include "player_character.hpp" #include "shared_parameters.hpp" //STL @@ -98,6 +97,7 @@ protected: Image buttonImage; RasterFont font; TileSheet tileSheet; + //TODO: sprites //map RegionPager regionPager; @@ -114,7 +114,6 @@ protected: FrameRate fps; //game - std::map playerCharacters; PlayerCharacter* localCharacter = nullptr; }; diff --git a/client/shared_parameters.hpp b/client/shared_parameters.hpp index 5963789..3a38a9c 100644 --- a/client/shared_parameters.hpp +++ b/client/shared_parameters.hpp @@ -22,10 +22,19 @@ #ifndef SHAREDPARAMETERS_HPP_ #define SHAREDPARAMETERS_HPP_ +#include "character_data.hpp" +#include "enemy_data.hpp" + +#include + struct SharedParameters { int clientIndex = -1; int accountIndex = -1; int characterIndex = -1; + + std::map characterMap; + std::map combatMap; + std::map enemyMap; }; #endif diff --git a/common/gameplay/character_data.hpp b/common/gameplay/character_data.hpp index 642c34a..8d75293 100644 --- a/common/gameplay/character_data.hpp +++ b/common/gameplay/character_data.hpp @@ -31,7 +31,7 @@ #include //the speeds that the characters move -constexpr double CHARACTER_WALKING_SPEED = 140; +constexpr double CHARACTER_WALKING_SPEED = 140.0; constexpr double CHARACTER_WALKING_MOD = 1.0/sqrt(2.0); struct CharacterData {