Screen and display gestion

This commit is contained in:
Shadow15510 2021-08-18 16:37:59 +02:00
parent da17beef2a
commit cba3e7ba75
7 changed files with 42 additions and 30 deletions

View File

@ -3,7 +3,7 @@
<editorsettings>
<export target="../maps/world.json" format="json"/>
</editorsettings>
<tileset firstgid="1" source="tileset.json"/>
<tileset firstgid="1" source="tileset.tsx"/>
<layer id="1" name="Calque de Tuiles 1" width="25" height="25">
<data encoding="csv">
55,55,55,6,55,55,6,6,55,6,59,6,55,6,6,55,55,6,55,6,55,55,6,55,6,
@ -35,25 +35,25 @@
</layer>
<layer id="2" name="Calque de Tuiles 2" width="25" height="25">
<data encoding="csv">
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
455,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,514,738,739,739,739,739,739,739,739,739,739,739,740,514,0,289,0,0,0,0,0,0,0,
0,0,563,787,736,837,837,837,837,837,837,837,837,737,789,563,0,0,0,0,0,0,0,0,0,
0,0,0,787,789,0,0,0,0,0,0,0,0,787,789,0,0,0,0,0,289,0,0,0,0,
0,0,514,787,789,0,0,0,0,0,0,0,0,787,789,514,0,0,0,0,0,0,0,0,0,
0,0,563,787,789,0,0,0,0,0,0,0,0,787,789,563,0,0,0,0,0,0,0,0,0,
0,0,0,787,789,0,0,0,0,0,0,0,0,787,789,0,0,0,0,0,0,0,0,0,0,
0,0,514,787,789,0,0,0,0,0,0,0,0,787,789,514,0,0,0,291,292,532,0,0,0,
0,0,514,787,789,0,0,0,0,0,0,0,0,787,789,514,0,0,0,291,292,532,0,0,472,
0,0,563,787,789,0,0,0,0,0,0,0,0,787,789,563,0,514,0,340,341,532,532,0,0,
0,0,0,787,785,739,739,739,739,739,739,739,739,786,789,0,0,563,313,0,0,0,0,0,0,
0,0,514,836,837,837,837,837,837,837,837,837,837,837,838,514,0,0,0,406,0,359,359,0,0,
0,0,563,0,0,0,0,0,0,0,0,0,0,0,0,563,0,0,0,0,0,0,0,0,0,
0,0,563,0,0,0,0,0,0,0,0,0,0,0,0,563,0,0,0,313,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,514,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,563,0,0,0,514,0,0,0,0,0,514,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,563,0,0,0,0,0,563,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,514,0,0,0,0,0,0,0,0,0,0,0,909,761,761,910,0,0,0,0,0,0,0,
0,0,563,0,0,0,0,0,0,0,1023,1020,1020,1020,958,761,761,959,0,0,0,0,0,0,0,
0,0,514,0,0,0,0,0,0,0,0,0,0,0,909,914,914,910,0,0,0,0,0,0,0,
0,0,563,0,0,0,0,0,0,0,1023,1020,1020,1020,958,963,963,959,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,1023,1024,0,0,1007,960,960,1008,0,0,0,16,0,0,0,
0,0,0,0,0,0,0,0,0,0,1023,1024,0,0,0,383,0,0,0,60,60,109,0,0,0,
0,0,0,0,0,0,0,0,0,0,1023,1019,1020,1020,0,33,0,383,20,256,256,305,0,0,0,

View File

@ -15,7 +15,7 @@
"y":0
},
{
"data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 514, 738, 739, 739, 739, 739, 739, 739, 739, 739, 739, 739, 740, 514, 0, 289, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 787, 736, 837, 837, 837, 837, 837, 837, 837, 837, 737, 789, 563, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 0, 0, 0, 0, 0, 289, 0, 0, 0, 0, 0, 0, 514, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 514, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 563, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 514, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 514, 0, 0, 0, 291, 292, 532, 0, 0, 0, 0, 0, 563, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 563, 0, 514, 0, 340, 341, 532, 532, 0, 0, 0, 0, 0, 787, 785, 739, 739, 739, 739, 739, 739, 739, 739, 786, 789, 0, 0, 563, 313, 0, 0, 0, 0, 0, 0, 0, 0, 514, 836, 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, 838, 514, 0, 0, 0, 406, 0, 359, 359, 0, 0, 0, 0, 563, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 514, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 0, 0, 0, 514, 0, 0, 0, 0, 0, 514, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 0, 0, 0, 0, 0, 563, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 514, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 909, 761, 761, 910, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 0, 0, 0, 0, 0, 0, 0, 1023, 1020, 1020, 1020, 958, 761, 761, 959, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1023, 1024, 0, 0, 1007, 960, 960, 1008, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1023, 1024, 0, 0, 0, 383, 0, 0, 0, 60, 60, 109, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1023, 1019, 1020, 1020, 0, 33, 0, 383, 20, 256, 256, 305, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 934, 936, 0, 0, 0, 0, 0, 0, 0, 0, 0, 885, 886, 886, 886, 886, 886, 886, 886, 886, 886, 886, 886, 886, 886, 933, 936, 0, 0, 0, 0, 0, 0, 0, 0, 0, 983, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 985, 0, 0, 0, 0, 0, 0, 0, 0],
"data":[455, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 514, 738, 739, 739, 739, 739, 739, 739, 739, 739, 739, 739, 740, 514, 0, 289, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 787, 736, 837, 837, 837, 837, 837, 837, 837, 837, 737, 789, 563, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 0, 0, 0, 0, 0, 289, 0, 0, 0, 0, 0, 0, 514, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 514, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 563, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 514, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 514, 0, 0, 0, 291, 292, 532, 0, 0, 472, 0, 0, 563, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 563, 0, 514, 0, 340, 341, 532, 532, 0, 0, 0, 0, 0, 787, 785, 739, 739, 739, 739, 739, 739, 739, 739, 786, 789, 0, 0, 563, 313, 0, 0, 0, 0, 0, 0, 0, 0, 514, 836, 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, 838, 514, 0, 0, 0, 406, 0, 359, 359, 0, 0, 0, 0, 563, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 0, 0, 0, 313, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 514, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 0, 0, 0, 514, 0, 0, 0, 0, 0, 514, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 0, 0, 0, 0, 0, 563, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 514, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 909, 914, 914, 910, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 0, 0, 0, 0, 0, 0, 0, 1023, 1020, 1020, 1020, 958, 963, 963, 959, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1023, 1024, 0, 0, 1007, 960, 960, 1008, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1023, 1024, 0, 0, 0, 383, 0, 0, 0, 60, 60, 109, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1023, 1019, 1020, 1020, 0, 33, 0, 383, 20, 256, 256, 305, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 934, 936, 0, 0, 0, 0, 0, 0, 0, 0, 0, 885, 886, 886, 886, 886, 886, 886, 886, 886, 886, 886, 886, 886, 886, 933, 936, 0, 0, 0, 0, 0, 0, 0, 0, 0, 983, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 985, 0, 0, 0, 0, 0, 0, 0, 0],
"height":25,
"id":2,
"name":"Calque de Tuiles 2",
@ -35,7 +35,7 @@
"tilesets":[
{
"firstgid":1,
"source":"..\/Tiled\/tileset.json"
"source":"..\/Tiled\/tileset.tsx"
}],
"tilewidth":16,
"type":"map",

View File

@ -7,18 +7,19 @@ void display_map(const int x_offset, const int y_offset)
for (int layer = 0 ; layer < map_world.nb_layers; layer++)
{
for (int y = 0 ; y <= map_world.height; y ++)
for (int y = 0 ; y <= SCREEN_HEIGHT; y ++)
{
for (int x = 0 ; x <= map_world.width; x ++)
for (int x = 0 ; x <= SCREEN_WIDTH; x ++)
{
unsigned int tile_id = map_world.layers[layer][y * map_world.width + x];
unsigned int tile_id = map_world.layers[layer][(y + y_offset / TILE_SIZE) * map_world.width + (x + x_offset / TILE_SIZE)];
if (tile_id != 0)
{
tile_id --;
unsigned int tile_x = (TILE_SIZE + 1) * (tile_id % TILESET_WIDTH);
unsigned int tile_y = (TILE_SIZE + 1) * (tile_id / TILESET_WIDTH);
dsubimage(x_offset + x * TILE_SIZE, y_offset + y * TILE_SIZE, &img_tileset, tile_x, tile_y, TILE_SIZE, TILE_SIZE, DIMAGE_NONE);
dsubimage(x * TILE_SIZE - (x_offset % TILE_SIZE), y * TILE_SIZE - (y_offset % TILE_SIZE), &img_tileset, tile_x, tile_y, TILE_SIZE, TILE_SIZE, DIMAGE_NONE);
}
}
}

View File

@ -2,20 +2,7 @@
#define _DISPLAY_ENGINE_H
#include <gint/display.h>
#define TILE_SIZE 16
#define TILESET_WIDTH 49
#define SCREEN_WIDTH 24
#define SCREEN_HEIGHT 14
struct map
{
int width, height, nb_layers;
// to get the (x; y) cell : layers[layer_number][y * map_width + x]
uint16_t *layers[];
};
#include "map.h"
// display_map : show the current map with x, y offsets
void display_map(const int x_offset, const int y_offset);

View File

@ -2,22 +2,24 @@
void keyboard_manager(const int key, int *x_offset, int *y_offset)
{
extern const struct map map_world;
switch(key)
{
case KEY_UP:
*y_offset -= 4;
if (*y_offset - 1 >= 0) *y_offset -= 2;
break;
case KEY_RIGHT:
*x_offset += 4;
if (*x_offset + 396 < map_world.width * TILE_SIZE) *x_offset += 2;
break;
case KEY_DOWN:
*y_offset += 4;
if (*y_offset + 224 < map_world.height * TILE_SIZE) *y_offset += 2;
break;
case KEY_LEFT:
*x_offset -= 4;
if (*x_offset - 1 >= 0) *x_offset -= 2;
break;
}
}

View File

@ -2,6 +2,7 @@
#define _GAME_ENGINE_H
#include <gint/keyboard.h>
#include "map.h"
void keyboard_manager(const int key, int *x_offset, int *y_offset);

21
src/map.h Normal file
View File

@ -0,0 +1,21 @@
#ifndef _MAP_H
#define _MAP_H
#include <stdlib.h>
#include <gint/display.h>
#define TILE_SIZE 16
#define TILESET_WIDTH 49
#define SCREEN_WIDTH 24
#define SCREEN_HEIGHT 14
struct map
{
int width, height, nb_layers;
// to get the (x; y) cell : layers[layer_number][y * map_width + x]
uint16_t *layers[];
};
#endif /* _MAP_H */