Commits

Mihael Peklar committed 7fb10df

Shows pathfinder path. Minor bugfixes. Updated win32 project file.

  • Participants
  • Parent commits 0f6e8c3

Comments (0)

Files changed (5)

 #define TESTING
 
 TESTING extern Font* test;
+TESTING std::vector<int> path;
 
 GM_Battle::GM_Battle()
 {
 	glLoadIdentity();
 	glPushMatrix();
     glTranslatef(offsetX, offsetY, 0);
+    glPushMatrix();
+    this->map->paintSelf();
 	btnTest->paintSelf();
-    this->map->paintSelf();
 	glPopMatrix();
-	glPushMatrix();
 	//glOrtho(0, 0, this->adjustedWidth(), this->adjustedHeight(), -1, 1);
 	//glColor3b(255, 255, 255);
 	//TESTING test->drawLine("This is Sparta!", 0, 0);
+	if(!path.empty())
+        this->map->drawPath(path);
 	glPopMatrix();
 
 	SDL_GL_SwapBuffers();
 						Unit *unit = *it;
 						if(unit->isSelected())
 						{
-							printf("%d\n", this->map->find_path(this->map->findTile(unit->getX(), unit->getY()), this->map->findTile(adjustedMouseX, adjustedMouseY)).size());
+							printf("%d\n", (path=this->map->find_path(this->map->findTile(unit->getX(), unit->getY()), this->map->findTile(adjustedMouseX, adjustedMouseY))).size());
 							unit->defaultOrder(adjustedMouseX, adjustedMouseY);
 						}
 					}
 	double v;
 	int x, p;
 	_pnode() {}
-	_pnode(int V, int A, int B) : v(V), x(A), p(B) {}
+	_pnode(double V, int A, int B) : v(V), x(A), p(B) {}
 	friend bool operator < (const _pnode& a, const _pnode& b)
 	{
-		return a.v>b.v;	
+		return a.v>b.v;
 	}
 };
 
 	std::priority_queue< pnode > dot;
 	if(s<0 || e<0 || s>=this->tiles.size() || e>=this->tiles.size())
 		return res;
+//    res.push_back(s);
 	dot.push(pnode(0.0, s, -1));
 	int c=-1, p;
 	double d;
 			dot.push(pnode(d+distance(c, c+tilesPerRow), c+tilesPerRow, mem.size()-1));
 		//printf("STEP\n");
 	}
-	blocked[s]=1;
+	//blocked[s]=1;
+	//res.clear();
 	if(b)
+	{
+	    res.clear();
 		return res;
+    }
 	//Commented out for testing purposes
 	blocked[s]=0;
 	blocked[e]=1;
 	for(int i=mem.size()-1; mem[i].second>=0; i=mem[i].second)
 		res.push_back(mem[i].first);
+	res.push_back(s);
 	return res;
 }
 
+#include<GL/gl.h>
 
+void Map::drawPath(vector<int> path)
+{
+    glDisable(GL_TEXTURE_2D);
+    glPointSize(10.0);
+    glColor4f(1.0,0.0,0.0,0.7);
+    glLineWidth(5);
+    glBegin(GL_LINE_STRIP);
+    for(vector<int>::iterator i=path.begin(); i!=path.end(); ++i)
+    {
+        glVertex2f((*i%this->tilesPerRow)*TILE_WIDTH, -(*i/this->tilesPerRow)*TILE_HEIGHT);
+        printf("%g %g, ", (*i%this->tilesPerRow)*TILE_WIDTH, -(*i/this->tilesPerRow)*TILE_HEIGHT);
+    }
+    printf("voila!\n");
+    glEnd();
+    glBegin(GL_POINTS);
+    for(vector<int>::iterator i=path.begin(); i!=path.end(); ++i)
+        glVertex2f(*i%this->tilesPerRow*TILE_WIDTH, -*i/this->tilesPerRow*TILE_HEIGHT);
+    glEnd();
+    glColor4f(1.0,1.0,1.0,1.0);
+}
+
     UnitContainer units;
     std::vector<int> find_path(int st, int et);
     int findTile(float x, float y);
+    void drawPath(std::vector<int> path);
 
     private:
     Tileset* tileset;

thecombat-win32.cbp

 				<Option object_output="obj\Debug\" />
 				<Option type="1" />
 				<Option compiler="gcc" />
+				<Option use_console_runner="0" />
 				<Compiler>
 					<Add option="-g" />
 				</Compiler>
 		<Unit filename="thecombat.cpp" />
 		<Unit filename="tile.cpp" />
 		<Unit filename="tile.h" />
+		<Unit filename="tiledesc.cpp" />
+		<Unit filename="tiledesc.h" />
 		<Unit filename="tileset.cpp" />
 		<Unit filename="tileset.h" />
 		<Unit filename="unit.cpp" />
     	test=new Font("FreeSans.ttf");
 	glViewport(0,0,screen->w,screen->h);
 	glClearColor(0,0,0,1);
-
+    glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
+    glEnable( GL_POINT_SMOOTH );
 	game = new GM_Battle();
 	game->setScreenSize(screen->w, screen->h);
 	int oldticks = 0;