Fixed vmap, added a function to check for collisions.
This commit is contained in:
parent
a26d25e498
commit
75e7ef772d
|
@ -14,7 +14,8 @@ SRC = src/start.c \
|
|||
src/memory.c \
|
||||
src/rtc.c \
|
||||
src/ext/img.c \
|
||||
src/ext/gametools/map.c
|
||||
src/ext/gametools/map.c \
|
||||
src/ext/gametools/collisions.c
|
||||
OBJ = $(SRC:src/%=build/%.o)
|
||||
|
||||
CFLAGS = -Os -Wall -Wextra -Wpedantic -Werror -std=c89
|
||||
|
|
|
@ -22,14 +22,10 @@ typedef struct {
|
|||
|
||||
/* Prototypes */
|
||||
|
||||
/* void vmap(int padx, int pady, int w, int h, int sx, int sy, MMap *map);
|
||||
/* void vmap(int sx, int sy, MMap *map);
|
||||
|
||||
Draws a map contained in a MMap struct.
|
||||
dmap draw the map from sx, sy, at padx, pady on the screen with width w and
|
||||
height h on screen.
|
||||
The map should be the first thing to be drawn, because the map is not perfectly
|
||||
drawn at (padx, pady), and vplayer and vitem use some variables that are updated
|
||||
when calling vmap.
|
||||
vmap draw the map with the player at sx, sy.
|
||||
*/
|
||||
|
||||
void vmap(int sx, int sy, MMap *map);
|
||||
|
@ -54,4 +50,14 @@ anim_frame is the frame of the animation of item that should be drawn.
|
|||
void vitem(MMap *map, int x, int y, int w, int h, unsigned char **item,
|
||||
int anim_frame);
|
||||
|
||||
/******* COLLISIONS *******/
|
||||
|
||||
/* int vget_tile_at_point(MMap *map, int x, int y);
|
||||
|
||||
Get the tile located at x, y on MMap map map.
|
||||
Returns the tile number or -1 if the tile is outside of the map.
|
||||
*/
|
||||
|
||||
int vget_tile_at_point(MMap *map, int x, int y);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
#include "../../../include/microfx/ext/gametools.h"
|
||||
|
||||
int vget_tile_at_point(MMap *map, int x, int y) {
|
||||
/* tx and ty contain the tile position. */
|
||||
int tx = x/map->tw, ty = y/map->th;
|
||||
if(tx>=0 && tx < map->w && ty>=0 && ty < map->h){
|
||||
return (int)map->map[ty*map->w+tx];
|
||||
}
|
||||
return -1;
|
||||
}
|
|
@ -27,8 +27,8 @@ void vmap(int sx, int sy, MMap *map) {
|
|||
}else if(sx+w/2>mw){
|
||||
/* If I can't center the player because I'm near the right border of the
|
||||
map. */
|
||||
map->px = sx-(mw-w/2);
|
||||
sx = mw-w/2;
|
||||
map->px = sx-(mw-w);
|
||||
sx = mw-w;
|
||||
}else{
|
||||
/* I can center the player. */
|
||||
sx = sx-w/2;
|
||||
|
@ -43,8 +43,8 @@ void vmap(int sx, int sy, MMap *map) {
|
|||
}else if(sy+h/2>mh){
|
||||
/* If I can't center the player because I'm near the bottom border of
|
||||
the map. */
|
||||
map->py = sy-(mh-h/2);
|
||||
sy = mh-h/2;
|
||||
map->py = sy-(mh-h);
|
||||
sy = mh-h;
|
||||
}else{
|
||||
/* I can center the player. */
|
||||
sy = sy-h/2;
|
||||
|
@ -76,8 +76,8 @@ void vmap(int sx, int sy, MMap *map) {
|
|||
}
|
||||
|
||||
void vplayer(MMap *map, unsigned char **player_sprites, int anim_frame) {
|
||||
simage(map->px, map->py, map->pw, map->ph, player_sprites[anim_frame],
|
||||
SNORMAL);
|
||||
simage(map->px-map->pw/2, map->py-map->ph/2, map->pw, map->ph,
|
||||
player_sprites[anim_frame], SNORMAL);
|
||||
}
|
||||
|
||||
void vitem(MMap *map, int x, int y, int w, int h, unsigned char **item,
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue