protected AbstractFractionController(float interval, GDGameScreen owner, Cannon cannon, Fraction fraction)
		{
			updateInterval = interval;
			Cannon = cannon;
			Fraction = fraction;
			Owner = owner;
		}
		public NeutralKIController(GDGameScreen owner, Cannon cannon, Fraction fraction)
			: base(NEUTRAL_UPDATE_TIME, owner, cannon, fraction)
		{
			intelligence = new List<Func<GameEntity>>
			{
				FindTargetAttackingBullet
			};
		}
Beispiel #3
0
		private Fraction(Color c, Fraction nfrac, FractionType type, float mult, FractionDifficulty diff)
		{
			Color = c;
			Type = type;
			Difficulty = diff;
			neutralFraction = (Type == FractionType.NeutralFraction) ? this : nfrac;
			Multiplicator = mult;
			BackgroundColor = IsNeutral ? Color.Magenta : ColorMath.Blend(FlatColors.Background, c, 0.25f);
		}
Beispiel #4
0
		public Bullet(GameScreen scrn, Cannon shooter, Vector2 pos, Vector2 velo, float entityScale)
			: base(scrn)
		{
			BulletPosition = pos;
			initialVelocity = velo;
			Source = shooter;
			Fraction = Source.Fraction;
			Scale = entityScale;

			DrawingBoundingBox = new FSize(BULLET_DIAMETER, BULLET_DIAMETER);
		}
		public BackgroundParticle(BackgroundParticle source, float px, float py, Direction4 dir)
		{
			OriginX = source.OriginX;
			OriginY = source.OriginY;

			X = px;
			Y = py;

			Fraction = source.Fraction;
			RemainingPower = source.RemainingPower - 1;
			Direction = dir;
		}
		public BackgroundParticle(int ox, int oy, Fraction f, float px, float py, Direction4 dir)
		{
			OriginX = ox;
			OriginY = oy;

			X = px;
			Y = py;

			Fraction = f;
			RemainingPower = INITIAL_POWER;
			Direction = dir;
		}
		public BulletSplitter(GameScreen scrn, Bullet b, Direction8 d) : base(scrn)
		{
			scale = b.Scale;
			ShapePosition = b.BulletPosition;
			ShapeAlpha = 1f;
			Fraction = b.Fraction;
			velocity = VELOCITIES[(int)d] * FloatMath.GetRangedRandom(0.5f, 2f) + ConvertUnits.ToDisplayUnits(b.PhysicsBody.LinearVelocity)/10f;
			maxLifetime = FloatMath.GetRangedRandom(SPLITTER_LIFETIME_MIN, SPLITTER_LIFETIME_MAX);
			ShapeRotation = FloatMath.ToRadians((int) d * 45f);
			rotationSpeed = FloatMath.GetRangedRandom(-FloatMath.TAU, FloatMath.TAU);

			DrawingBoundingBox = new FSize(Bullet.BULLET_DIAMETER, Bullet.BULLET_DIAMETER) * scale;
		}
Beispiel #8
0
		public Cannon(GDGameScreen scrn, LPCannon blueprint, Fraction[] fractions) : base(scrn)
		{
			Fraction = fractions[blueprint.Player];

			Center = new Vector2(blueprint.X, blueprint.Y);
			Scale = blueprint.Scale;
			DrawingBoundingBox = new FSize(CANNON_OUTER_DIAMETER, CANNON_OUTER_DIAMETER) * Scale;

			Rotation = new DeltaLimitedModuloFloat(FloatMath.ToRadians(blueprint.Rotation), ROTATION_SPEED, FloatMath.TAU);
			
			CannonHealth.SetForce(Fraction.IsNeutral ? 0f : 1f);

			FindParticleSpawns();
		}
		public StandardKIController(GDGameScreen owner, Cannon cannon, Fraction fraction)
			: base(STANDARD_UPDATE_TIME, owner, cannon, fraction)
		{
			intelligence = new List<Func<GameEntity>>
			{
				FindTargetAttackingBullet,
				FindTargetSupportCannon,
				FindTargetNeutralCannon,
				FindTargetEnemyCannon,
				FindTargetFriendlyCannon,
				FindTargetBlockedEnemyCannon,
				FindTargetBlockedFriendlyCannon,
				FindNearestEnemyCannon
			};
		}
Beispiel #10
0
		public static Fraction CreatePlayerFraction(Fraction neutral)
		{
			return new Fraction(COLOR_PLAYER, neutral, FractionType.PlayerFraction, FractionDifficultyHelper.MULTIPLICATOR_PLAYER, FractionDifficulty.PLAYER);
		}
Beispiel #11
0
		public void TakeDamage(Fraction source)
		{
			if (source.IsNeutral)
			{
				ResetChargeAndBooster();
			}
			else if (Fraction.IsNeutral)
			{
				SetFraction(source);
				CannonHealth.Set(HEALTH_HIT_GEN);
			}
			else
			{
				CannonHealth.Dec(HEALTH_HIT_DROP);

				if (FloatMath.IsZero(CannonHealth.TargetValue))
				{
					// Never tell me the odds

					SetFraction(Fraction.GetNeutral());
				}
				else if (CannonHealth.TargetValue < 0)
				{
					SetFraction(source);
					CannonHealth.Set(FloatMath.Abs(CannonHealth.TargetValue));
				}
			}
		}
Beispiel #12
0
		private void Initialize()
		{
			ConvertUnits.SetDisplayUnitToSimUnitRatio(GDSettings.PHYSICS_CONVERSION_FACTOR);

#if DEBUG
			DebugSettings.AddTrigger("SetQuality_1", this, Keys.D1, KeyboardModifiers.Control, x => Textures.ChangeQuality(Game.Content, TextureQuality.FD));
			DebugSettings.AddTrigger("SetQuality_2", this, Keys.D2, KeyboardModifiers.Control, x => Textures.ChangeQuality(Game.Content, TextureQuality.BD));
			DebugSettings.AddTrigger("SetQuality_3", this, Keys.D3, KeyboardModifiers.Control, x => Textures.ChangeQuality(Game.Content, TextureQuality.LD));
			DebugSettings.AddTrigger("SetQuality_4", this, Keys.D4, KeyboardModifiers.Control, x => Textures.ChangeQuality(Game.Content, TextureQuality.MD));
			DebugSettings.AddTrigger("SetQuality_5", this, Keys.D5, KeyboardModifiers.Control, x => Textures.ChangeQuality(Game.Content, TextureQuality.HD));

			DebugSettings.AddSwitch("PhysicsDebugView", this, Keys.F1, KeyboardModifiers.None, false);
			DebugSettings.AddSwitch("DebugTextDisplay", this, Keys.F2, KeyboardModifiers.None, true);
			DebugSettings.AddSwitch("DebugBackground", this, Keys.F3, KeyboardModifiers.None, false);
			DebugSettings.AddSwitch("DebugHUDBorders", this, Keys.F4, KeyboardModifiers.None, false);
			DebugSettings.AddSwitch("DebugCannonView", this, Keys.F5, KeyboardModifiers.None, true);
			DebugSettings.AddSwitch("ShowMatrixTextInfos", this, Keys.F6, KeyboardModifiers.None, false);
			DebugSettings.AddSwitch("ShowDebugMiniMap", this, Keys.F7, KeyboardModifiers.None, false);
			DebugSettings.AddSwitch("DebugEntityBoundaries", this, Keys.F8, KeyboardModifiers.None, false);

			DebugSettings.AddPush("ShowDebugShortcuts", this, Keys.Tab, KeyboardModifiers.None);

			DebugSettings.AddPush("AssimilateCannon", this, Keys.A, KeyboardModifiers.None);
			DebugSettings.AddPush("AbandonCannon", this, Keys.S, KeyboardModifiers.None);
#endif

#if DEBUG
			DebugDisp = new DebugTextDisplay(Graphics.GraphicsDevice, Textures.DebugFont);
			{
				DebugDisp.AddLine(() => $"FPS = {FPSCounter.AverageAPS:0000.0} (current = {FPSCounter.CurrentAPS:0000.0} | delta = {FPSCounter.AverageDelta * 1000:000.00} | min = {FPSCounter.MinimumAPS:0000.0} | total = {FPSCounter.TotalActions:000000})");
				DebugDisp.AddLine(() => $"UPS = {UPSCounter.AverageAPS:0000.0} (current = {UPSCounter.CurrentAPS:0000.0} | delta = {UPSCounter.AverageDelta * 1000:000.00} | min = {UPSCounter.MinimumAPS:0000.0} | total = {UPSCounter.TotalActions:000000})");
				DebugDisp.AddLine(() => $"Quality = {Textures.TEXTURE_QUALITY} | Texture.Scale={1f / Textures.DEFAULT_TEXTURE_SCALE.X:#.00} | Pixel.Scale={Textures.GetDeviceTextureScaling(Game.GraphicsDevice):#.00} | Viewport=[{Game.GraphicsDevice.Viewport.Width}|{Game.GraphicsDevice.Viewport.Height}]");
				DebugDisp.AddLine(() => $"Entities = {Entities.Count(),3} | Particles = {Entities.Enumerate().OfType<IParticleOwner>().Sum(p => p.ParticleCount),3} (Visible: {Entities.Enumerate().Where(p => p.IsInViewport).OfType<IParticleOwner>().Sum(p => p.ParticleCount),3})"); DebugDisp.AddLine(() => $"HUD.Size=(T:{GameHUD.Top}|L:{GameHUD.Left}|R:{GameHUD.Right}|B:{GameHUD.Bottom}) | HUD.AllElements={GameHUD.DeepCount()} | HUD.RootElements={GameHUD.FlatCount()} | Background.Particles={GDBackground.Particles.Count,3}");
				DebugDisp.AddLine(() => $"Pointer = ({InputStateMan.GetCurrentState().PointerPosition.X:000.0}|{InputStateMan.GetCurrentState().PointerPosition.Y:000.0})");
				DebugDisp.AddLine(() => $"OGL Sprites = {LastReleaseRenderSpriteCount:0000} (+ {LastDebugRenderSpriteCount:0000}); OGL Text = {LastReleaseRenderTextCount:0000} (+ {LastDebugRenderTextCount:0000})");

				DebugDisp.AddLine("ShowMatrixTextInfos", () => $"GraphicsDevice.Viewport=[{Game.GraphicsDevice.Viewport.Width}|{Game.GraphicsDevice.Viewport.Height}]");
				DebugDisp.AddLine("ShowMatrixTextInfos", () => $"Adapter.VirtualGuaranteedSize={VAdapter.VirtualGuaranteedSize}");
				DebugDisp.AddLine("ShowMatrixTextInfos", () => $"Adapter.RealGuaranteedSize={VAdapter.RealGuaranteedSize}");
				DebugDisp.AddLine("ShowMatrixTextInfos", () => $"Adapter.VirtualTotalSize={VAdapter.VirtualTotalSize}");
				DebugDisp.AddLine("ShowMatrixTextInfos", () => $"Adapter.RealTotalSize={VAdapter.RealTotalSize}");
				DebugDisp.AddLine("ShowMatrixTextInfos", () => $"Adapter.VirtualOffset={VAdapter.VirtualGuaranteedBoundingsOffset}");
				DebugDisp.AddLine("ShowMatrixTextInfos", () => $"Adapter.RealOffset={VAdapter.RealGuaranteedBoundingsOffset}");
				DebugDisp.AddLine("ShowMatrixTextInfos", () => $"Adapter.Scale={VAdapter.Scale}");

				DebugDisp.AddLine("ShowDebugShortcuts", DebugSettings.GetSummary);
			}

			//InputStateMan.PointerDown += (o, a) => DebugDisp.AddDecayLine($"Mouse::OnDown({a.X:0000}|{a.Y:0000})", 0.75f, 0.5f, 0.25f);
			//InputStateMan.PointerUp += (o, a) => DebugDisp.AddDecayLine($"Mouse::OnUp({a.X:0000}|{a.Y:0000})", 0.75f, 0.5f, 0.25f);
#endif


			//--------------------

			fractionNeutral = Fraction.CreateNeutralFraction();
			fractionPlayer = Fraction.CreatePlayerFraction(fractionNeutral);
			fractionComputer1 = Fraction.CreateComputerFraction(Fraction.COLOR_COMPUTER_01, fractionNeutral, difficulty);
			fractionComputer2 = Fraction.CreateComputerFraction(Fraction.COLOR_COMPUTER_02, fractionNeutral, difficulty);
			fractionComputer3 = Fraction.CreateComputerFraction(Fraction.COLOR_COMPUTER_03, fractionNeutral, difficulty);

			LoadLevelFromBlueprint();
		}
Beispiel #13
0
		private void EndGame(Fraction winner)
		{
			HasFinished = true;

			if (winner.IsPlayer)
			{
				if (GDOwner.Profile.GetLevelData(LevelName).HasCompleted(difficulty))
				{
					GDGameHUD.ShowScorePanel(GDOwner.Profile, null, true);
				}
				else
				{
					GDOwner.Profile.GetLevelData(LevelName).SetCompleted(difficulty);
					GDOwner.SaveProfile();
					GDGameHUD.ShowScorePanel(GDOwner.Profile, difficulty, true);
				}

			}
			else
			{
				GDGameHUD.ShowScorePanel(GDOwner.Profile, null, false);
			}

			foreach (var cannon in Entities.Enumerate().OfType<Cannon>())
			{
				cannon.ForceUpdateController();
			}

		}
		public void SpawnParticles(Fraction fraction, int x, int y)
		{
			AddParticle(new BackgroundParticle(x, y, fraction, x * GDConstants.TILE_WIDTH, y * GDConstants.TILE_WIDTH - 0.01f, Direction4.North), x, y, true);
			AddParticle(new BackgroundParticle(x, y, fraction, x * GDConstants.TILE_WIDTH + 0.01f, y * GDConstants.TILE_WIDTH, Direction4.East), x, y, true);
			AddParticle(new BackgroundParticle(x, y, fraction, x * GDConstants.TILE_WIDTH, y * GDConstants.TILE_WIDTH + 0.01f, Direction4.South), x, y, true);
			AddParticle(new BackgroundParticle(x, y, fraction, x * GDConstants.TILE_WIDTH - 0.01f, y * GDConstants.TILE_WIDTH, Direction4.West), x, y, true);
		}
		private void ColorGridCellDirect(Fraction f, int x, int y, float power)
		{
			if (x < 0 || y < 0 || x >= TILE_COUNT_X || y >= TILE_COUNT_Y) power *= 4;

			if (f.IsNeutral)
			{
				bool convert;
				gridColor[x + 1, y + 1].Strength = FloatMath.LimitedDec(gridColor[x + 1, y + 1].Strength, power, 0f, out convert);

				if (convert)
				{
					gridColor[x + 1, y + 1].Fraction = null;
					gridColor[x + 1, y + 1].Strength = 0f;
				}
			}
			else if (gridColor[x + 1, y + 1].Fraction == f)
			{
				gridColor[x + 1, y + 1].Strength = FloatMath.LimitedInc(gridColor[x + 1, y + 1].Strength, power, 1f);
			}
			else if (gridColor[x + 1, y + 1].Fraction == null)
			{
				gridColor[x + 1, y + 1].Fraction = f;
				gridColor[x + 1, y + 1].Strength = 0f;
			}
			else
			{
				bool convert;
				gridColor[x + 1, y + 1].Strength = FloatMath.LimitedDec(gridColor[x + 1, y + 1].Strength, power, 0f, out convert);

				if (convert)
				{
					gridColor[x + 1, y + 1].Fraction = f;
					gridColor[x + 1, y + 1].Strength = 0f;
				}
			}
		}
Beispiel #16
0
		private void SetFraction(Fraction f)
		{
			Fraction = f;
			ResetChargeAndBooster();
			controller = Fraction.CreateController(this.GDOwner(), this);
		}
Beispiel #17
0
		public static Fraction CreateComputerFraction(Color c, Fraction neutral, FractionDifficulty diff)
		{
			return new Fraction(c, neutral, FractionType.ComputerFraction, FractionDifficultyHelper.GetMultiplicator(diff), diff);
		}
		public PlayerController(GDGameScreen owner, Cannon cannon, Fraction fraction) 
			: base(0f, owner, cannon, fraction)
		{
			innerBoundings = new CircleF(Cannon.Center, Cannon.Scale * Cannon.CANNON_OUTER_DIAMETER / 2);
		}
Beispiel #19
0
		protected KIController(float interval, GDGameScreen owner, Cannon cannon, Fraction fraction) 
			: base(interval, owner, cannon, fraction)
		{
			crng = new ConstantRandom(cannon);
		}
		public EmptyController(GDGameScreen owner, Cannon cannon, Fraction fraction) 
			: base(0, owner, cannon, fraction)
		{
		}