This repository has been archived by the owner on Dec 14, 2020. It is now read-only.
forked from manfriedn64/castlen64
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2dmap.h
148 lines (128 loc) · 3.25 KB
/
2dmap.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#ifndef _2DMAP_H_
#define _2DMAP_H_
#include "2dlibrary.h"
#define COLLISION_NONE 0
#define COLLISION_BLOCK 1
#define COLLISION_HURT 2
#define COLLISION_ACTION_NONE 0
#define COLLISION_ACTION_BLOCK 1
#define COLLISION_ACTION_SMASH 2
#define COLLISION_ACTION_PUSH 3
#define TILE_ACTION_NONE -1
#define TILE_ACTION_CLOSED 0
#define TILE_ACTION_OPENED 1
#define TILE_ACTION_LEVER_CLOSED 0
#define TILE_ACTION_LEVER_INTER1 1
#define TILE_ACTION_LEVER_INTER2 2
#define TILE_ACTION_LEVER_OPENED 3
#define TILE_FOREGROUND_NEVER -1
#define TILE_FOREGROUND_ALWAYS 1000
typedef struct Tile Tile;
typedef struct Map Map;
typedef struct MapRow MapRow;
typedef struct MapColumn MapColumn;
typedef struct CollisionBox CollisionBox;
typedef struct MapDraw MapDraw;
typedef struct Character Character;
typedef struct CharacterSides CharacterSides;
struct MapDraw {
int first_column;
int first_row;
int x;
int y;
};
struct MapRow {
int y;
MapRow* previous;
MapRow* next;
Tile* tile;
int state;
MapRow* related_row;
void (*action)(MapRow* );
void (*over)(MapRow* );
};
struct MapColumn {
int x;
MapColumn* previous;
MapColumn* next;
MapRow* first_row;
};
struct CollisionBox {
int start_x;
int start_y;
int end_x;
int end_y;
int action;
} ;
struct Tile {
int (*checkCollision)(CollisionBox*, MapRow*, int);
Texture* texture;
Animation* animation;
int (*action)(MapRow* );
int foreground;
} ;
struct Map {
int nbr_columns;
int nbr_rows;
int nbr_tiles;
int max_columns;
int max_rows;
int max_tiles;
int column_width;
int row_height;
int max_column;
int max_row;
MapColumn* start;
MapRow* rows;
MapColumn* columns;
Tile* tiles;
};
struct CharacterSides {
AnimatedSprite attack;
AnimatedSprite defend;
AnimatedSprite hurt;
AnimatedSprite idle;
AnimatedSprite walk;
AnimatedSprite dead;
int (*collision)(Map*, int, int, int );
int (*action)(Map*, int, int, int );
int (*push)(Map*, int, int, int );
};
struct Character {
CharacterSides back;
CharacterSides front;
CharacterSides left;
CharacterSides right;
Animation animation;
CharacterSides* side;
int x;
int y;
int move_x;
int move_y;
int status; // playing or not
int life;
int state;
int keys;
Character* next;
Character* previous;
int (*collision)(Map*, int, int, int );
};
void freeMap(Map* map);
void initMap(Map* map, int columns, int rows, int tiles, int width, int height);
void appendMapColumn(Map* map, MapColumn* new_column);
MapColumn* findMapColumn(Map* map, int x);
MapColumn* nextMapColumn(Map* map, int x);
MapRow* findMapRow(MapRow* row, int y);
MapRow* sortRows(Map* map, MapRow* row);
MapRow* sortMap(Map* map);
void appendMapRow(MapColumn* column, MapRow* row);
MapRow* nextMapRow(Map* map, int y, Tile* tile);
void drawMap(Map* map, Character* character);
MapDraw checkMapPosition(Map* map, int x, int y);
int characterIsInTile(Map* map, Character* character, int tile_x, int tile_y);
int testCollisionBox(Map*, CollisionBox*, int, int, int);
int collisionWall(CollisionBox*, MapRow*, int);
int collisionNone(CollisionBox*, MapRow*, int);
int checkIntersection(int start1, int end1, int start2, int end2);
void actionRow(MapRow* );
#endif /* _2DMAP_H_*/