External Exam Download Resources Web Applications Games Recycle Bin

upgrades and inventory | gml

objPlayer Create

inventory = ds_list_create();

objPlayer Step

//------------ Movement:
x += (keyboard_check(vk_right) - keyboard_check(vk_left))*3;
y += (keyboard_check(vk_down) - keyboard_check(vk_up))*3;

//------------ Collect upgrades:
var flash = instance_position(x,y,objFlashPickup);
if flash != noone {
    instance_destroy(flash);
    ds_list_add(inventory, "Flash press F");
}

var invisible = instance_position(x,y,objInvisiblePickup);
if invisible != noone {
    instance_destroy(invisible);
    ds_list_add(inventory, "Invisible press I");
}

//------------ Apply upgrades:
if keyboard_check_pressed(ord("F")){
    for (var i = 0; i < ds_list_size(inventory); i++){
        var item = ds_list_find_value(inventory, i);
        if item == "Flash press F"{
            ds_list_delete(inventory, i);
            sprite_index = sprPlayerFlash;
        }
    }
}

if keyboard_check_pressed(ord("I")){
    for (var i = 0; i < ds_list_size(inventory); i++){
        var item = ds_list_find_value(inventory, i);
        if item == "Invisible press I"{
            ds_list_delete(inventory, i);
            image_alpha = 0;
        }
    }
}

objPlayer Draw GUI

draw_set_font(font0);
draw_text(5,5,"Inventory Items:");
for (var i = 0; i < ds_list_size(inventory); i++){
    draw_text(5,(25 + i*25),ds_list_find_value(inventory, i));
}

Challenges - Add:

  1. other upgrades
  2. upgrades only apply for limited time, then reset
  3. respawn / randomize upgrades