D
DenHead
Guest
I'm trying my best to find easy ways to do an upgrade menu in my game. I have a sprite that looks like a battery and when you click it, it charges up indicating that you have upgraded that skill. The main issue I'm having is that I either have to make different objects for each individual part of the menu that I want to be interactive or I have to do it all in the draw event of my game controller. I have this code already in my game controller but I feel as though this isn't the best way to do it as it takes up a ton of space and I have to do it repeatedly for each individual upgrade button.
height = sprite_get_height(spr_upgradeBattery);
width = sprite_get_width(spr_upgradeBattery);
//Damage Upgrade
upgrade1x = room_width/3
upgrade1y = room_height/3
if (upgrade1 = 0) draw_sprite(spr_upgradeBattery,0,upgrade1x,upgrade1y)
if (upgrade1 = 1) draw_sprite(spr_upgradeBattery,1,upgrade1x,upgrade1y)
if (upgrade1 = 2) draw_sprite(spr_upgradeBattery,2,upgrade1x,upgrade1y)
if (upgrade1 = 3) draw_sprite(spr_upgradeBattery,3,upgrade1x,upgrade1y)
if (upgrade1 = 4) draw_sprite(spr_upgradeBattery,4,upgrade1x,upgrade1y)
if point_in_rectangle(mouse_x,mouse_y,upgrade1x-width/2,upgrade1y-height/2,upgrade1x+width/2,upgrade1y+height/2) && device_mouse_check_button_released(0,mb_left)
{
if upgrade1 < 4
{
upgrade1 += 1;
global.playerdmg += 1
}
else
{
audio_play_sound(snd_error,1,false)
}
}
Is there an easier way to make this work without all these unnecessary variables like upgrade1,upgrade2,upgrade3, etc.? How do you guys do it?
height = sprite_get_height(spr_upgradeBattery);
width = sprite_get_width(spr_upgradeBattery);
//Damage Upgrade
upgrade1x = room_width/3
upgrade1y = room_height/3
if (upgrade1 = 0) draw_sprite(spr_upgradeBattery,0,upgrade1x,upgrade1y)
if (upgrade1 = 1) draw_sprite(spr_upgradeBattery,1,upgrade1x,upgrade1y)
if (upgrade1 = 2) draw_sprite(spr_upgradeBattery,2,upgrade1x,upgrade1y)
if (upgrade1 = 3) draw_sprite(spr_upgradeBattery,3,upgrade1x,upgrade1y)
if (upgrade1 = 4) draw_sprite(spr_upgradeBattery,4,upgrade1x,upgrade1y)
if point_in_rectangle(mouse_x,mouse_y,upgrade1x-width/2,upgrade1y-height/2,upgrade1x+width/2,upgrade1y+height/2) && device_mouse_check_button_released(0,mb_left)
{
if upgrade1 < 4
{
upgrade1 += 1;
global.playerdmg += 1
}
else
{
audio_play_sound(snd_error,1,false)
}
}
Is there an easier way to make this work without all these unnecessary variables like upgrade1,upgrade2,upgrade3, etc.? How do you guys do it?