BitmapWars/src/map.c

94 lines
1.8 KiB
C

#include "map.h"
#include "item.h"
#include <gint/std/string.h>
#define DIM_X 5
#define DIM_Y 5
// 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=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[0][0].item.type=WALL;
map[0][1].item.type=WALL;
map[0][2].item.type=WALL;
map[2][0].item.type=WALL;
map[2][1].item.type=WALL;
map[2][2].item.type=WALL;
map[1][0].item.type=WALL;
map[1][2].item.type=WALL;
}
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 true;
return 1-map[y][x].explored;
}
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();
}