public MainClass(List <AEntity> startEntitys, IShip startPlayerShip, CoupleDouble mapSize) { Entitys = startEntitys; playerShip = startPlayerShip; Score = 0; MapSize = mapSize; }
private bool PositionsToIntersect(IShip first, AEntity second) { double distance = second.Pos.GetDistance(first.Pos); CoupleDouble totalSize = first.Size + second.Size; return((Math.Abs(distance) < totalSize.X) && (Math.Abs(distance) < totalSize.Y)); }
public Ship() { Pos = new CoupleDouble(0, 0); Weapons = new List <IWeapon>(); Size = CoupleDouble.ones; Direction = new Degree(); }
public ViewObject(string name, CoupleDouble pos, CoupleDouble size, Degree angle) { Name = name; Pos = pos; Size = size; RotateAngle = angle; }
private void DrawShip(CoupleDouble pos, CoupleDouble size, Degree angle, Graphics e) { Point[] points = new Point[4]; Brush shipBrush; angle += 90; points[0] = (pos + size * angle.GetProjections()).GetPoint(); points[1] = (pos + (size / 3) * (angle - 90).GetProjections()).GetPoint(); points[2] = (pos + size * (angle + 180).GetProjections()).GetPoint(); points[3] = (pos + (size / 3) * (angle + 90).GetProjections()).GetPoint(); shipBrush = Brushes.DarkGray; e.FillPolygon(shipBrush, points); points[0] = (pos + size * (angle - 90).GetProjections()).GetPoint(); points[1] = (pos + size * (angle + 60).GetProjections()).GetPoint(); points[2] = (pos + (size / 2) * (angle + 90).GetProjections()).GetPoint(); points[3] = (pos + size * (angle + 120).GetProjections()).GetPoint(); shipBrush = Brushes.LightBlue; e.FillPolygon(shipBrush, points); e.DrawPolygon(new Pen(Brushes.Black), points); points[0] = (pos + size * 0.3 * (angle - 90).GetProjections()).GetPoint(); points[1] = (pos + size * 0.3 * (angle + 60).GetProjections()).GetPoint(); points[2] = (pos + (size / 2) * 0.3 * (angle + 90).GetProjections()).GetPoint(); points[3] = (pos + size * 0.3 * (angle + 120).GetProjections()).GetPoint(); shipBrush = Brushes.Black; e.FillPolygon(shipBrush, points); }
public EnemiFarm(CoupleDouble pos, CoupleDouble size, CoupleDouble speed, IShip ship) : base(pos, size, speed) { Size = new CoupleDouble(0, 0); Speed = new CoupleDouble(0, 0); position = pos; playerShip = ship; }
public override void GetImage(ViewObject obj, Graphics grap) { CoupleDouble point = obj.Pos * scale + offset; CoupleDouble size = obj.Size * scale; switch (obj.Name) { case "Ship": DrawShip(point, size, obj.RotateAngle, grap); break; case "Asteroid": DrawAsteroid(point, size, obj.RotateAngle, grap); break; case "Ufo": DrawUfo(point, size, obj.RotateAngle, grap); break; case "Exsplosion": DrawExplosion(point, size, obj.RotateAngle, grap); break; case "LaserBulet": DrawLaserBullet(point, size, obj.RotateAngle, grap); break; case "GunBullet": DrawGunBullet(point, size, obj.RotateAngle, grap); break; } }
internal override List <AEntity> Interaction(AEntity interactionEntity) { if (typeof(EnemyFarmPseudoEntity) == interactionEntity.GetType()) { Random ran = new Random(); List <AEntity> output = new List <AEntity>(); CoupleDouble speed = new CoupleDouble(0.1, 0.1) * new Degree(ran.Next(360)).GetProjections(); int ranX = ran.Next(2 * _maxX); int ranY = ran.Next(2 * _maxY); if ((Math.Abs(ranX - _maxX - playerShip.Pos.X) > 50) && ((Math.Abs(ranY - _maxY - playerShip.Pos.Y) > 50))) { CoupleDouble ranPos = new CoupleDouble(ranX - _maxX, ranY - _maxY); if (ran.NextDouble() < 0.02) { output.Add(new Ufo(ranPos, new CoupleDouble(5, 5), speed, playerShip)); } if (ran.NextDouble() < 0.06) { output.Add(new Asteroid(ranPos, new CoupleDouble(6, 6), speed, 2)); } return(output); } } return(null); }
internal AEntity(CoupleDouble pos, CoupleDouble size, CoupleDouble speed) { this.Pos = pos; this.Size = size; this.Speed = speed; WasKilled = false; }
public List <AEntity> Shot(CoupleDouble pos, Degree direction) { return(new List <AEntity> { new MockEntity(pos, new CoupleDouble(1, 1), new CoupleDouble(0, 0)) }); }
internal AEntity(CoupleDouble pos, CoupleDouble size, CoupleDouble speed, Degree angle) { Pos = pos; Size = size; Speed = speed; _angle = angle; WasKilled = false; }
public EnemiFarm(CoupleDouble pos, CoupleDouble size, CoupleDouble speed, int maxX, int maxY) : base(pos, size, speed) { this.Size = new CoupleDouble(0, 0); this.Speed = new CoupleDouble(0, 0); this._maxX = maxX; this._maxY = maxY; }
public List <AEntity> Shot(CoupleDouble pos, Degree direction) { List <AEntity> output = new List <AEntity> { new GunBullet(pos + direction.GetProjections(), new CoupleDouble(1, 1), direction.GetProjections() * 3, direction) }; return(output); }
internal override void ChengeState(CoupleDouble maxPos) { Pos.X = Pos.X + Speed.X; Pos.Y = Pos.Y + Speed.Y; if ((Pos.X > maxPos.X) || (Pos.Y > maxPos.Y)) { WasKilled = true; } }
public static Point[] GetPoints(CoupleDouble centr, CoupleDouble size, Degree angle) { Point[] output = new Point[3]; output[0] = (centr + size * (angle - 45).GetProjections()).GetPoint(); output[1] = (centr + size * (angle - 135).GetProjections()).GetPoint(); output[2] = (centr + size * (angle + 45).GetProjections()).GetPoint(); return(output); }
internal override void ChengeState(CoupleDouble maxPos) { Pos = Pos + Speed; Pos.X = Math.Abs(Pos.X) > maxPos.X ? -Pos.X : Pos.X; Pos.Y = Math.Abs(Pos.Y) > maxPos.Y ? -Pos.Y : Pos.Y; }
public void MoutionTest() { GunBullet testedGunBullet = new GunBullet(new CoupleDouble(1, 1), new CoupleDouble(1, 1), new CoupleDouble(-1, -1)); for (int i = 2; i <= 5; i++) { testedGunBullet.ChengeState(new CoupleDouble(100, 100)); CoupleDouble expected = new CoupleDouble(i, i); Assert.AreEqual(expected, testedGunBullet.Pos); } }
private void DrawGunBullet(CoupleDouble pos, CoupleDouble size, Degree angle, Graphics e) { Point[] points = new Point[4]; Brush shipBrush; angle += 90; points[0] = (pos + size * (angle - 90).GetProjections()).GetPoint(); points[1] = (pos + size * (angle + 60).GetProjections()).GetPoint(); points[2] = (pos + (size / 2) * (angle + 90).GetProjections()).GetPoint(); points[3] = (pos + size * (angle + 120).GetProjections()).GetPoint(); shipBrush = Brushes.Gold; e.FillPolygon(shipBrush, points); }
public void MovingTest() { //organization Asteroid asteroid = new Asteroid(new CoupleDouble(1, 1), new CoupleDouble(1, 1), new CoupleDouble(1, 1)); CoupleDouble expPos = new CoupleDouble { X = asteroid.Pos.X + asteroid.Speed.X, Y = asteroid.Pos.Y + asteroid.Speed.Y }; //activity asteroid.ChengeState(new CoupleDouble(100, 100)); //assertion Assert.AreEqual(asteroid.Pos, expPos); }
private void DrawAsteroid(CoupleDouble pos, CoupleDouble size, Degree angle, Graphics e) { List <Point> points = new List <Point>(); for (int i = 0; i < 36; i++) { if ((((i >= 1) && (i <= 9)) || ((i > 13) && (i < 18)) || ((i > 20) && (i < 24)) || ((i >= 29) && (i <= 33)))) { points.Add((pos + (size) * (angle + 10 * i).GetProjections()).GetPoint()); } } Brush shipBrush = Brushes.SlateGray; e.FillPolygon(shipBrush, points.ToArray()); e.DrawPolygon(new Pen(Brushes.Black), points.ToArray()); }
internal override void ChengeState(CoupleDouble maxPos) { if (null != PlayerShip) { Pos.X = PlayerShip.Pos.X > Pos.X ? Pos.X + 0.5 : PlayerShip.Pos.X < Pos.X ? Pos.X - 0.5 : Pos.X; Pos.Y = PlayerShip.Pos.Y > Pos.Y ? Pos.Y + 0.5 : PlayerShip.Pos.Y < Pos.Y ? Pos.Y - 0.5 : Pos.Y; Pos.X = Math.Abs(Pos.X) > maxPos.X ? -Pos.X : Pos.X; Pos.Y = Math.Abs(Pos.Y) > maxPos.Y ? -Pos.Y : Pos.Y; } else { throw new NullReferenceException("No ship"); } }
public List <AEntity> Shot(CoupleDouble pos, Degree direction) { if (Charge > 1) { --Charge; List <AEntity> output = new List <AEntity>(); CoupleDouble positions = new CoupleDouble(pos.X, pos.Y); for (int i = 0; i < Distance; i++) { positions = positions + direction.GetProjections(); output.Add(new LaserBullet(positions, new CoupleDouble(2, 2), CoupleDouble.zero, direction)); } return(output.Count != 0 ? output : null); } else { return(null); } }
public override void GetImage(ViewObject obj, Graphics grap) { CoupleDouble point = obj.Pos * scale + offset; CoupleDouble size = obj.Size * scale; Bitmap ship = new Bitmap(32, 32); Graphics shipGraphics = Graphics.FromImage(ship); Rectangle shipRectangle = new Rectangle(0, 0, 32, 32); string name = obj.Name; Image image = null; _sourcesList.Images.TryGetValue(name, out image); Brush shipBrush = null != image? new TextureBrush(image) : Brushes.Black; shipGraphics.FillRectangle(shipBrush, shipRectangle); grap.DrawImage(ship, RotatingRectangle.GetPoints(point, size, obj.RotateAngle)); }
public void LoadTest() { CoupleDouble defaultSyze = new CoupleDouble(1, 1); CoupleDouble defaultSpeed = new CoupleDouble(1, 1); Ship playerShip = new Ship(); List <IWeapon> weapons = new List <IWeapon> { new Gun(), new Laser() }; List <AEntity> startEntitys = new List <AEntity> { new EnemiFarm(new CoupleDouble(0, 1), defaultSyze, defaultSpeed, playerShip), new EnemyFarmPseudoEntity(new CoupleDouble(0, 1), defaultSyze, defaultSpeed) }; MainClass expectedGame = new MainClass(startEntitys, playerShip, new CoupleDouble(100, 100)); Assert.AreEqual(expectedGame, GameLoaderInjector.GetGame()); }
private void DrawExplosion(CoupleDouble pos, CoupleDouble size, Degree angle, Graphics e) { Random ran = new Random(); List <Point> points = new List <Point>(); for (int i = 0; i < 6; i++) { if ((((i >= 1) && (i <= 9)) || ((i > 13) && (i < 18)) || ((i > 20) && (i < 24)) || ((i >= 29) && (i <= 33)))) { points.Add((pos + (size) * (angle + 60 * i + 30 * ran.NextDouble()).GetProjections()).GetPoint()); } } Brush shipBrush = Brushes.Yellow; Pen explosionPen = new Pen(Brushes.Red); explosionPen.Width = 5; e.FillPolygon(shipBrush, points.ToArray()); e.DrawPolygon(explosionPen, points.ToArray()); }
private void DrawUfo(CoupleDouble pos, CoupleDouble size, Degree angle, Graphics e) { Point[] points = new Point[36]; for (int i = 0; i < 36; i++) { points[i] = (pos + size * (angle + 10 * i).GetProjections()).GetPoint(); } Brush shipBrush = Brushes.DarkGray; e.FillPolygon(shipBrush, points); e.DrawPolygon(new Pen(Brushes.Black), points); for (int i = 0; i < 36; i++) { points[i] = (pos + size / 5 * (angle + 10 * i).GetProjections()).GetPoint(); } shipBrush = Brushes.Black; e.FillPolygon(shipBrush, points); }
internal override void ChengeState(CoupleDouble maxPos) { }
public EnemyFarmPseudoEntity(CoupleDouble pos, CoupleDouble size, CoupleDouble speed) : base(pos, size, speed) { }
internal abstract void ChengeState(CoupleDouble maxPos);
public LaserBullet(CoupleDouble pos, CoupleDouble size, CoupleDouble speed) : base(pos, size, speed) { }