2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Graphics;
7 using Microsoft.Xna.Framework.Content;
8 using System.Security.Cryptography;
10 namespace SuperPolarity
12 class StandardShip : Ship
15 protected bool Flashing;
16 protected int ChangeRate;
17 protected int CurrentTime;
18 public int AngleChangeProbability;
19 protected int BouncePadding;
20 protected float RotationFactor;
21 protected Random Random;
22 protected bool AddingAngle;
24 public StandardShip(SuperPolarity newGame) : base(newGame) {}
26 public override void Initialize(Texture2D texture, Vector2 position)
28 base.Initialize(texture, position);
30 var cryptoResult = new byte[4];
31 new RNGCryptoServiceProvider().GetBytes(cryptoResult);
34 AngleChangeProbability = 50;
38 RotationFactor = (float) (3 * Math.PI / 180);
39 Random = new Random(BitConverter.ToInt32(cryptoResult, 0));
43 public override void Magnetize(Ship ship, float distance, float angle)
45 if (ship.GetType() == typeof(MainShip)) {
46 base.Magnetize(ship, distance, angle);
50 public override void Update(GameTime gameTime)
52 CurrentTime += gameTime.ElapsedGameTime.Milliseconds;
65 Color = new Color(255, 255, 255, 128);
74 protected void AutoMove()
76 float newAngle = Angle;
78 if (CurrentTime < ChangeRate)
83 if (Random.Next(AngleChangeProbability) == 2)
85 AddingAngle = !AddingAngle;
92 newAngle += (float) ( Random.NextDouble() * RotationFactor);
96 newAngle -= (float) (Random.NextDouble() * RotationFactor);
99 Velocity.X = (float) (MaxVelocity * Math.Cos(newAngle));
100 Velocity.Y = (float) (MaxVelocity * Math.Sin(newAngle));
103 protected void BounceBack()
105 if (Position.X + Width < -BouncePadding && Velocity.X < 0)
107 Velocity.X = -Velocity.X;
110 if (Position.Y + Height < -BouncePadding && Velocity.Y < 0)
112 Velocity.Y = -Velocity.Y;
115 if (Position.X > game.GraphicsDevice.Viewport.Width + BouncePadding && Velocity.X > 0)
117 Velocity.X = -Velocity.X;
120 if (Position.Y > game.GraphicsDevice.Viewport.Height + BouncePadding && Velocity.Y > 0)
122 Velocity.Y = -Velocity.Y;
126 public override void Collide(Actor other, Rectangle collision)
133 if (other.GetType() == typeof(MainShip))
139 if (other.GetType() == typeof(Bullet))
141 var theBullet = (Bullet)other;
142 TakeDamage(theBullet.Power);
147 protected override void Die()
149 ActorManager.CheckOut(this);
150 Renderer.CheckOut(this);
151 game.Player.AddScore(Value);
152 game.Player.AddMultiplier(1);