Carte/src/main.c

136 lines
6.0 KiB
C
Raw Normal View History

2020-04-18 23:33:56 +02:00
#include <gint/display.h>
#include <gint/keyboard.h>
int main(void)
{
2020-04-19 13:43:36 +02:00
//Initialisation de la map
int xMap = 50;
int yMap = 20;
int map[20][50] = { {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1},
{2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1}};
2020-04-19 13:43:36 +02:00
extern image_t img_grass_1;
extern image_t img_grass_2;
extern image_t img_grass_3;
//Initialisation du joueur
int x = 0;
2020-04-18 23:33:56 +02:00
int y = 0;
2020-04-19 13:43:36 +02:00
extern image_t img_player;
2020-04-18 23:33:56 +02:00
2020-04-19 13:43:36 +02:00
//Initialisation de la camera
int xCamera, yCamera;
int xCameraOffset = 12;
int yCameraOffset = 7;
int xCameraMax = 0;
2020-04-18 23:33:56 +02:00
2020-04-19 13:43:36 +02:00
//Boucle de jeu
2020-04-18 23:33:56 +02:00
while(1)
{
2020-04-19 13:43:36 +02:00
//Positionement de la caméra par rapport au joueur
xCameraMax = 0;
2020-04-19 13:43:36 +02:00
if (x-xCameraOffset < 0)
{
xCamera = 0;
} else if (x+xCameraOffset > xMap-1)
2020-04-19 13:43:36 +02:00
{
xCamera = xMap-1-xCameraOffset*2;
xCameraMax = 1;
2020-04-19 13:43:36 +02:00
}else
{
xCamera = x-xCameraOffset;
}
if (y-yCameraOffset < 0)
{
yCamera = 0;
} else if (y+yCameraOffset > yMap)
{
2020-04-19 14:13:39 +02:00
yCamera = yMap-yCameraOffset*2;
2020-04-19 13:43:36 +02:00
}else
{
yCamera = y-yCameraOffset;
}
//Chargement de la partie de la map à afficher
dclear(C_WHITE);
int i, j;
for(j=0;j<14;j++)
{
for(i=0; i<25; i++)
{
switch(map[j+yCamera][i+xCamera])
{
case 0:
dimage(i*16-(4*xCameraMax), j*16, &img_grass_1);
2020-04-19 13:43:36 +02:00
break;
case 1:
dimage(i*16-(4*xCameraMax), j*16, &img_grass_2);
2020-04-19 13:43:36 +02:00
break;
case 2:
dimage(i*16-(4*xCameraMax), j*16, &img_grass_3);
2020-04-19 13:43:36 +02:00
break;
}
}
}
//Affichage de l'écran
dimage((x-xCamera)*16-(4*xCameraMax), (y-yCamera)*16, &img_player);
2020-04-18 23:33:56 +02:00
dupdate();
2020-04-19 13:43:36 +02:00
//Gestion du clavier
2020-04-18 23:33:56 +02:00
switch(getkey().key)
{
case KEY_UP:
2020-04-19 13:43:36 +02:00
y--;
if (y < 0)
{
2020-04-19 14:48:40 +02:00
y = 0;
}
2020-04-18 23:33:56 +02:00
break;
case KEY_DOWN:
2020-04-19 13:43:36 +02:00
y++;
if (y > yMap)
{
2020-04-19 14:48:40 +02:00
y = yMap;
}
2020-04-18 23:33:56 +02:00
break;
case KEY_LEFT:
2020-04-19 13:43:36 +02:00
x--;
if (x < 0)
{
2020-04-19 14:48:40 +02:00
x = 0;
}
2020-04-18 23:33:56 +02:00
break;
case KEY_RIGHT:
2020-04-19 13:43:36 +02:00
x++;
if (x > xMap)
{
2020-04-19 14:48:40 +02:00
x = xMap;
}
break;
2020-04-18 23:33:56 +02:00
break;
2020-04-19 13:43:36 +02:00
case KEY_EXE:
2020-04-18 23:33:56 +02:00
return 0;
}
}
return 0;
}