Game Mechanics Armour / weapons / Stats

O

Orthodox & Occult

Guest
I'm looking for a way to implement a system in which the player can equip armour and weapons, that not only affect stats but also changes the appearence of the player, but I have no idea how I would code it

I've though of 2 possible solutions but still, I've no idea how to code it in GML

SOLUTION 1
1 create finite state machine
2 check state (check inventory slots?)
3 Apply armour sprite (or) index frame

SOLUTION 2
1 set all armour types to separate frames in the same sprite
2 set player default as index 1 (no armour)
3 when players equips armour run code attached to armour object telling to change player index to (x)

as well as that but how could I apply armour animation to each armour set (run cycle)
 

NicoDT

Member
Hi! I think option 1 would work fine (a finite state machine is always a good idea, not just for this)

You could do something like this in the draw event

Code:
switch (armor) {
   case "bronze armor":  sprite_index = spr_bronze_armor; break;
   case "silver armor":     sprite_index = spr_silver_armor; break;
   ...
   default:  sprite_index = spr_whatever_armor; break;
}
Don't do it based on image index (frame), or you won't be able to have them animated.
 

Yal

šŸ§ *penguin noises*
GMC Elder
SOLUTION 2
1 set all armour types to separate frames in the same sprite
2 set player default as index 1 (no armour)
3 when players equips armour run code attached to armour object telling to change player index to (x)

as well as that but how could I apply armour animation to each armour set (run cycle)
Definitely recommending this approach over using a state machine for armor... but you could have one sprite per armor set instead of one image per set, and then have a global array that lists all the sprites for each armor.

Code:
//In your title screen object's create event or something
global.armor = 1
global.armor_sprite[0] = spr_armor_ naked
global.armor_sprite[1] = spr_armor_wood
global.armor_sprite[2] = spr_armor_iron
global.armor_sprite[3] = spr_armor_bronze
global.armor_sprite[4] = spr_armor_asbesthos
global.armor_sprite[5] = spr_armor_diamond
Code:
//Player's step event
sprite_index = global.armor_sprite[global.armor]
 

SnoutUp

Member
I'm ds_map person, so here's how I'm doing it in Pork Chopper. I basically create a ds_map for every item, which has values like ID, title, sprite_index, inventory slot and etc, then my character has a ds_map called inventory, which contains slots where items could be applied, so it allows me to have scripts like these:
Code:
/// EquipItem(id, slot)

var _id    = argument0; // ITEM_FANCY_HAT
var _slot = argument1; // SLOT_HAT

var item = global.itemMap[? _id];
inventory[? _slot] = item;

// change sprite of the hat
if (_slot == SLOT_HAT) hatSprite = item[? "SPRITE"];
 

Genetix

Member
You could us a single image for armor, overlay it over the player sprite and if designed right have it 'fit' the player animation... Not easy to get just right though.
 
Top