BitmapWars/src/map.c

114 lines
2.2 KiB
C
Raw Permalink Normal View History

2019-08-05 14:32:22 +02:00
#include "map.h"
#include "item.h"
#include <gint/std/string.h>
2019-08-05 14:32:22 +02:00
2019-08-06 20:14:02 +02:00
#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()
2019-08-05 14:32:22 +02:00
{
// effacement
for (int x=0;x<DIM_X;x++)
{
for (int y=0;y<DIM_Y;y++)
{
map[y][x].terrain=EARTH;
2019-08-06 20:14:02 +02:00
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;
}
2019-08-06 20:14:02 +02:00
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;
2019-08-06 20:14:02 +02:00
map[2][3].item.type=WALL;
map[2][2].item.type=HOUSE;
2019-08-06 20:14:02 +02:00
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;
2019-08-05 14:32:22 +02:00
}
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)
{
2019-08-06 20:14:02 +02:00
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()
2019-08-05 14:32:22 +02:00
{
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();
2019-08-05 14:32:22 +02:00
}