Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "monster.hpp"
- #include <iostream>
- using namespace std;
- 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){
- this->runQueue = 0;
- }
- bool Monster::getNewTarget(int x, int y) {
- int curPosition[2];
- int tarPosition[2];
- map->getFieldPos(getX(),getY(),curPosition);
- map->getFieldPos(x,y,tarPosition);
- cout << "Move fairy from (" << curPosition[0] << "," << curPosition[1] << ") to (" << tarPosition[0] << "," << tarPosition[1] << ")!" << endl;
- cout << curPosition[0] << " JONZII " << curPosition[1] << endl;
- if(this->pathFinding->getPath(curPosition[0],curPosition[1],tarPosition[0],tarPosition[1])) {
- this->runQueue = this->pathFinding->pathLenght;
- cout << "path was found" << endl;
- } else cout << "path wasnt found" << endl;
- }
- void Monster::moveToTarget() {
- if(runQueue<=0) return;
- int l = this->pathFinding->pathLenght;
- int x = this->pathFinding->path[l-runQueue].act->x;
- int y = this->pathFinding->path[l-runQueue].act->y;
- if(moveTowartsWaypoint(x, y)) {
- cout << "waypoint was passed!!" << endl;
- --runQueue;
- moveToTarget();
- }
- }
- bool Monster::moveTowartsWaypoint(int x, int y) {
- int point[2];
- map->getScreenPos(x,y,point);
- if(point[0]<getX()) move(-1,0);
- if(point[1]<getY()) move(0,-1);
- if(point[0]>getX()) move(1,0);
- if(point[1]>getY()) move(0,1);
- if(point[0]==getX() && point[1]==getY()) return true;
- return false;
- }
Add Comment
Please, Sign In to add comment