From 9be21c70fb550eaa1a782d87ad6d150ec9c40982 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 13 Mar 2021 22:05:55 +0100 Subject: [PATCH] top view --- CMakeLists.txt | 6 ++-- assets-cg/1.png | Bin 704 -> 748 bytes assets-cg/2.png | Bin 901 -> 956 bytes assets-cg/3.png | Bin 819 -> 869 bytes {src => include}/define.h | 0 include/drawiso.h | 2 ++ {src => include}/player.h | 0 src/drawiso.c | 64 +++++++++++++++----------------------- src/drawiso.h | 6 ---- src/main.c | 9 ++++-- src/player.c | 2 +- 11 files changed, 36 insertions(+), 53 deletions(-) rename {src => include}/define.h (100%) create mode 100644 include/drawiso.h rename {src => include}/player.h (100%) delete mode 100644 src/drawiso.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e702e77..e55fe26 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,7 @@ project(MyAddin) include(GenerateG1A) include(GenerateG3A) include(Fxconv) +include_directories(include) find_package(Gint 2.1 REQUIRED) set(SOURCES @@ -33,10 +34,7 @@ add_executable(myaddin ${SOURCES} ${ASSETS} ${ASSETS_${FXSDK_PLATFORM}}) target_compile_options(myaddin PRIVATE -Wall -Wextra -Os) target_link_libraries(myaddin Gint::Gint) -if("${FXSDK_PLATFORM_LONG}" STREQUAL fx9860G) - generate_g1a(TARGET myaddin OUTPUT "MyAddin.g1a" - NAME "MyAddin" ICON assets-fx/icon.png) -elseif("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50) +if("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50) generate_g3a(TARGET myaddin OUTPUT "isometric.g3a" NAME "isometri" ICONS assets-cg/icon-uns.png assets-cg/icon-sel.png) endif() diff --git a/assets-cg/1.png b/assets-cg/1.png index 38c837d32b3c3c14827f77f8550dce9470e5e691..ebc7ef5f4398bba7ba68b1b4164ebea0778c5d63 100644 GIT binary patch delta 717 zcmV;;0y6!;1?&Zo7YaZK1^@s6dyaLkks%m=o=HSORA_S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5<;jel%;jZ0Yu zy6+D>QR1B(-K~sf@y{2_Zzr&oa@j!cQ*B8uouRkAHt_U91cr$$y0#hGRbVTB#iHKv zD^7Gp8|i#_cktX&1TNoZI*Vhw4DU%`D>E}Xb6{)AJt-T)xcM7%MCP9(4s{xXK|L z8}GV#bJ>j>PrG%CBS&ay*;~>4Jm%@yBe;TZkweLwLeIo6sb10E{+YHmG8ww7Tn^;( z$P-inmobTDRJ@9jt)tj~Tq7!#5tYh0YinO25=o`15Ozp$6C6oAi?8EGbx~g-!4=R6MET*DC!r zr&Br|YHkh%LFn}9P#`oU)GU-1qO+F5Y8!~>cZEU%N&Kl?rWNzJ<3R;$HTL-nAq4-F UEVGEQ00000NkvXXu0mh|g5FAe`~Uy| diff --git a/src/define.h b/include/define.h similarity index 100% rename from src/define.h rename to include/define.h diff --git a/include/drawiso.h b/include/drawiso.h new file mode 100644 index 0000000..c18a329 --- /dev/null +++ b/include/drawiso.h @@ -0,0 +1,2 @@ +void draw_map_player(int map[], int taillex, int tailley, int taillemap, char isometric); +void draw(int posx, int posy, char isometric, bopti_image_t *image, int height); diff --git a/src/player.h b/include/player.h similarity index 100% rename from src/player.h rename to include/player.h diff --git a/src/drawiso.c b/src/drawiso.c index 5c12be2..48323b1 100644 --- a/src/drawiso.c +++ b/src/drawiso.c @@ -6,33 +6,15 @@ extern bopti_image_t img_1; extern bopti_image_t img_2; extern bopti_image_t img_3; -extern bopti_image_t img_3; -void draw_map_at(tile_t map[], int posx, int posy, int width) { - int j = 0; - int x = 0; - for(int i=0; i < width; i++) { - switch(map[i]) { - case 1: - draw_iso(x,j,posx,posy,&img_1); - break; - case 2: - draw_iso(x,j,posx,posy,&img_2); - break; - case 3: - draw_from_bottom(x,j,posx,posy,&img_3,16); - break; - case 9: - draw_iso(x,j,posx,posy,&img_3); - break; - } - x++; - if(!(i%level_width) && i != 0) { j++; x = 0; } - } - dupdate(); -} - -void draw_map_player(tile_t map[], int indx, int indy, int taillemap) { +/* 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) { int j = 0; int x = 0; @@ -88,16 +70,13 @@ void draw_map_player(tile_t map[], int indx, int indy, int taillemap) { int y = j + (2-ycentre); switch(map[i]) { case 1: - draw_iso(x,y,150,60,&img_1); + draw(x,y,isometric,&img_1,0); break; case 2: - draw_iso(x,y,150,60,&img_2); + draw(x,y,isometric,&img_2,0); break; - case 3: - draw_from_bottom(x,y,150,60,&img_3,16); - break; - case 9: - draw_iso(x,y,150,60,&img_3); + case 3: + draw(x,y,isometric,&img_3,16); break; } x++; @@ -109,10 +88,17 @@ void draw_map_player(tile_t map[], int indx, int indy, int taillemap) { } } -void draw_iso(int i, int j, int posx, int posy, bopti_image_t *image) { - dimage(posx+(-j*tile+i*tile),posy+((i*tile/2)+(j*tile/2)),image); -} - -void draw_from_bottom(int i, int j, int posx, int posy, bopti_image_t *image, int height) { - draw_iso(i,j,posx,posy-height,image); +/* 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); + } } diff --git a/src/drawiso.h b/src/drawiso.h deleted file mode 100644 index a695357..0000000 --- a/src/drawiso.h +++ /dev/null @@ -1,6 +0,0 @@ -typedef uint8_t tile_t; - -void draw_map_at(tile_t map[], int taillex, int tailley, int width); -void draw_map_player(tile_t map[], int taillex, int tailley, int taillemap); -void draw_iso(int i, int j, int posx, int posy, bopti_image_t *image); -void draw_from_bottom(int i, int j, int posx, int posy, bopti_image_t *image, int height); diff --git a/src/main.c b/src/main.c index bf9eb69..eb4a969 100644 --- a/src/main.c +++ b/src/main.c @@ -8,18 +8,19 @@ int main(void) { dclear(C_WHITE); - tile_t map[450] = { 0, 0, 0, 1, 2, 0, 2, 2, 3, 0, 0, 2, 0, 1, 3, 0, 0, 0, 3, 0, 0, 3, 3, 0, 3, 2, 2, 2, 3, 0, 1, 0, 0, 2, 0, 3, 1, 2, 2, 0, 1, 1, 2, 0, 2, 2, 3, 2, 2, 1, 3, 0, 3, 1, 0, 2, 2, 1, 2, 1, 3, 3, 1, 3, 2, 2, 3, 1, 1, 1, 3, 0, 2, 2, 3, 2, 1, 1, 2, 3, 1, 3, 3, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 2, 1, 0, 1, 0, 3, 2, 2, 0, 2, 3, 0, 3, 0, 2, 2, 1, 1, 2, 2, 3, 0, 2, 2, 2, 3, 1, 3, 2, 1, 1, 1, 3, 1, 2, 2, 1, 3, 2, 0, 2, 2, 2, 0, 2, 2, 3, 3, 0, 1, 1, 0, 2, 0, 1, 0, 2, 2, 2, 3, 0, 3, 1, 3, 3, 0, 3, 0, 0, 0, 3, 0, 1, 0, 0, 1, 3, 3, 1, 2, 1, 0, 1, 3, 3, 3, 0, 0, 0, 1, 3, 3, 0, 2, 1, 3, 1, 0, 2, 1, 2, 3, 0, 1, 2, 0, 1, 0, 2, 0, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 0, 1, 0, 0, 2, 0, 3, 3, 1, 2, 2, 1, 1, 1, 3, 1, 0, 0, 1, 2, 1, 0, 1, 1, 3, 1, 3, 2, 1, 0, 1, 3, 3, 2, 2, 1, 0, 1, 2, 3, 3, 1, 0, 0, 0, 0, 3, 3, 0, 0, 0, 0, 1, 3, 1, 1, 2, 2, 2, 2, 1, 1, 1, 2, 3, 3, 3, 3, 2, 1, 1, 1, 1, 3, 3, 1, 0, 1, 0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, 0, 1, 2, 1, 0, 1, 1, 3, 1, 3, 2, 1, 0, 1, 3, 3, 2, 2, 1, 0, 1, 2, 3, 3, 1, 0, 0, 0, 0, 3, 3, 0, 0, 0, 0, 1, 3, 1, 1, 2, 2, 2, 2, 1, 1, 1, 2, 3, 3, 3, 3, 2, 1, 1, 1, 1, 3, 3, 1, 0, 1, 0, 0, 1, 1, 3, 2, 2, 2, 0, 0, 1, 1, 0, 3, 3, 3, 2, 3, 1, 2, 1, 1, 0, 1, 1, 0, 0, 2, 0, 0, 2, 1, 1, 2, 0, 0, 3, 2, 0, 2, 3, 3, 2, 0, 3, 2, 3, 2, 0, 0, 3, 0, 2, 0, 1, 0, 3, 3, 3, 0, 1, 3, 3, 0, 0, 0, 0, 0, 3, 0, 0, 3, 0, 0, 0, 0, 1, 0, 3, 1, 1, 3, 2, 0, 0, 2, 1, 0, 1, 0, 3, 0, 1, 1, 3, 3, 0, 1, 2, 2, 3, 0, 1, 1, 1, 0 }; int x = 5; int y = 2; int buffer = 0; int nbtiles = 400; + char view_type = 0; while(1) { dclear(C_WHITE); //draw_map_at(map,80,30,50); - draw_map_player(map,x,y,nbtiles); + draw_map_player(map,x,y,nbtiles,view_type); draw_player(3,1); dprint(1,1,C_BLACK,"(%d;%d)",x,y); dprint(1,30,C_BLACK,"%d",map[x+y*level_width]); @@ -29,11 +30,13 @@ int main(void) { break; } + if(keydown(KEY_F1)) view_type = 0; + if(keydown(KEY_F2)) view_type = 1; if(keydown(KEY_RIGHT) && x+1 < level_width && !buffer) x+=1; if(keydown(KEY_LEFT) && x > 0 && !buffer) x-=1; if(keydown(KEY_UP) && y > 0 && !buffer) y-=1; if(keydown(KEY_DOWN) && y+1 < nbtiles/level_width && !buffer) y+=1; - if(keydown_any(KEY_RIGHT,KEY_LEFT,KEY_UP,KEY_DOWN)) { + if(keydown_any(KEY_RIGHT,KEY_LEFT,KEY_UP,KEY_DOWN,KEY_SHIFT)) { buffer = 1; } else { buffer = 0; diff --git a/src/player.c b/src/player.c index c722aee..4be4378 100644 --- a/src/player.c +++ b/src/player.c @@ -6,5 +6,5 @@ extern bopti_image_t img_player; void draw_player(int posx, int posy) { - draw_iso(posx,posy,150,60,&img_player); + dimage(150+(-posy*tile+posx*tile),60+((posx*tile/2)+(posy*tile/2)),&img_player); }