Tenho um inventário e não sei como adapto ele para receber items do tipo, ex: Armor, Shield, Helmet, etc...
Create do obj_inventory:
Código: Selecionar todos
open = true;
ld = 32; // distancia entre os slots
slotT = 16; // total de slots
mouse = 0;
for(i = 1; i <= slotT; i++){
slot[i] = 0; // item do slot 1
}
Código: Selecionar todos
/// @description Insert description here
// You can write your code in this editor
if open{
//vx = view_xview, vy = view_yview
var h = 0, k = 0, vx = camera_get_view_x(view_camera[0]), vy = camera_get_view_y(view_camera[0]), color = c_ltgray;
for(i = 1; i <= slotT; i++){
var sx = vx+ld*k, sy = vy+ld*h;
// interações
if point_in_rectangle(mouse_x, mouse_y, sx, sy, sx+32, sy+32){
if mouse_check_button_pressed(mb_left){
// mouse vazio e slot completo
if mouse == 0 and slot[i] != 0{
mouse = slot[i];
slot[i] = 0;
}
// mouse completo e slot vazio
else if mouse != 0 and slot[i] == 0{
slot[i] = mouse;
mouse = 0;
}
// mouse completo e slot completo
else if mouse != 0 and slot[i] != 0{
var _item = slot[i];
slot[i] = mouse;
mouse = _item;
//show_message("Este slot não está vázio");
}
}
color = c_yellow;
}else{
color = c_ltgray;
}
// fundo
draw_sprite_ext(spBorde, 0, sx, sy, 1, 1, 0, color, 1);
// Borde
//draw_sprite_ext(spBorde, 0, sx, sy, 1, 1, 0, c_white, 1);
// item
if slot[i] != 0{
draw_sprite(spItems, slot[i], sx, sy);
}
// Aumentar coordenadas
k++;
if frac(i/4) = 0{
h += 1;
k = 0;
}
}
}
if mouse != 0{
draw_sprite(spItems, mouse, mouse_x-8, mouse_y-8);
if mouse_check_button_pressed(mb_right){
with(instance_create_layer(obj_player.x-8, obj_player.y-8, "Instances", obItems)){
item = other.mouse;
}
mouse = 0;
}
}
/// @description Insert description here
// You can write your code in this editor
if open{
//vx = view_xview, vy = view_yview
var h = 0, k = 0, vx = camera_get_view_x(view_camera[0]), vy = camera_get_view_y(view_camera[0]), color = c_ltgray;
for(i = 1; i <= slotT; i++){
var sx = vx+ld*k, sy = vy+ld*h;
// interações
if point_in_rectangle(mouse_x, mouse_y, sx, sy, sx+32, sy+32){
if mouse_check_button_pressed(mb_left){
// mouse vazio e slot completo
if mouse == 0 and slot[i] != 0{
mouse = slot[i];
slot[i] = 0;
}
// mouse completo e slot vazio
else if mouse != 0 and slot[i] == 0{
slot[i] = mouse;
mouse = 0;
}
// mouse completo e slot completo
else if mouse != 0 and slot[i] != 0{
var _item = slot[i];
slot[i] = mouse;
mouse = _item;
//show_message("Este slot não está vázio");
}
}
color = c_yellow;
}else{
color = c_ltgray;
}
// fundo
draw_sprite_ext(spBorde, 0, sx, sy, 1, 1, 0, color, 1);
// Borde
//draw_sprite_ext(spBorde, 0, sx, sy, 1, 1, 0, c_white, 1);
// item
if slot[i] != 0{
draw_sprite(spItems, slot[i], sx, sy);
}
// Aumentar coordenadas
k++;
if frac(i/4) = 0{
h += 1;
k = 0;
}
}
}
if mouse != 0{
draw_sprite(spItems, mouse, mouse_x-8, mouse_y-8);
if mouse_check_button_pressed(mb_right){
with(instance_create_layer(obj_player.x-8, obj_player.y-8, "Instances", obItems)){
item = other.mouse;
}
mouse = 0;
}
}
Código: Selecionar todos
var _item = argument0;
with(obInventory){
for(i = 1; i <= slotT; i++){
if slot[i] = 0{
slot[i] = _item;
return(1);
exit;
}
}
return(0);
}