Ghost.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "AIPlayer.h"
  2. #include "Ghost.h"
  3. #include "Graphics.h"
  4. #include "Logger.h"
  5. #include <luwra.hpp>
  6. using Pacman::Entity;
  7. using Pacman::Ghost;
  8. using Pacman::ButtonInput;
  9. using Pacman::MoveIntent;
  10. using WalrusRPG::Camera;
  11. using WalrusRPG::Graphics::Pixel;
  12. using namespace WalrusRPG::Graphics;
  13. using namespace WalrusRPG::Input;
  14. using namespace WalrusRPG;
  15. Ghost::Ghost(int x, int y, GameState &g, const char* filename, const char* ghost_name): AIEntity(x, y, g, ghost_name, filename),
  16. weak(false), dead_timer(0)
  17. {
  18. intent = UP;
  19. }
  20. Ghost::~Ghost()
  21. {
  22. }
  23. void Ghost::update(unsigned dt)
  24. {
  25. if(dead_timer > 0) {
  26. dead_timer --;
  27. return;
  28. }
  29. updateAI();
  30. if(g.is_there_collision(this, g.p1)){
  31. if(weak)
  32. kill();
  33. else
  34. g.p1->dead = true;
  35. }
  36. if(g.is_there_collision(this, g.p2)){
  37. if(weak)
  38. kill();
  39. else
  40. g.p2->dead = true;
  41. }
  42. if(weak) {
  43. weak_timer--;
  44. if(weak_timer <= 0)
  45. weak = false;
  46. }
  47. }
  48. void Ghost::render(unsigned dt, Camera& cam, Pixel col)
  49. {
  50. if(dead_timer) {
  51. col = dead_timer % 2 ? col : DarkGray;
  52. } else if(weak){
  53. if(weak_timer > 60 || (weak_timer % 10 < 5) )
  54. col = Blue;
  55. else
  56. col = White;
  57. }
  58. put_rectangle({x-cam.get_x(), y-cam.get_y(),16,16}, col);
  59. if(x < 0)
  60. put_rectangle({x-cam.get_x()+224, y-cam.get_y(),16,16}, col);
  61. if(x > 232)
  62. put_rectangle({x-cam.get_x()-224, y-cam.get_y(),16,16}, col);
  63. }