From 7bc9c274de7b2a212ea70b351104516a81221fd3 Mon Sep 17 00:00:00 2001 From: tognee Date: Wed, 18 Sep 2019 00:39:14 +0200 Subject: [PATCH] Added in head crafting and pickup button --- source/Crafting.c | 9 ++++-- source/Crafting.h | 2 +- source/IngameMenu.c | 6 ++-- source/Menu.c | 4 +-- source/Player.c | 77 ++++++++++++++++++++++++++++++++++++++++++++- source/main.c | 4 +-- 6 files changed, 91 insertions(+), 11 deletions(-) diff --git a/source/Crafting.c b/source/Crafting.c index cc9867e..aed5c03 100755 --- a/source/Crafting.c +++ b/source/Crafting.c @@ -87,11 +87,15 @@ Recipe defineRecipe(int item, int amountOrLevel, int numArgs, ...){ } void initRecipes(){ - curPlace = 0; + + inHeadRecipes.size = 1; + inHeadRecipes.recipes = (Recipe*)malloc(sizeof(Recipe) * (inHeadRecipes.size)); + inHeadRecipes.recipes[0] = defineRecipe(ITEM_WORKBENCH,1,1,ITEM_WOOD,10); + workbenchRecipes.size = 22; workbenchRecipes.recipes = (Recipe*)malloc(sizeof(Recipe) * (workbenchRecipes.size)); - workbenchRecipes.recipes[0] = defineRecipe(ITEM_WORKBENCH,1,1,ITEM_WOOD,20); + workbenchRecipes.recipes[0] = defineRecipe(ITEM_WORKBENCH,1,1,ITEM_WOOD,10); workbenchRecipes.recipes[1] = defineRecipe(ITEM_FURNACE,1,1,ITEM_STONE,20); workbenchRecipes.recipes[2] = defineRecipe(ITEM_OVEN,1,1,ITEM_STONE,20); workbenchRecipes.recipes[3] = defineRecipe(ITEM_CHEST,1,1,ITEM_WOOD,20); @@ -172,6 +176,7 @@ void initRecipes(){ /* Free up allocated memory */ void freeRecipes(){ + free(inHeadRecipes.recipes); free(workbenchRecipes.recipes); free(ovenRecipes.recipes); free(furnaceRecipes.recipes); diff --git a/source/Crafting.h b/source/Crafting.h index e28148f..21d0f0f 100755 --- a/source/Crafting.h +++ b/source/Crafting.h @@ -21,7 +21,7 @@ typedef struct _recipeManager { Recipe * recipes; } RecipeManager; - +RecipeManager inHeadRecipes; RecipeManager workbenchRecipes; RecipeManager furnaceRecipes; RecipeManager ovenRecipes; diff --git a/source/IngameMenu.c b/source/IngameMenu.c index d134ee7..6247f54 100644 --- a/source/IngameMenu.c +++ b/source/IngameMenu.c @@ -56,7 +56,7 @@ void ingameMenuTick(PlayerData *pd, int menu) { } break; case MENU_INVENTORY: - if (pd->inputs.k_menu.clicked || pd->inputs.k_decline.clicked){ + if (pd->inputs.k_menu.clicked || pd->inputs.k_use.clicked || pd->inputs.k_decline.clicked){ pd->ingameMenu = MENU_NONE; pd->activeItem = &noItem; pd->entity.p.isCarrying = false; @@ -75,7 +75,7 @@ void ingameMenuTick(PlayerData *pd, int menu) { break; case MENU_CRAFTING: - if (pd->inputs.k_menu.clicked || pd->inputs.k_decline.clicked) pd->ingameMenu = MENU_NONE; + if (pd->inputs.k_menu.clicked || pd->inputs.k_use.clicked || pd->inputs.k_decline.clicked) pd->ingameMenu = MENU_NONE; if (pd->inputs.k_accept.clicked){ if(craftItem(&(pd->currentRecipes), &(pd->currentRecipes.recipes[pd->ingameMenuInvSel]), &(pd->inventory))){ playSoundPositioned(snd_craft, pd->entity.level, pd->entity.x, pd->entity.y); @@ -313,7 +313,7 @@ void ingameMenuRender(PlayerData *pd, int menu) { int ttlCst = rec->costs[i].costAmount; int col = 0xFFFFFFFF; if(amntcosts[i].costItem,1,128,48+(i*8)); - sprintf(craftText,"%d/%d",amnt,ttlCst); + sprintf(craftText,"%d/%d",ttlCst,amnt); drawTextColor(craftText,274,96+(i*18),col); } } diff --git a/source/Menu.c b/source/Menu.c index 402beb3..9387798 100755 --- a/source/Menu.c +++ b/source/Menu.c @@ -376,8 +376,8 @@ void tickMenu(int menu){ keyProp[3] = KEY_DRIGHT | KEY_CPAD_RIGHT | KEY_CSTICK_RIGHT; keyProp[4] = KEY_A; keyProp[5] = KEY_B; - keyProp[6] = KEY_Y; - keyProp[7] = KEY_X ; + keyProp[6] = KEY_X; + keyProp[7] = KEY_Y ; keyProp[8] = KEY_START; keyProp[9] = KEY_A; keyProp[10] = KEY_B; diff --git a/source/Player.c b/source/Player.c index 8d3ec55..854606c 100644 --- a/source/Player.c +++ b/source/Player.c @@ -61,10 +61,10 @@ void playerInitInventory(PlayerData *pd) { pd->inventory.lastSlot = 0; pd->activeItem = &noItem; - addItemToInventory(newItem(ITEM_WORKBENCH,0), &(pd->inventory)); addItemToInventory(newItem(ITEM_POWGLOVE,0), &(pd->inventory)); if(shouldRenderDebug && playerCount < 2) { + addItemToInventory(newItem(ITEM_WORKBENCH,0), &(pd->inventory)); addItemToInventory(newItem(ITEM_GOLD_APPLE,1), &(pd->inventory)); addItemToInventory(newItem(ITEM_STRENGTH_POTION,1), &(pd->inventory)); addItemToInventory(newItem(ITEM_REGEN_POTION,1), &(pd->inventory)); @@ -506,6 +506,81 @@ void tickPlayer(PlayerData *pd, bool inmenu) { } } + //picking up furniture + if(pd->inputs.k_pickup.clicked){ + if (pd->entity.p.isCarrying){ + if (pd->entity.p.stamina != 0) { + if(!shouldRenderDebug) pd->entity.p.stamina--; + pd->entity.p.staminaRecharge = 0; + playerAttack(pd); + } + }else{ + int yo = -2; + int range = 12; + // see if entity near player + int x0, y0, x1, y1 = 0; + switch(pd->entity.p.dir){ + case 0: + x0 = pd->entity.x - 8; + y0 = pd->entity.y + 4 + yo; + x1 = pd->entity.x + 8; + y1 = pd->entity.y + range + yo; + break; + case 1: + x0 = pd->entity.x - 8; + y0 = pd->entity.y - range + yo; + x1 = pd->entity.x + 8; + y1 = pd->entity.y - 4 + yo; + break; + case 2: + x0 = pd->entity.x - range; + y0 = pd->entity.y - 8 + yo; + x1 = pd->entity.x - 4; + y1 = pd->entity.y + 8 + yo; + break; + case 3: + x0 = pd->entity.x + 4; + y0 = pd->entity.y - 8 + yo; + x1 = pd->entity.x + range; + y1 = pd->entity.y + 8 + yo; + break; + } + Entity * es[eManager.lastSlot[pd->entity.level]]; + int eSize = getEntities(es, pd->entity.level, x0, y0, x1, y1); + int i; + for (i = 0; i < eSize; ++i) { + Entity * ent = es[i]; + if (ent != &(pd->entity)){ + if(ent->type == ENTITY_FURNITURE){ + //Important: close all crafting windows using this furniture (only applies to chest) or else they will write invalid memory + for(int i=0; ientityFurniture.itemID,0); + if(ent->entityFurniture.itemID == ITEM_CHEST) nItem.chestPtr = ent->entityFurniture.inv; + pushItemToInventoryFront(nItem, &(pd->inventory)); + + removeEntityFromList(ent, ent->level, &eManager); + pd->activeItem = &(pd->inventory.items[0]); + pd->entity.p.isCarrying = true; + } + } + } + } + } + + // in head crafting + if(pd->inputs.k_use.clicked){ + pd->ingameMenuInvSel = 0; + if(!playerUse(pd)){ + pd->currentCraftTitle = "Crafting"; + openCraftingMenu(pd, &inHeadRecipes, "Crafting"); + } + } + if (pd->inputs.k_menu.clicked){ pd->ingameMenuInvSel = 0; if(!playerUse(pd)) pd->ingameMenu = MENU_INVENTORY; diff --git a/source/main.c b/source/main.c index a64e98e..a253153 100755 --- a/source/main.c +++ b/source/main.c @@ -165,8 +165,8 @@ int main() { localInputs.k_right.input = KEY_DRIGHT | KEY_CPAD_RIGHT | KEY_CSTICK_RIGHT; localInputs.k_attack.input = KEY_A; localInputs.k_pickup.input = KEY_B; - localInputs.k_use.input = KEY_Y; - localInputs.k_menu.input = KEY_X ; + localInputs.k_use.input = KEY_X; + localInputs.k_menu.input = KEY_Y ; localInputs.k_pause.input = KEY_START; localInputs.k_accept.input = KEY_A; localInputs.k_decline.input = KEY_B;