#include #include #include struct OpenPos getOpenPos(){ int chooseAnother=1; struct OpenPos openPos; while(chooseAnother){ spaceExists: openPos.y=(rand()%(viewportWinRows-2)+1); openPos.x=(rand()%(viewportWinCols-2)+1); if(mvwinch(viewportWin,openPos.y,openPos.x)==' ' && ((openPos.y > allEntities[0].curYpos+5 || openPos.y < allEntities[0].curYpos-5) || (openPos.x > allEntities[0].curXpos+5 || openPos.x < allEntities[0].curXpos-5))){ int i; for(i=1;i allEntities[0].curYpos+5 || y < allEntities[0].curYpos-5) || (x > allEntities[0].curXpos+5 || x < allEntities[0].curXpos-5))){ chooseAnother=1; goto spaceExists; } } } openPos.y=0; openPos.x=0; return openPos; } } } void getNextPos(int y, int x, int y2, int x2){ int w = x2 - x; int h = y2 - y; int dx1 = 0, dy1 = 0, dx2 = 0, dy2 =0; if (w<0){ dx1 = -1; } else if(w>0){ dx1 = 1; } if (h<0){ dy1 = -1; } else if(h>0){ dy1 = 1; } if (w<0){ dx2 = -1; } else if(w>0){ dx2 = 1; } int longest = abs(w); int shortest = abs(h); if (!(longest>shortest)) { longest = abs(h); shortest = abs(w); if (h<0){ dy2 = -1; } else if (h>0){ dy2 = 1; } dx2 = 0; } int numerator = longest >> 1; numerator += shortest; if (!(numerator