Added in head crafting and pickup button

This commit is contained in:
tognee 2019-09-18 00:39:14 +02:00
parent 24460ee48c
commit 7bc9c274de
6 changed files with 91 additions and 11 deletions

View file

@ -87,11 +87,15 @@ Recipe defineRecipe(int item, int amountOrLevel, int numArgs, ...){
} }
void initRecipes(){ void initRecipes(){
curPlace = 0; 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.size = 22;
workbenchRecipes.recipes = (Recipe*)malloc(sizeof(Recipe) * (workbenchRecipes.size)); 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[1] = defineRecipe(ITEM_FURNACE,1,1,ITEM_STONE,20);
workbenchRecipes.recipes[2] = defineRecipe(ITEM_OVEN,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); workbenchRecipes.recipes[3] = defineRecipe(ITEM_CHEST,1,1,ITEM_WOOD,20);
@ -172,6 +176,7 @@ void initRecipes(){
/* Free up allocated memory */ /* Free up allocated memory */
void freeRecipes(){ void freeRecipes(){
free(inHeadRecipes.recipes);
free(workbenchRecipes.recipes); free(workbenchRecipes.recipes);
free(ovenRecipes.recipes); free(ovenRecipes.recipes);
free(furnaceRecipes.recipes); free(furnaceRecipes.recipes);

View file

@ -21,7 +21,7 @@ typedef struct _recipeManager {
Recipe * recipes; Recipe * recipes;
} RecipeManager; } RecipeManager;
RecipeManager inHeadRecipes;
RecipeManager workbenchRecipes; RecipeManager workbenchRecipes;
RecipeManager furnaceRecipes; RecipeManager furnaceRecipes;
RecipeManager ovenRecipes; RecipeManager ovenRecipes;

View file

@ -56,7 +56,7 @@ void ingameMenuTick(PlayerData *pd, int menu) {
} }
break; break;
case MENU_INVENTORY: 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->ingameMenu = MENU_NONE;
pd->activeItem = &noItem; pd->activeItem = &noItem;
pd->entity.p.isCarrying = false; pd->entity.p.isCarrying = false;
@ -75,7 +75,7 @@ void ingameMenuTick(PlayerData *pd, int menu) {
break; break;
case MENU_CRAFTING: 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 (pd->inputs.k_accept.clicked){
if(craftItem(&(pd->currentRecipes), &(pd->currentRecipes.recipes[pd->ingameMenuInvSel]), &(pd->inventory))){ if(craftItem(&(pd->currentRecipes), &(pd->currentRecipes.recipes[pd->ingameMenuInvSel]), &(pd->inventory))){
playSoundPositioned(snd_craft, pd->entity.level, pd->entity.x, pd->entity.y); 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 ttlCst = rec->costs[i].costAmount;
int col = 0xFFFFFFFF; if(amnt<ttlCst) col = 0xFF7F7F7F; int col = 0xFFFFFFFF; if(amnt<ttlCst) col = 0xFF7F7F7F;
renderItemIcon(rec->costs[i].costItem,1,128,48+(i*8)); renderItemIcon(rec->costs[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); drawTextColor(craftText,274,96+(i*18),col);
} }
} }

View file

@ -376,8 +376,8 @@ void tickMenu(int menu){
keyProp[3] = KEY_DRIGHT | KEY_CPAD_RIGHT | KEY_CSTICK_RIGHT; keyProp[3] = KEY_DRIGHT | KEY_CPAD_RIGHT | KEY_CSTICK_RIGHT;
keyProp[4] = KEY_A; keyProp[4] = KEY_A;
keyProp[5] = KEY_B; keyProp[5] = KEY_B;
keyProp[6] = KEY_Y; keyProp[6] = KEY_X;
keyProp[7] = KEY_X ; keyProp[7] = KEY_Y ;
keyProp[8] = KEY_START; keyProp[8] = KEY_START;
keyProp[9] = KEY_A; keyProp[9] = KEY_A;
keyProp[10] = KEY_B; keyProp[10] = KEY_B;

View file

@ -61,10 +61,10 @@ void playerInitInventory(PlayerData *pd) {
pd->inventory.lastSlot = 0; pd->inventory.lastSlot = 0;
pd->activeItem = &noItem; pd->activeItem = &noItem;
addItemToInventory(newItem(ITEM_WORKBENCH,0), &(pd->inventory));
addItemToInventory(newItem(ITEM_POWGLOVE,0), &(pd->inventory)); addItemToInventory(newItem(ITEM_POWGLOVE,0), &(pd->inventory));
if(shouldRenderDebug && playerCount < 2) { if(shouldRenderDebug && playerCount < 2) {
addItemToInventory(newItem(ITEM_WORKBENCH,0), &(pd->inventory));
addItemToInventory(newItem(ITEM_GOLD_APPLE,1), &(pd->inventory)); addItemToInventory(newItem(ITEM_GOLD_APPLE,1), &(pd->inventory));
addItemToInventory(newItem(ITEM_STRENGTH_POTION,1), &(pd->inventory)); addItemToInventory(newItem(ITEM_STRENGTH_POTION,1), &(pd->inventory));
addItemToInventory(newItem(ITEM_REGEN_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; i<playerCount; i++) {
if(players[i].curChestEntity==ent) {
players[i].ingameMenu = MENU_NONE;
}
}
Item nItem = newItem(ent->entityFurniture.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){ if (pd->inputs.k_menu.clicked){
pd->ingameMenuInvSel = 0; pd->ingameMenuInvSel = 0;
if(!playerUse(pd)) pd->ingameMenu = MENU_INVENTORY; if(!playerUse(pd)) pd->ingameMenu = MENU_INVENTORY;

View file

@ -165,8 +165,8 @@ int main() {
localInputs.k_right.input = KEY_DRIGHT | KEY_CPAD_RIGHT | KEY_CSTICK_RIGHT; localInputs.k_right.input = KEY_DRIGHT | KEY_CPAD_RIGHT | KEY_CSTICK_RIGHT;
localInputs.k_attack.input = KEY_A; localInputs.k_attack.input = KEY_A;
localInputs.k_pickup.input = KEY_B; localInputs.k_pickup.input = KEY_B;
localInputs.k_use.input = KEY_Y; localInputs.k_use.input = KEY_X;
localInputs.k_menu.input = KEY_X ; localInputs.k_menu.input = KEY_Y ;
localInputs.k_pause.input = KEY_START; localInputs.k_pause.input = KEY_START;
localInputs.k_accept.input = KEY_A; localInputs.k_accept.input = KEY_A;
localInputs.k_decline.input = KEY_B; localInputs.k_decline.input = KEY_B;