• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Weapon upgrade system and shopping

Axl Trauts

Member
Hi guys,

I am making a weapon system and a shop which I'd like to make better, I hope you can help.

Well, I am making an action game where the player gets upgrades on the level and changes its main gun, only there are 3 types, only one type at a time can be carried, and each one can be upgraded with consecutive powerup grabs/collisions with the powerup object (ie. first you shoot one missile, then two; and so for each type).

Then I wanted to start implementing a shop, where the player can buy the powerup upgrade and/or buy extra weapons which can be carried along with the main gun.

So, I have three questions:

1.: I have created a global variable called global.var_powerup that ranges from 1-3 for one type (regular shot) and its upgrades, 11-13 for the second (missiles), etc. They are easily handled because one is selected at a time.

Now that I think of it, if you have the powerup at 3 (shot level 3) and you change for missiles you start at 11 (missile level 1), and if you change back to regular shot, you go back to shot level 2. Maybe that is not fair.

Code:
//Object powerup 1, collision with object player
//Same goes with powerup 2 and 3
if global.var_powerup=0 or global.var_powerup>10
{ global.var_powerup=1; exit;}
if global.var_powerup=1
{ global.var_powerup=2; exit;}
if global.var_powerup=1
{ global.var_powerup=2; exit;}
2.: For extras, on the other hand, the player can carry more than one. I can create a different global variable for each extra, but maybe there is a better idea?

3.: Anyways, for the shop thing, I am having trouble with texts.
I created an item object, the missile, that in its Draw event when you hover over the object a Text is drawn elsewere stating the price, as long as the mouse is over the object. When you purchase, the price is substracted from the "purse" and a text saying "Gracias" (Thanks) is shown below the price, but I´d like it to be more persistent, as it last only a bit. The "Thanks" message will be erased after a while or when you hover over another item object. I am not sure how.

Code:
//object obj_item_misil, Draw event
if distance_to_point(mouse_x,mouse_y)<=0 and var_comprado=1
{   draw_sprite(spr_item_misil_on,image_index,x,y)
    draw_text(448,224,"VALOR (Value) $20")
    if mouse_check_button_released(mb_left) and global.var_player_purse>=item_cost
    {   global.var_player_purse=global.var_player_purse - item_cost
        draw_text(448,244,"Gracias (Thanks)")
     }
    else if mouse_check_button_pressed(mb_left) and global.var_player_purse<item_cost
    {   draw_text(448,264,"NO HAY SUFICIENTE DINERO (Not enough money)");
    }
}
else draw_self();
 
J

JTC

Guest
Hey mate,

I think your use of global.var_powerup is confusing and not really a good way to approach this problem. Mostly because it restricts your flexibility in terms of game design. What if you decide you want to add an extra gun type, or an extra level of upgrade? Your solution doesn't handle this very well. I think a good lesson to learn is that you should be thinking as far forward as possible with these things - you never know what you might want to do in the future, so it's good to try and have an organised and modular approach to how you design things (if you don't understand these terms right now, don't fret. It will become apparent over time).

Instead, what I'd do is have a ds_list somewhere that manages the status of each gun type. Let's say this is managed by the player object - although where you actually store this information will depend on how you've made your game thus far). In each entry of the list, you could have a ds_map that stores the characteristics of that weapon. Let's say you want to track what power-up level it's on, how much ammo they have left in total, and how much ammo they have left in the current clip.

You might be able to make a ds_map that looks something like this when visualised, with the idea being that you'd have one of these for each gun type:

{
"WeaponName" -> "Regular"
"TotalAmmo" -> 20
"CurrentAmmo" -> 8
"UpgradeLevel -> 1
}

If you stored 3 of the above maps in a list, you could loop through them, take away guns, add guns, and do all sorts of wonderful things very easily that your method doesn't allow you to do. This also solves your problem of the player carrying more than one gun, as you could have a property in the list that says whether the player has actually obtained that weapon yet. Of course, you'd have to be careful to avoid memory leaks.

For your shop problem, the simplest solution is probably to create a new object that draws "Gracias" at the appropriate location. But also, in the Create event, is sets an alarm to a certain amount of time. When that alarm is triggered, the object would destroy itself, effectively removing the text. You could also include something in the step event that would destroy itself if the mouse moved over another object. I hope this helps you!
 
Top