Bez popisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bug.cpp 979B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "bug.h"
  2. #include "debuggers.h"
  3. #include <iostream>
  4. #include <random>
  5. namespace pabloader {
  6. Bug::Bug(Debuggers* game)
  7. : Entity(game)
  8. {
  9. w = game->enemiesSprite.width / 4;
  10. h = game->enemiesSprite.height / 4;
  11. }
  12. void Bug::Update(float dt)
  13. {
  14. y += yv * dt;
  15. yv += 30 * dt;
  16. rotation += 3.14 / 8 * rotationSpeed * dt;
  17. transform.Reset();
  18. transform.Rotate(rotation);
  19. transform.Translate(x, y);
  20. }
  21. void Bug::Draw()
  22. {
  23. #ifdef _DEBUG
  24. game->DrawRect(x - w / 2, y - h / 2, w, h, olc::RED);
  25. #endif
  26. olc::GFX2D::DrawPartialSprite(&game->enemiesSprite, 0, kind * h, w, h, transform, true);
  27. }
  28. bool Bug::IsActive()
  29. {
  30. return y - h / 2 < game->GameScreenHeight();
  31. }
  32. void Bug::ResetPosition()
  33. {
  34. y = -20 - std::rand() % game->ScreenHeight();
  35. x = w + std::rand() % (game->ScreenWidth() - w * 2);
  36. yv = 0;
  37. kind = std::rand() % 4;
  38. rotationSpeed = -8 + rand()%17;
  39. }
  40. void Bug::Kill()
  41. {
  42. y = game->GameScreenHeight() + 100;
  43. }
  44. }