PlayerKam.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #include "PlayerKam.h"
  2. #include <Globals.h>
  3. #include "Game.h"
  4. #include "Globals.h"
  5. PlayerKam::PlayerKam(Framework::Bildschirm3D* zScreen)
  6. : Kam3D()
  7. {
  8. kameraControll = 0;
  9. setBildschirmPosition(0, 0);
  10. setBildschirmSize(zScreen->getBackBufferSize());
  11. setStyle(
  12. Kam3D::Style::Tick | Kam3D::Style::Movable | Kam3D::Style::Rotatable);
  13. setRotation({(float)PI / 2.f, 0, 0});
  14. entityId = -1;
  15. }
  16. void PlayerKam::setDirection(Framework::Vec3<float> direction)
  17. {
  18. if (direction.getLengthSq() > 0)
  19. {
  20. float rotZ = std::atan2(direction.y, direction.x) + (float)PI / 2;
  21. setRotation({getRotation().x, getRotation().y, rotZ});
  22. }
  23. }
  24. void PlayerKam::doTastaturEreignis(Framework::TastaturEreignis& te)
  25. {
  26. if (te.id == TE_Press)
  27. {
  28. if (te.taste[0] >= '0' && te.taste[0] <= '9')
  29. {
  30. char action[5];
  31. action[0] = 3;
  32. *(int*)(action + 1) = te.taste[0] - '1';
  33. if (*(int*)(action + 1) < 0) *(int*)(action + 1) = 9;
  34. World::INSTANCE->zClient()->sendPlayerAction(action, 5);
  35. }
  36. }
  37. if (te.id == TE_Release)
  38. {
  39. if (te.virtualKey == T_Esc)
  40. {
  41. bool oldControl = kameraControll;
  42. kameraControll = 0;
  43. setShowCursor(true);
  44. if (!oldControl)
  45. ((Game*)(Menu*)menuRegister->get("game"))->closeCurrentDialog();
  46. }
  47. if (te.virtualKey == T_Tab)
  48. {
  49. char action = 4; // open inventory
  50. World::INSTANCE->zClient()->sendPlayerAction(&action, 1);
  51. }
  52. if (te.taste[0] == 'q')
  53. {
  54. char action = 9; // open quest dialog
  55. World::INSTANCE->zClient()->sendPlayerAction(&action, 1);
  56. }
  57. if (te.taste[0] == 'm')
  58. {
  59. ((Game*)(Menu*)menuRegister->get("game"))->zMap()->setVisibility(1);
  60. }
  61. }
  62. }
  63. void PlayerKam::doMausEreignis(Framework::MausEreignis& me)
  64. {
  65. if (me.verarbeitet && me.id != ME_RLinks && me.id != ME_RRechts)
  66. {
  67. kameraControll = 0;
  68. setShowCursor(true);
  69. }
  70. else
  71. {
  72. if (!kameraControll && me.id != ME_RLinks && me.id != ME_RRechts)
  73. {
  74. if (me.id == ME_PLinks) setControlEnabled(1);
  75. }
  76. else
  77. {
  78. if (kameraControll || me.id == ME_RLinks || me.id == ME_RRechts)
  79. {
  80. if (me.id == ME_PLinks)
  81. {
  82. char action[2] = {1, 8};
  83. World::INSTANCE->zClient()->sendPlayerAction(action, 2);
  84. }
  85. if (me.id == ME_RLinks)
  86. {
  87. char action[2] = {0, 8};
  88. World::INSTANCE->zClient()->sendPlayerAction(action, 2);
  89. }
  90. if (me.id == ME_PRechts)
  91. {
  92. char action[2] = {1, 9};
  93. World::INSTANCE->zClient()->sendPlayerAction(action, 2);
  94. }
  95. if (me.id == ME_RRechts)
  96. {
  97. char action[2] = {0, 9};
  98. World::INSTANCE->zClient()->sendPlayerAction(action, 2);
  99. }
  100. }
  101. }
  102. me.verarbeitet = 1;
  103. }
  104. }
  105. bool PlayerKam::tick(double time)
  106. {
  107. __int64 style = 0;
  108. if (hatStyle(Style::Movable)) style |= Style::Movable;
  109. if (hatStyle(Style::Rotatable)) style |= Style::Rotatable;
  110. if (hatStyle(Style::Zoomable)) style |= Style::Zoomable;
  111. removeStyle(Style::Movable | Style::Rotatable | Style::Zoomable);
  112. bool result = Kam3D::tick(time);
  113. addStyle(style);
  114. if (kameraControll)
  115. {
  116. Punkt dir
  117. = window->getGröße() / 2 - (getMausPos() - window->getPosition());
  118. setRotation(
  119. {min(max(getRotation().x - dir.y * (float)time * 0.2f, 0.4f), 3.1f),
  120. getRotation().y,
  121. getRotation().z - dir.x * (float)time * 0.2f});
  122. if (getRotation().z > 2 * PI)
  123. setRotation({getRotation().x,
  124. getRotation().y,
  125. getRotation().z - 2.f * (float)PI});
  126. if (getRotation().z < -2 * PI)
  127. setRotation({getRotation().x,
  128. getRotation().y,
  129. getRotation().z + 2.f * (float)PI});
  130. SetCursorPos(window->getPosition().x + window->getKörperGröße().x / 2,
  131. window->getPosition().y + window->getKörperGröße().y / 2);
  132. setShowCursor(false);
  133. setMausPos(window->getPosition() + window->getGröße() / 2);
  134. }
  135. return 1;
  136. }
  137. void PlayerKam::setEntityId(int id)
  138. {
  139. entityId = id;
  140. }
  141. void PlayerKam::setControlEnabled(bool enabled)
  142. {
  143. kameraControll = enabled;
  144. setShowCursor(!kameraControll);
  145. if (kameraControll)
  146. {
  147. SetCursorPos(window->getPosition().x + window->getKörperGröße().x / 2,
  148. window->getPosition().y + window->getKörperGröße().y / 2);
  149. }
  150. }
  151. int PlayerKam::getEntityId() const
  152. {
  153. return entityId;
  154. }
  155. Framework::Vec3<float> PlayerKam::getDirection() const
  156. {
  157. return getWorldDirection(getScreenPos() + getScreenSize() / 2);
  158. }