diff --git a/client/client_application.cpp b/client/client_application.cpp index 0f5e45e..cbf2f68 100644 --- a/client/client_application.cpp +++ b/client/client_application.cpp @@ -122,10 +122,10 @@ void ClientApplication::LoadScene(SceneList sceneIndex) { activeScene = new LobbyMenu(&config, &network, &clientIndex, &accountIndex, &characterIndex); break; case SceneList::INWORLD: - activeScene = new InWorld(&config, &network, &clientIndex, &accountIndex, &characterIndex); + activeScene = new InWorld(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap); break; case SceneList::INCOMBAT: - activeScene = new InCombat(&config, &network, &clientIndex, &accountIndex, &characterIndex); + activeScene = new InCombat(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap, &enemyMap); break; default: throw(std::logic_error("Failed to recognize the scene index")); diff --git a/client/client_application.hpp b/client/client_application.hpp index 46680bb..54df4ff 100644 --- a/client/client_application.hpp +++ b/client/client_application.hpp @@ -56,8 +56,8 @@ private: int accountIndex = -1; int characterIndex = -1; - std::map characterMap; std::map combatMap; + std::map characterMap; std::map enemyMap; }; diff --git a/client/in_combat.cpp b/client/in_combat.cpp index 243df51..c8321d5 100644 --- a/client/in_combat.cpp +++ b/client/in_combat.cpp @@ -30,13 +30,19 @@ InCombat::InCombat( UDPNetworkUtility* const argNetwork, int* const argClientIndex, int* const argAccountIndex, - int* const argCharacterIndex + int* const argCharacterIndex, + std::map* argCombatMap, + std::map* argCharacterMap, + std::map* argEnemyMap ): config(*argConfig), network(*argNetwork), clientIndex(*argClientIndex), accountIndex(*argAccountIndex), - characterIndex(*argCharacterIndex) + characterIndex(*argCharacterIndex), + combatMap(*argCombatMap), + characterMap(*argCharacterMap), + enemyMap(*argEnemyMap) { // } diff --git a/client/in_combat.hpp b/client/in_combat.hpp index 2bbc28f..dbd802b 100644 --- a/client/in_combat.hpp +++ b/client/in_combat.hpp @@ -36,6 +36,10 @@ #include "config_utility.hpp" #include "frame_rate.hpp" +#include "combat_data.hpp" +#include "character_data.hpp" +#include "enemy_data.hpp" + //client #include "base_scene.hpp" @@ -47,7 +51,10 @@ public: UDPNetworkUtility* const argNetwork, int* const argClientIndex, int* const argAccountIndex, - int* const argCharacterIndex + int* const argCharacterIndex, + std::map* argCombatMap, + std::map* argCharacterMap, + std::map* argEnemyMap ); ~InCombat(); @@ -84,6 +91,9 @@ protected: int& clientIndex; int& accountIndex; int& characterIndex; + std::map& combatMap; + std::map& characterMap; + std::map& enemyMap; //graphics //TODO: graphics diff --git a/client/in_world.cpp b/client/in_world.cpp index 8e2cc26..d43ad14 100644 --- a/client/in_world.cpp +++ b/client/in_world.cpp @@ -36,13 +36,17 @@ InWorld::InWorld( UDPNetworkUtility* const argNetwork, int* const argClientIndex, int* const argAccountIndex, - int* const argCharacterIndex + int* const argCharacterIndex, + std::map* argCombatMap, + std::map* argCharacterMap ): config(*argConfig), network(*argNetwork), clientIndex(*argClientIndex), accountIndex(*argAccountIndex), - characterIndex(*argCharacterIndex) + characterIndex(*argCharacterIndex), + combatMap(*argCombatMap), + characterMap(*argCharacterMap), { //setup the utility objects buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp"); @@ -108,14 +112,21 @@ void InWorld::Update(double delta) { //update the characters for (auto& it : playerCharacters) { - it.second.Update(delta); + if (it.second.motion.x && it.second.motion.y) { + //TODO: refactor this into a method + it.second.position += it.second.motion * CHARACTER_WALKING_SPEED * CHARACTER_WALKING_MOD; + } + else if (it.second.motion != 0) { + it.second.position += it.second.motion * CHARACTER_WALKING_SPEED; + } + //TODO: SPRITE: fix sprite } //TODO: sort the players and entities by Y position //update the camera if(localCharacter) { - camera.x = localCharacter->GetPosition().x - camera.marginX; - camera.y = localCharacter->GetPosition().y - camera.marginY; + camera.x = localCharacter->position.x - camera.marginX; + camera.y = localCharacter->position.y - camera.marginY; } //check the map @@ -327,8 +338,8 @@ void InWorld::HandleCharacterNew(SerialPacket packet) { camera.width = GetScreen()->w; camera.height = GetScreen()->h; //center on the player's character - camera.marginX = (GetScreen()->w / 2 - localCharacter->GetSprite()->GetImage()->GetClipW() / 2); - camera.marginY = (GetScreen()->h / 2 - localCharacter->GetSprite()->GetImage()->GetClipH() / 2); + camera.marginX = (GetScreen()->w / 2 - localCharacter->sprite->GetImage()->GetClipW() / 2); + camera.marginY = (GetScreen()->h / 2 - localCharacter->sprite->GetImage()->GetClipH() / 2); } } @@ -357,8 +368,8 @@ void InWorld::SendPlayerUpdate() { packet.characterInfo.clientIndex = clientIndex; packet.characterInfo.accountIndex = accountIndex; packet.characterInfo.characterIndex = characterIndex; - packet.characterInfo.position = localCharacter->GetPosition(); - packet.characterInfo.motion = localCharacter->GetMotion(); + packet.characterInfo.position = localCharacter->position; + packet.characterInfo.motion = localCharacter->motion; serialize(&packet, buffer); network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE); diff --git a/client/in_world.hpp b/client/in_world.hpp index 8b3c149..60a96a8 100644 --- a/client/in_world.hpp +++ b/client/in_world.hpp @@ -42,8 +42,8 @@ #include "config_utility.hpp" #include "frame_rate.hpp" -#include "character_data.hpp" #include "combat_data.hpp" +#include "character_data.hpp" //client #include "base_scene.hpp" @@ -59,7 +59,9 @@ public: UDPNetworkUtility* const argNetwork, int* const argClientIndex, int* const argAccountIndex, - int* const argCharacterIndex + int* const argCharacterIndex, + std::map* argCombatMap, + std::map* argCharacterMap ); ~InWorld(); @@ -102,6 +104,8 @@ protected: int& clientIndex; int& accountIndex; int& characterIndex; + std::map& combatMap; + std::map& characterMap; //graphics Image buttonImage;