1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
class Menu
{
public:
Menu(int x1, int y1, int Selections, const char * n, ...);
void destroyMenu_bitmaps();
void displayMenu_bitmaps();
int x, y, numSelections, selected, menuW, menuH;
//bitmap array, 0 is unselected bitmap and 1 is selected, which make 1 selection together, so can have max of 10 selections to choose from in the menu
BITMAP * menubmp[20];
};
//this allows the user to type in as many bitmaps as they want to be included in the list, and display it at x1,y1 and define how many selections there are
Menu::Menu(int x1, int y1, int Selections, const char * n, ...)
{
va_list ap;
va_start(ap, n);
const char * p;
x = x1;
y = y1;
menuH = 0;
menuW = 0;
selected = 1;
numSelections = Selections;
menubmp[0] = load_bitmap(n,NULL);
for (int m = 1 ; m < (numSelections * 2) ; m++)
{
p = va_arg(ap, char *);
menubmp[m] = load_bitmap(p,NULL);
}
va_end(ap);
}
void Menu :: destroyMenu_bitmaps()
//destroy_bitmap (menubmp);
void Menu :: displayMenu_bitmaps()
{
///////////////Get Screen////////////
//code to get current screen, create menubuffer
BITMAP * menuBuffer;
for (int n = 1 ; n < (numSelections*2 ) ; n+=2)
menuH += menubmp[n]->h;
menuW += menubmp[0]->w;
menuBuffer = create_bitmap (menuW, menuH);
//////////////create menu////////////
menubmp[numSelections*2] = create_bitmap(menuW, menuH);
rectfill(menubmp[numSelections*2],0,0,menuW,menuH,makecol(255,139,3));
for (int n = 0 ; n < (numSelections*2 ) ; n+=2)
{
draw_sprite(menubmp[numSelections*2], menubmp[n], 0 , n/2 * menubmp[n]->h);
}
int yDraw = 0;
////////////display menu/////////////
while (!key[KEY_Y])
{
draw_sprite(menuBuffer, menubmp[numSelections*2], 0 , 0);
yDraw = 0;
for (int l = 1; l<selected ; l++)
yDraw += menubmp[l*2]->h;
draw_sprite(menuBuffer, menubmp[selected*2 - 1], 0, yDraw);
//////////interact with menu/////////
//navigate w keypress
if (key[KEY_UP])
{
selected--;
rest(100);
}
else if (key[KEY_DOWN])
{
selected++;
rest(100);
}
if (selected > numSelections )
selected = 1;
else if(selected < 1)
selected = (numSelections);
/////////menu functionality//////////
if (key[KEY_ENTER])
{
switch (selected)
{
case 0:
break;
case 1:
//convert characters of itemFunction into tasks might have to specify w each menu
player->speed += 1;
break;
and so on
}
}
//vsync();
acquire_screen();
stretch_sprite(menuBuffer, player_image[0], 100, 125, 150, 192);
blit(menuBuffer, screen, 0, 0, x, y, menuW, menuH);
release_screen();
}
}
|