Commit 929b2e50 authored by Robert Scott James's avatar Robert Scott James

Changes to be committed:

 	modified:   src/entity/vision/alive/mob/randomMove.cpp
 	modified:   src/game/game.cpp
 	modified:   src/game/game.h

Added an array of mobs called Entities that 'should' allow the mobs to take turns. However this doesn't work and I can't figure out why it doesn't update.
parent b3c33e6a
......@@ -17,15 +17,19 @@ void RandomMove::turn(){
int toY=y;
switch (dist(generator)){
case 1:
std::cout << "Moving to: (" << toX+1 << "," << toY << ")" << std::endl;
toX++;
break;
case 2:
std::cout << "Moving to: (" << toX << "," << toY+1 << ")" << std::endl;
toY++;
break;
case 3:
std::cout << "Moving to: (" << toX-1 << "," << toY << ")" << std::endl;
toX--;
break;
case 4:
std::cout << "Moving to: (" << toX << "," << toY-1 << ")" << std::endl;
toY--;
break;
}
......
......@@ -50,6 +50,23 @@ void Game::loop(){
BasicSolverHero levelHero = BasicSolverHero(levels.back(),std::get<0>(heroStart), std::get<1>(heroStart));
theHero = &levelHero;
// Generate nMobs
std::default_random_engine generator;
generator.seed(milliseconds_since_epoch);
for(int n = 0; n < 10; n++){
// Generate random coordinates for the starting point for each mob
std::uniform_int_distribution<int> x_dist(0, levels.back().getWidth() );
std::uniform_int_distribution<int> y_dist(0, levels.back().getHeight() );
int mobx = x_dist(generator);
int moby = y_dist(generator);
while(levels.back().getTile(mobx,moby) != FLOOR ){
mobx = x_dist(generator);
moby = y_dist(generator);
}
entities.emplace_back( RandomMove( levels.back(), mobx, moby, milliseconds_since_epoch) );
}
int scale = wa.width/levels.back().getWidth();
if (wa.height/levels.back().getHeight() < scale){
scale = wa.height/levels.back().getHeight();
......@@ -64,18 +81,34 @@ void Game::loop(){
// Take hero turn.
theHero->turn();
// Now all the other Entities take turns but none extra for now
for(int _nMob = 0; _nMob < entities.size(); _nMob++){
entities[_nMob].turn();
}
// Now draw the hero
theHero->draw(dpy,double_buffer,gc,scale);
for(int _nMob = 0; _nMob < entities.size(); _nMob++){
entities[_nMob].draw(dpy,double_buffer,gc,scale);
}
XCopyArea(dpy, double_buffer, w, gc, 0, 0, wa.width, wa.height, 0, 0);
XFlush(dpy);
if(theHero->levelComplete() == true){
break;
}
}
if(theHero->getCurrentHealth() == 0){
break;
}
// Clean up the Mobs because otherwise you'll end up with loads of old Mobs
entities.clear();
}
}
......@@ -19,8 +19,9 @@ class Game {
void loop();
protected:
std::vector<Dungeon> levels;
std::vector<Entity> entities;
BasicSolverHero *theHero;
std::vector<Mob> entities;
Hero *theHero;
int dungeonLevel;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment