diff --git a/assets-fx/microfont.png b/assets-fx/microfont.png index 03bef7c..5e69e1e 100644 Binary files a/assets-fx/microfont.png and b/assets-fx/microfont.png differ diff --git a/latest-build/Builder.g1a b/latest-build/Builder.g1a index 149808b..4ace49b 100644 Binary files a/latest-build/Builder.g1a and b/latest-build/Builder.g1a differ diff --git a/src/gamesettings.h b/src/gamesettings.h index 5b96c58..a7c66fd 100644 --- a/src/gamesettings.h +++ b/src/gamesettings.h @@ -5,4 +5,4 @@ # define WORLD_HEIGHT 64 // World height. # define INVENTORY_SIZE 5 // Size of the inventory. # define CRAFTSIZE 9 // How many different blocks you can use to craft something. -# define CRAFTINGS 1 // How many things you can craft. \ No newline at end of file +# define CRAFTINGS 2 // How many things you can craft. \ No newline at end of file diff --git a/src/main.c b/src/main.c index 65ea600..ffe5c4e 100644 --- a/src/main.c +++ b/src/main.c @@ -258,6 +258,9 @@ void drawcrafting(){ case 6: dimage(36, 28, &woodplanks_tile); break; } + dtext(36, 38, C_BLACK, MULTIPLY); + itoa(craftingnum[crafting.selected], tmp_char); + dtext(36, 44, C_BLACK, tmp_char); pos = 4; for(i=crafting.selected*CRAFTSIZE;i!=(crafting.selected+1)*CRAFTSIZE;i++){ if(craftingsnum[i]!=0){ @@ -288,7 +291,7 @@ int main(void) { dimage(16, TITLE_IMAGE_MARGIN, &title_img); dtext(1, TITLE_MARGIN, C_BLACK, TITLE_START); dupdate(); - int key = 0, game = 0, selected = 0, i; + int key = 0, game = 0, selected = 0, i, n; unsigned short terrain[WORLD_WIDTH*WORLD_HEIGHT]; while(keydown(KEY_EXIT) == 0){ ////////// TITLE SCREEN ////////// @@ -604,6 +607,7 @@ int main(void) { }else{ crafting.selected=CRAFTINGS-1; } + clearevents(); while(keydown(KEY_LEFT)){ clearevents(); } @@ -614,10 +618,71 @@ int main(void) { }else{ crafting.selected=0; } + clearevents(); while(keydown(KEY_RIGHT)){ clearevents(); } } + if(keydown(KEY_SHIFT)){ + crafting.ispossible = 0; + pos = 0; + for(i=0;i!=5;i++){ + if((player.inventoryitems[i]==craftingitem[crafting.selected] || player.inventoryitems[i]==0) && player.inventorynum[i]<=64-craftingnum[crafting.selected]){ + crafting.ispossible = 1; + pos = i; + break; + } + } + crafting.hasanything = 0; + for(n=crafting.selected*CRAFTSIZE;n!=(crafting.selected+1)*CRAFTSIZE;n++){ + crafting.hasitem = 0; + for(i=0;i!=5;i++){ + if(craftingsitems[n]==player.inventoryitems[i] && craftingsnum[n]<=player.inventorynum[i]){ + crafting.hasitem = 1; + } + } + crafting.hasanything += crafting.hasitem; + } + if(crafting.hasanything == CRAFTSIZE && crafting.ispossible == 1){ + player.inventoryitems[pos] = craftingitem[crafting.selected]; + player.inventorynum[pos] += craftingnum[crafting.selected]; + for(n=crafting.selected*CRAFTSIZE;n!=(crafting.selected+1)*CRAFTSIZE;n++){ + for(i=0;i!=5;i++){ + if(craftingsitems[n]==player.inventoryitems[i] && craftingsnum[n]<=player.inventorynum[i]){ + player.inventorynum[i]-=craftingsnum[n]; + if(player.inventorynum[i]==0){ + player.inventoryitems[i]=0; + } + } + } + } + dfont(µfont); + dclear(C_WHITE); + dtext(10, 29, C_BLACK, ITEM_BUILT); + dtext(10, 35, C_BLACK, PRESS_SHIFT); + dfont_default(); + dupdate(); + clearevents(); + while(keydown(KEY_SHIFT)){ + clearevents(); + } + }else{ + dfont(µfont); + dclear(C_WHITE); + dtext(10, 29, C_BLACK, ITEM_NOT_BUILT); + dtext(10, 35, C_BLACK, PRESS_SHIFT); + dfont_default(); + dupdate(); + clearevents(); + while(keydown(KEY_SHIFT)){ + clearevents(); + } + } + clearevents(); + while(keydown(KEY_SHIFT)){ + clearevents(); + } + } } clearevents(); } diff --git a/src/msg_fr.h b/src/msg_fr.h index 48a637f..9a9aae0 100644 --- a/src/msg_fr.h +++ b/src/msg_fr.h @@ -10,4 +10,7 @@ # define STEEL_TILE "M. aci." # define WOOD_TILE "Bois" # define WOODPLANKS_TILE "Planche" -# define MULTIPLY "x" \ No newline at end of file +# define MULTIPLY "x" +# define ITEM_BUILT "Item construit." +# define ITEM_NOT_BUILT "Peut pas construire." +# define PRESS_SHIFT "Appuyez sur SHIFT" \ No newline at end of file diff --git a/src/objects.h b/src/objects.h index 94697f5..6b52f95 100644 --- a/src/objects.h +++ b/src/objects.h @@ -28,13 +28,22 @@ typedef struct Crafting Crafting; struct Crafting{ int selected; int ispossible; + int hasanything; + int hasitem; }; const int craftingsitems[CRAFTINGS*CRAFTSIZE] = { 5, 0, 0, 0, 0, 0, 0, 0, 0, + 6, 0, 0, 0, 0, 0, 0, 0, 0 }; const int craftingsnum[CRAFTINGS*CRAFTSIZE] = { 1, 0, 0, 0, 0, 0, 0, 0, 0, + 4, 0, 0, 0, 0, 0, 0, 0, 0 }; const int craftingitem[CRAFTINGS] = { 6, + 5 +}; +const int craftingnum[CRAFTINGS] = { + 4, + 1 }; \ No newline at end of file