-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTilemap.h
61 lines (49 loc) · 1.69 KB
/
Tilemap.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef TILEMAP_H
#define TILEMAP_H
#define MAX_CHUNK_DISTANCE 9
#define MIN(a, b) ((a) < (b)) ? (a) : (b)
#include <stdio.h>
#include <sys/mman.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdbool.h>
#include "Block.h"
#include "Entity.h"
#include "PerlinNoise.h"
#include "Chunk.h"
#include "Coordinate.h"
typedef struct TilemapBlock_S
{
Block_s *m_block;
struct TilemapBlock_S *m_next;
} TilemapBlock_s;
typedef struct Tilemap_S
{
int m_width;
int m_height;
Block_s ***m_blocks;
struct Chunk_S *m_chunks[MAX_CHUNK_DISTANCE][MAX_CHUNK_DISTANCE];
struct Entitieslist_S *m_entities;
struct Player_S *m_player;
// Previous player chunk
struct Chunk_S *m_previous_chunk;
// Does the chunk need to be saved
bool m_save_previous_chunk;
Coordinate_s m_top_coord;
} Tilemap_s;
Tilemap_s* CreateTilemap(const int m_wdith, const int m_height);
//void FillTilemap(Tilemap_s* tilemap, const char* mapfile);
// Tilemap_s* CreateTilemapFromFile(const char* mapfile);
Tilemap_s *CreateTilemapProcedurally(int width, int height, int seed);
void PrintTilemap(Tilemap_s* tilemap);
void addEntityToTilemap(Tilemap_s *tilemap, struct Entity_S *entity);
void freeTilemap(Tilemap_s *tilemap);
void freeEntitiesList(struct Entitieslist_S *list);
/************************** COORDINATE CALCULATION ***********************************/
Coordinate_s getEntityTilemapCoordinate(struct Entity_S *entity);
Coordinate_s getTopCoordinateFromChunk(Tilemap_s *tilemap, Coordinate_s chunk_coord);
Coordinate_s getEntityCoordinateInChunk(struct Entity_S *entity);
Coordinate_s TilemapToChunkCoordinates(Coordinate_s tilemap_coord);
#endif /* !TILEMAP_H */