From 1f4a8a24be660f5e83962d48634c03c81f78ea9a Mon Sep 17 00:00:00 2001 From: SilicaAndPina Date: Wed, 29 Jul 2020 11:29:00 +1200 Subject: [PATCH] Add inventory. --- Spaceinator.project.gmx | 7 +- objects/obj_asteriod.object.gmx | 23 ++ objects/obj_controller.object.gmx | 4 +- objects/obj_controller_world_gen.object.gmx | 5 +- objects/obj_dropped_item.object.gmx | 103 +++++- objects/obj_dropped_stone.object.gmx | 53 +++ objects/obj_hotbar.object.gmx | 338 ++++++++++++++++++++ objects/obj_inv_controller.object.gmx | 62 +++- objects/obj_inventory.object.gmx | 87 +++++ objects/obj_player.object.gmx | 27 ++ rooms/rm_game.room.gmx | 2 + scripts/add_item_to_inventory.gml | 21 ++ sprites/images/spr_blocks_0.png | Bin 121 -> 103 bytes sprites/images/spr_hotbar_0.png | Bin 763 -> 692 bytes sprites/images/spr_intentory_0.png | Bin 0 -> 2772 bytes sprites/spr_hotbar.sprite.gmx | 8 +- sprites/spr_intentory.sprite.gmx | 25 ++ 17 files changed, 751 insertions(+), 14 deletions(-) create mode 100644 objects/obj_dropped_stone.object.gmx create mode 100644 objects/obj_hotbar.object.gmx create mode 100644 objects/obj_inventory.object.gmx create mode 100644 scripts/add_item_to_inventory.gml create mode 100644 sprites/images/spr_intentory_0.png create mode 100644 sprites/spr_intentory.sprite.gmx diff --git a/Spaceinator.project.gmx b/Spaceinator.project.gmx index c0a6f0f..932f6a2 100644 --- a/Spaceinator.project.gmx +++ b/Spaceinator.project.gmx @@ -22,6 +22,7 @@ sprites\spr_gameover sprites\spr_button sprites\spr_hotbar + sprites\spr_intentory @@ -33,6 +34,7 @@ + @@ -51,9 +53,12 @@ objects\obj_button objects\obj_respawn objects\obj_gameover_overlay + objects\obj_inventory + objects\obj_hotbar objects\obj_dropped_item + objects\obj_dropped_stone @@ -62,7 +67,7 @@ 32 16 - 0 + 0 1 diff --git a/objects/obj_asteriod.object.gmx b/objects/obj_asteriod.object.gmx index d342e3d..179a607 100644 --- a/objects/obj_asteriod.object.gmx +++ b/objects/obj_asteriod.object.gmx @@ -32,6 +32,29 @@ angle = random_range(0,180); direction = angle; image_angle = angle; + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + instance_create(x,y,obj_dropped_stone); diff --git a/objects/obj_controller.object.gmx b/objects/obj_controller.object.gmx index 850b39f..3225f6d 100644 --- a/objects/obj_controller.object.gmx +++ b/objects/obj_controller.object.gmx @@ -58,9 +58,7 @@ if(!global.debug) draw_healthbar(10,40,300,60,(obj_player.hp/obj_player.hp_max)*100,c_gray,c_red,c_green,0,true,false); draw_text(11,43,string(obj_player.hp)+" / "+string(obj_player.hp_max)); - - // Draw hotbar - draw_sprite(spr_hotbar,0,960/2,544); + } diff --git a/objects/obj_controller_world_gen.object.gmx b/objects/obj_controller_world_gen.object.gmx index a10ad3e..09a1c19 100644 --- a/objects/obj_controller_world_gen.object.gmx +++ b/objects/obj_controller_world_gen.object.gmx @@ -25,8 +25,7 @@ 1 - global.allchunks = ds_list_create(); - + @@ -57,7 +56,7 @@ for(var i = 0; i < 16; i ++) { show_debug_message("Generating Chunk: "+string(cX[i])+","+string(cY[i])); var chunkInstId = instance_create(cX[i],cY[i],obj_chunk); - ds_list_add(global.allchunks,chunkInstId); + } else // load { diff --git a/objects/obj_dropped_item.object.gmx b/objects/obj_dropped_item.object.gmx index c467ce8..ac1d27a 100644 --- a/objects/obj_dropped_item.object.gmx +++ b/objects/obj_dropped_item.object.gmx @@ -5,9 +5,108 @@ -1 0 0 - <undefined> + self <undefined> - + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + image_xscale = 0.5; +image_yscale = 0.5; +image_speed = 0; + +item_id = 0; +image_index = item_id; + +alarm[0] = 5*60*room_speed; + + + + + + + + 1 + 203 + 0 + 0 + 0 + -1 + 1 + action_kill_object + + self + 0 + 0 + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + pull_towards_black_holes(); + +var distance = distance_to_point(obj_player.x,obj_player.y) +if(distance <= 100) +{ + direction = point_direction(x,y,obj_player.x,obj_player.y); + speed = 10; +} +else +{ + speed = 0; +} + + + + + + + + + + 1 + 203 + 0 + 0 + 0 + -1 + 1 + action_kill_object + + self + 0 + 0 + + + 0 0 0 diff --git a/objects/obj_dropped_stone.object.gmx b/objects/obj_dropped_stone.object.gmx new file mode 100644 index 0000000..efbe5ba --- /dev/null +++ b/objects/obj_dropped_stone.object.gmx @@ -0,0 +1,53 @@ + + + spr_blocks + 0 + -1 + 0 + 0 + obj_dropped_item + <undefined> + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + image_xscale = 0.5; +image_yscale = 0.5; +image_speed = 0; + +item_id = STONE; +image_index = item_id; + + + + + + + + 0 + 0 + 0 + 0.5 + 0.100000001490116 + 0 + 0.100000001490116 + 0.100000001490116 + 0.200000002980232 + -1 + 0 + + diff --git a/objects/obj_hotbar.object.gmx b/objects/obj_hotbar.object.gmx new file mode 100644 index 0000000..a8694eb --- /dev/null +++ b/objects/obj_hotbar.object.gmx @@ -0,0 +1,338 @@ + + + spr_hotbar + 0 + -1 + 0 + 0 + <undefined> + <undefined> + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + selected_slot = 0; + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + x = view_xview[0]+view_wview[0]/2 - (424/2) +y = view_yview[0]+view_hview[0]-59; + + +if((mouse_x >= x && mouse_x <= x+424) && (mouse_y >= y && mouse_y <= y+59)) +{ + var i = 0; + + for(var xx = 5; xx < (9*45); xx+=45) + { + if(mouse_x >= x+xx && mouse_x <= x+xx+45) + { + selected_slot = i; + } + + i++; + } + + +} + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + draw_self(); +var i = 0; +var yy = 7; +for(var xx = 5; xx < (9*45); xx+=45+1) +{ + draw_sprite(spr_blocks,obj_inv_controller.inventory[i],x+xx+6,y+yy+7); + if(i == selected_slot) + { + draw_set_color(make_colour_rgb(100,100,100)); + draw_rectangle(x+xx,y+yy,x+xx+45,y+yy+44,false) + } + var count = obj_inv_controller.inventoryCount[i]; + var xoffset = string_width(string(count)) + if(count > 1) + { + draw_set_color(c_white); + draw_text(x+xx+45-xoffset,y+yy+30,string(count)); + } + i++ +} + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + selected_slot = 8; + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + selected_slot = 7; + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + selected_slot = 6; + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + selected_slot = 5; + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + selected_slot = 4; + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + selected_slot = 3; + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + selected_slot = 2; + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + selected_slot = 1; + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + selected_slot = 0; + + + + + + + 0 + 0 + 0 + 0.5 + 0.100000001490116 + 0 + 0.100000001490116 + 0.100000001490116 + 0.200000002980232 + -1 + 0 + + diff --git a/objects/obj_inv_controller.object.gmx b/objects/obj_inv_controller.object.gmx index eeed8ac..55a48bd 100644 --- a/objects/obj_inv_controller.object.gmx +++ b/objects/obj_inv_controller.object.gmx @@ -7,7 +7,67 @@ 0 <undefined> <undefined> - + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + inventory = array_create(9*5); +inventoryCount = array_create(9*5); + +is_open = false; +inv_obj = 0; + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + if(!is_open) +{ + inv_obj = instance_create(0,0,obj_inventory); + is_open = true; +} +else +{ + instance_destroy(inv_obj); + is_open = false; +} + + + + + + 0 0 0 diff --git a/objects/obj_inventory.object.gmx b/objects/obj_inventory.object.gmx new file mode 100644 index 0000000..6fe8bc0 --- /dev/null +++ b/objects/obj_inventory.object.gmx @@ -0,0 +1,87 @@ + + + spr_intentory + 0 + -1 + -4000 + 0 + <undefined> + <undefined> + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + x = view_xview[0]+view_wview[0]/2 - (424/2); +y = view_yview[0]+view_hview[0]/2 - (254/2); + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + draw_self(); +var xx = 6; +var yy = 8; +var i = 0; +for(yy = 8; yy < (5*44); yy+=45+1) +{ + for(xx = 6; xx < (9*45); xx+=45+1) + { + draw_sprite(spr_blocks,obj_inv_controller.inventory[i],x+xx+6,y+yy+7); + var count = obj_inv_controller.inventoryCount[i]; + var xoffset = string_width(string(count)) + if(count > 1) + draw_text(x+xx+45-xoffset,y+yy+30,string(count)); + i++ + } +} + + + + + + + + 0 + 0 + 0 + 0.5 + 0.100000001490116 + 0 + 0.100000001490116 + 0.100000001490116 + 0.200000002980232 + -1 + 0 + + diff --git a/objects/obj_player.object.gmx b/objects/obj_player.object.gmx index 6f758c4..be1fa15 100644 --- a/objects/obj_player.object.gmx +++ b/objects/obj_player.object.gmx @@ -161,6 +161,33 @@ if(invuln_counter != invuln_counter_max) 1 ///pull_towards_black_holes(); pull_towards_black_holes(); + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + var didAdd = add_item_to_inventory(other.item_id); +if(didAdd) +{ + instance_destroy(other); +} diff --git a/rooms/rm_game.room.gmx b/rooms/rm_game.room.gmx index e4b05d5..892e135 100644 --- a/rooms/rm_game.room.gmx +++ b/rooms/rm_game.room.gmx @@ -54,6 +54,8 @@ + + 0 diff --git a/scripts/add_item_to_inventory.gml b/scripts/add_item_to_inventory.gml new file mode 100644 index 0000000..11f780c --- /dev/null +++ b/scripts/add_item_to_inventory.gml @@ -0,0 +1,21 @@ +///add_item_to_inventory(itemId) +var itemId = argument0; + +for(var i = 0; i < (9*4); i ++) +{ + var itm = obj_inv_controller.inventory[i]; + + if(itm == 0) + { + obj_inv_controller.inventory[i] = itemId; + obj_inv_controller.inventoryCount[i] = 1; + return true; + } + else if(itm == itemId) + { + obj_inv_controller.inventoryCount[i] ++; + return true; + } +} +return false; + diff --git a/sprites/images/spr_blocks_0.png b/sprites/images/spr_blocks_0.png index 806f5a8f0502ffb1312c6bfcadb80b35188bfc11..4cea42c6c8d2d50a3b3199d9f92d3c81f5d37a9d 100644 GIT binary patch delta 72 zcmb}B-DlpiTsz`8^G;BCxq3RA$D}V;y_r=!f4y4DI7y}U z>m>%yN&BiY8&o{w_tx{;+uIix78jRq&3JZhhipjZojc)oyVKtF+;*IL>}>7Ty`#dz sHcWo+=kuDhB!!rCV&X7q$@+gx=Bpo8-Iw4h1*S#@Pgg&ebxsLQ03Z{Bga7~l literal 763 zcmeAS@N?(olHy`uVBq!ia0y~yU~C1ltvT3$45^s&_Uguo5uQBG z2RU<{Z=ZSZ#du<2GylTg^ouW>4uAjs`}cem&-$v&29=lAdrcfBeVH34rQrF?PoH;! zO6~ILY#x*LUG`>H@x1@?@7oWbKL=mm|G;1R&As5y@7BJnKl)B{%9S_UcHh}SgXg7kNP7Is|1hZAvh$5d1~5@Gc)I$ztaD0e F0suNl)3g8p diff --git a/sprites/images/spr_intentory_0.png b/sprites/images/spr_intentory_0.png new file mode 100644 index 0000000000000000000000000000000000000000..be676e33b13043650594ebf38c7cd70ddeaedbbb GIT binary patch literal 2772 zcmeAS@N?(olHy`uVBq!ia0y~yU|a!Yzvo~BlFMf}EMQ>Zn(gW07*a9k?X`uCDvUhL z2RYw5?LPBgcm`{?%1&)&V-)wujv z?gFpJ&-T5FGbv8L!?wyK@7?Nmqr$^COyYT`sCb^7=imNi(Z8+l6>}fF%fGlcX@GuUOdeeYODyr3XvX{DlUEkNfrE&Lu*YAsFT0b@m zSXx*dU#dTAr*R&0sFeBl&{5&x8z%48vw2Ngl5&2zb5-E~Ti+*`6@1_RVzfyx;@U%h juR3^6n(~I2#-x2I_q9W@yvp{#)+&RitDnm{r-UW|^+eVm literal 0 HcmV?d00001 diff --git a/sprites/spr_hotbar.sprite.gmx b/sprites/spr_hotbar.sprite.gmx index 924bcc2..599ecbc 100644 --- a/sprites/spr_hotbar.sprite.gmx +++ b/sprites/spr_hotbar.sprite.gmx @@ -1,14 +1,14 @@ 0 - 194 - 59 + 0 + 0 1 0 0 0 0 - 388 + 423 0 58 0 @@ -17,7 +17,7 @@ 0 0 - 389 + 424 59 images\spr_hotbar_0.png diff --git a/sprites/spr_intentory.sprite.gmx b/sprites/spr_intentory.sprite.gmx new file mode 100644 index 0000000..f299ff2 --- /dev/null +++ b/sprites/spr_intentory.sprite.gmx @@ -0,0 +1,25 @@ + + + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 423 + 0 + 238 + 0 + 0 + + 0 + + 0 + 424 + 239 + + images\spr_intentory_0.png + +