/// <summary> /// Creates a blachole object. /// </summary> /// <param name="position">Spawn position of object.</param> public Blackhole(Vector2 position) : base(ECS.GetNextId()) { // Register components Components = new IComponent[] { new AnimationComponent() { Sprite = "Objects/Blackhole" }, new PositionComponent() { Position = new Vector2(position.X, position.Y), Momentum = new Vector2(), Direction = 0, AngularMomentum = 0, CollisionMask = new CollisionMaskCircle( new Vector2(position.X, position.Y), 400 ) }, new WorldComponent() { Entity = this } }; // Link components Position = ((PositionComponent)Components[1]).Position; CollisionMask = ((PositionComponent)Components[1]).CollisionMask; ((WorldComponent)Components[2]).PositionComponent = (PositionComponent)Components[1]; ((WorldComponent)Components[2]).Entity = this; // Register components RegisterComponents(); }
/// <summary> /// Creates a new instance of a debri entity. /// </summary> /// <param name="spawn">Spawn location.</param> public Debri(Vector2 spawn) : base(ECS.GetNextId()) { Random random = new Random(); // Components Components = new IComponent[] { new PositionComponent() { Position = spawn, Momentum = Blackhole.GetInitialMomentum(spawn), AngularMomentum = random.Next(-40, 40), Direction = random.Next(0, 360), CollisionMask = new CollisionMaskCircle( spawn, 32 ) }, new AnimationComponent() { Sprite = "Objects/Resources/Debri" }, new AffectedByBlackholeComponent() { Entity = this }, new WorldComponent() { Entity = this }, new CombatComponent() { Health = 1, MaxHealth = 1, Armour = 0, MaxArmour = 0, Entity = this }, new ResourceComponent() { Value = 50 } }; // Link as required ((AffectedByBlackholeComponent)Components[2]).Position = Position; ((WorldComponent)Components[3]).PositionComponent = Position; // Register components RegisterComponents(); }
/// <summary> /// Creates a new instance of a projectile. /// </summary> /// <param name="x">Initial x position.</param> /// <param name="y">Initial y position.</param> /// <param name="direction">Initial direction.</param> /// <param name="team">Team who owns projectile.</param> /// <param name="owner">Player who owns projectile.</param> public Projectile(float x, float y, float direction, Team team = null, Entity owner = null) : base(ECS.GetNextId()) { // Todo(Chris): Get rid of magic numbers. Components = new IComponent[] { new PositionComponent() { Position = new Vector2(x, y), Direction = direction, Momentum = new Vector2( (float)Math.Cos(MathHelper.ToRadians(direction)), (float)Math.Sin(MathHelper.ToRadians(direction)) ) * 1000, AngularMomentum = 0, CollisionMask = new CollisionMaskLine( new Vector2(x, y), 20, direction ) }, new AnimationComponent() { Sprite = "Objects/Weapons/line_projectile" }, new WorldComponent(), new LifetimeComponent() { LifetimeRemaining = 1000 }, new ProjectileComponent() { Team = team } }; // Link components: World.Entity = this; World.PositionComponent = Position; Lifetime.Entity = this; ProjectileComponent.Entity = this; ProjectileComponent.Position = Position; ProjectileComponent.World = World; Owner = owner; // Register components RegisterComponents(); }
/// <summary> /// Creates a Mothership entity. /// </summary> public Mothership(int x, int y, Team team) : base(ECS.GetNextId()) { // Register components. Components = new IComponent[] { new PositionComponent() { Position = new Vector2(x, y), Momentum = Blackhole.GetInitialMomentum( new Vector2(x, y) ), Direction = 0, AngularMomentum = 0, CollisionMask = new CollisionMaskCircle( new Vector2(x, y), 128 ) }, new WorldComponent(), new AnimationComponent() { Sprite = "Objects/Ships/Mothership" }, new AffectedByBlackholeComponent() { Entity = this }, new TeamComponent() { Team = team }, new ResourceComponent() { Value = 0 } }; // Link components World.Entity = this; World.PositionComponent = Position; ((AffectedByBlackholeComponent)Components[3]).Position = Position; Team.Team.Mothership = this; // Register components RegisterComponents(); }
/// <summary> /// Creates a new player, but copies game data from old object. /// </summary> /// <param name="oldPlayer">Previous iterate of same player.</param> public PlayerEntity(PlayerEntity oldPlayer) : base(ECS.GetNextId()) { throw (new NotImplementedException()); }
/// <summary> /// Creates a new player entity. /// </summary> public PlayerEntity(Team team) : base(ECS.GetNextId()) { // Create components Components = new IComponent[] { new NetworkingClientComponent(this), new PositionComponent() { Position = new Vector2(), Momentum = new Vector2(), AngularMomentum = 0, Direction = 0, CollisionMask = new CollisionMaskCircle(new Vector2(), 128), }, new WorldComponent(), new AnimationComponent() { Sprite = "Objects/Ships/GreenBeacon" }, new EngineComponent() { InputForce = new Vector2() }, new ShipLimiterComponent() { HandlingRank = 0, SpeedRank = 0 }, new TeamComponent() { Team = team }, new CombatComponent() { Health = 100, MaxHealth = 100, Armour = 100, MaxArmour = 100, Entity = this }, new WeaponComponent() { Cooldown = 200, CurrentCooldown = 0, Direction = 0f, Trigger = false, Parent = this }, new ResourceComponent() { Value = 0 } }; // Link components as required Client.Entity = this; World.PositionComponent = Position; World.Entity = this; Engine.Position = Position; ShipLimiter.Position = Position; ShipLimiter.Engine = Engine; Weapon.Position = Position; Weapon.Team = Team; // Register to team Team.Team.RegisterPlayer(this); // Spawn according to team respawn Position.Position = Team.Team.Mothership.Position.Position + new Vector2(100, 0); Position.Momentum = Blackhole.GetInitialMomentum(Position.Position); Position.Direction = (new Random()).Next(0, 180); Position.AngularMomentum = (new Random()).Next(-20, 20); // Register components RegisterComponents(); }
/// <summary> /// Creates a new team. /// </summary> public Team() { Members = new PlayerEntity[Settings.MaxTeamSize]; Id = ECS.GetNextId(); MemberCount = 0; }
/// <summary> /// Creates a new server manager, which will listen for clients /// on a given port. /// </summary> /// <param name="port">Port to listen on.</param> /// <param name="teamSize">Team Size as specified by login.</param> /// <param name="tokens">User tokens for connection.</param> public ServerManager(int port, int teamSize, int[] tokens) { GameMaster.State = GameMaster.GameState.Loading; GameMaster.StartMasterTimer(); // Initialise teams Trace.WriteLine("Initialising Teams."); Trace.Indent(); Settings.MaxTeamSize = teamSize; Team teamA = new Team(); Team teamB = new Team(); Trace.Unindent(); Trace.WriteLine("Teams initialised."); // Register ECS systems Trace.WriteLine("Registering ECS Systems."); Trace.Indent(); // Networking ECS.RegisterSystem(new NetworkingSystem()); ECS.RegisterSystem(new NetworkingClientSystem()); // World partioning ECS.RegisterSystem(new WorldSystem()); // Game systems (Alphabetical order). ECS.RegisterSystem(new AnimationSystem()); ECS.RegisterSystem(new BlachholeSystem()); ECS.RegisterSystem(new CombatSystem()); ECS.RegisterSystem(new EngineSystem()); ECS.RegisterSystem(new PositionSystem()); ECS.RegisterSystem(new ResourceSystem()); ECS.RegisterSystem(new ShipLimiterSystem()); ECS.RegisterSystem(new TeamSystem()); ECS.RegisterSystem(new WeaponSystem()); ECS.RegisterSystem(new LifetimeSystem()); ECS.RegisterSystem(new ProjectileSystem()); // Create networking component without an entity NetworkState = new NetworkingComponent(port, tokens, teamA, teamB); ECS.RegisterComponentToSystem( ComponentSystemId.NetworkingSystem, ECS.GetNextId(), NetworkState ); Trace.Unindent(); Trace.WriteLine("ECS Registered."); // Load map data Trace.WriteLine("Loading map data."); Trace.Indent(); MapData.SpawnWorld(teamA, teamB); Trace.Unindent(); Trace.WriteLine("Map loaded."); // Register to State event handlers GameMaster.OnStartCountdown += HandleOnCountdown; GameMaster.OnStartGame += HandleOnGameStart; GameMaster.OnEndGame += HandleOnGameEnd; // Start timers Timer = new Stopwatch(); Timer.Start(); FrameTimer = new Stopwatch(); FrameTimer.Start(); GameMaster.State = GameMaster.GameState.WaitingForPlayers; }