Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
89 KB
Referenced Files
None
Subscribers
None
diff --git a/src/DungeonMap.cpp b/src/DungeonMap.cpp
index 9401fc8..d730cc2 100644
--- a/src/DungeonMap.cpp
+++ b/src/DungeonMap.cpp
@@ -1,1543 +1,1543 @@
#include "DungeonMap.h"
#include "GameFloor.h"
#include "ItemEntity.h"
#include "ChestEntity.h"
#include "sfml_game/ImageManager.h"
#include <cstdlib>
#include <stdio.h>
#include <iostream>
#include "WitchBlastGame.h"
DungeonMap::DungeonMap(int width, int height) : GameMap(width, height)
{
}
DungeonMap::DungeonMap(GameFloor* gameFloor, int x, int y) : GameMap(MAP_WIDTH, MAP_HEIGHT)
{
this->gameFloor = gameFloor;
this->x = x;
this->y = y;
cleared = false;
visited = false;
known = false;
randomTileElement.type = -1;
randomTileElement.x = 0;
randomTileElement.y = 0;
randomTileElement.rotation = 0;
}
DungeonMap::~DungeonMap()
{
}
bool DungeonMap::isVisited()
{
return visited;
}
void DungeonMap::setVisited(bool b)
{
visited = b;
}
bool DungeonMap::isKnown()
{
return known;
}
void DungeonMap::setKnown(bool b)
{
known = b;
}
bool DungeonMap::isCleared()
{
return cleared;
}
void DungeonMap::setCleared(bool b)
{
cleared = b;
}
roomTypeEnum DungeonMap::getRoomType()
{
return roomType;
}
void DungeonMap::setRoomType(roomTypeEnum roomType)
{
this->roomType = roomType;
}
int DungeonMap::getObjectTile(int x, int y)
{
return objectsMap[x][y];
}
logicalMapStateEnum DungeonMap::getLogicalTile(int x, int y)
{
return logicalMap[x][y];
}
void DungeonMap::setObjectTile(int x, int y, int n)
{
objectsMap[x][y] = n;
}
void DungeonMap::setLogicalTile(int x, int y, logicalMapStateEnum state)
{
logicalMap[x][y] = state;
}
int DungeonMap::getFloorOffset()
{
return floorOffset;
}
int DungeonMap::getWallType()
{
return wallType;
}
void DungeonMap::setFloorOffset(int n)
{
floorOffset = n;
}
void DungeonMap::setWallType(int n)
{
wallType = n;
}
std::list<DungeonMap::itemListElement> DungeonMap::getItemList()
{
return (itemList);
}
std::list<DungeonMap::chestListElement> DungeonMap::getChestList()
{
return (chestList);
}
std::list<DungeonMap::spriteListElement> DungeonMap::getSpriteList()
{
return (spriteList);
}
DungeonMap::RandomTileElement DungeonMap::getRandomTileElement()
{
return randomTileElement;
}
void DungeonMap::setRandomTileElement (RandomTileElement rt)
{
randomTileElement = rt;
hasChanged = true;
}
void DungeonMap::displayToConsole()
{
for (int j=0; j < MAP_HEIGHT; j++)
{
for (int i=0; i < MAP_WIDTH; i++)
{
printf("%d", map[i][j]);
}
printf("\n");
}
printf("\n");
}
bool DungeonMap::isDownBlocking(int x, int y)
{
if (!inMap(x, y)) return false;
return (logicalMap[x][y] != LogicalFloor);
}
bool DungeonMap::isUpBlocking(int x, int y)
{
if (!inMap(x, y)) return false;
return (logicalMap[x][y] != LogicalFloor);
}
bool DungeonMap::isLeftBlocking(int x, int y)
{
if (!inMap(x, y)) return false;
return (logicalMap[x][y] != LogicalFloor);
}
bool DungeonMap::isRightBlocking(int x, int y)
{
if (!inMap(x, y)) return false;
return (logicalMap[x][y] != LogicalFloor);
}
bool DungeonMap::isWalkable(int x, int y)
{
if (!inMap(x, y)) return true;
if (roomType == roomTypeKey && !cleared)
{
int x0 = MAP_WIDTH / 2;
int y0 = MAP_HEIGHT / 2;
if (x >= x0 - 1 && x <= x0 +1 && y >= y0 - 1 && y <= y0 + 1)
return false;
}
return (logicalMap[x][y] == LogicalFloor);
}
bool DungeonMap::isFlyable(int x, int y)
{
if (x < 0) return true;
if (x > MAP_WIDTH - 1) return true;
if (y < 0) return true;
if (y > MAP_HEIGHT - 1) return true;
return (logicalMap[x][y] != LogicalWall);
}
bool DungeonMap::isShootable(int x, int y)
{
if (!inMap(x, y)) return true;
return (logicalMap[x][y] != LogicalWall && logicalMap[x][y] != LogicalObstacle);
}
bool DungeonMap::containsHealth()
{
ItemList::iterator it;
for (it = itemList.begin (); it != itemList.end ();)
{
itemListElement ilm = *it;
it++;
if (ilm.type >= ItemHealthVerySmall && ilm.type <= ItemHealthVerySmallPoison)
return true;
}
return false;
}
void DungeonMap::randomize(int n)
{
int i, j;
int x0 = MAP_WIDTH / 2;
int y0 = MAP_HEIGHT / 2;
initRoom();
// bonus
if (n == 5)
{
roomType = roomTypeBonus;
}
// others
else if (n > 0)
{
int r = rand() % 4;
if (r == 0) // corner blocks
{
map[1][1] = 4;
map[1][MAP_HEIGHT -2] = 4;
map[MAP_WIDTH - 2][1] = 4;
map[MAP_WIDTH - 2][MAP_HEIGHT -2] = 4;
}
else if (r == 1) // bloc in the middle
{
for (i = x0-1; i <= x0+1; i++)
for (j = y0-1; j <= y0+1; j++)
map[i][j] = 4;
}
else if (r == 2) // checker
{
for (i = 2; i < MAP_WIDTH - 2; i = i + 2)
for (j = 2; j < MAP_HEIGHT - 2; j = j + 2)
map[i][j] = 4;
}
cleared = false;
roomType = (roomTypeEnum)(rand() % 3);
}
else
{
cleared = true;
}
}
int DungeonMap::hasNeighbourLeft()
{
if (x > 0 && gameFloor->getRoom(x-1, y) > 0)
{
if (gameFloor->getRoom(x-1, y) == roomTypeBoss) return 2;
else return 1;
}
return 0;
}
int DungeonMap::hasNeighbourRight()
{
if (x < MAP_WIDTH -1 && gameFloor->getRoom(x+1, y) > 0)
{
if (gameFloor->getRoom(x+1, y) == roomTypeBoss) return 2;
else return 1;
}
return 0;
}
int DungeonMap::hasNeighbourUp()
{
if (y > 0 && gameFloor->getRoom(x, y-1) > 0)
{
if (gameFloor->getRoom(x, y-1) == roomTypeBoss) return 2;
else return 1;
}
return 0;
}
int DungeonMap::hasNeighbourDown()
{
if (y < MAP_HEIGHT -1 && gameFloor->getRoom(x, y+1) > 0)
{
if (gameFloor->getRoom(x, y+1) == roomTypeBoss) return 2;
else return 1;
}
return 0;
}
roomTypeEnum DungeonMap::getNeighbourLeft()
{
if (x > 0) return gameFloor->getRoom(x - 1, y);
else return roomTypeNULL;
}
roomTypeEnum DungeonMap::getNeighbourRight()
{
if (x < MAP_WIDTH - 1) return gameFloor->getRoom(x + 1, y);
else return roomTypeNULL;
}
roomTypeEnum DungeonMap::getNeighbourUp()
{
if (y > 0) return gameFloor->getRoom(x, y - 1);
else return roomTypeNULL;
}
roomTypeEnum DungeonMap::getNeighbourDown()
{
if (y < MAP_HEIGHT - 1) return gameFloor->getRoom(x, y + 1);
else return roomTypeNULL;
}
int DungeonMap::getDivinity(int x, int y)
{
if (x <= 0 || (x >= MAP_WIDTH - 1) || y <= 0 || (y >= MAP_HEIGHT - 1)) return -1;
if (map[x][y] >= MAP_TEMPLE && map[x][y] < MAP_TEMPLE + NB_DIVINITY)
return (map[x][y] - MAP_TEMPLE);
else
return -1;
}
void DungeonMap::initRoom()
{
int x0 = MAP_WIDTH / 2;
int y0 = MAP_HEIGHT / 2;
int i, j;
// style
floorOffset = ((game().getLevel() - 1) % 8) * 24 ;
wallType = 0; //((game().getLevel() - 1) % 3) ;
int wallOffset = wallType * 24;
// outer walls
map[0][0] = wallOffset + MAP_WALL_7 + rand() % 2;
for ( i = 1 ; i < width -1 ; i++)
{
if (i == width / 2)
{
map[i][0] = wallOffset + MAP_WALL_8 + rand() % 2;
map[i][height - 1] = wallOffset + MAP_WALL_8 + rand() % 2;
}
else if (i < width / 2)
{
map[i][0] = wallOffset + MAP_WALL_87 + rand() % 8;
map[i][height - 1] = wallOffset + MAP_WALL_87 + rand() % 8;
}
else
{
map[i][0] = wallOffset + MAP_WALL_87 + rand() % 8;
map[i][height - 1] = wallOffset + MAP_WALL_87 + rand() % 8;
}
}
map[width - 1][0] = wallOffset + MAP_WALL_7 + rand() % 2;
for ( int i = 1 ; i < height -1 ; i++)
{
if (i == height / 2)
{
map[0][i] = wallOffset + MAP_WALL_8 + rand() % 2;
map[width - 1][i] = wallOffset + MAP_WALL_8 + rand() % 2;
}
else if (i < height / 2)
{
map[0][i] = wallOffset + MAP_WALL_87 + rand() % 8;
map[width - 1][i] = wallOffset + MAP_WALL_87 + rand() % 8;
}
else
{
map[0][i] = wallOffset + MAP_WALL_87 + rand() % 8;
map[width - 1][i] = wallOffset + MAP_WALL_87 + rand() % 8;
}
}
map[0][height - 1] = wallOffset + MAP_WALL_7 + rand() % 2;
map[width - 1][height - 1] = wallOffset + MAP_WALL_7 + rand() % 2;
// floor
for ( j = 1 ; j < height - 1 ; j++)
{
for ( i = 1 ; i < width - 1 ; i++)
{
map[i][j] = floorOffset + rand()%(MAP_NORMAL_FLOOR);
while (map[i][j] == map[i - 1][j] || map[i][j] == map[i][j - 1] || map[i][j] == map[i - 1][j - 1] || map[i][j] == map[i + 1][j - 1])
map[i][j] = floorOffset + rand()%(MAP_NORMAL_FLOOR);
}
}
// objects
for ( j = 0 ; j < height; j++)
{
for ( i = 0 ; i < width; i++)
{
objectsMap[i][j] = 0;
if (i == 0 || j == 0 || i == width - 1 || j == height - 1)
logicalMap[i][j] = LogicalWall;
else
logicalMap[i][j] = LogicalFloor;
}
}
// alternative floor
for (i = 0; i < 8; i++)
{
if (rand() % 2 > 0)
{
map[1 + rand() % (MAP_WIDTH - 2)][1 + rand() % (MAP_HEIGHT - 2)] = floorOffset + 16 + i;
}
}
// alternative walls
for (i = 0; i < 8; i++)
{
if (rand() % 2 > 0)
{
int xTile = 0;
int yTile = 0;
int horizontal = rand() % 2;
if (horizontal == 0)
{
yTile = rand() % 2 == 0 ? 0 : MAP_HEIGHT - 1;
xTile = 1 + rand() % 12;
if (xTile > 6) xTile++;
}
else
{
xTile = rand() % 2 == 0 ? 0 : MAP_WIDTH - 1;
yTile = 1 + rand() % 6;
if (yTile > 3) yTile++;
}
map[xTile][yTile] = i + wallOffset + MAP_WALL_87 + 8;
}
}
/*if (hasNeighbourUp() && rand() % 3 == 0)
{
map[x0 - 2][0] = 9 + wallOffset + MAP_WALL_ALTERN;
map[x0 + 2][0] = 9 + wallOffset + MAP_WALL_ALTERN;
}
if (hasNeighbourDown() && rand() % 3 == 0)
{
map[x0 - 2][MAP_HEIGHT - 1] = 9 + wallOffset + MAP_WALL_ALTERN;
map[x0 + 2][MAP_HEIGHT - 1] = 9 + wallOffset + MAP_WALL_ALTERN;
}
if (hasNeighbourLeft() && rand() % 3 == 0)
{
map[0][y0 - 2] = 9 + wallOffset + MAP_WALL_ALTERN;
map[0][y0 + 2] = 9 + wallOffset + MAP_WALL_ALTERN;
}
if (hasNeighbourRight() && rand() % 3 == 0)
{
map[MAP_WIDTH - 1][y0 - 2] = 9 + wallOffset + MAP_WALL_ALTERN;
map[MAP_WIDTH - 1][y0 + 2] = 9 + wallOffset + MAP_WALL_ALTERN;
}*/
// doors ?
if (gameFloor != NULL)
{
if (x > 0 && gameFloor->getRoom(x - 1, y) > 0)
{
map[0][MAP_HEIGHT / 2] = floorOffset;
map[0][MAP_HEIGHT / 2 - 1] = floorOffset;
map[0][MAP_HEIGHT / 2 + 1] = floorOffset;
openDoor(0, y0);
}
if (x < MAP_WIDTH - 1 && gameFloor->getRoom(x + 1, y) > 0)
{
map[MAP_WIDTH - 1][MAP_HEIGHT / 2] = floorOffset;
map[MAP_WIDTH - 1][MAP_HEIGHT / 2 - 1] = floorOffset;
map[MAP_WIDTH - 1][MAP_HEIGHT / 2 + 1] = floorOffset;
openDoor(MAP_WIDTH - 1, y0);
}
if (y > 0 && gameFloor->getRoom(x, y - 1) > 0)
{
map[MAP_WIDTH / 2][0] = floorOffset;
map[MAP_WIDTH / 2 - 1][0] = floorOffset;
map[MAP_WIDTH / 2 + 1][0] = floorOffset;
openDoor(x0, 0);
}
if (y < MAP_HEIGHT -1 && gameFloor->getRoom(x, y + 1) > 0)
{
map[MAP_WIDTH / 2][MAP_HEIGHT - 1] = floorOffset;
map[MAP_WIDTH / 2 - 1][MAP_HEIGHT - 1] = floorOffset;
map[MAP_WIDTH / 2 + 1][MAP_HEIGHT - 1] = floorOffset;
openDoor(x0, MAP_HEIGHT -1);
}
}
}
void DungeonMap::openDoor(int x, int y)
{
objectsMap[x][y] = MAPOBJ_DOOR_OPEN;
logicalMap[x][y] = LogicalFloor;
}
void DungeonMap::closeDoor(int x, int y)
{
objectsMap[x][y] = MAPOBJ_DOOR_CLOSED;
logicalMap[x][y] = LogicalWall;
}
bool DungeonMap::isDoor(int x, int y)
{
return objectsMap[x][y] == MAPOBJ_DOOR_OPEN || objectsMap[x][y] == MAPOBJ_DOOR_CLOSED;
}
void DungeonMap::makePatternTile(int x, int y)
{
if (map[x][y] < 24 * 8 && (map[x][y] % 24) < 8) map[x][y] += 8;
else map[x][y] = (game().getLevel() - 1) * 24 + 8;
}
void DungeonMap::initPattern(patternEnum n)
{
int i, j;
if (n == PatternSmallChecker)
{
for ( i = 2 ; i < width - 2 ; i++)
for ( j = 2 ; j < height - 2 ; j++)
{
if ((i + j) % 2 == 1) makePatternTile(i, j);
}
}
if (n == PatternBigChecker)
{
for ( i = 1 ; i < width - 1 ; i++)
for ( j = 1 ; j < height - 1 ; j++)
{
if ((i + j) % 2 == 1) makePatternTile(i, j);
}
}
if (n == PatternBorder)
{
for ( i = 1 ; i < width - 1 ; i++)
for ( j = 1 ; j < height - 1 ; j++)
{
if (i == 1 || j == 1 || i == width - 2 || j == height - 2)
makePatternTile(i, j);
}
}
if (n == PatternBigCircle)
{
for ( i = 2 ; i < width - 2 ; i++)
for ( j = 2 ; j < height - 2 ; j++)
{
if (i == 2 || j == 2 || i == width - 3 || j == height - 3)
makePatternTile(i, j);
}
}
if (n == PatternSmallCircle || n == PatternSmallStar)
{
for ( i = 5 ; i < 10 ; i++)
for ( j = 2 ; j < height - 2 ; j++)
{
if (i == 5 || i == 9 || j == 2 || j == height - 3)
makePatternTile(i, j);
}
}
if (n == PatternSmallStar)
{
makePatternTile(7, 1);
makePatternTile(7, height - 2);
makePatternTile(4, 4);
makePatternTile(10, 4);
}
if (n == PatternSmallDisc)
{
for ( i = 5 ; i < 10 ; i++)
for ( j = 2 ; j < height - 2 ; j++)
{
makePatternTile(i, j);
}
}
}
void DungeonMap::generateInselRoom()
{
for (int i = 1; i < MAP_WIDTH - 1; i++)
for (int j = 1; j < MAP_HEIGHT - 1; j++)
{
if (i != MAP_WIDTH / 2 && j != MAP_HEIGHT / 2
&& !(i == MAP_WIDTH / 2 - 1 && j == MAP_HEIGHT / 2 - 1)
&& !(i == MAP_WIDTH / 2 - 1 && j == MAP_HEIGHT / 2 + 1)
&& !(i == MAP_WIDTH / 2 + 1 && j == MAP_HEIGHT / 2 - 1)
&& !(i == MAP_WIDTH / 2 + 1 && j == MAP_HEIGHT / 2 + 1)
)
addHole(i, j);
}
objectsMap[MAP_WIDTH / 2 - 2][MAP_HEIGHT / 2 - 1] = MAPOBJ_WALL_SPECIAL;
objectsMap[MAP_WIDTH / 2 - 1][MAP_HEIGHT / 2 - 2] = MAPOBJ_WALL_SPECIAL;
logicalMap[MAP_WIDTH / 2 - 2][MAP_HEIGHT / 2 - 1] = LogicalObstacle;
logicalMap[MAP_WIDTH / 2 - 1][MAP_HEIGHT / 2 - 2] = LogicalObstacle;
objectsMap[MAP_WIDTH / 2 + 2][MAP_HEIGHT / 2 - 1] = MAPOBJ_WALL_SPECIAL + 1;
objectsMap[MAP_WIDTH / 2 + 1][MAP_HEIGHT / 2 - 2] = MAPOBJ_WALL_SPECIAL + 1;
logicalMap[MAP_WIDTH / 2 + 2][MAP_HEIGHT / 2 - 1] = LogicalObstacle;
logicalMap[MAP_WIDTH / 2 + 1][MAP_HEIGHT / 2 - 2] = LogicalObstacle;
objectsMap[MAP_WIDTH / 2 - 2][MAP_HEIGHT / 2 + 1] = MAPOBJ_WALL_SPECIAL + 2;
objectsMap[MAP_WIDTH / 2 - 1][MAP_HEIGHT / 2 + 2] = MAPOBJ_WALL_SPECIAL + 2;
logicalMap[MAP_WIDTH / 2 - 2][MAP_HEIGHT / 2 + 1] = LogicalObstacle;
logicalMap[MAP_WIDTH / 2 - 1][MAP_HEIGHT / 2 + 2] = LogicalObstacle;
objectsMap[MAP_WIDTH / 2 + 2][MAP_HEIGHT / 2 + 1] = MAPOBJ_WALL_SPECIAL + 3;
objectsMap[MAP_WIDTH / 2 + 1][MAP_HEIGHT / 2 + 2] = MAPOBJ_WALL_SPECIAL + 3;
logicalMap[MAP_WIDTH / 2 + 2][MAP_HEIGHT / 2 + 1] = LogicalObstacle;
logicalMap[MAP_WIDTH / 2 + 1][MAP_HEIGHT / 2 + 2] = LogicalObstacle;
if (!hasNeighbourUp())
addHole(MAP_WIDTH / 2, 1);
if (!hasNeighbourDown())
addHole(MAP_WIDTH / 2, MAP_HEIGHT - 2);
if (!hasNeighbourLeft())
for (int i = 0; i < 4; i++)
{
addHole(1 + i, MAP_HEIGHT / 2);
addHole(1 + i, MAP_HEIGHT / 2 + 1);
}
if (!hasNeighbourRight())
for (int i = 0; i < 4; i++)
{
addHole(MAP_WIDTH - 2 - i, MAP_HEIGHT / 2);
addHole(MAP_WIDTH - 2 - i, MAP_HEIGHT / 2 + 1);
}
addHole(MAP_WIDTH / 2 - 1 , MAP_HEIGHT - 2);
addHole(MAP_WIDTH / 2 + 1 , MAP_HEIGHT - 2);
addHole(MAP_WIDTH / 2 - 2 , MAP_HEIGHT - 3);
addHole(MAP_WIDTH / 2 + 2 , MAP_HEIGHT - 3);
if (rand() % 2 == 0) makePatternTile(MAP_WIDTH / 2, MAP_HEIGHT / 2);
}
Vector2D DungeonMap::generateBonusRoom()
{
initRoom();
int x0 = MAP_WIDTH / 2;
int y0 = MAP_HEIGHT / 2;
if (game().getLevel() == 1 || rand() % 3 > 0)
{
if (rand() % 3 == 0)
{
if (rand() % 2 == 0) initPattern(PatternSmallDisc);
else initPattern(PatternSmallStar);
}
objectsMap[x0 - 1][y0 - 1] = MAPOBJ_WALL_SPECIAL;
objectsMap[x0 - 1][y0 + 1] = MAPOBJ_WALL_SPECIAL + 2;
objectsMap[x0 + 1][y0 - 1] = MAPOBJ_WALL_SPECIAL + 1;
objectsMap[x0 + 1][y0 + 1] = MAPOBJ_WALL_SPECIAL + 3;
logicalMap[x0 - 1][y0 - 1] = LogicalObstacle;
logicalMap[x0 - 1][y0 + 1] = LogicalObstacle;
logicalMap[x0 + 1][y0 - 1] = LogicalObstacle;
logicalMap[x0 + 1][y0 + 1] = LogicalObstacle;
}
else
{
generateInselRoom();
}
generateRandomTile();
return (Vector2D(x0 * TILE_WIDTH + TILE_WIDTH / 2, y0 * TILE_HEIGHT + TILE_HEIGHT / 2));
}
void DungeonMap::generateTemple(int x, int y, enumDivinityType type)
{
map[x][y] = MAP_TEMPLE + (int)type;
addHole(x - 1, y - 2);
addHole(x - 1, y - 1);
addHole(x - 1, y);
addHole(x + 1, y - 2);
addHole(x + 1, y - 1);
addHole(x + 1, y );
objectsMap[x][y - 2] = MAPOBJ_TEMPLE_WALL + (int)type;
objectsMap[x][y - 1] = MAPOBJ_TEMPLE_WALL + 10 + (int)type;
logicalMap[x][y - 2] = LogicalObstacle;
logicalMap[x][y - 1] = LogicalObstacle;
}
void DungeonMap::generateTempleRoom()
{
initRoom();
int x0 = MAP_WIDTH / 2;
int y0 = 1 + MAP_HEIGHT / 2;
if (rand() % 3 == 0)
{
if (rand() % 2 == 0) initPattern(PatternSmallDisc);
else initPattern(PatternSmallStar);
}
int d0, d1, d2;
d0 = rand() % NB_DIVINITY;
d1 = d0;
while (d0 == d1) d1 = rand() % NB_DIVINITY;
if (rand() % 2 == 0)
{
// three temple
d2 = d0;
while (d0 == d2 || d1 == d2) d2 = rand() % NB_DIVINITY;
generateTemple(x0 - 2, y0, (enumDivinityType)d0);
generateTemple(x0 + 2, y0, (enumDivinityType)d1);
generateTemple(x0, y0, (enumDivinityType)d2);
}
else
{
// two temples
generateTemple(x0 - 1, y0, (enumDivinityType)d0);
generateTemple(x0 + 1, y0, (enumDivinityType)d1);
}
generateRandomTile();
}
void DungeonMap::generateCarpet(int x0, int y0, int w, int h, int n)
{
int xf = x0 + w - 1;
int yf = y0 + h - 1;
map[x0][y0] = n;
map[x0][yf] = n + 6;
map[xf][y0] = n + 2;
map[xf][yf] = n + 8;
int i, j;
for (i = x0 + 1; i <= xf - 1; i++)
{
map[i][y0] = n + 1;
map[i][yf] = n + 7;
for (j = y0 + 1; j <= yf - 1; j++)
map[i][j] = n + 4;
}
for (j = y0 + 1; j <= yf - 1; j++)
{
map[x0][j] = n + 3;
map[xf][j] = n + 5;
}
}
void DungeonMap::generateTable(int x0, int y0, int w, int h, int n)
{
int xf = x0 + w - 1;
int yf = y0 + h - 1;
objectsMap[x0][y0] = n;
objectsMap[x0][yf] = n + 6;
objectsMap[xf][y0] = n + 2;
objectsMap[xf][yf] = n + 8;
int i, j;
for (i = x0 + 1; i <= xf - 1; i++)
{
objectsMap[i][y0] = n + 1;
objectsMap[i][yf] = n + 7;
for (j = y0 + 1; j <= yf - 1; j++)
objectsMap[i][j] = n + 4;
}
for (j = y0 + 1; j <= yf - 1; j++)
{
objectsMap[x0][j] = n + 3;
objectsMap[xf][j] = n + 5;
}
for (i = x0; i <= xf; i++)
for (j = y0; j <= yf; j++)
logicalMap[i][j] = LogicalObstacle;
}
void DungeonMap::generateLongObject(int x0, int y0, int w, int n)
{
int xf = x0 + w - 1;
objectsMap[x0][y0] = n;
logicalMap[x0][y0] = LogicalObstacle;
for (int i = x0 + 1; i <= xf - 1; i++)
{
objectsMap[i][y0] = n + 1;
logicalMap[i][y0] = LogicalObstacle;
}
objectsMap[xf][y0] = n + 2;
logicalMap[xf][y0] = LogicalObstacle;
}
Vector2D DungeonMap::generateMerchantRoom()
{
initRoom();
int x0 = MAP_WIDTH / 2;
int y0 = MAP_HEIGHT / 2;
for (int i = x0 - 3; i <= x0 + 3; i++)
{
if (i == x0 - 3) objectsMap[i][y0] = MAPOBJ_SHOP_LEFT;
else if (i == x0 + 3) objectsMap[i][y0] = MAPOBJ_SHOP_RIGHT;
else objectsMap[i][y0] = MAPOBJ_SHOP;
logicalMap[i][y0] = LogicalObstacle;
}
if (!hasNeighbourUp())
{
objectsMap[x0 - 1][0] = MAPOBJ_PNW;
objectsMap[x0][0] = MAPOBJ_PNW + 1;
objectsMap[x0 + 1][0] = MAPOBJ_PNW + 2;
}
else
{
objectsMap[x0 - 1][MAP_HEIGHT - 1] = MAPOBJ_PNW +3;
objectsMap[x0][MAP_HEIGHT - 1] = MAPOBJ_PNW + 4;
objectsMap[x0 + 1][MAP_HEIGHT - 1] = MAPOBJ_PNW + 5;
}
generateRandomTile();
return (Vector2D(x0 * TILE_WIDTH + TILE_WIDTH / 2, y0 * TILE_HEIGHT + TILE_HEIGHT / 2));
}
Vector2D DungeonMap::generateKeyRoom()
{
initRoom();
int x0 = MAP_WIDTH / 2;
int y0 = MAP_HEIGHT / 2;
objectsMap[x0 - 1][y0 - 1] = MAPOBJ_WALL_SPECIAL;
objectsMap[x0 - 1][y0 + 1] = MAPOBJ_WALL_SPECIAL + 2;
objectsMap[x0 + 1][y0 - 1] = MAPOBJ_WALL_SPECIAL + 1;
objectsMap[x0 + 1][y0 + 1] = MAPOBJ_WALL_SPECIAL + 3;
logicalMap[x0 - 1][y0 - 1] = LogicalObstacle;
logicalMap[x0 - 1][y0 + 1] = LogicalObstacle;
logicalMap[x0 + 1][y0 - 1] = LogicalObstacle;
logicalMap[x0 + 1][y0 + 1] = LogicalObstacle;
if (rand() % 3 == 0)
{
if (rand() % 2 == 0) initPattern(PatternSmallCircle);
else initPattern(PatternSmallStar);
}
map[x0][y0] = MAP_TILE_KEY;
map[x0 -1][y0] = MAP_TILE_KEY;
map[x0 + 1][y0] = MAP_TILE_KEY;
map[x0][y0 - 1] = MAP_TILE_KEY;
map[x0][y0 + 1] = MAP_TILE_KEY;
generateRandomTile();
return (Vector2D(x0 * TILE_WIDTH + TILE_WIDTH / 2, y0 * TILE_HEIGHT + TILE_HEIGHT / 2));
}
void DungeonMap::generateExitRoom()
{
initRoom();
int x0 = MAP_WIDTH / 2;
map[x0][0] = floorOffset;
map[x0 - 1][0] = floorOffset;
map[x0 + 1][0] = floorOffset;
logicalMap[x0][0] = LogicalFloor;
if (rand() % 3 == 0) initPattern(PatternBorder);
generateRandomTile();
}
void DungeonMap::generateRoomRandom(int type)
{
if (rand() % 3 == 0) generateRoomWithHoles(type);
else generateRoomWithoutHoles(type);
}
void DungeonMap::generateRoomWithoutHoles(int type)
{
initRoom();
int x0 = MAP_WIDTH / 2;
int y0 = MAP_HEIGHT / 2;
int i, j, r;
if (type <= 0) // empty room
{
if (roomType == roomTypeStarting)
{
generateCarpet(5, 3, 5, 3, MAP_CARPET);
if (game().getLevel() > 1)
{
//map[x0 - 1][MAP_HEIGHT - 1] = wallOffset + MAP_WALL_START_L;
- //map[x0][MAP_HEIGHT - 1] = wallOffset + MAP_WALL_START_M;
+ map[x0][MAP_HEIGHT - 1] = floorOffset;
//map[x0 + 1][MAP_HEIGHT - 1] = wallOffset + MAP_WALL_START_R;
}
}
else if (roomType == roomTypeBoss && (game().getLevel() == 2) ) // giant slime
{
// good ?
objectsMap[1][1] = MAPOBJ_GRID;
objectsMap[1][MAP_HEIGHT -2] = MAPOBJ_GRID;
objectsMap[MAP_WIDTH - 2][1] = MAPOBJ_GRID;
objectsMap[MAP_WIDTH - 2][MAP_HEIGHT -2] = MAPOBJ_GRID;
}
if (roomType == roomTypeStandard)
{
if (rand() % 3 > 0 && gameFloor->neighboorCount(x, y) > 1)
{
if (type == 0 && game().getLevel() < 6) generateCorridors();
}
else
{
if (rand() % 3 == 0) initPattern((patternEnum)(rand() % 4));
}
}
}
if (type == 1) // corner block
{
if (rand() % 3 == 0) initPattern(PatternSmallChecker);
int wallOffset = wallType * 24;
map[0][0] = MAP_WALL_X;
map[0][1] = wallOffset + MAP_WALL_7;
map[1][1] = wallOffset + MAP_WALL_77;
map[1][0] = wallOffset + MAP_WALL_7;
logicalMap[1][1] = LogicalWall;
map[0][MAP_HEIGHT - 1] = MAP_WALL_X;
map[0][MAP_HEIGHT - 2] = wallOffset + MAP_WALL_7;
map[1][MAP_HEIGHT - 2] = wallOffset + MAP_WALL_77;
map[1][MAP_HEIGHT - 1] = wallOffset + MAP_WALL_7;
logicalMap[1][MAP_HEIGHT -2] = LogicalWall;
map[MAP_WIDTH - 1][0] = MAP_WALL_X;
map[MAP_WIDTH - 1][1] = wallOffset + MAP_WALL_7;
map[MAP_WIDTH - 2][1] = wallOffset + MAP_WALL_77;
map[MAP_WIDTH - 2][0] = wallOffset + MAP_WALL_7;
logicalMap[MAP_WIDTH - 2][1] = LogicalWall;
map[MAP_WIDTH - 1][MAP_HEIGHT -1] = MAP_WALL_X;
map[MAP_WIDTH - 1][MAP_HEIGHT -2] = wallOffset + MAP_WALL_7;
map[MAP_WIDTH - 2][MAP_HEIGHT -2] = wallOffset + MAP_WALL_77;
map[MAP_WIDTH - 2][MAP_HEIGHT -1] = wallOffset + MAP_WALL_7;
logicalMap[MAP_WIDTH - 2][MAP_HEIGHT -2] = LogicalWall;
}
if (type == 2) // blocks in the middle
{
if (rand() % 3 == 0) initPattern(PatternBorder);
r = 1 + rand() % 3;
generateTable(x0 - r, y0 - 1, 1 + 2 * r, 3, MAPOBJ_BIG_OBSTACLE);
}
if (type == 3)
{
// big blocks in the corners
generateTable(2, 2, 2, 2, MAPOBJ_BIG_OBSTACLE);
generateTable(2, MAP_HEIGHT - 4, 2, 2, MAPOBJ_BIG_OBSTACLE);
generateTable(MAP_WIDTH - 4, MAP_HEIGHT - 4, 2, 2, MAPOBJ_BIG_OBSTACLE);
generateTable(MAP_WIDTH - 4, 2, 2, 2, MAPOBJ_BIG_OBSTACLE);
}
if (type == 4)
{
// objects
if (rand() % 2 == 0)
{
// type 1
if (rand() % 3 == 0) initPattern(PatternSmallChecker);
bool leftOriented = rand() % 2 == 0;
int bankType = rand() % 3;
if (bankType == 2)
{
int xPlayer = game().getPlayerPosition().x;
if (xPlayer > GAME_WIDTH - TILE_WIDTH && xPlayer < GAME_WIDTH + TILE_WIDTH)
bankType = rand() % 2;
}
int x0 = leftOriented ? 5 : 3;
if (leftOriented)
{
objectsMap[2][4] = MAPOBJ_CHURCH_FURN_L;
logicalMap[2][4] = LogicalObstacle;
}
else
{
objectsMap[12][4] = MAPOBJ_CHURCH_FURN_R;
logicalMap[12][4] = LogicalObstacle;
}
for (int i = 0; i < 3; i++)
{
int xPos = x0 + i * 3;
switch (bankType)
{
case 0:
objectsMap[xPos][2] = MAPOBJ_BANK_TOP;
objectsMap[xPos][3] = MAPOBJ_BANK_BOTTOM;
objectsMap[xPos][5] = MAPOBJ_BANK_TOP;
objectsMap[xPos][6] = MAPOBJ_BANK_BOTTOM;
for (int j = 2; j <= 6; j++) if (j != 4) logicalMap[xPos][j] = LogicalObstacle;
break;
case 1:
objectsMap[xPos][2] = MAPOBJ_BANK_TOP;
objectsMap[xPos][3] = MAPOBJ_BANK;
objectsMap[xPos][4] = MAPOBJ_BANK;
objectsMap[xPos][5] = MAPOBJ_BANK;
objectsMap[xPos][6] = MAPOBJ_BANK_BOTTOM;
for (int j = 2; j <= 6; j++) logicalMap[xPos][j] = LogicalObstacle;
break;
case 2:
objectsMap[xPos][1] = MAPOBJ_BANK_TOP;
objectsMap[xPos][2] = MAPOBJ_BANK;
objectsMap[xPos][3] = MAPOBJ_BANK_BOTTOM;
objectsMap[xPos][5] = MAPOBJ_BANK_TOP;
objectsMap[xPos][6] = MAPOBJ_BANK;
objectsMap[xPos][7] = MAPOBJ_BANK_BOTTOM;
for (int j = 1; j <= 7; j++) if (j != 4) logicalMap[xPos][j] = LogicalObstacle;
break;
}
}
}
else
{
initPattern(PatternSmallStar);
generateLongObject(2, 2, 3, MAPOBJ_LONG_LEFT);
generateLongObject(2, 6, 3, MAPOBJ_LONG_LEFT);
generateLongObject(10, 2, 3, MAPOBJ_LONG_LEFT);
generateLongObject(10, 6, 3, MAPOBJ_LONG_LEFT);
generateLongObject(6, 4, 3, MAPOBJ_LONG_LEFT);
}
}
if (type == ROOM_TYPE_CHECKER)
{
// "checker"
if (rand() % 3 == 0) initPattern(PatternSmallChecker);
for (i = 2; i < MAP_WIDTH - 2; i = i + 2)
for (j = 2; j < MAP_HEIGHT - 2; j = j + 2)
{
objectsMap[i][j] = game().getLevel() >= 6 ? MAPOBJ_TOMB : MAPOBJ_OBSTACLE;
logicalMap[i][j] = LogicalObstacle;
}
}
generateRandomTile();
}
void DungeonMap::addHole(int x, int y)
{
int n = MAPOBJ_HOLE;
if (y > 0 && logicalMap[x][y - 1] == LogicalHole)
n = MAPOBJ_HOLE_BOTTOM;
else if (logicalMap[x - 1][y] == LogicalHole && logicalMap[x - 1][y - 1] == LogicalHole)
n = MAPOBJ_HOLE_LEFT;
else if (logicalMap[x + 1][y] == LogicalHole && logicalMap[x + 1][y - 1] == LogicalHole)
n = MAPOBJ_HOLE_RIGHT;
objectsMap[x][y] = n;
logicalMap[x][y] = LogicalHole;
if (logicalMap[x][y + 1] == LogicalHole && objectsMap[x - 1][y + 1] == MAPOBJ_HOLE_TOP)
objectsMap[x - 1][y + 1] = MAPOBJ_HOLE_LEFT;
if (logicalMap[x][y + 1] == LogicalHole && objectsMap[x + 1][y + 1] == MAPOBJ_HOLE_TOP)
objectsMap[x + 1][y + 1] = MAPOBJ_HOLE_RIGHT;
}
void DungeonMap::generateRoomWithHoles(int type)
{
initRoom();
int x0 = MAP_WIDTH / 2;
int y0 = MAP_HEIGHT / 2;
int i, j, r;
if (type == 0)
{
if (roomType == roomTypeStarting)
{
generateCarpet(5, 3, 5, 3, MAP_CARPET);
if (game().getLevel() > 1)
{
map[x0 - 1][MAP_HEIGHT - 1] = 62;
map[x0][MAP_HEIGHT - 1] = 63;
map[x0 + 1][MAP_HEIGHT - 1] = 64;
}
}
/*else if (rand() % 2 == 0)
{
for (int i = 1; i <= MAP_WIDTH - 2; i++)
{
if (i != MAP_WIDTH / 2 || !hasNeighbourUp()) addHole(i, 1);
}
for (int i = 2; i <= MAP_HEIGHT - 3; i++)
{
if (i != MAP_HEIGHT / 2 || !hasNeighbourLeft()) addHole(1, i);
if (i != MAP_HEIGHT / 2 || !hasNeighbourRight()) addHole(MAP_WIDTH - 2, i);
}
addHole(MAP_WIDTH - 2, MAP_HEIGHT - 2);
for (int i = 1; i <= MAP_WIDTH - 3; i++)
{
if (i != MAP_WIDTH / 2 || !hasNeighbourDown()) addHole(i, MAP_HEIGHT - 2);
}
}*/
}
else if (type == 1)
{
// corner hole
if (rand() % 3 == 0) initPattern(PatternSmallChecker);
addHole(1, 1);
addHole(MAP_WIDTH - 2, MAP_HEIGHT -2);
addHole(1, MAP_HEIGHT -2);
addHole(MAP_WIDTH - 2, 1);
}
else if (type == 2)
{
// blocks in the middle
if (rand() % 3 == 0) initPattern(PatternBorder);
/*if (false) //irregular // TO CORRECT
{
r = 1; //rand() % 2;
for (i = x0 - r; i <= x0 + r; i++)
{
if (rand() % 3 == 0) addHole(i, y0 - 1);
addHole(i, y0);
if (rand() % 3 == 0) addHole(i, y0 + 1);
}
for (j = y0 - 1; j <= y0 + 1; j++)
{
if (rand() % 3 == 0) addHole(x0 - r - 1, j);
if (rand() % 3 == 0) addHole(x0 + r + 1, j);
}
}
else*/
{
r = 1 + rand() % 2;
for (i = x0 - r; i <= x0 + r; i++)
for (j = y0 - 1; j <= y0 + 1; j++)
{
addHole(i, j);
}
}
}
else if (type == 3)
{
// 4 holes
addHole(2, 2);
addHole(2, 3);
addHole(3, 2);
addHole(3, 3);
addHole(MAP_WIDTH - 4, 2);
addHole(MAP_WIDTH - 4, 3);
addHole(MAP_WIDTH - 3, 2);
addHole(MAP_WIDTH - 3, 3);
addHole(2, MAP_HEIGHT - 4);
addHole(2, MAP_HEIGHT - 3);
addHole(3, MAP_HEIGHT - 4);
addHole(3, MAP_HEIGHT - 3);
addHole(MAP_WIDTH - 4, MAP_HEIGHT - 4);
addHole(MAP_WIDTH - 4, MAP_HEIGHT - 3);
addHole(MAP_WIDTH - 3, MAP_HEIGHT - 4);
addHole(MAP_WIDTH - 3, MAP_HEIGHT - 3);
}
else if (type == 4)
{
if (rand() % 2 == 0)
{
// holes and (sometimes) obstacles randomly
if (rand() % 3 == 0) initPattern(PatternBigCircle);
int r = 6 + rand()% 5;
int obstacleType = rand() % 2;
for (int i = 0; i < r; i++)
{
int rx = 1 + rand() % (MAP_WIDTH - 3);
int ry = 1 + rand() % (MAP_HEIGHT - 3);
bool ok = true;
bool isObstacle = (obstacleType == 1) && rand() % 2 == 0;
if ( (rx == 1 && ry == MAP_HEIGHT / 2)
|| (rx == MAP_WIDTH - 2 && ry == MAP_HEIGHT / 2)
|| (rx == MAP_WIDTH /2 && ry == MAP_HEIGHT - 2)
|| (rx == MAP_WIDTH /2 && ry == 1) )
{
ok = false;
}
else
{
for (int ix = -1; ix <= 1; ix++)
for (int iy = -1; iy <= 1; iy++)
{
ok = ok && logicalMap[rx + ix][ry + iy] != LogicalHole;
ok = ok && logicalMap[rx + ix][ry + iy] != LogicalObstacle;
}
}
if (ok)
{
if (!isObstacle)
{
addHole(rx, ry);
}
else
{
objectsMap[rx][ry] = MAPOBJ_OBSTACLE;
logicalMap[rx][ry] = LogicalObstacle;
}
}
else
{
i--;
}
}
}
else
{
// big holes left and right
bool holesNW = rand() % 2 == 0;
for (int i = 0; i < 5; i++)
{
if (holesNW)
{
addHole(1 + i, 1);
addHole(1 + i, 2);
addHole(MAP_WIDTH - 2 - i, MAP_HEIGHT - 3);
addHole(MAP_WIDTH - 2 - i, MAP_HEIGHT - 2);
}
else
{
addHole(1 + i, MAP_HEIGHT - 3);
addHole(1 + i, MAP_HEIGHT - 2);
addHole(MAP_WIDTH - 2 - i, 1);
addHole(MAP_WIDTH - 2 - i, 2);
}
}
}
}
else //if (type == 5)
{
// "checker"
for (i = 2; i < MAP_WIDTH - 2; i = i + 2)
for (j = 2; j < MAP_HEIGHT - 2; j = j + 2)
{
addHole(i, j);
}
}
generateRandomTile();
}
void DungeonMap::addItem(int itemType, float x, float y, bool merch)
{
itemListElement ilm;
ilm.type = itemType;
ilm.x = x;
ilm.y = y;
ilm.merch = merch;
itemList.push_back(ilm);
}
void DungeonMap::addSprite(int spriteType, int frame, float x, float y, float scale)
{
spriteListElement slm;
slm.type = spriteType;
slm.frame = frame;
slm.x = x;
slm.y = y;
slm.scale = scale;
spriteList.push_back(slm);
}
void DungeonMap::addChest(int chestType, bool state, float x, float y)
{
chestListElement clm;
clm.type = chestType;
clm.state = state;
clm.x = x;
clm.y = y;
chestList.push_back(clm);
}
void DungeonMap::restoreItems()
{
ItemList::iterator it;
for (it = itemList.begin (); it != itemList.end ();)
{
itemListElement ilm = *it;
it++;
ItemEntity* itemEntity = new ItemEntity((enumItemType)(ilm.type), ilm.x, ilm.y);
itemEntity->setMerchandise(ilm.merch);
}
}
void DungeonMap::restoreSprites()
{
SpriteList::iterator it;
for (it = spriteList.begin (); it != spriteList.end ();)
{
spriteListElement ilm = *it;
it++;
if (ilm.type == ENTITY_BLOOD)
game().getCurrentMapEntity()->addBlood(ilm.x, ilm.y, ilm.frame, ilm.scale);
else if (ilm.type == ENTITY_CORPSE)
game().getCurrentMapEntity()->addCorpse(ilm.x, ilm.y, ilm.frame);
}
}
void DungeonMap::restoreChests()
{
ChestList::iterator it;
for (it = chestList.begin (); it != chestList.end ();)
{
chestListElement clm = *it;
it++;
new ChestEntity(clm.x, clm.y, clm.type, clm.state);
}
}
void DungeonMap::restoreMapObjects()
{
restoreItems();
restoreSprites();
restoreChests();
cleanMapObjects();
}
void DungeonMap::cleanMapObjects()
{
itemList.clear();
spriteList.clear();
chestList.clear();
}
void DungeonMap::addRandomGrids(int n)
{
int counter = n;
while (counter > 0)
{
int rx = 1 + rand() % (MAP_WIDTH - 2);
int ry = 1 + rand() % (MAP_HEIGHT - 2);
if (logicalMap[rx][ry] == LogicalFloor
|| objectsMap[rx][ry] == 0)
{
objectsMap[rx][ry] = MAPOBJ_GRID;
counter--;
}
}
}
void DungeonMap::generateCorridors()
{
int xCor = 1 + rand()% 4;
int yCor = 1 + rand()% 1;
int wallOffset = wallType * 24;
if (!hasNeighbourLeft())
{
for (int i = 0; i < xCor; i++)
for (int j = 0; j < MAP_HEIGHT; j++)
{
map[i][j] = MAP_WALL_X;
logicalMap[i][j] = LogicalWall;
}
}
if (!hasNeighbourRight())
{
for (int i = MAP_WIDTH - 1; i > MAP_WIDTH - 1 - xCor; i--)
for (int j = 0; j < MAP_HEIGHT; j++)
{
map[i][j] = MAP_WALL_X;
logicalMap[i][j] = LogicalWall;
}
}
if (!hasNeighbourUp())
{
for (int i = 0; i < MAP_WIDTH; i++)
for (int j = 0; j < yCor; j++)
{
map[i][j] = MAP_WALL_X;
logicalMap[i][j] = LogicalWall;
}
}
if (!hasNeighbourDown())
{
for (int i = 0; i < MAP_WIDTH; i++)
for (int j = MAP_HEIGHT - 1; j > MAP_HEIGHT - 1 - yCor; j--)
{
map[i][j] = MAP_WALL_X;
logicalMap[i][j] = LogicalWall;
}
}
//
for (int i = 0; i < MAP_WIDTH; i++)
{
for (int j = 0; j < MAP_HEIGHT; j++)
{
if (map[i][j] != MAP_WALL_X)
{
if (getTile(i - 1, j) == MAP_WALL_X)
{
if (j == 0 || getTile(i, j - 1) == MAP_WALL_X)
{
map[i][j] = wallOffset + MAP_WALL_7;
}
else if (j == MAP_HEIGHT - 1 || getTile(i, j + 1) == MAP_WALL_X)
{
map[i][j] = wallOffset + MAP_WALL_7;
}
else
{
if (j < MAP_HEIGHT / 2) map[i][j] = wallOffset + MAP_WALL_87 + rand() % 8;
else if (j > MAP_HEIGHT / 2) map[i][j] = wallOffset + MAP_WALL_87 + rand() % 8;
else map[i][j] = wallOffset + MAP_WALL_8;
}
logicalMap[i][j] = LogicalWall;
}
else if (getTile(i + 1, j) == MAP_WALL_X)
{
if (j == 0 || getTile(i, j - 1) == MAP_WALL_X)
{
map[i][j] = wallOffset + MAP_WALL_7;
map[i][j] = wallOffset + MAP_WALL_7;
}
else if (j == MAP_HEIGHT - 1 || getTile(i, j + 1) == MAP_WALL_X) map[i][j] = wallOffset + MAP_WALL_7;
else
{
if (j < MAP_HEIGHT / 2) map[i][j] = wallOffset + MAP_WALL_87 + rand() % 8;
else if (j > MAP_HEIGHT / 2) map[i][j] = wallOffset + MAP_WALL_87 + rand() % 8;
else map[i][j] = wallOffset + MAP_WALL_8;
}
logicalMap[i][j] = LogicalWall;
}
else if (getTile(i, j - 1) == MAP_WALL_X)
{
if (i == 0) map[i][j] = wallOffset + MAP_WALL_7;
else if (i == MAP_WIDTH - 1) map[i][j] = wallOffset + MAP_WALL_7;
else
{
if (i < MAP_WIDTH / 2) map[i][j] = wallOffset + MAP_WALL_87 + rand() % 8;
else if (i > MAP_WIDTH / 2) map[i][j] = wallOffset + MAP_WALL_87 + rand() % 8;
else map[i][j] = wallOffset + MAP_WALL_8;
}
logicalMap[i][j] = LogicalWall;
}
else if (getTile(i, j + 1) == MAP_WALL_X)
{
if (i == 0) map[i][j] = wallOffset + MAP_WALL_7;
else if (i == MAP_WIDTH - 1) map[i][j] = wallOffset + MAP_WALL_7;
else
{
if (i < MAP_WIDTH / 2) map[i][j] = wallOffset + MAP_WALL_87 + rand() % 8;
else if (i > MAP_WIDTH / 2) map[i][j] = wallOffset + MAP_WALL_87 + rand() % 8;
else map[i][j] = wallOffset + MAP_WALL_8;
}
logicalMap[i][j] = LogicalWall;
}
}
}
}
}
void DungeonMap::generateRandomTile()
{
bool ok = false;
for (int i = 0; !ok && i < NB_RANDOM_TILE_TRY; i++)
{
int n = rand() % NB_RANDOM_TILES;
int xTile, yTile;
if (randomDungeonTiles[n].canBeOnWall && roomType != roomTypeKey)
{
xTile = rand() % (GAME_WIDTH - randomDungeonTiles[n].width);
yTile = rand() % (GAME_HEIGHT - randomDungeonTiles[n].height);
}
else
{
xTile = TILE_WIDTH + rand() % (GAME_WIDTH - 2 * TILE_WIDTH - randomDungeonTiles[n].width);
yTile = TILE_HEIGHT + rand() % (GAME_HEIGHT - 2 * TILE_HEIGHT - randomDungeonTiles[n].height);
}
int x0 = xTile / TILE_WIDTH;
int xf = (xTile + randomDungeonTiles[n].width) / TILE_WIDTH;
int y0 = yTile / TILE_HEIGHT;
int yf = (yTile + randomDungeonTiles[n].height) / TILE_HEIGHT;
ok = true;
if (!randomDungeonTiles[n].randomPlace)
{
for (int ix = x0; ix <= xf; ix++)
for (int iy = y0; iy <= yf; iy++)
{
ok = ok && isWalkable(ix, iy);
}
}
if (ok)
{
randomTileElement.type = n;
randomTileElement.x = xTile;
randomTileElement.y = yTile;
if (randomDungeonTiles[n].canRotate)
randomTileElement.rotation = rand()% 360;
else
randomTileElement.rotation = 0;
}
}
}
diff --git a/src/DungeonMapEntity.cpp b/src/DungeonMapEntity.cpp
index 8441d5e..8f3e4cd 100644
--- a/src/DungeonMapEntity.cpp
+++ b/src/DungeonMapEntity.cpp
@@ -1,1232 +1,1233 @@
#include <iostream>
#include <sstream>
#include "WitchBlastGame.h"
#include "DungeonMapEntity.h"
#include "Constants.h"
#include "sfml_game/ImageManager.h"
DungeonMapEntity::DungeonMapEntity() : GameEntity (0.0f, 0.0f)
{
this->z = -1.0f;
type = 0;
hasChanged = true;
DungeonMapEntityPost* post = new DungeonMapEntityPost(this);
post->setZ(-0.2f);
post->setType(0);
DungeonMapEntityOverlay* over = new DungeonMapEntityOverlay(this);
over->setZ(1000);
over->setType(0);
overlaySprite.setTexture(*ImageManager::getInstance().getImage(IMAGE_OVERLAY));
roomType = roomTypeStarting;
keyRoomEffect.delay = -1.0f;
randomSprite.setTexture(*ImageManager::getInstance().getImage(IMAGE_RANDOM_DUNGEON));
doorSprite.setTexture(*ImageManager::getInstance().getImage(IMAGE_DOORS));
doorSprite.setOrigin(96, 32);
keyStoneSprite.setTexture(*ImageManager::getInstance().getImage(IMAGE_DOORS));
keyStoneSprite.setOrigin(96, 32);
doorWallSprite.setTexture(*ImageManager::getInstance().getImage(IMAGE_TILES));
doorWallSprite.setOrigin(96, 32);
shadowType = ShadowTypeStandard;
}
void DungeonMapEntity::animate(float delay)
{
age += delay;
bool needCompute = getChanged() || game().getCurrentMap()->getChanged();
if (needCompute)
{
computeVertices();
computeOverVertices();
computeShadowVertices();
}
// blood
bool moving = false;
for (unsigned int i = 0; i < blood.size(); i++)
{
if (blood[i].moving)
{
moving = true;
if (checkFalling(blood[i], 16, 16))
{
SpriteEntity* spriteEntity
= new SpriteEntity(ImageManager::getInstance().getImage(IMAGE_BLOOD),
blood[i].x + 8,
blood[i].y + 8,
16, 16, 6);
spriteEntity->setAge(0.0f);
spriteEntity->setLifetime(3.0f);
spriteEntity->setShrinking(true);
spriteEntity->setFading(true);
spriteEntity->setFrame(blood[i].frame);
spriteEntity->setScale(blood[i].scale, blood[i].scale);
blood.erase(blood.begin() + i);
}
else
{
animateParticle(blood[i], delay, 0.95f);
if ((game().getParameters().bloodSpread && blood[i].frame < 12) || blood[i].frame >= 36)
{
if (blood[i].velocity.x * blood[i].velocity.x + blood[i].velocity.y * blood[i].velocity.y > 80
&& rand() % 4 == 0)
{
addBlood(blood[i].x, blood[i].y, blood[i].frame, blood[i].scale);
blood[i].scale *= 0.85f;
bool xPos = blood[i].velocity.x > 0;
bool yPos = blood[i].velocity.y > 0;
float norm = sqrtf(blood[i].velocity.x * blood[i].velocity.x + blood[i].velocity.y * blood[i].velocity.y);
blood[i].velocity = Vector2D(norm);
if (xPos && blood[i].velocity.x < 0) blood[i].velocity.x = - blood[i].velocity.x;
else if (!xPos && blood[i].velocity.x > 0) blood[i].velocity.x = - blood[i].velocity.x;
if (yPos && blood[i].velocity.y < 0) blood[i].velocity.y = - blood[i].velocity.y;
else if (!yPos && blood[i].velocity.y > 0) blood[i].velocity.y = - blood[i].velocity.y;
}
}
}
}
}
if (moving) computeBloodVertices();
// corpses
int CorpsesBox = 38, CorpsesLargeBox = 76;
moving = false;
for (unsigned int i = 0; i < corpses.size(); i++)
{
if (corpses[i].moving)
{
moving = true;
if (corpses[i].frame != FRAME_CORPSE_SLIME_VIOLET
&& collideWithWall(corpses[i], CorpsesBox, CorpsesBox))
{
if (checkFalling(corpses[i], 48, 48))
{
SpriteEntity* spriteEntity
= new SpriteEntity(ImageManager::getInstance().getImage(IMAGE_CORPSES),
corpses[i].x,
corpses[i].y,
64, 64, 10);
spriteEntity->setAge(0.0f);
spriteEntity->setLifetime(3.0f);
spriteEntity->setShrinking(true);
spriteEntity->setFading(true);
spriteEntity->setFrame(corpses[i].frame);
corpses.erase(corpses.begin() + i);
}
else
{
if (corpses[i].velocity.x < 15.0f && corpses[i].velocity.x > -15.0f
&& corpses[i].velocity.y < 15.0f && corpses[i].velocity.y > -15.0f)
autoSpeed(corpses[i], 200);
animateParticle(corpses[i], delay, 1.0f);
}
}
else
{
float oldx = corpses[i].x;
float oldy = corpses[i].y;
animateParticle(corpses[i], delay, 0.8f);
if (corpses[i].frame != FRAME_CORPSE_SLIME_VIOLET
&& collideWithWall(corpses[i], CorpsesBox, CorpsesBox))
{
corpses[i].x = oldx;
corpses[i].y = oldy;
moving = false;
}
}
}
}
for (unsigned int i = 0; i < corpsesLarge.size(); i++)
{
if (corpsesLarge[i].moving)
{
moving = true;
if (collideWithWall(corpsesLarge[i], CorpsesLargeBox, CorpsesLargeBox))
{
if (corpsesLarge[i].velocity.x < 15.0f && corpsesLarge[i].velocity.x > -15.0f
&& corpsesLarge[i].velocity.y < 15.0f && corpsesLarge[i].velocity.y > -15.0f)
autoSpeed(corpsesLarge[i], 200);
animateParticle(corpsesLarge[i], delay, 1.0f);
}
else
{
float oldx = corpsesLarge[i].x;
float oldy = corpsesLarge[i].y;
animateParticle(corpsesLarge[i], delay, 0.8f);
if (collideWithWall(corpsesLarge[i], CorpsesLargeBox, CorpsesLargeBox))
{
corpsesLarge[i].x = oldx;
corpsesLarge[i].y = oldy;
moving = false;
}
}
}
}
for (unsigned int i = 0; i < corpsesLarge.size(); i++)
{
if (corpsesLarge[i].moving)
{
moving = true;
animateParticle(corpsesLarge[i], delay, 0.95f);
}
}
if (moving) computeCorpsesVertices();
if (game().getCurrentMap()->getRoomType() == roomTypeKey && !game().getCurrentMap()->isCleared())
{
keyRoomEffect.delay -= delay;
if (keyRoomEffect.delay <= 0.0f)
{
keyRoomEffect.delay = KeyRoomFXDelay;
keyRoomEffect.amplitude = 120 + rand() % 100;
keyRoomEffect.isBlinking = false;
}
}
}
void DungeonMapEntity::animateParticle(displayEntityStruct &particle, float delay, float viscosity)
{
particle.velocity.x *= viscosity;
particle.velocity.y *= viscosity;
if (particle.velocity.x < -5 || particle.velocity.x > 5
|| particle.velocity.y < -5 || particle.velocity.y > 5)
{
particle.x += delay * particle.velocity.x;
particle.y += delay * particle.velocity.y;
}
else
particle.moving = false;
}
bool DungeonMapEntity::collideWithWall(displayEntityStruct &particle, int boxWidth, int boxHeight)
{
float x0 = particle.x - boxWidth / 2;
float xf = particle.x + boxWidth / 2;
float y0 = particle.y - boxHeight / 2;
float yf = particle.y + boxHeight / 2;
if (particle.x < TILE_WIDTH && particle.velocity.x < -1.0f) particle.velocity.x = -particle.velocity.x;
else if (particle.x > TILE_WIDTH * (MAP_WIDTH - 2) && particle.velocity.x > 1.0f) particle.velocity.x = -particle.velocity.x;
if (particle.y < TILE_HEIGHT && particle.velocity.y < -1.0f) particle.velocity.y = -particle.velocity.y;
else if (particle.y > TILE_HEIGHT * (MAP_HEIGHT - 2) && particle.velocity.y > 1.0f) particle.velocity.y = -particle.velocity.y;
collide[NordWest] = !game().getCurrentMap()->isWalkable(x0 / TILE_WIDTH, y0 / TILE_HEIGHT);
collide[SudWest] = !game().getCurrentMap()->isWalkable(x0 / TILE_WIDTH, yf / TILE_HEIGHT);
collide[NordEast] = !game().getCurrentMap()->isWalkable(xf / TILE_WIDTH, y0 / TILE_HEIGHT);
collide[SudEast] = !game().getCurrentMap()->isWalkable(xf / TILE_WIDTH, yf / TILE_HEIGHT);
return collide[NordWest] || collide[SudWest] || collide[NordEast] || collide[SudEast];
}
bool DungeonMapEntity::checkFalling(displayEntityStruct &particle, int boxWidth, int boxHeight)
{
int tilex = (particle.x + boxWidth / 2) / TILE_WIDTH;
int tiley = (particle.y + boxHeight / 2) / TILE_HEIGHT;
if (game().getCurrentMap()->getLogicalTile(tilex, tiley) != LogicalHole) return false;
tilex = (particle.x + boxWidth / 2 - boxWidth / 3) / TILE_WIDTH;
tiley = (particle.y + boxHeight / 2 - boxHeight / 3) / TILE_HEIGHT;
if (game().getCurrentMap()->getLogicalTile(tilex, tiley) != LogicalHole) return false;
tilex = (particle.x + boxWidth / 2 + boxWidth / 3) / TILE_WIDTH;
tiley = (particle.y + boxHeight / 2 + boxHeight / 3) / TILE_HEIGHT;
if (game().getCurrentMap()->getLogicalTile(tilex, tiley) != LogicalHole) return false;
return true;
}
void DungeonMapEntity::autoSpeed(displayEntityStruct &particle, float speed)
{
if (!collide[NordWest] && !collide[NordEast])
{
particle.velocity.x = 0;
particle.velocity.y = -speed;
}
else if (!collide[SudWest] && !collide[SudEast])
{
particle.velocity.x = 0;
particle.velocity.y = speed;
}
else if (!collide[SudWest] && !collide[NordWest])
{
particle.velocity.x = -speed;
particle.velocity.y = 0;
}
else if (!collide[SudEast] && !collide[NordEast])
{
particle.velocity.x = speed;
particle.velocity.y = 0;
}
else if (!collide[NordWest])
{
particle.velocity.x = -speed * 0.7f;
particle.velocity.y = -speed * 0.7f;
}
else if (!collide[NordEast])
{
particle.velocity.x = speed * 0.7f;
particle.velocity.y = -speed * 0.7f;
}
else if (!collide[SudWest])
{
particle.velocity.x = -speed * 0.7f;
particle.velocity.y = speed * 0.7f;
}
else if (!collide[SudEast])
{
particle.velocity.x = speed * 0.7f;
particle.velocity.y = speed * 0.7f;
}
else
particle.velocity = Vector2D(speed);
}
bool DungeonMapEntity::getChanged()
{
bool result = hasChanged;
hasChanged = false;
return result;
}
void DungeonMapEntity::render(sf::RenderTarget* app)
{
app->draw(vertices, ImageManager::getInstance().getImage(IMAGE_TILES));
// doors
renderDoors(app);
// random tile
if ( game().getCurrentMap()->getRandomTileElement().type > -1) app->draw(randomSprite);
// over tiles
app->draw(overVertices, ImageManager::getInstance().getImage(IMAGE_DUNGEON_OBJECTS));
if (game().getCurrentMap()->getRoomType() == roomTypeTemple)
{
for (int i = 1; i < MAP_WIDTH - 2 ; i++)
for (int j = 1; j < MAP_WIDTH - 2 ; j++)
if (game().getCurrentMap()->getTile(i, j) >= MAP_TEMPLE
&& game().getCurrentMap()->getTile(i, j) < MAP_TEMPLE + 10)
{
sf::Sprite tile;
tile.setTexture(*ImageManager::getInstance().getImage(IMAGE_TILES));
tile.setPosition(i * TILE_WIDTH, j * TILE_HEIGHT);
tile.setTextureRect(sf::IntRect((game().getCurrentMap()->getTile(i, j) % 24) * TILE_WIDTH,
(1 + game().getCurrentMap()->getTile(i, j) / 24) * TILE_HEIGHT,
TILE_WIDTH, TILE_HEIGHT));
int fade = 127 + 127 * (cosf(6.0f * game().getAbsolutTime()));
tile.setColor(sf::Color(255, 255, 255, fade));
app->draw(tile);
}
}
else if (game().getCurrentMap()->getRoomType() == roomTypeKey && !game().getCurrentMap()->isCleared())
{
int fade = 0;
if (keyRoomEffect.isBlinking)
{
fade = (int)(25.0f * game().getAbsolutTime()) % 2 == 0 ? 0 : 255;
}
else
{
if (keyRoomEffect.delay > KeyRoomFXDelay / 2)
fade = keyRoomEffect.amplitude - keyRoomEffect.amplitude * (keyRoomEffect.delay - KeyRoomFXDelay / 2) / KeyRoomFXDelay * 2;
else
fade = keyRoomEffect.amplitude - keyRoomEffect.amplitude * (KeyRoomFXDelay / 2 - keyRoomEffect.delay) / KeyRoomFXDelay * 2;
}
sf::Sprite tiles;
tiles.setTexture(*ImageManager::getInstance().getImage(IMAGE_KEY_AREA));
tiles.setPosition((MAP_WIDTH / 2 - 1) * TILE_WIDTH, (MAP_HEIGHT / 2 - 1) * TILE_HEIGHT);
tiles.setTextureRect(sf::IntRect(0, 0, 3 * TILE_WIDTH, 3 * TILE_HEIGHT));
app->draw(tiles);
tiles.setColor(sf::Color(255, 255, 255, fade));
tiles.setTextureRect(sf::IntRect(3 * TILE_WIDTH, 0, 3 * TILE_WIDTH, 3 * TILE_HEIGHT));
app->draw(tiles);
}
}
void DungeonMapEntity::renderKeyStone(sf::RenderTarget* app)
{
int x = game().getFloorX();
int y = game().getFloorY();
int doorType = 0;
int doorStypeStandard = DoorStandard_0 + (game().getLevel() - 1) % 5;
if (game().getCurrentMap()->getNeighbourUp() || game().getCurrentMap()->getRoomType() == roomTypeExit)
{
if (game().getCurrentMap()->getRoomType() == roomTypeBoss
|| game().getCurrentFloor()->getRoom(x, y - 1) == roomTypeBoss)
doorType = int (DoorBoss);
else if (game().getCurrentMap()->getRoomType() == roomTypeChallenge
|| game().getCurrentFloor()->getRoom(x, y - 1) == roomTypeChallenge)
doorType = int (DoorChallenge);
else
doorType = doorStypeStandard;
keyStoneSprite.setTextureRect(sf::IntRect(64, 128 + 192 * doorType, 192, 64));
keyStoneSprite.setPosition(TILE_WIDTH * MAP_WIDTH / 2, TILE_HEIGHT / 2);
keyStoneSprite.setRotation(0);
app->draw(keyStoneSprite);
}
if (game().getCurrentMap()->getNeighbourDown())
{
if (game().getCurrentMap()->getRoomType() == roomTypeBoss
|| game().getCurrentFloor()->getRoom(x, y + 1) == roomTypeBoss)
doorType = int (DoorBoss);
else if (game().getCurrentMap()->getRoomType() == roomTypeChallenge
|| game().getCurrentFloor()->getRoom(x, y + 1) == roomTypeChallenge)
doorType = int (DoorChallenge);
else
doorType = doorStypeStandard;
keyStoneSprite.setTextureRect(sf::IntRect(64, 128 + 192 * doorType, 192, 64));
keyStoneSprite.setPosition(TILE_WIDTH * MAP_WIDTH / 2, TILE_HEIGHT * MAP_HEIGHT - TILE_HEIGHT / 2);
keyStoneSprite.setRotation(180);
app->draw(keyStoneSprite);
}
if (game().getCurrentMap()->getNeighbourLeft())
{
if (game().getCurrentMap()->getRoomType() == roomTypeBoss
|| game().getCurrentFloor()->getRoom(x - 1, y) == roomTypeBoss)
doorType = int (DoorBoss);
else if (game().getCurrentMap()->getRoomType() == roomTypeChallenge
|| game().getCurrentFloor()->getRoom(x - 1, y) == roomTypeChallenge)
doorType = int (DoorChallenge);
else
doorType = doorStypeStandard;
keyStoneSprite.setTextureRect(sf::IntRect(64, 128 + 192 * doorType, 192, 64));
keyStoneSprite.setPosition(TILE_WIDTH / 2, TILE_HEIGHT * MAP_HEIGHT / 2);
keyStoneSprite.setRotation(270);
app->draw(keyStoneSprite);
}
if (game().getCurrentMap()->getNeighbourRight())
{
if (game().getCurrentMap()->getRoomType() == roomTypeBoss
|| game().getCurrentFloor()->getRoom(x + 1, y) == roomTypeBoss)
doorType = int (DoorBoss);
else if (game().getCurrentMap()->getRoomType() == roomTypeChallenge
|| game().getCurrentFloor()->getRoom(x + 1, y) == roomTypeChallenge)
doorType = int (DoorChallenge);
else
doorType = doorStypeStandard;
keyStoneSprite.setTextureRect(sf::IntRect(64, 128 + 192 * doorType, 192, 64));
keyStoneSprite.setPosition(TILE_WIDTH * MAP_WIDTH - TILE_WIDTH / 2, TILE_HEIGHT * MAP_HEIGHT / 2);
keyStoneSprite.setRotation(90);
app->draw(keyStoneSprite);
}
}
void DungeonMapEntity::renderDoors(sf::RenderTarget* app)
{
int x = game().getFloorX();
int y = game().getFloorY();
int doorType = 0;
int doorStypeStandard = DoorStandard_0 + (game().getLevel() - 1) % 5;
// fading from doors
doorWallSprite.setTextureRect(sf::IntRect(DOOR_SHADOW_SPRITE_X, DOOR_SHADOW_SPRITE_Y, 192, 64));
if (game().getCurrentMap()->hasNeighbourUp())
{
doorWallSprite.setPosition(TILE_WIDTH * MAP_WIDTH / 2, TILE_HEIGHT / 2);
doorWallSprite.setRotation(0);
app->draw(doorWallSprite);
}
- if (game().getCurrentMap()->hasNeighbourDown())
+ if (game().getCurrentMap()->hasNeighbourDown()
+ || (game().getLevel() > 1 && game().getCurrentMap()->getRoomType() == roomTypeStarting) )
{
doorWallSprite.setPosition(TILE_WIDTH * MAP_WIDTH / 2, TILE_HEIGHT * MAP_HEIGHT - TILE_HEIGHT / 2);
doorWallSprite.setRotation(180);
app->draw(doorWallSprite);
}
if (game().getCurrentMap()->hasNeighbourLeft())
{
doorWallSprite.setPosition(TILE_WIDTH / 2, TILE_HEIGHT * MAP_HEIGHT / 2);
doorWallSprite.setRotation(270);
app->draw(doorWallSprite);
}
if (game().getCurrentMap()->hasNeighbourRight())
{
doorWallSprite.setPosition(TILE_WIDTH * MAP_WIDTH - TILE_WIDTH / 2, TILE_HEIGHT * MAP_HEIGHT / 2);
doorWallSprite.setRotation(90);
app->draw(doorWallSprite);
}
game().renderDoors();
if (game().getCurrentMap()->hasNeighbourUp()
|| game().getCurrentMap()->getRoomType() == roomTypeExit)
{
if (game().getCurrentMap()->getRoomType() == roomTypeBoss
|| game().getCurrentFloor()->getRoom(x, y - 1) == roomTypeBoss)
{
doorType = int (DoorBoss);
}
else if (game().getCurrentMap()->getRoomType() == roomTypeChallenge
|| game().getCurrentFloor()->getRoom(x, y - 1) == roomTypeChallenge)
{
doorType = DoorChallenge;
}
else
doorType = doorStypeStandard;
doorWallSprite.setTextureRect(sf::IntRect(DOOR_WALL_SPRITE_X, game().getCurrentMap()->getWallType() * 64 + DOOR_WALL_SPRITE_Y, 192, 64));
doorWallSprite.setPosition(TILE_WIDTH * MAP_WIDTH / 2, TILE_HEIGHT / 2);
doorWallSprite.setRotation(0);
app->draw(doorWallSprite);
if (game().getCurrentMap()->getRoomType() == roomTypeExit)
{
doorWallSprite.setTextureRect(sf::IntRect(DOOR_STAIRS_SPRITE_X, DOOR_STAIRS_SPRITE_Y, 192, 64));
app->draw(doorWallSprite);
}
doorSprite.setTextureRect(sf::IntRect(64, 64 + 192 * doorType, 192, 64));
doorSprite.setPosition(TILE_WIDTH * MAP_WIDTH / 2, TILE_HEIGHT / 2);
doorSprite.setRotation(0);
app->draw(doorSprite);
}
if (game().getCurrentMap()->hasNeighbourDown()
|| (game().getLevel() > 1 && game().getCurrentMap()->getRoomType() == roomTypeStarting))
{
if (game().getCurrentMap()->getRoomType() == roomTypeBoss
|| game().getCurrentFloor()->getRoom(x, y + 1) == roomTypeBoss)
{
doorType = int (DoorBoss);
}
else if (game().getCurrentMap()->getRoomType() == roomTypeChallenge
|| game().getCurrentFloor()->getRoom(x, y + 1) == roomTypeChallenge)
{
doorType = DoorChallenge;
}
else
doorType = doorStypeStandard;
doorWallSprite.setPosition(TILE_WIDTH * MAP_WIDTH / 2, TILE_HEIGHT * MAP_HEIGHT - TILE_HEIGHT / 2);
doorWallSprite.setRotation(180);
doorWallSprite.setTextureRect(sf::IntRect(DOOR_WALL_SPRITE_X, game().getCurrentMap()->getWallType() * 64 + DOOR_WALL_SPRITE_Y, 192, 64));
app->draw(doorWallSprite);
if (game().getLevel() > 1 && game().getCurrentMap()->getRoomType() == roomTypeStarting)
{
doorWallSprite.setRotation(0);
doorWallSprite.setTextureRect(sf::IntRect(DOOR_GRID_SPRITE_X, DOOR_GRID_SPRITE_Y, 192, 64));
app->draw(doorWallSprite);
}
doorSprite.setPosition(TILE_WIDTH * MAP_WIDTH / 2, TILE_HEIGHT * MAP_HEIGHT - TILE_HEIGHT / 2);
doorSprite.setRotation(180);
doorSprite.setTextureRect(sf::IntRect(64, 64 + 192 * doorType, 192, 64));
app->draw(doorSprite);
}
if (game().getCurrentMap()->hasNeighbourLeft())
{
if (game().getCurrentMap()->getRoomType() == roomTypeBoss
|| game().getCurrentFloor()->getRoom(x - 1, y) == roomTypeBoss)
{
doorType = int (DoorBoss);
}
else if (game().getCurrentMap()->getRoomType() == roomTypeChallenge
|| game().getCurrentFloor()->getRoom(x - 1, y) == roomTypeChallenge)
{
doorType = DoorChallenge;
}
else
doorType = doorStypeStandard;
doorWallSprite.setPosition(TILE_WIDTH / 2, TILE_HEIGHT * MAP_HEIGHT / 2);
doorWallSprite.setRotation(270);
doorWallSprite.setTextureRect(sf::IntRect(DOOR_WALL_SPRITE_X, game().getCurrentMap()->getWallType() * 64 + DOOR_WALL_SPRITE_Y, 192, 64));
app->draw(doorWallSprite);
doorSprite.setTextureRect(sf::IntRect(64, 64 + 192 * doorType, 192, 64));
doorSprite.setPosition(TILE_WIDTH / 2, TILE_HEIGHT * MAP_HEIGHT / 2);
doorSprite.setRotation(270);
app->draw(doorSprite);
}
if (game().getCurrentMap()->hasNeighbourRight())
{
if (game().getCurrentMap()->getRoomType() == roomTypeBoss
|| game().getCurrentFloor()->getRoom(x + 1, y) == roomTypeBoss)
{
doorType = int (DoorBoss);
}
else if (game().getCurrentMap()->getRoomType() == roomTypeChallenge
|| game().getCurrentFloor()->getRoom(x + 1, y) == roomTypeChallenge)
{
doorType = DoorChallenge;
}
else
doorType = doorStypeStandard;
doorWallSprite.setPosition(TILE_WIDTH * MAP_WIDTH - TILE_WIDTH / 2, TILE_HEIGHT * MAP_HEIGHT / 2);
doorWallSprite.setRotation(90);
doorWallSprite.setTextureRect(sf::IntRect(DOOR_WALL_SPRITE_X, game().getCurrentMap()->getWallType() * 64 + DOOR_WALL_SPRITE_Y, 192, 64));
app->draw(doorWallSprite);
doorSprite.setTextureRect(sf::IntRect(64, 64 + 192 * doorType, 192, 64));
doorSprite.setPosition(TILE_WIDTH * MAP_WIDTH - TILE_WIDTH / 2, TILE_HEIGHT * MAP_HEIGHT / 2);
doorSprite.setRotation(90);
app->draw(doorSprite);
}
}
void DungeonMapEntity::renderPost(sf::RenderTarget* app)
{
displayBlood(app);
displayCorpses(app);
switch (shadowType)
{
case ShadowTypeStandard:
app->draw(shadowVertices, ImageManager::getInstance().getImage(IMAGE_TILES_SHADOW));
break;
case ShadowTypeCorner:
app->draw(shadowVertices, ImageManager::getInstance().getImage(IMAGE_TILES_SHADOW_CORNER));
break;
case ShadowTypeSmall:
app->draw(shadowVertices, ImageManager::getInstance().getImage(IMAGE_TILES_SHADOW_SMALL));
break;
case ShadowTypeMedium:
app->draw(shadowVertices, ImageManager::getInstance().getImage(IMAGE_TILES_SHADOW_MEDIUM));
break;
}
}
void DungeonMapEntity::renderOverlay(sf::RenderTarget* app)
{
renderKeyStone(app);
app->draw(overlaySprite);
}
std::vector <displayEntityStruct> DungeonMapEntity::getBlood()
{
return blood;
}
std::vector <displayEntityStruct> DungeonMapEntity::getCorpses()
{
auto result = corpses;
result.insert( result.end(), corpsesLarge.begin(), corpsesLarge.end() );
return result;
}
void DungeonMapEntity::displayBlood(sf::RenderTarget* app)
{
app->draw(bloodVertices, ImageManager::getInstance().getImage(IMAGE_BLOOD));
}
void DungeonMapEntity::displayCorpses(sf::RenderTarget* app)
{
app->draw(corpsesVertices, ImageManager::getInstance().getImage(IMAGE_CORPSES));
app->draw(corpsesLargeVertices, ImageManager::getInstance().getImage(IMAGE_CORPSES_BIG));
}
void DungeonMapEntity::refreshMap()
{
hasChanged = true;
blood.clear();
corpses.clear();
corpsesLarge.clear();
computeBloodVertices();
computeCorpsesVertices();
}
bool DungeonMapEntity::shouldBeTransformed(int part)
{
part -= game().getCurrentMap()->getWallType() * 24;
if (part >= MAP_WALL_8 && part < MAP_WALL_8 + 24) return true;
else return false;
}
void DungeonMapEntity::computeVertices()
{
DungeonMap* gameMap = game().getCurrentMap();
int tilesProLine = 24;
int tileWidth = 64;
int tileHeight = 64;
int tileBoxWidth = 64;
int tileBoxHeight = 64;
vertices.setPrimitiveType(sf::Quads);
vertices.resize(gameMap->getWidth() * gameMap->getHeight() * 4);
for (int i = 0; i < gameMap->getWidth(); i++)
for (int j = 0; j < gameMap->getHeight(); j++)
{
int nx = gameMap->getTile(i, j) % tilesProLine;
int ny = gameMap->getTile(i, j) / tilesProLine;
sf::Vertex* quad = &vertices[(i + j * gameMap->getWidth()) * 4];
if (shouldBeTransformed(gameMap->getTile(i, j)))
{
if (j == 0 && i <= MAP_WIDTH / 2)
{
quad[0].position = sf::Vector2f(x + i * tileWidth, y + j * tileHeight);
quad[1].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + j * tileHeight);
quad[2].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
quad[3].position = sf::Vector2f(x + i * tileWidth, y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
}
else if (j == 0 && i > MAP_HEIGHT / 2)
{
quad[1].position = sf::Vector2f(x + i * tileWidth, y + j * tileHeight);
quad[0].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + j * tileHeight);
quad[3].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
quad[2].position = sf::Vector2f(x + i * tileWidth, y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
}
else if (j == MAP_HEIGHT - 1 && i <= MAP_WIDTH / 2)
{
quad[3].position = sf::Vector2f(x + i * tileWidth, y + j * tileHeight);
quad[2].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + j * tileHeight);
quad[1].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
quad[0].position = sf::Vector2f(x + i * tileWidth, y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
}
else if (j == MAP_HEIGHT - 1 && i > MAP_WIDTH / 2)
{
quad[2].position = sf::Vector2f(x + i * tileWidth, y + j * tileHeight);
quad[3].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + j * tileHeight);
quad[0].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
quad[1].position = sf::Vector2f(x + i * tileWidth, y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
}
else if (i == 0 && j <= MAP_HEIGHT / 2)
{
quad[0].position = sf::Vector2f(x + i * tileWidth, y + j * tileHeight);
quad[3].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + j * tileHeight);
quad[2].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
quad[1].position = sf::Vector2f(x + i * tileWidth, y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
}
else if (i == 0 && j > MAP_HEIGHT / 2)
{
quad[1].position = sf::Vector2f(x + i * tileWidth, y + j * tileHeight);
quad[2].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + j * tileHeight);
quad[3].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
quad[0].position = sf::Vector2f(x + i * tileWidth, y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
}
else if (i == MAP_WIDTH - 1 && j <= MAP_HEIGHT / 2)
{
quad[3].position = sf::Vector2f(x + i * tileWidth, y + j * tileHeight);
quad[0].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + j * tileHeight);
quad[1].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
quad[2].position = sf::Vector2f(x + i * tileWidth, y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
}
else if (i == MAP_WIDTH - 1 && j > MAP_HEIGHT / 2)
{
quad[2].position = sf::Vector2f(x + i * tileWidth, y + j * tileHeight);
quad[1].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + j * tileHeight);
quad[0].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
quad[3].position = sf::Vector2f(x + i * tileWidth, y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
}
// corridors
else if (i < MAP_WIDTH / 2 && j <= MAP_HEIGHT / 2 && gameMap->getTile(i, j - 1) != game().getCurrentMap()->getWallType() * 24 + MAP_WALL_X)
{
quad[0].position = sf::Vector2f(x + i * tileWidth, y + j * tileHeight);
quad[3].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + j * tileHeight);
quad[2].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
quad[1].position = sf::Vector2f(x + i * tileWidth, y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
}
else if (i < MAP_WIDTH / 2 && j > MAP_HEIGHT / 2 && gameMap->getTile(i, j + 1) != game().getCurrentMap()->getWallType() * 24 + MAP_WALL_X)
{
quad[1].position = sf::Vector2f(x + i * tileWidth, y + j * tileHeight);
quad[2].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + j * tileHeight);
quad[3].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
quad[0].position = sf::Vector2f(x + i * tileWidth, y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
}
else if (i > MAP_WIDTH / 2 && j <= MAP_HEIGHT / 2 && gameMap->getTile(i, j - 1) != game().getCurrentMap()->getWallType() * 24 + MAP_WALL_X)
{
quad[3].position = sf::Vector2f(x + i * tileWidth, y + j * tileHeight);
quad[0].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + j * tileHeight);
quad[1].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
quad[2].position = sf::Vector2f(x + i * tileWidth, y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
}
else if (i > MAP_WIDTH / 2 && j > MAP_HEIGHT / 2 && gameMap->getTile(i, j + 1) != game().getCurrentMap()->getWallType() * 24 + MAP_WALL_X)
{
quad[2].position = sf::Vector2f(x + i * tileWidth, y + j * tileHeight);
quad[1].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + j * tileHeight);
quad[0].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
quad[3].position = sf::Vector2f(x + i * tileWidth, y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
}
else if (j < MAP_HEIGHT / 2 && i <= MAP_WIDTH / 2)
{
quad[0].position = sf::Vector2f(x + i * tileWidth, y + j * tileHeight);
quad[1].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + j * tileHeight);
quad[2].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
quad[3].position = sf::Vector2f(x + i * tileWidth, y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
}
else if (j < MAP_HEIGHT / 2 && i > MAP_HEIGHT / 2)
{
quad[1].position = sf::Vector2f(x + i * tileWidth, y + j * tileHeight);
quad[0].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + j * tileHeight);
quad[3].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
quad[2].position = sf::Vector2f(x + i * tileWidth, y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
}
else if (j > MAP_HEIGHT / 2 && i <= MAP_WIDTH / 2)
{
quad[3].position = sf::Vector2f(x + i * tileWidth, y + j * tileHeight);
quad[2].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + j * tileHeight);
quad[1].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
quad[0].position = sf::Vector2f(x + i * tileWidth, y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
}
else if (j > MAP_HEIGHT / 2 && i > MAP_WIDTH / 2)
{
quad[2].position = sf::Vector2f(x + i * tileWidth, y + j * tileHeight);
quad[3].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + j * tileHeight);
quad[0].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
quad[1].position = sf::Vector2f(x + i * tileWidth, y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
}
}
else
{
quad[0].position = sf::Vector2f(x + i * tileWidth, y + j * tileHeight);
quad[1].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + j * tileHeight);
quad[2].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
quad[3].position = sf::Vector2f(x + i * tileWidth, y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
}
quad[0].texCoords = sf::Vector2f(nx * tileBoxWidth, ny * tileBoxHeight);
quad[1].texCoords = sf::Vector2f((nx + 1) * tileBoxWidth, ny * tileBoxHeight);
quad[2].texCoords = sf::Vector2f((nx + 1) * tileBoxWidth, (ny + 1) * tileBoxHeight);
quad[3].texCoords = sf::Vector2f(nx * tileBoxWidth, (ny + 1) * tileBoxHeight);
}
//if (roomType != game().getCurrentMap()->getRoomType())
{
std::stringstream ss;
roomType = game().getCurrentMap()->getRoomType();
switch (roomType)
{
case roomTypeChallenge:
ImageManager::getInstance().getImage(IMAGE_OVERLAY)->loadFromFile("media/overlay_boss_01.png");
break;
case roomTypeTemple:
ImageManager::getInstance().getImage(IMAGE_OVERLAY)->loadFromFile("media/overlay_temple.png");
break;
case roomTypeMerchant:
ImageManager::getInstance().getImage(IMAGE_OVERLAY)->loadFromFile("media/overlay_shop.png");
break;
case roomTypeBoss:
ss << "media/overlay_boss_0" << game().getLevel() << ".png";
ImageManager::getInstance().getImage(IMAGE_OVERLAY)->loadFromFile(ss.str());
break;
default:
if ( gameMap->getObjectTile(6, 2) == MAPOBJ_BANK_TOP
|| gameMap->getObjectTile(6, 2) == MAPOBJ_BANK
|| gameMap->getObjectTile(6, 2) == MAPOBJ_BANK_BOTTOM
|| gameMap->getObjectTile(8, 2) == MAPOBJ_BANK_TOP
|| gameMap->getObjectTile(8, 2) == MAPOBJ_BANK
|| gameMap->getObjectTile(8, 2) == MAPOBJ_BANK_BOTTOM
)
ImageManager::getInstance().getImage(IMAGE_OVERLAY)->loadFromFile("media/overlay_temple.png");
else
ImageManager::getInstance().getImage(IMAGE_OVERLAY)->loadFromFile("media/overlay_00.png");
break;
}
overlaySprite.setTexture(*ImageManager::getInstance().getImage(IMAGE_OVERLAY));
}
int n = game().getCurrentMap()->getRandomTileElement().type;
if ( n > -1)
{
randomSprite.setPosition(game().getCurrentMap()->getRandomTileElement().x + randomDungeonTiles[n].width / 2,
game().getCurrentMap()->getRandomTileElement().y + randomDungeonTiles[n].height / 2);
randomSprite.setOrigin(randomDungeonTiles[n].width / 2, randomDungeonTiles[n].height / 2);
randomSprite.setTextureRect(sf::IntRect(randomDungeonTiles[n].xOffset, randomDungeonTiles[n].yOffset, randomDungeonTiles[n].width, randomDungeonTiles[n].height));
randomSprite.setRotation(game().getCurrentMap()->getRandomTileElement().rotation);
}
}
void DungeonMapEntity::computeOverVertices()
{
DungeonMap* gameMap = game().getCurrentMap();
int tilesProLine = 10;
int tileWidth = 64;
int tileHeight = 64;
int tileBoxWidth = 64;
int tileBoxHeight = 64;
overVertices.setPrimitiveType(sf::Quads);
overVertices.resize(gameMap->getWidth() * gameMap->getHeight() * 4);
for (int i = 0; i < gameMap->getWidth(); i++)
for (int j = 0; j < gameMap->getHeight(); j++)
{
//if (gameMap->getObjectTile(i, j) > 2)
{
int nx = gameMap->getObjectTile(i, j) % tilesProLine;
int ny = gameMap->getObjectTile(i, j) / tilesProLine;
sf::Vertex* quad = &overVertices[(i + j * gameMap->getWidth()) * 4];
{
quad[0].position = sf::Vector2f(x + i * tileWidth, y + j * tileHeight);
quad[1].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + j * tileHeight);
quad[2].position = sf::Vector2f(x + (i + 1) * tileWidth + (tileBoxWidth -tileWidth), y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
quad[3].position = sf::Vector2f(x + i * tileWidth, y + (j + 1) * tileHeight + (tileBoxHeight - tileHeight));
}
quad[0].texCoords = sf::Vector2f(nx * tileBoxWidth, ny * tileBoxHeight);
quad[1].texCoords = sf::Vector2f((nx + 1) * tileBoxWidth, ny * tileBoxHeight);
quad[2].texCoords = sf::Vector2f((nx + 1) * tileBoxWidth, (ny + 1) * tileBoxHeight);
quad[3].texCoords = sf::Vector2f(nx * tileBoxWidth, (ny + 1) * tileBoxHeight);
}
}
}
void DungeonMapEntity::computeShadowVertices()
{
DungeonMap* gameMap = game().getCurrentMap();
int tileWidth = 64;
int tileHeight = 64;
int tileBoxWidth = 64;
int tileBoxHeight = 64;
int x0 = 0;
int y0 = 0;
int xf = MAP_WIDTH - 1;
int yf = MAP_HEIGHT - 1;
int xd = 4;
int yd = 4;
if (gameMap->getLogicalTile(1, 1) == LogicalWall
&& gameMap->getLogicalTile(2, 1) != LogicalWall
&& gameMap->getLogicalTile(1, 2) != LogicalWall)
{
// corner
shadowType = ShadowTypeCorner;
}
else
{
x0 = MAP_WIDTH / 2;
while (gameMap->getLogicalTile(x0, MAP_HEIGHT / 2 + 1) != LogicalWall) x0--;
xf = MAP_WIDTH / 2;
while (gameMap->getLogicalTile(xf, MAP_HEIGHT / 2 + 1) != LogicalWall) xf++;
y0 = MAP_HEIGHT / 2;
while (gameMap->getLogicalTile(MAP_WIDTH / 2 + 1, y0) != LogicalWall) y0--;
yf = MAP_HEIGHT / 2;
while (gameMap->getLogicalTile(MAP_WIDTH / 2 + 1, yf) != LogicalWall) yf++;
if (yf - y0 <= 4)
{
shadowType = ShadowTypeSmall;
xd = 3;
yd = 2;
}
else if (yf - y0 <= 6 || xf - x0 <= 6)
{
shadowType = ShadowTypeMedium;
xd = 3;
yd = 3;
}
else
{
shadowType = ShadowTypeStandard;
}
}
shadowVertices.setPrimitiveType(sf::Quads);
shadowVertices.resize(8 * 4);
int xm0 = x0 + xd;
int xmf = xf - xd;
int ym0 = y0 + yd;
int ymf = yf - yd;
// top left
{
sf::Vertex* quad = &shadowVertices[0 * 4];
quad[0].position = sf::Vector2f(x0 * tileWidth, y0 * tileHeight);
quad[1].position = sf::Vector2f((x0 + xd)* tileWidth, y0 * tileHeight);
quad[2].position = sf::Vector2f((x0 + xd) * tileWidth, (y0 + yd) * tileHeight);
quad[3].position = sf::Vector2f(x0 * tileWidth, (y0 + yd) * tileHeight);
quad[0].texCoords = sf::Vector2f(0 * tileBoxWidth, 0 * tileBoxHeight);
quad[1].texCoords = sf::Vector2f(xd * tileBoxWidth, 0 * tileBoxHeight);
quad[2].texCoords = sf::Vector2f(xd * tileBoxWidth, yd * tileBoxHeight);
quad[3].texCoords = sf::Vector2f(0 * tileBoxWidth, yd * tileBoxHeight);
}
// top
{
sf::Vertex* quad = &shadowVertices[1 * 4];
quad[0].position = sf::Vector2f(xm0 * tileWidth, y0 * tileHeight);
quad[1].position = sf::Vector2f((xmf + 1)* tileWidth, y0 * tileHeight);
quad[2].position = sf::Vector2f((xmf + 1) * tileWidth, (y0 + yd) * tileHeight);
quad[3].position = sf::Vector2f(xm0 * tileWidth, (y0 + yd) * tileHeight);
quad[0].texCoords = sf::Vector2f(xd * tileBoxWidth, 0 * tileBoxHeight);
quad[1].texCoords = sf::Vector2f((xd + 1) * tileBoxWidth, 0 * tileBoxHeight);
quad[2].texCoords = sf::Vector2f((xd + 1) * tileBoxWidth, yd * tileBoxHeight);
quad[3].texCoords = sf::Vector2f(xd * tileBoxWidth, yd * tileBoxHeight);
}
// top right
{
sf::Vertex* quad = &shadowVertices[2 * 4];
quad[0].position = sf::Vector2f((xf - xd + 1) * tileWidth, y0 * tileHeight);
quad[1].position = sf::Vector2f((xf + 1)* tileWidth, y0 * tileHeight);
quad[2].position = sf::Vector2f((xf + 1) * tileWidth, (y0 + yd) * tileHeight);
quad[3].position = sf::Vector2f((xf - xd + 1) * tileWidth, (y0 + yd) * tileHeight);
quad[0].texCoords = sf::Vector2f((xd + 1) * tileBoxWidth, 0 * tileBoxHeight);
quad[1].texCoords = sf::Vector2f((xd + xd + 1) * tileBoxWidth, 0 * tileBoxHeight);
quad[2].texCoords = sf::Vector2f((xd + xd + 1) * tileBoxWidth, yd * tileBoxHeight);
quad[3].texCoords = sf::Vector2f((xd + 1) * tileBoxWidth, yd * tileBoxHeight);
}
// left
{
sf::Vertex* quad = &shadowVertices[3 * 4];
quad[0].position = sf::Vector2f(x0 * tileWidth, ym0 * tileHeight);
quad[1].position = sf::Vector2f((x0 + xd) * tileWidth, ym0 * tileHeight);
quad[2].position = sf::Vector2f((x0 + xd) * tileWidth, (ymf + 1) * tileHeight);
quad[3].position = sf::Vector2f(x0 * tileWidth, (ymf + 1) * tileHeight);
quad[0].texCoords = sf::Vector2f(0 * tileBoxWidth, yd * tileBoxHeight);
quad[1].texCoords = sf::Vector2f(xd * tileBoxWidth, yd * tileBoxHeight);
quad[2].texCoords = sf::Vector2f(xd * tileBoxWidth, (yd + 1) * tileBoxHeight);
quad[3].texCoords = sf::Vector2f(0 * tileBoxWidth, (yd + 1) * tileBoxHeight);
}
// right
{
sf::Vertex* quad = &shadowVertices[4 * 4];
quad[0].position = sf::Vector2f((xf - xd + 1) * tileWidth, ym0 * tileHeight);
quad[1].position = sf::Vector2f((xf + 1) * tileWidth, ym0 * tileHeight);
quad[2].position = sf::Vector2f((xf + 1) * tileWidth, (ymf + 1) * tileHeight);
quad[3].position = sf::Vector2f((xf - xd + 1) * tileWidth, (ymf + 1) * tileHeight);
quad[0].texCoords = sf::Vector2f((xd + 1) * tileBoxWidth, yd * tileBoxHeight);
quad[1].texCoords = sf::Vector2f((xd + xd + 1) * tileBoxWidth, yd * tileBoxHeight);
quad[2].texCoords = sf::Vector2f((xd + xd + 1) * tileBoxWidth, (yd + 1) * tileBoxHeight);
quad[3].texCoords = sf::Vector2f((xd + 1) * tileBoxWidth, (yd + 1) * tileBoxHeight);
}
// bottom left
{
sf::Vertex* quad = &shadowVertices[5 * 4];
quad[0].position = sf::Vector2f(x0 * tileWidth, (yf - yd + 1) * tileHeight);
quad[1].position = sf::Vector2f((x0 + xd)* tileWidth, (yf - yd + 1) * tileHeight);
quad[2].position = sf::Vector2f((x0 + xd) * tileWidth, (1 + yf) * tileHeight);
quad[3].position = sf::Vector2f(x0 * tileWidth, (1 + yf) * tileHeight);
quad[0].texCoords = sf::Vector2f(0 * tileBoxWidth, (yd + 1) * tileBoxHeight);
quad[1].texCoords = sf::Vector2f(xd * tileBoxWidth, (yd + 1) * tileBoxHeight);
quad[2].texCoords = sf::Vector2f(xd * tileBoxWidth, (yd + yd + 1) * tileBoxHeight);
quad[3].texCoords = sf::Vector2f(0 * tileBoxWidth, (yd + yd + 1) * tileBoxHeight);
}
// bottom
{
sf::Vertex* quad = &shadowVertices[6 * 4];
quad[0].position = sf::Vector2f(xm0 * tileWidth, (yf - yd + 1) * tileHeight);
quad[1].position = sf::Vector2f((xmf + 1)* tileWidth, (yf - yd + 1) * tileHeight);
quad[2].position = sf::Vector2f((xmf + 1) * tileWidth, (1 + yf) * tileHeight);
quad[3].position = sf::Vector2f(xm0 * tileWidth, (1 + yf) * tileHeight);
quad[0].texCoords = sf::Vector2f(xd * tileBoxWidth, (yd + 1) * tileBoxHeight);
quad[1].texCoords = sf::Vector2f((xd + 1) * tileBoxWidth, (yd + 1) * tileBoxHeight);
quad[2].texCoords = sf::Vector2f((xd + 1) * tileBoxWidth, (yd + yd + 1) * tileBoxHeight);
quad[3].texCoords = sf::Vector2f(xd * tileBoxWidth, (yd + yd + 1) * tileBoxHeight);
}
// bottom right
{
sf::Vertex* quad = &shadowVertices[7 * 4];
quad[0].position = sf::Vector2f((xf - xd + 1) * tileWidth, (yf - yd + 1) * tileHeight);
quad[1].position = sf::Vector2f((xf + 1)* tileWidth, (yf - yd + 1) * tileHeight);
quad[2].position = sf::Vector2f((xf + 1) * tileWidth, (1 + yf) * tileHeight);
quad[3].position = sf::Vector2f((xf - xd + 1) * tileWidth, (1 + yf) * tileHeight);
quad[0].texCoords = sf::Vector2f((xd + 1) * tileBoxWidth, (yd + 1) * tileBoxHeight);
quad[1].texCoords = sf::Vector2f((xd + xd + 1) * tileBoxWidth, (yd + 1) * tileBoxHeight);
quad[2].texCoords = sf::Vector2f((xd + xd + 1) * tileBoxWidth, (yd + yd + 1) * tileBoxHeight);
quad[3].texCoords = sf::Vector2f((xd + 1) * tileBoxWidth, (yd + yd + 1) * tileBoxHeight);
}
}
void DungeonMapEntity::computeBloodVertices()
{
bloodVertices.setPrimitiveType(sf::Quads);
bloodVertices.resize(blood.size() * 4);
for (unsigned int i = 0; i < blood.size(); i++)
{
auto particle = blood[i];
sf::Vertex* quad = &bloodVertices[i * 4];
float middle = 8.0f * particle.scale;
int nx = particle.frame % 6;
int ny = particle.frame / 6;
quad[0].position = sf::Vector2f(particle.x - middle, particle.y - middle);
quad[1].position = sf::Vector2f(particle.x + middle, particle.y - middle);
quad[2].position = sf::Vector2f(particle.x + middle, particle.y + middle);
quad[3].position = sf::Vector2f(particle.x - middle, particle.y + middle);
quad[0].texCoords = sf::Vector2f(nx * 16, ny * 16);
quad[1].texCoords = sf::Vector2f((nx + 1) * 16, ny * 16);
quad[2].texCoords = sf::Vector2f((nx + 1) * 16, (ny + 1) * 16);
quad[3].texCoords = sf::Vector2f(nx * 16, (ny + 1) * 16);
}
}
void DungeonMapEntity::computeCorpsesVertices()
{
corpsesVertices.setPrimitiveType(sf::Quads);
corpsesVertices.resize(corpses.size() * 4);
for (unsigned int i = 0; i < corpses.size(); i++)
{
auto particle = corpses[i];
sf::Vertex* quad = &corpsesVertices[i * 4];
float middle = 32;
int nx = particle.frame % 10;
int ny = particle.frame / 10;
quad[0].position = sf::Vector2f(particle.x - middle, particle.y - middle);
quad[1].position = sf::Vector2f(particle.x + middle, particle.y - middle);
quad[2].position = sf::Vector2f(particle.x + middle, particle.y + middle);
quad[3].position = sf::Vector2f(particle.x - middle, particle.y + middle);
quad[0].texCoords = sf::Vector2f(nx * 64, ny * 64);
quad[1].texCoords = sf::Vector2f((nx + 1) * 64, ny * 64);
quad[2].texCoords = sf::Vector2f((nx + 1) * 64, (ny + 1) * 64);
quad[3].texCoords = sf::Vector2f(nx * 64, (ny + 1) * 64);
}
corpsesLargeVertices.setPrimitiveType(sf::Quads);
corpsesLargeVertices.resize(corpsesLarge.size() * 4);
for (unsigned int i = 0; i < corpsesLarge.size(); i++)
{
auto particle = corpsesLarge[i];
sf::Vertex* quad = &corpsesLargeVertices[i * 4];
float middle = 64;
int nx = (particle.frame - FRAME_CORPSE_KING_RAT) % 8;
int ny = (particle.frame - FRAME_CORPSE_KING_RAT) / 8;
quad[0].position = sf::Vector2f(particle.x - middle, particle.y - middle);
quad[1].position = sf::Vector2f(particle.x + middle, particle.y - middle);
quad[2].position = sf::Vector2f(particle.x + middle, particle.y + middle);
quad[3].position = sf::Vector2f(particle.x - middle, particle.y + middle);
quad[0].texCoords = sf::Vector2f(nx * 128, ny * 128);
quad[1].texCoords = sf::Vector2f((nx + 1) * 128, ny * 128);
quad[2].texCoords = sf::Vector2f((nx + 1) * 128, (ny + 1) * 128);
quad[3].texCoords = sf::Vector2f(nx * 128, (ny + 1) * 128);
}
}
displayEntityStruct& DungeonMapEntity::generateBlood(float x, float y, BaseCreatureEntity::enumBloodColor bloodColor)
{
displayEntityStruct bloodEntity;
int b0 = 0 + 6 * (int)bloodColor;
bloodEntity.frame = b0 + rand()%6;
bloodEntity.velocity = Vector2D(rand()%250);
bloodEntity.x = x;
bloodEntity.y = y;
bloodEntity.scale = /*bloodColor == 0 ?*/ 1.0f + (rand() % 10) * 0.1f /*: 1.0f*/;
bloodEntity.moving = true;
blood.push_back(bloodEntity);
return blood[blood.size() - 1];
}
void DungeonMapEntity::addBlood(float x, float y, int frame, float scale)
{
displayEntityStruct bloodEntity;
bloodEntity.frame = frame;
bloodEntity.x = x;
bloodEntity.y = y;
bloodEntity.velocity.x = 0;
bloodEntity.velocity.y = 0;
bloodEntity.scale = scale;
bloodEntity.moving = true;
blood.push_back(bloodEntity);
}
void DungeonMapEntity::addCorpse(float x, float y, int frame)
{
displayEntityStruct corpseEntity;
corpseEntity.frame = frame;
corpseEntity.x = x;
corpseEntity.y = y;
corpseEntity.velocity.x = 0;
corpseEntity.velocity.y = 0;
corpseEntity.scale = 0.0f;
corpseEntity.moving = true;
if (frame >= FRAME_CORPSE_KING_RAT)
{
corpsesLarge.push_back(corpseEntity);
}
else
{
corpses.push_back(corpseEntity);
}
}
void DungeonMapEntity::activateKeyRoomEffect()
{
keyRoomEffect.isBlinking = true;
keyRoomEffect.delay = 1.0f;
}
/////////////////////////////////////////////////////////////////////////
DungeonMapEntityPost::DungeonMapEntityPost(DungeonMapEntity* parent) : GameEntity (0.0f, 0.0f)
{
this->parent = parent;
}
void DungeonMapEntityPost::animate(float delay)
{
}
void DungeonMapEntityPost::render(sf::RenderTarget* app)
{
parent->renderPost(app);
}
/////////////////////////////////////////////////////////////////////////
DungeonMapEntityOverlay::DungeonMapEntityOverlay(DungeonMapEntity* parent) : GameEntity (0.0f, 0.0f)
{
this->parent = parent;
}
void DungeonMapEntityOverlay::animate(float delay)
{
}
void DungeonMapEntityOverlay::render(sf::RenderTarget* app)
{
parent->renderOverlay(app);
}

File Metadata

Mime Type
text/x-diff
Expires
Mon, Jun 15, 11:39 PM (2 w, 2 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
70211
Default Alt Text
(89 KB)

Event Timeline