90 lines
2.8 KiB
C
90 lines
2.8 KiB
C
#include "../../../include/microfx/ext/gametools.h"
|
|
#include "../../../include/microfx/ext/img.h"
|
|
#include "../../../include/microfx/microfx.h"
|
|
|
|
void vmap(int sx, int sy, MMap *map) {
|
|
/* Dessine la map à l'écran. */
|
|
int padx = map->padx, pady = map->pady;
|
|
int w = map->sw, h = map->sh;
|
|
/* x and y will contain the position in the loop. */
|
|
int x, y;
|
|
/* The positions where we start drawing the tiles will be in tx and ty. */
|
|
int tx, ty;
|
|
/* mx and my will contain how many pixels will be hidden on x and on y. */
|
|
int mx, my;
|
|
/* dw and dh contain the amount of tiles that will be drawn on x and on y. */
|
|
int dw = w/map->tw+1, dh = h/map->th+1;
|
|
/* mw and mh will contain the height and the width of the map. */
|
|
int mw = map->w*map->tw, mh = map->h*map->th;
|
|
/* tile contains the tile to draw. */
|
|
unsigned char tile;
|
|
/* Fix sx. */
|
|
if(sx<w/2){
|
|
/* If I can't center the player because I'm near the left border of the
|
|
map. */
|
|
map->px = sx;
|
|
sx = 0;
|
|
}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;
|
|
}else{
|
|
/* I can center the player. */
|
|
sx = sx-w/2;
|
|
map->px = w/2;
|
|
}
|
|
/* Fix sy. */
|
|
if(sy<h/2){
|
|
/* If I can't center the player because I'm near the top border of the
|
|
map. */
|
|
map->py = sy;
|
|
sy = 0;
|
|
}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;
|
|
}else{
|
|
/* I can center the player. */
|
|
sy = sy-h/2;
|
|
map->py = h/2;
|
|
}
|
|
tx = sx/map->tw;
|
|
ty = sy/map->th;
|
|
mx = sx-tx*map->tw;
|
|
my = sy-ty*map->th;
|
|
for(y=0;y<dh;y++){
|
|
for(x=0;x<dw;x++){
|
|
/* I get the tile number if his position is inside the map unsigned
|
|
char*. Then I draw it. */
|
|
if(tx+x>=0 && tx+x < map->w && ty+y>=0 && ty+y < map->h){
|
|
tile = map->map[(ty+y)*map->w+tx+x];
|
|
if(tile > 0){
|
|
simage(x*map->tw-mx+padx, y*map->th-my+pady, map->tw,
|
|
map->th, map->tileset[(int)tile-1], SNORMAL);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
map->sx = sx;
|
|
map->sy = sy;
|
|
map->sw = w;
|
|
map->sh = h;
|
|
map->padx = padx;
|
|
map->pady = pady;
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
void vitem(MMap *map, int x, int y, int w, int h, unsigned char **item,
|
|
int anim_frame) {
|
|
int dx = x-map->sx, dy = y-map->sy;
|
|
if(dx+w>=0 && dx<map->sw && dy+h>=0 && dy<map->sh) {
|
|
simage(dx, dy, w, h, item[anim_frame], SNORMAL);
|
|
}
|
|
}
|