114 lines
2.2 KiB
C
114 lines
2.2 KiB
C
#include "map.h"
|
|
#include "item.h"
|
|
#include <gint/std/string.h>
|
|
|
|
|
|
#define DIM_X 16
|
|
#define DIM_Y 8
|
|
|
|
// la map correspond à un système par couches successives :
|
|
|
|
// fond de carte => terrain constructible ou pas, accessible ou pas...
|
|
// les items (troupes, maisons, routes, murs)
|
|
|
|
|
|
|
|
generic_map map[DIM_Y][DIM_X];
|
|
void create_map()
|
|
{
|
|
// effacement
|
|
for (int x=0;x<DIM_X;x++)
|
|
{
|
|
for (int y=0;y<DIM_Y;y++)
|
|
{
|
|
map[y][x].terrain=EARTH;
|
|
map[y][x].explored=true;//false;
|
|
map[y][x].item.type=0;
|
|
}
|
|
}
|
|
// ajout du village allié et de la zone d'exploration
|
|
|
|
// ajout du village ennemi
|
|
|
|
// ajout des bords
|
|
for (int x=0;x<DIM_X;x++)
|
|
{
|
|
map[0][x].terrain=WATER;
|
|
map[DIM_Y-1][x].terrain=WATER;
|
|
}
|
|
for (int y=0;y<DIM_Y;y++)
|
|
{
|
|
map[y][0].terrain=WATER;
|
|
map[y][DIM_X-1].terrain=WATER;
|
|
}
|
|
|
|
map[1][1].item.type=WALL;
|
|
map[1][2].item.type=WALL;
|
|
map[1][3].item.type=WALL;
|
|
|
|
map[3][1].item.type=WALL;
|
|
map[3][2].item.type=WALL;
|
|
map[3][3].item.type=WALL;
|
|
|
|
map[2][1].item.type=WALL;
|
|
map[2][3].item.type=WALL;
|
|
map[2][2].item.type=HOUSE;
|
|
|
|
map[5][3].item.type=HOUSE;
|
|
map[5][2].item.type=HOUSE;
|
|
map[6][2].item.type=HOUSE;
|
|
|
|
|
|
map[6][4].terrain=WATER;
|
|
map[6][5].terrain=WATER;
|
|
map[6][6].terrain=WATER;
|
|
|
|
map[5][5].terrain=WATER;
|
|
map[5][6].terrain=WATER;
|
|
map[5][7].terrain=WATER;
|
|
|
|
}
|
|
|
|
|
|
int dx=0, dy=0; // delta(en items) pour l'affichage
|
|
|
|
generic_item* get_item(int x, int y)
|
|
{
|
|
if (x<0||x>=DIM_X||y<0||y>=DIM_Y)
|
|
return 0;
|
|
return &map[y][x].item;
|
|
}
|
|
|
|
bool get_visibility(int x, int y)
|
|
{
|
|
if (x<0||x>=DIM_X||y<0||y>=DIM_Y)
|
|
return false;
|
|
return map[y][x].explored;
|
|
}
|
|
int get_terrain(int x,int y)
|
|
{
|
|
if (x<0||x>=DIM_X||y<0||y>=DIM_Y)
|
|
return WATER;
|
|
return map[y][x].terrain;
|
|
}
|
|
|
|
void set_item(int x, int y, generic_item const * const item)
|
|
{
|
|
if (x<0||x>=DIM_X||y<0||y>DIM_Y)
|
|
return;
|
|
memcpy(&map[y][x].item,item,sizeof(generic_item));
|
|
}
|
|
|
|
|
|
void display()
|
|
{
|
|
dclear(C_WHITE);
|
|
for (int x=0;x<16;x++)
|
|
{
|
|
for (int y=0;y<8;y++)
|
|
{
|
|
display_case(x-dx,y-dy,8*x,8*y);
|
|
}
|
|
}
|
|
dupdate();
|
|
} |