Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // obj_inventory ////////////////////////////////////////////////////////////////////
- /// Create the system (Create Event)
- enum item {
- none = 0,
- lemon = 1
- }
- /// Initialize
- width = 6;
- height = 1;
- box_size = 48;
- draw_set_font(fnt_inventory);
- // Create the grid
- // Items
- box = ds_grid_create(width, height);
- ds_grid_clear(box, item.none);
- // Item Cound
- count = ds_grid_create(width, height);
- ds_grid_clear(count, 0);
- // Add/ Remove some items
- repeat(5) {
- scr_inventory_pickup_item(item.lemon);
- }
- scr_inventory_remove_item(0, 0);
- /// Draw the inventory (Draw Event)
- for (var yy = 0; yy < width; yy++) {
- for (var xx = 0; xx < height; xx++) {
- var tx = x+(xx*box_size);
- var ty = y+(yy*box_size);
- draw_sprite(spr_inventory, box[# xx, yy], tx, ty);
- if (count[# xx, yy] > 0) {
- draw_circle_color(tx, ty-2, 6, c_white, c_white, false);
- draw_text(tx-1, ty-8, count[# xx, yy]);
- }
- }
- }
- // Scripts ////////////////////////////////////////////////////////////////////////////////////////////////
- /// scr_inventory_add_item(x, y, item)
- var xx = argument[0];
- var yy = argument[1];
- var add_item = argument[2];
- // Check if out of range
- if (xx != median(0, xx, obj_inventory.width-1) || yy != median(0, yy, obj_inventory.height-1)) {
- show_debug_message("Not in range!")
- exit;
- }
- // Get the item count
- var item_count = obj_inventory.count[# xx, yy];
- if (item_count == 0) {
- obj_inventory.box[# xx, yy] = add_item;
- obj_inventory.count[#xx, yy]++;
- return true;
- } else if (item_count > 0) {
- if (obj_inventory.box[# xx, yy] == add_item) {
- obj_inventory.count[#xx, yy]++;
- return true
- } else {
- show_debug_message("Taken");
- return false;
- }
- } else {
- show_error("The item cound is less then 0", false);
- }
- /// inventory_remove_item(x, y);
- var xx = argument[0];
- var yy = argument[1];
- // Check if out of range
- if (xx != median(0, xx, obj_inventory.width-1) || yy != median(0, yy, obj_inventory.height-1)) {
- show_debug_message("Not in range!")
- exit;
- }
- // Get the item count
- var item_count = obj_inventory.count[# xx, yy];
- // Make sure we have items
- if (item_count > 0) {
- obj_inventory.count[# xx, yy]--;
- var remove_item = obj_inventory.box[# xx, yy];
- if (item_count == 0) {
- obj_inventory.box[# xx, yy] = item.none;
- }
- return remove_item;
- } else if (item_count == 0) {
- show_debug_message("No Item");
- return item.none;
- } else {
- show_error("Taken", false);
- }
- /// scr_inventory_pickup_item(item)
- var add_item = argument[0];
- // Check for item
- for (var yy = 0; yy < obj_inventory.height; yy++) {
- for (var xx = 0; xx < obj_inventory.width; xx++) {
- if (obj_inventory.box[# xx, yy] == add_item) {
- obj_inventory.count[# xx, yy]++;
- return true;
- }
- }
- }
- // Check for empty slot
- for (var yy = 0; yy < obj_inventory.height; yy++) {
- for (var xx = 0; xx < obj_inventory.width; xx++) {
- if (obj_inventory.box[# xx, yy] == item.none) {
- obj_inventory.box[# xx, yy] = add_item;
- obj_inventory.box[# xx, yy]++;
- return true;
- }
- }
- }
- // Show debug message
- show_debug_message("The inventory is full");
- return false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement