private static Physical.Rectangle GetShape(Comps.Character.Kind kind) { switch (kind) { case Comps.Character.Kind.Link: return(new Physical.Rectangle(64.0f, 64.0f)); case Comps.Character.Kind.Aquamentus: return(new Physical.Rectangle(128.0f, 128.0f)); case Comps.Character.Kind.Zol: return(new Physical.Rectangle(64.0f, 64.0f)); case Comps.Character.Kind.Goriya: return(new Physical.Rectangle(64.0f, 64.0f)); case Comps.Character.Kind.Dodongos: return(new Physical.Rectangle(96.0f, 64.0f)); case Comps.Character.Kind.Stalfos: return(new Physical.Rectangle(64.0f, 64.0f)); case Comps.Character.Kind.Rope: return(new Physical.Rectangle(64.0f, 64.0f)); case Comps.Character.Kind.Keese: return(new Physical.Rectangle(64.0f, 64.0f)); case Comps.Character.Kind.Wallmaster: return(new Physical.Rectangle(64.0f, 64.0f)); default: throw new System.NotImplementedException(); } }
private static Comps.Inventory GetInventory(Comps.Character.Kind kind) { var result = new Comps.Inventory(); switch (kind) { case Comps.Character.Kind.Link: case Comps.Character.Kind.Aquamentus: result.data[Comps.Item.Kind.Heart].Count = 5; result.data[Comps.Item.Kind.Rupee].Count = 10; break; case Comps.Character.Kind.Wallmaster: result.data[Comps.Item.Kind.Heart].Count = 4; result.data[Comps.Item.Kind.Rupee].Count = 5; break; case Comps.Character.Kind.Dodongos: case Comps.Character.Kind.Goriya: result.data[Comps.Item.Kind.Heart].Count = 3; result.data[Comps.Item.Kind.Rupee].Count = 3; break; case Comps.Character.Kind.Rope: result.data[Comps.Item.Kind.Heart].Count = 2; result.data[Comps.Item.Kind.Rupee].Count = 2; break; } return(result); }
public static Entity Create( Comps.Character.Kind kind, PhysicalVector2 position, Ecs.Registry registry ) { var result = registry.CreateEntity(); registry.AssignComponent( result, new Comps.Position { data = position } ); registry.AssignComponent( result, new Comps.Orientations.Cardinal { data = Physical.Orientation.Cardinal.Right } ); registry.AssignComponent( result, GetInventory(kind) ); registry.AssignComponent( result, new Comps.Velocity() { data = PhysicalVector2.Zero } ); registry.AssignComponent( result, new Comps.Solid() ); registry.AssignComponent( result, new Comps.Character { kind = kind } ); registry.AssignComponent( result, new Comps.Shapes.Rectangle { data = GetShape(kind) } ); return(result); }
public static Entity CreateEnemy( Comps.Character.Kind kind, PhysicalVector2 position, Ecs.Registry registry ) { var result = Create(kind, position, registry); registry.AssignComponent( result, GetAutonomous(kind) ); return(result); }
public static Entity CreatePlayer( Comps.Character.Kind kind, PhysicalVector2 position, ClientId clientId, Ecs.Registry registry ) { var result = Create(kind, position, registry); registry.AssignComponent( result, new Comps.Playable { clientId = clientId } ); return(result); }
private static Comps.Autonomous GetAutonomous(Comps.Character.Kind kind) { switch (kind) { case Comps.Character.Kind.Aquamentus: return(new Comps.Autonomous() { attackType = Comps.Projectile.Kind.Fireball, attackChance = 0.75f, stopWhileAttacking = false, kind = Comps.Autonomous.Kind.Shuffling, moveSpeed = 0.75f, changePeriod = 1.5f, spreadShots = true }); case Comps.Character.Kind.Dodongos: return(new Comps.Autonomous() { changePeriod = 2, moveSpeed = 0.5f }); case Comps.Character.Kind.Goriya: return(new Comps.Autonomous() { attackType = Comps.Projectile.Kind.Boomerang, attackChance = 0.25f }); case Comps.Character.Kind.Keese: return(new Comps.Autonomous() { kind = Comps.Autonomous.Kind.Flying, changePeriod = 0.5f, moveSpeed = 3 }); case Comps.Character.Kind.Rope: return(new Comps.Autonomous() { kind = Comps.Autonomous.Kind.Charging, moveSpeed = 5 }); case Comps.Character.Kind.Stalfos: return(new Comps.Autonomous()); case Comps.Character.Kind.Wallmaster: return(new Comps.Autonomous() { moveSpeed = 0.5f }); case Comps.Character.Kind.Zol: return(new Comps.Autonomous() { moveSpeed = 0.75f, changePeriod = 2 }); default: throw new ArgumentException( String.Format("{0} is not a valid enemy kind", kind), "kind" ); } }
public static void Kill( Entity victim, Entity damager, Registry registry, Game game ) { // Note: `damager` is not necessarily the `killer`. For example, a // projectile is the damager, but the killer is the owner of the // projectile. var projectileCompOpt = registry .GetComponent <Comps.Projectile>(damager); if (projectileCompOpt.HasValue) { var projectileComp = projectileCompOpt.ValueOrFailure(); Entity owner = new Entity(projectileComp.ownerId); Kill(victim, owner, registry, game); return; } // --- var killerPlayableCompOpt = registry .GetComponent <Comps.Playable>(damager); var victimPlayableCompOpt = registry .GetComponent <Comps.Playable>(victim); var killerCharacterCompOpt = registry .GetComponent <Comps.Character>(damager); var victimCharacterCompOpt = registry .GetComponent <Comps.Character>(victim); // Announce kill if (killerPlayableCompOpt.HasValue && victimPlayableCompOpt.HasValue) { // Player killed player var killerPlayableComp = killerPlayableCompOpt.ValueOrFailure(); var victimPlayableComp = victimPlayableCompOpt.ValueOrFailure(); ClientId killerClientId = killerPlayableComp.clientId; ClientId victimClientId = victimPlayableComp.clientId; System.Console.WriteLine( "Player {0} killed player {1}", killerClientId, victimClientId ); } else if (killerPlayableCompOpt.HasValue && victimCharacterCompOpt.HasValue) { // Player killed enemy var killerPlayableComp = killerPlayableCompOpt.ValueOrFailure(); var victimCharacterComp = victimCharacterCompOpt.ValueOrFailure(); ClientId killerClientId = killerPlayableComp.clientId; Comps.Character.Kind victimCharacterKind = victimCharacterComp.kind; System.Console.WriteLine( "Player {0} killed a {1}", killerClientId, victimCharacterKind ); } else if (killerCharacterCompOpt.HasValue && victimPlayableCompOpt.HasValue) { // Enemy killed player var killerCharacterComp = killerCharacterCompOpt.ValueOrFailure(); var victimPlayableComp = victimPlayableCompOpt.ValueOrFailure(); Comps.Character.Kind killerCharacterKind = killerCharacterComp.kind; ClientId victimClientId = victimPlayableComp.clientId; System.Console.WriteLine( "Enemy {0} killed player {1}", killerCharacterKind, victimClientId ); } else if (killerCharacterCompOpt.HasValue && victimCharacterCompOpt.HasValue) { // Enemy killed enemy var killerCharacterComp = killerCharacterCompOpt.ValueOrFailure(); var victimCharacterComp = victimCharacterCompOpt.ValueOrFailure(); Comps.Character.Kind killerCharacterKind = killerCharacterComp.kind; Comps.Character.Kind victimCharacterKind = victimCharacterComp.kind; System.Console.WriteLine( "Enemy {0} killed enemy {1}", killerCharacterKind, victimCharacterKind ); } // Scoring if (killerPlayableCompOpt.HasValue) { var killerPlayableComp = killerPlayableCompOpt.ValueOrFailure(); ClientId killerClientId = killerPlayableComp.clientId; Player killer = game.players[killerClientId]; killer.score++; System.Console.WriteLine( "Player {0} now has a score of {1}", killerClientId, killer.score ); } Inventory.Drop(victim, registry); registry.Remove(victim); }