#include #include "PlayerKam.h" #include "Globals.h" #include "Game.h" PlayerKam::PlayerKam(Framework::Bildschirm3D* zScreen) : Kam3D() { kameraControll = 0; setBildschirmPosition(0, 0); setBildschirmSize(zScreen->getBackBufferSize()); setStyle(Kam3D::Style::Tick | Kam3D::Style::Movable | Kam3D::Style::Rotatable); setRotation({ (float)PI / 2.f, 0, 0 }); entityId = -1; } void PlayerKam::setDirection(Framework::Vec3 direction) { if (direction.getLengthSq() > 0) { float rotZ = std::atan2(direction.y, direction.x) + (float)PI / 2; setRotation({ getRotation().x, getRotation().y, rotZ }); } } void PlayerKam::doTastaturEreignis(Framework::TastaturEreignis& te) { if (te.id == TE_Press) { if (te.taste >= '0' && te.taste <= '9') { char action[5]; action[0] = 3; *(int*)(action + 1) = te.taste - '1'; if (*(int*)(action + 1) < 0) *(int*)(action + 1) = 9; network->zFactoryClient()->sendPlayerAction(action, 5); } } if (te.id == TE_Release) { if (te.taste == T_Esc) { bool oldControl = kameraControll; kameraControll = 0; setShowCursor(true); if (!oldControl) ((Game*)(Menu*)menuRegister->get("game"))->closeCurrentDialog(); } if (te.taste == T_Tab) { char action = 4; network->zFactoryClient()->sendPlayerAction(&action, 1); } } } void PlayerKam::doMausEreignis(Framework::MausEreignis& me) { if (me.verarbeitet) { kameraControll = 0; setShowCursor(true); } else { if (!kameraControll) { if (me.id == ME_PLinks) setControlEnabled(1); } else { if (kameraControll) { if (me.id == ME_PLinks) { char action[2] = { 1, 8 }; network->zFactoryClient()->sendPlayerAction(action, 2); } if (me.id == ME_RLinks) { char action[2] = { 0, 8 }; network->zFactoryClient()->sendPlayerAction(action, 2); } if (me.id == ME_PRechts) { char action[2] = { 1, 9 }; network->zFactoryClient()->sendPlayerAction(action, 2); } if (me.id == ME_RRechts) { char action[2] = { 0, 9 }; network->zFactoryClient()->sendPlayerAction(action, 2); } } } me.verarbeitet = 1; } } bool PlayerKam::tick(double time) { __int64 style = 0; if (hatStyle(Style::Movable)) style |= Style::Movable; if (hatStyle(Style::Rotatable)) style |= Style::Rotatable; if (hatStyle(Style::Zoomable)) style |= Style::Zoomable; removeStyle(Style::Movable | Style::Rotatable | Style::Zoomable); bool result = Kam3D::tick(time); addStyle(style); if (kameraControll) { Punkt dir = window->getGröße() / 2 - (getMausPos() - window->getPosition()); setRotation({ min(max(getRotation().x - dir.y * (float)time * 0.2f, 0.1f), 2.5f), getRotation().y, getRotation().z - dir.x * (float)time * 0.2f }); if (getRotation().z > 2 * PI) setRotation({ getRotation().x, getRotation().y, getRotation().z - 2.f * (float)PI }); if (getRotation().z < -2 * PI) setRotation({ getRotation().x, getRotation().y, getRotation().z + 2.f * (float)PI }); SetCursorPos(window->getPosition().x + window->getKörperGröße().x / 2, window->getPosition().y + window->getKörperGröße().y / 2); setShowCursor(false); setMausPos(window->getPosition() + window->getGröße() / 2); } return result; } void PlayerKam::setEntityId(int id) { entityId = id; } void PlayerKam::setControlEnabled(bool enabled) { kameraControll = enabled; setShowCursor(!kameraControll); if (kameraControll) { SetCursorPos(window->getPosition().x + window->getKörperGröße().x / 2, window->getPosition().y + window->getKörperGröße().y / 2); } } int PlayerKam::getEntityId() const { return entityId; } Framework::Vec3 PlayerKam::getDirection() const { return getWorldDirection(getScreenPos() + getScreenSize() / 2); }