Exemplo n.º 1
0
void Dungeon::generateRooms()
{
	//Création des salles
	std::vector<Room*> rooms;
	unsigned int rooms_number = rand() % (DUNGEON_ROOM_MAX - 2) + 2;
	for (unsigned int i = 0; i != rooms_number; i++)
	{
		Room* room = new Room();
		room->_width = rand() % (ROOM_WIDTH_MAX - 5) + 5;
		room->_height = rand() % (ROOM_HEIGHT_MAX - 5) + 5;
		room->_x = rand() % (_width - room->_width - 10) + 5;
		room->_y = rand() % (_height - room->_height- 10) + 5;

		//test de collision avec les autres salles
		bool error = false;
		unsigned int u = 0;
		while (u != rooms.size() && !error)
		{
			if (room->_x + room->_width >= rooms[u]->_x && room->_x <= rooms[u]->_x + rooms[u]->_width) //test de collision horizontal
			{
				if (room->_y + room->_height >= rooms[u]->_y && room->_y <= rooms[u]->_y + rooms[u]->_height)
				{
					error = true;
				}
			}
			u++;
		}

		//analyse des résultats
		if (!error)
		{
			//ajout de la salle à la liste
			rooms.push_back(room);
		}
	}
	//selection d'une salle au hasard de départ
	Room* start = rooms[rand() % rooms.size()];
	generatePassages(rooms, start);
	//applications des salles à la map et suppression de leur existence en mémoire
	for (unsigned int i = 0; i != rooms.size(); i++)
	{
		for (unsigned int x = 0; x != rooms[i]->_width; x++)
		{
			for (unsigned int y = 0; y != rooms[i]->_height; y++)
			{
				_map[x + rooms[i]->_x][y + rooms[i]->_y] = CELL_FLOOR;
			}
		}
		delete rooms[i];
	}
	//Génération des murs
	generateWalls();

}
Exemplo n.º 2
0
void generateMaze(Matrix maze, Position *hero, Position *exit)
{
    fillMatrixWithValue(maze, 0);
    generateBorder(maze);

    *exit = generateExit(maze.width, maze.height);
    maze.matrix[exit->y][exit->x] = 0;

    generateWalls(maze, *exit);
    generateHero(maze, hero);
}
Exemplo n.º 3
0
Mode PlayMode::frame()
{
  if(!paused)
  {
    background->draw();
    if(!handleInput())
      return MENU;
    if(!crashed)
    {
      moveField();
      background->update();
      updatePlayer();
      generateWalls();
      generateObstacles();
      generateItems();
    }
    updatePlayerTail();
    particles->draw(0);
    particles->draw(2);
    drawStuff();
    particles->draw(4);
    drawPlayer();
    particles->draw(1);
    floating->draw();
    collisionDetect();
    obstacleCounter();
    drawScorePanel();
    if(crashed && !gameOverExplosionTime--)
    {
      globalStore->seconds = playtime / 60;
      globalStore->score = score;
      globalStore->obstacles = passed;
      globalStore->stars = collected;
      storage->read();
      storage->insert(score);
      return GAMEOVER;
    }
    particles->update();
    floating->update();
  } else
  {
    drawPauseScreen();
    if(!handleInput())
      return MENU;
  }
  return PLAY;
}