Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Clothing System for Character

I'm attempting to create a flexible system for clothing my character in my game. Right now I've got a base class from which all child clothing classes will extend, and additional interfaces to bring which body parts they actually clothe into the equation. Here's my code:

public class Clothing
{
    public EClothingBind[] Types;
    public int ID;
    public int Priority;
    public bool HidesUnderlying;
    public AnimatedSpriteMap Graphic;
    public Color Blend = Color.White;

    public virtual void Update(GameTime gameTime) 
    {
        Graphic.Update(gameTime);
    }

    public virtual void Draw(Vector2 position)
    {
        Graphic.Tint = Blend;
        Graphic.Draw(position);
    }
}

public interface IClothingHead { ... }
public interface IClothingChest { ... }
public interface IClothingLegs { ... }
public interface IClothingFeet { ... }

Right now this doesn't work well, as the design doesn't really restrict what can implement my IClothing interfaces. Is there a way to restrict interface implementation to certain types? I don't want to turn my interfaces into classes because I'd like an article of clothing, say a robe, to cover the whole body (implementing all four). I'm a bit lost on what's the best way to go about doing this, and all input is much appreciated. Thanks.

like image 681
pajm Avatar asked Dec 28 '22 09:12

pajm


2 Answers

I think you're setting yourself up for some tough times ahead with this approach. Sure, a robe covers all, and graphically it will and perhaps affect the "armour" value of the 4 areas. But implementing it like this looks very cumbersome. You probably just want a single IClothing interface and have some some identification of where it can be put (e.g: Hands/Feet, etc). Traditionally, robes are generally a chest-piece, but graphically they cover the entire character.

enum PositionType
{
    Head,
    Chest,
    Hand,
    Feet,
    Finger,
    Neck
}


public interface IClothing
{
    PositionType Type { get; }
    // Other things you need IClothing-classed to implement
}

I think this might be a better approach rather than trying to fine-tune exactly what body-parts a particular item of clothing does by way of implementing multiple interfaces.

like image 55
Moo-Juice Avatar answered Dec 29 '22 23:12

Moo-Juice


This extends moo-Juice's answer (just not putting it in the comment as formatting is not allowed).

You can have your PositionType have the attribute [Flags] so you can do:

[Flags]
enum PositionType
{
    Head,
    Chest,
    Hand,
    Feet,
    Finger,
    Neck
}

Armor robe = new Armor(); //sure why not.
robe.ArmorValue = 125.3;
robe.Appeal = 100;    
robe.PositionType = PositionType.Chest | PositionType.Arms | PositionType.BellyButton; 

etc.

like image 37
Ryan Ternier Avatar answered Dec 30 '22 00:12

Ryan Ternier