PlayerKam.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #include "PlayerKam.h"
  2. #include "Globals.h"
  3. PlayerKam::PlayerKam( Framework::Bildschirm3D* zScreen )
  4. : Kam3D()
  5. {
  6. setBildschirmPosition( 0, 0 );
  7. setBildschirmSize( zScreen->getBackBufferSize() );
  8. setStyle( Kam3D::Style::Tick | Kam3D::Style::Movable | Kam3D::Style::Rotatable );
  9. setRotation( { 0, 0, 0 } );
  10. }
  11. void PlayerKam::setDirection( Framework::Vec2<float> direction )
  12. {
  13. if( direction.getLengthSq() > 0 )
  14. {
  15. float rotZ = std::atan2( direction.y, direction.x ) + (float)PI / 2;
  16. setRotation( { (float)PI / 2.f, getRotation().y, rotZ } );
  17. }
  18. }
  19. void PlayerKam::doTastaturEreignis( Framework::TastaturEreignis& te )
  20. {
  21. char action[ 2 ];
  22. if( te.id == TE_Press )
  23. {
  24. action[ 0 ] = 1;
  25. if( te.taste == 'w' || te.taste == 'W' )
  26. {
  27. action[ 1 ] = 0;
  28. network->zFactoryClient()->sendPlayerAction( action, 2 );
  29. }
  30. if( te.taste == 'a' || te.taste == 'A' )
  31. {
  32. action[ 1 ] = 1;
  33. network->zFactoryClient()->sendPlayerAction( action, 2 );
  34. }
  35. if( te.taste == 's' || te.taste == 'S' )
  36. {
  37. action[ 1 ] = 2;
  38. network->zFactoryClient()->sendPlayerAction( action, 2 );
  39. }
  40. if( te.taste == 'd' || te.taste == 'D' )
  41. {
  42. action[ 1 ] = 3;
  43. network->zFactoryClient()->sendPlayerAction( action, 2 );
  44. }
  45. if( te.taste == T_Shift )
  46. {
  47. action[ 1 ] = 4;
  48. network->zFactoryClient()->sendPlayerAction( action, 2 );
  49. }
  50. if( te.taste == 'q' || te.taste == 'Q' )
  51. {
  52. action[ 1 ] = 5;
  53. network->zFactoryClient()->sendPlayerAction( action, 2 );
  54. }
  55. if( te.taste == 'e' || te.taste == 'E' )
  56. {
  57. action[ 1 ] = 6;
  58. network->zFactoryClient()->sendPlayerAction( action, 2 );
  59. }
  60. if( te.taste == T_Space )
  61. {
  62. action[ 1 ] = 7;
  63. network->zFactoryClient()->sendPlayerAction( action, 2 );
  64. }
  65. }
  66. if( te.id == TE_Release )
  67. {
  68. action[ 0 ] = 0;
  69. if( te.taste == 'w' || te.taste == 'W' )
  70. {
  71. action[ 1 ] = 0;
  72. network->zFactoryClient()->sendPlayerAction( action, 2 );
  73. }
  74. if( te.taste == 'a' || te.taste == 'A' )
  75. {
  76. action[ 1 ] = 1;
  77. network->zFactoryClient()->sendPlayerAction( action, 2 );
  78. }
  79. if( te.taste == 's' || te.taste == 'S' )
  80. {
  81. action[ 1 ] = 2;
  82. network->zFactoryClient()->sendPlayerAction( action, 2 );
  83. }
  84. if( te.taste == 'd' || te.taste == 'D' )
  85. {
  86. action[ 1 ] = 3;
  87. network->zFactoryClient()->sendPlayerAction( action, 2 );
  88. }
  89. if( te.taste == T_Shift )
  90. {
  91. action[ 1 ] = 4;
  92. network->zFactoryClient()->sendPlayerAction( action, 2 );
  93. }
  94. if( te.taste == 'q' || te.taste == 'Q' )
  95. {
  96. action[ 1 ] = 5;
  97. network->zFactoryClient()->sendPlayerAction( action, 2 );
  98. }
  99. if( te.taste == 'e' || te.taste == 'E' )
  100. {
  101. action[ 1 ] = 6;
  102. network->zFactoryClient()->sendPlayerAction( action, 2 );
  103. }
  104. if( te.taste == T_Space )
  105. {
  106. action[ 1 ] = 7;
  107. network->zFactoryClient()->sendPlayerAction( action, 2 );
  108. }
  109. }
  110. }
  111. void PlayerKam::doMausEreignis( Framework::MausEreignis& me )
  112. {
  113. }
  114. bool PlayerKam::tick( double time )
  115. {
  116. __int64 style = 0;
  117. if( hatStyle( Style::Movable ) )
  118. style |= Style::Movable;
  119. if( hatStyle( Style::Rotatable ) )
  120. style |= Style::Rotatable;
  121. if( hatStyle( Style::Zoomable ) )
  122. style |= Style::Zoomable;
  123. removeStyle( Style::Movable | Style::Rotatable | Style::Zoomable );
  124. bool result = Kam3D::tick( time );
  125. addStyle( style );
  126. return result;
  127. }