I have this code and I want to make a copy of characters[currentCharacter]without a memory reference. Do i have to copy the value of each variable individually?
public void Choose(object _info)
{
choosing = false;
characters[currentCharacter].SetDimentions(new Vector2(80,80));
world = new World(characters[currentCharacter]);
}
public class Character : Unit
{
protected _Keyboard keyboard;
protected string name;
protected string description;
protected bool shield;
protected double currentTime;
protected float cooldown;
protected bool readyToShoot;
public Character(string _path, Vector2 _position, Vector2 _dimensions, int _ownerId, List<Projectile> _projectiles) : base(_path, _position, _dimensions, _ownerId)
{
keyboard = new _Keyboard();
shield = false;
readyToShoot = true;
}
public string GetName()
{
return name;
}
public string GetDescription()
{
return description;
}
public void SetShieldStatus(bool _status)
{
shield = _status;
}
public bool HasShield()
{
return shield;
}
public virtual void Update(Vector2 _offset,PassObject _scroll,MapManager map, List<Projectile> _projectiles)
{
bool checkScroll = false;
int mapTileX, mapTileY, tileType;
keyboard.Update();
if (keyboard.GetPress("A"))
{
mapTileX = (int)((position.X - speed) / map.GetTiles().GetTilesWidht());
mapTileY = (int)(position.Y / map.GetTiles().GetTilesHeight());
tileType = map.GetTileType(mapTileX, mapTileY);
if(map.GetTiles().GetTile(tileType).UnitCross())
{
SetPosition(new Vector2(position.X - speed, position.Y));
checkScroll = true;
}
}
if (keyboard.GetPress("D"))
{
mapTileX = (int)((position.X + speed) / map.GetTiles().GetTilesWidht()) +1;
mapTileY = (int)(position.Y / map.GetTiles().GetTilesHeight());
Debug.WriteLine("TILE X: " + mapTileX);
tileType = map.GetTileType(mapTileX, mapTileY);
if (map.GetTiles().GetTile(tileType).UnitCross())
{
SetPosition(new Vector2(position.X + speed, position.Y));
checkScroll = true;
}
}
if (keyboard.GetPress("W"))
{
mapTileX = (int)position.X / map.GetTiles().GetTilesWidht();
mapTileY = (int)(position.Y - speed) / map.GetTiles().GetTilesHeight();
tileType = map.GetTileType(mapTileX, mapTileY);
if (map.GetTiles().GetTile(tileType).UnitCross())
{
SetPosition(new Vector2(GetPosition().X, GetPosition().Y - speed)); //Y is inverted, this means that 0 is on top .So if the player wants to go up Y has do decrease
checkScroll = true;
}
}
if (keyboard.GetPress("S"))
{
mapTileX = (int)position.X/ map.GetTiles().GetTilesWidht();
mapTileY = (int) (position.Y + speed) / map.GetTiles().GetTilesHeight() + 1;
tileType = map.GetTileType(mapTileX, mapTileY);
if (map.GetTiles().GetTile(tileType).UnitCross())
{
SetPosition(new Vector2(GetPosition().X, GetPosition().Y + speed)); //Again, Y is inverted
checkScroll = true;
}
}
if (checkScroll)
{
_scroll(GetPosition());
}
keyboard.UpdateOld();
mouseControl.Update();
SetRotation(RotateTowards(GetPosition(), new Vector2(mouseControl.newMousePos.X, mouseControl.newMousePos.Y) - _offset));
mouseControl.UpdateOld();
}
public override void Draw(Vector2 _offset)
{
base.Draw(_offset);
}
}