Hey guys,
Ok someone wrote me a short example for a simple inventory and item menu. I’m at the point now that I need it but the OG poster is now where around. ive also been on three different sites with no help. I’m really hoping some one can help me figure this out.
Here is the test sketch. please ignore the gb parts.
#ifndef _Menu_H_
#define _Menu_H_
#include "Variables.h"
int menu_1 = 1;
int key_1 = 1;
int key_2 = 1;
int sox_1 = 1;
int menuy = -84;
int keyy = -76;
int scroll1;
/////add item_loc's here////
int key_loc;
int key2_loc;
int sox_loc;
////item slot locations////
int keyslot;
int keyslot2;
int soxslot;
int Active_slot;
int S1 = 0;
int S2 = 0;
int S3 = 0;
int S4 = 0;
if(S1==0 && S2==0 && S3==0 && S4==0){Active_slot = 1;}
else if(S1==1 && S2==0 && S3==0 && S4==0){Active_slot = 2;}
else if(S1==1 && S2==1 && S3==0 && S4==0){Active_slot = 3;}
else if(S1==1 && S2==1 && S3==1 && S4==0){Active_slot = 4;}
else if(S1==1 && S2==1 && S3==1 && S4==1){Active_slot = 0;}
else if(S1==1 && S2==0 && S3==1 && S4==0){Active_slot = 2;}
else if(S1==1 && S2==0 && S3==1 && S4==1){Active_slot = 2;}
else if(S1==1 && S2==0 && S3==0 && S4==1){Active_slot = 2;}
else if(S1==1 && S2==1 && S3==0 && S4==1){Active_slot = 3;}
else if(S1==0 && S2==1 && S3==0 && S4==0){Active_slot = 1;}
else if(S1==0 && S2==1 && S3==1 && S4==0){Active_slot = 1;}
else if(S1==0 && S2==1 && S3==1 && S4==1){Active_slot = 1;}
else if(S1==0 && S2==1 && S3==0 && S4==1){Active_slot = 1;}
else if(S1==0 && S2==0 && S3==1 && S4==0){Active_slot = 1;}
else if(S1==0 && S2==0 && S3==1 && S4==1){Active_slot = 1;}
else if(S1==0 && S2==0 && S3==0 && S4==1){Active_slot = 1;}
if (gb.buttons.pressed(BTN_C))){
menu_1 ++;}
if(menu_1 == 3){
scroll1 = 1;
gb.display.setColor(BLACK);
gb.display.drawBitmap(0,menuy,menu1);
gb.display.setColor(WHITE);
gb.display.drawBitmap(0,menuy,menu2);
gb.display.setColor(BLACK);}
else if(menu_1 >= 5){
scroll1 =2;
gb.display.setColor(BLACK);
gb.display.drawBitmap(0,menuy,menu1);
gb.display.setColor(WHITE);
gb.display.drawBitmap(0,menuy,menu2);
gb.display.setColor(BLACK);
}
if((menu_1 == 3 && key_1 == 3 && Active_slot==1) || (menu_1 == 5 && key_1 == 3 && Active_slot==1)){gb.display.drawBitmap(key_loc,keyy,key);}
if((menu_1 == 3 && key_1 == 3 && Active_slot==2) || (menu_1 == 5 && key_1 == 3 && Active_slot==2)){gb.display.drawBitmap(key_loc,keyy,key);}
if((menu_1 == 3 && key_1 == 3 && Active_slot==3) || (menu_1 == 5 && key_1 == 3 && Active_slot==3)){gb.display.drawBitmap(key_loc,keyy,key);}
if((menu_1 == 3 && key_1 == 3 && Active_slot==4) || (menu_1 == 5 && key_1 == 3 && Active_slot==4)){gb.display.drawBitmap(key_loc,keyy,key);}
if(keyslot==1 && gb.buttons.pressed(BTN_B)){key_1 = 5, S1 = 0, keyslot=0 ;} //////test remove item key
if(keyslot==2 && gb.buttons.pressed(BTN_B)){key_1 = 5, S2 = 0, keyslot=0 ;}
if(keyslot==3 && gb.buttons.pressed(BTN_B)){key_1 = 5, S3 = 0, keyslot=0 ;}
if(keyslot==4 && gb.buttons.pressed(BTN_B)){key_1 = 5, S4 = 0, keyslot=0 ;}
if((menu_1 == 3 && key_2 == 3 && Active_slot==1) || (menu_1 == 5 && key_2 == 3 && Active_slot==1)){gb.display.drawBitmap(key2_loc,keyy,key2);}
if((menu_1 == 3 && key_2 == 3 && Active_slot==2) || (menu_1 == 5 && key_2 == 3 && Active_slot==2)){gb.display.drawBitmap(key2_loc,keyy,key2);}
if((menu_1 == 3 && key_2 == 3 && Active_slot==3) || (menu_1 == 5 && key_2 == 3 && Active_slot==3)){gb.display.drawBitmap(key2_loc,keyy,key2);}
if((menu_1 == 3 && key_2 == 3 && Active_slot==4) || (menu_1 == 5 && key_2 == 3 && Active_slot==4)){gb.display.drawBitmap(key2_loc,keyy,key2);}
//if(keyslot2==1 && gb.buttons.pressed(BTN_B)){key_1 = 5, S1 = 0, keyslot2=0 ;} //////test remove item key
//if(keyslot2==2 && gb.buttons.pressed(BTN_B)){key_1 = 5, S2 = 0, keyslot2=0 ;}
//if(keyslot2==3 && gb.buttons.pressed(BTN_B)){key_1 = 5, S3 = 0, keyslot2=0 ;}
//if(keyslot2==4 && gb.buttons.pressed(BTN_B)){key_1 = 5, S4 = 0, keyslot2=0 ;}
if((menu_1 == 3 && sox_1 == 3 && Active_slot==1) || (menu_1 == 5 && sox_1 == 3 && Active_slot==1)){gb.display.drawBitmap(sox_loc,keyy,sox);}
if((menu_1 == 3 && sox_1 == 3 && Active_slot==2) || (menu_1 == 5 && sox_1 == 3 && Active_slot==2)){gb.display.drawBitmap(sox_loc,keyy,sox);}
if((menu_1 == 3 && sox_1 == 3 && Active_slot==3) || (menu_1 == 5 && sox_1 == 3 && Active_slot==3)){gb.display.drawBitmap(sox_loc,keyy,sox);}
if((menu_1 == 3 && sox_1 == 3 && Active_slot==4) || (menu_1 == 5 && sox_1 == 3 && Active_slot==4)){gb.display.drawBitmap(sox_loc,keyy,sox);}
//if(soxslot==1 && gb.buttons.pressed(BTN_B)){sox_1 = 5, S1 = 0;} //////test remove item sock
//if(soxslot==2 && gb.buttons.pressed(BTN_B)){sox_1 = 5, S2 = 0;}
//if(soxslot==3 && gb.buttons.pressed(BTN_B)){sox_1 = 5, S3 = 0;}
//if(soxslot==4 && gb.buttons.pressed(BTN_B)){sox_1 = 5, S4 = 0;}
if (scroll1 == 1 && menuy < 0){
menuy = menuy + 2; ////2 = menu speed down
keyy = keyy + 2;} ////2 = menu speed down
if (scroll1 == 2 && menuy > -84){
menuy = menuy - 2; ////2 = menu speed up
keyy = keyy - 2;} ////2 = menu speed up
if (menuy == -84 && scroll1 == 2){
menu_1 ++;}
if (menu_1 > 7){
menu_1 = 1;
scroll1 = 0;}
////PICKUP ITEMS/EMPTY LOCATIONS/////
else if((gb.display.solid[i].spritecol == houseB3) && room == 1 && key_1 == 1) {gb.popup(F(" ""It's locked!!"" "),20); return true;}
else if((gb.display.solid[i].spritecol == houseB3) && room == 6) {gb.popup(F(" ""It's locked!!"" "),20); return true;}
else if((gb.display.solid[i].spritecol == chest) && room == 1 && Active_slot == 1 && gb.buttons.pressed(BTN_A) && key_1 == 1) {gb.popup(F(" ""You got key"" "),20); key_1 = 3, S1=1, key_loc=8, keyslot=1; return true;}
else if((gb.display.solid[i].spritecol == chest) && room == 1 && Active_slot == 2 && gb.buttons.pressed(BTN_A) && key_1 == 1) {gb.popup(F(" ""You got key"" "),20); key_1 = 3, S2=1, key_loc=26, keyslot=2 ; return true;}
else if((gb.display.solid[i].spritecol == chest) && room == 1 && Active_slot == 3 && gb.buttons.pressed(BTN_A) && key_1 == 1) {gb.popup(F(" ""You got key"" "),20); key_1 = 3, S3=1, key_loc=44, keyslot=3; return true;}
else if((gb.display.solid[i].spritecol == chest) && room == 1 && Active_slot == 4 && gb.buttons.pressed(BTN_A) && key_1 == 1) {gb.popup(F(" ""You got key"" "),20); key_1 = 3, S4=1, key_loc=62, keyslot=4; return true;}
else if((gb.display.solid[i].spritecol == chest) && room == 1 && gb.buttons.pressed(BTN_A) && key_1 > 1) {gb.popup(F(" ""It's empty!!"" "),20); return true;}
//else if(gb.display.solid[i].spritecol == chest) return true;
else if((gb.display.solid[i].spritecol == chest) && room == 5 && Active_slot == 1 && gb.buttons.pressed(BTN_A) && key_2 == 1) {gb.popup(F(" ""You got key"" "),20); key_2 = 3, S1=1, key2_loc=8, keyslot2=1; return true;}
else if((gb.display.solid[i].spritecol == chest) && room == 5 && Active_slot == 2 && gb.buttons.pressed(BTN_A) && key_2 == 1) {gb.popup(F(" ""You got key"" "),20); key_2 = 3, S2=1, key2_loc=26, keyslot2=2 ; return true;}
else if((gb.display.solid[i].spritecol == chest) && room == 5 && Active_slot == 3 && gb.buttons.pressed(BTN_A) && key_2 == 1) {gb.popup(F(" ""You got key"" "),20); key_2 = 3, S3=1, key2_loc=44, keyslot2=3; return true;}
else if((gb.display.solid[i].spritecol == chest) && room == 5 && Active_slot == 4 && gb.buttons.pressed(BTN_A) && key_2 == 1) {gb.popup(F(" ""You got key"" "),20); key_2 = 3, S4=1, key2_loc=62, keyslot2=4; return true;}
else if((gb.display.solid[i].spritecol == chest) && room == 5 && gb.buttons.pressed(BTN_A) && key_2 > 1) {gb.popup(F(" ""It's empty!!"" "),20); return true;}
else if(gb.display.solid[i].spritecol == chest) return true;
else if((gb.display.solid[i].spritecol == bedsidebottom) && room == 5 && Active_slot == 1 && gb.buttons.pressed(BTN_A) && sox_1 == 1) {gb.popup(F(" ""You got a sock?"" "),20); sox_1 = 3, S1=1, sox_loc=7, soxslot=1; return true;}
else if((gb.display.solid[i].spritecol == bedsidebottom) && room == 5 && Active_slot == 2 && gb.buttons.pressed(BTN_A) && sox_1 == 1) {gb.popup(F(" ""You got a sock?"" "),20); sox_1 = 3, S2=1, sox_loc=25, soxslot=1; return true;}
else if((gb.display.solid[i].spritecol == bedsidebottom) && room == 5 && Active_slot == 3 && gb.buttons.pressed(BTN_A) && sox_1 == 1) {gb.popup(F(" ""You got a sock?"" "),20); sox_1 = 3, S3=1, sox_loc=43, soxslot=1; return true;}
else if((gb.display.solid[i].spritecol == bedsidebottom) && room == 5 && Active_slot == 4 && gb.buttons.pressed(BTN_A) && sox_1 == 1) {gb.popup(F(" ""You got a sock?"" "),20); sox_1 = 3, S4=1, sox_loc=61, soxslot=1; return true;}
else if((gb.display.solid[i].spritecol == bedsidebottom) && room == 5 && gb.buttons.pressed(BTN_A) && sox_1 > 1) {gb.popup(F(" ""It's empty!!"" "),20); return true;}
else if(gb.display.solid[i].spritecol == bedsidebottom) return true;
This example uses a slot system that automatically puts the item in an inventory slot on a special bitmap with slots left empty. Once in inventory the item should appear in a slot on the inventory menu, The problem is that I’m not seeing where the coordinates are for placing the item in its proper place in the inventory bitmap.
here goes the instruction I was given…
First off we start with an integer for the menu/inventory
(I called mine Menu but you van call yours whatever you like)
int menu_1 = 1;
next you build a bitmap for the item menu, omitted from above code.
then comes the code that actually displays/draws the menu…
if (gb.buttons.pressed(BTN_C)){
menu_1 = menu_1 + 1;}
if(menu_1 == 3){
gb.display.setColor(BLACK);
gb.display.drawBitmap(0,0,menu1);
gb.display.setColor(WHITE);
gb.display.drawBitmap(0,0,menu2);
gb.display.setColor(BLACK);}
else if(menu_1 >= 5){
menu_1 = 1;}
If button C is pressed our menu_1 integer increases (for some reason this increases by 2 each time?? work in progress lol)
If its 1 it does nothing
if its 3 it displays both our BLACK and WHITE menu/inventory sprite
if it goes to 5 then it resets to 1
next we add the item integer
int key_1 = 1;
We then write the code to say if the menu is active (on screen) and the key is in possetion - display key in inventory (this is simply drawing the key sprite in top of our menu/inventory)
if(menu_1 == 3 && key_1 == 3){
gb.display.drawBitmap(8,8,key);
}
But in the actual sketch its drawn like so,
if((menu_1 == 3 && key_1 == 3 && Active_slot==1) || (menu_1 == 5 && key_1 == 3 && Active_slot==1)){gb.display.drawBitmap(key_loc,keyy,key);}
if((menu_1 == 3 && key_1 == 3 && Active_slot==2) || (menu_1 == 5 && key_1 == 3 && Active_slot==2)){gb.display.drawBitmap(key_loc,keyy,key);}
if((menu_1 == 3 && key_1 == 3 && Active_slot==3) || (menu_1 == 5 && key_1 == 3 && Active_slot==3)){gb.display.drawBitmap(key_loc,keyy,key);}
if((menu_1 == 3 && key_1 == 3 && Active_slot==4) || (menu_1 == 5 && key_1 == 3 && Active_slot==4)){gb.display.drawBitmap(key_loc,keyy,key);}
but it never gives the actual x y coordinates for each slot. Can some one please help me understand how the item appears in the slot? You guys are my last resort