2021-02-26 12:09:25 +01:00
|
|
|
#include <gint/display.h>
|
|
|
|
|
|
|
|
#include "drawiso.h"
|
|
|
|
#include "define.h"
|
|
|
|
|
|
|
|
extern bopti_image_t img_1;
|
|
|
|
extern bopti_image_t img_2;
|
|
|
|
extern bopti_image_t img_3;
|
|
|
|
|
2021-03-13 22:05:55 +01:00
|
|
|
/* generate and draw the map around the player (player_view)
|
|
|
|
* @param map : the map you want to draw
|
|
|
|
* @param indx : the virtual x position of the player
|
|
|
|
* @param indy : the virtual y position of the player
|
|
|
|
* @param taillemap : the length of the map
|
|
|
|
* @param isometric : 0 = top view, 1 = isometric view
|
|
|
|
*/
|
|
|
|
void draw_map_player(int map[], int indx, int indy, int taillemap, char isometric) {
|
2021-03-01 19:09:25 +01:00
|
|
|
int j = 0;
|
|
|
|
int x = 0;
|
2021-02-28 01:00:14 +01:00
|
|
|
|
2021-03-01 19:09:25 +01:00
|
|
|
int coomap = indx + indy*level_width;
|
|
|
|
int beginmap = coomap - player_view - level_width*player_view;
|
2021-02-28 01:00:14 +01:00
|
|
|
|
2021-03-01 19:09:25 +01:00
|
|
|
int beginline = coomap - player_view * level_width - coomap%level_width;
|
2021-02-28 01:00:14 +01:00
|
|
|
|
2021-03-01 19:09:25 +01:00
|
|
|
if(beginmap < 0) {
|
|
|
|
beginmap = indx - player_view;
|
|
|
|
if(beginmap < 0) beginmap = 0;
|
|
|
|
}
|
2021-02-28 01:00:14 +01:00
|
|
|
|
2021-03-01 19:09:25 +01:00
|
|
|
if((coomap - player_view)%level_width > coomap%level_width) {
|
|
|
|
if(beginline > 0) {
|
|
|
|
beginmap = beginline;
|
|
|
|
} else {
|
|
|
|
beginmap = 0;
|
|
|
|
}
|
|
|
|
}
|
2021-02-28 01:00:14 +01:00
|
|
|
|
|
|
|
int next = indx + player_view + beginmap/level_width * level_width;
|
|
|
|
int endline = beginmap+level_width-beginmap%level_width-1;
|
|
|
|
|
2021-03-01 19:09:25 +01:00
|
|
|
if(next > endline) next = endline;
|
|
|
|
|
|
|
|
if(next < 0) {
|
|
|
|
next = indx + player_view;
|
|
|
|
}
|
|
|
|
|
|
|
|
int indypro = indy + player_view;
|
|
|
|
if(indypro > taillemap/level_width-1) {
|
|
|
|
indypro = taillemap/level_width-1;
|
|
|
|
}
|
|
|
|
int endmap = next%level_width + level_width*indypro;
|
|
|
|
|
|
|
|
int ecart = next - beginmap;
|
|
|
|
int xcentre = 0, ycentre = 0;
|
|
|
|
|
|
|
|
for(int i = beginmap; i <= endmap; i++) {
|
|
|
|
x++;
|
|
|
|
if(i == coomap) {xcentre = x-1; ycentre = j; break;}
|
|
|
|
if(i == beginmap + ecart + j * level_width) {
|
|
|
|
j++;
|
|
|
|
x=0;
|
|
|
|
i = beginmap + j*level_width-1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
j=0;
|
|
|
|
x=4-xcentre;
|
|
|
|
for(int i = beginmap; i <= endmap; i++) {
|
|
|
|
int y = j + (2-ycentre);
|
|
|
|
switch(map[i]) {
|
|
|
|
case 1:
|
2021-03-13 22:05:55 +01:00
|
|
|
draw(x,y,isometric,&img_1,0);
|
2021-03-01 19:09:25 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
2021-03-13 22:05:55 +01:00
|
|
|
draw(x,y,isometric,&img_2,0);
|
2021-03-01 19:09:25 +01:00
|
|
|
break;
|
2021-03-13 22:05:55 +01:00
|
|
|
case 3:
|
|
|
|
draw(x,y,isometric,&img_3,16);
|
2021-03-01 19:09:25 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
x++;
|
|
|
|
if(i==beginmap+ecart+j*level_width) {
|
|
|
|
j++;
|
|
|
|
x=4-xcentre;
|
|
|
|
i = beginmap + j*level_width-1;
|
|
|
|
}
|
|
|
|
}
|
2021-02-28 01:00:14 +01:00
|
|
|
}
|
|
|
|
|
2021-03-13 22:05:55 +01:00
|
|
|
/* draw at a certain position the block depends of the type of view
|
|
|
|
* @param posx : where to draw on the x axis
|
|
|
|
* @param posy : where to draw on the y axis
|
|
|
|
* @param isometric : type of view
|
|
|
|
* @param image : the texture
|
|
|
|
* @param height : draw the block upper. If you need to draw a higher block
|
|
|
|
*/
|
|
|
|
void draw(int posx, int posy, char isometric, bopti_image_t *image, int height) {
|
|
|
|
if(isometric) {
|
|
|
|
dsubimage(150+(-posy*tile+posx*tile),60-height+((posx*tile/2)+(posy*tile/2)),image,0,0,32,32+height,DIMAGE_NONE);
|
|
|
|
} else {
|
|
|
|
dsubimage(150+(posx-3)*tile*2,60+(posy-1)*tile*2,image,0,32+height,32,32,DIMAGE_NONE);
|
|
|
|
}
|
2021-02-26 12:09:25 +01:00
|
|
|
}
|