Guest User

Untitled

a guest
Apr 25th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1.  
  2. #include "monster.hpp"
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. Monster::Monster(Map* m,View* view,const char* path, int x, int y,int rx, int ry, int frames, int animDelay, int framesPerDirection): Character(view,path,x,y,rx,ry,frames,animDelay,framesPerDirection), Ai(m){
  8.     this->runQueue = 0;
  9. }
  10.  
  11. bool Monster::getNewTarget(int x, int y) {
  12.     int curPosition[2];
  13.     int tarPosition[2];
  14.     map->getFieldPos(getX(),getY(),curPosition);
  15.     map->getFieldPos(x,y,tarPosition);
  16.     cout << "Move fairy from (" << curPosition[0] << "," << curPosition[1] << ") to (" << tarPosition[0] << "," << tarPosition[1] << ")!" << endl;
  17.     cout << curPosition[0] << " JONZII  " << curPosition[1] << endl;
  18.     if(this->pathFinding->getPath(curPosition[0],curPosition[1],tarPosition[0],tarPosition[1])) {
  19.         this->runQueue = this->pathFinding->pathLenght;
  20.         cout << "path was found" << endl;
  21.     } else cout << "path wasnt found" << endl;
  22.    
  23. }
  24.  
  25. void Monster::moveToTarget() {
  26.     if(runQueue<=0) return;
  27.     int l = this->pathFinding->pathLenght;
  28.     int x = this->pathFinding->path[l-runQueue].act->x;
  29.     int y = this->pathFinding->path[l-runQueue].act->y;
  30.     if(moveTowartsWaypoint(x, y)) {
  31.         cout << "waypoint was passed!!" << endl;
  32.         --runQueue;
  33.         moveToTarget();
  34.     }
  35. }
  36.  
  37. bool Monster::moveTowartsWaypoint(int x, int y) {
  38.     int point[2];
  39.     map->getScreenPos(x,y,point);
  40.     if(point[0]<getX()) move(-1,0);
  41.     if(point[1]<getY()) move(0,-1);
  42.     if(point[0]>getX()) move(1,0);
  43.     if(point[1]>getY()) move(0,1);
  44.     if(point[0]==getX() && point[1]==getY()) return true;
  45.     return false;
  46. }
Add Comment
Please, Sign In to add comment