| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- #include "AIPlayer.h"
- #include "Ghost.h"
- #include "Graphics.h"
- #include "Logger.h"
- #include <luwra.hpp>
- using Pacman::Entity;
- using Pacman::Ghost;
- using Pacman::ButtonInput;
- using Pacman::MoveIntent;
- using WalrusRPG::Camera;
- using WalrusRPG::Graphics::Pixel;
- using namespace WalrusRPG::Graphics;
- using namespace WalrusRPG::Input;
- using namespace WalrusRPG;
- Ghost::Ghost(int x, int y, GameState &g, const char* filename, const char* ghost_name): AIEntity(x, y, g, ghost_name, filename),
- weak(false), dead_timer(0)
- {
- intent = UP;
- }
- Ghost::~Ghost()
- {
- }
- void Ghost::update(unsigned dt)
- {
- if(dead_timer > 0) {
- dead_timer --;
- return;
- }
- updateAI();
- if(g.is_there_collision(this, g.p1)){
- if(weak)
- kill();
- else
- g.p1->dead = true;
- }
- if(g.is_there_collision(this, g.p2)){
- if(weak)
- kill();
- else
- g.p2->dead = true;
- }
- if(weak) {
- weak_timer--;
- if(weak_timer <= 0)
- weak = false;
- }
- }
- void Ghost::render(unsigned dt, Camera& cam, Pixel col)
- {
- if(dead_timer) {
- col = dead_timer % 2 ? col : DarkGray;
- } else if(weak){
- if(weak_timer > 60 || (weak_timer % 10 < 5) )
- col = Blue;
- else
- col = White;
- }
- put_rectangle({x-cam.get_x(), y-cam.get_y(),16,16}, col);
- if(x < 0)
- put_rectangle({x-cam.get_x()+224, y-cam.get_y(),16,16}, col);
- if(x > 232)
- put_rectangle({x-cam.get_x()-224, y-cam.get_y(),16,16}, col);
- }
|