2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Content;
7 using Microsoft.Xna.Framework.Graphics;
9 namespace SuperPolarity
13 protected SuperPolarity game;
15 public List<Actor> Children;
20 public Vector4 BoxDimensions;
21 protected Texture2D BoxTexture;
22 protected Color Color;
24 // Physical Properties
25 public Vector2 Position;
27 protected Vector2 Velocity;
28 protected Vector2 Acceleration;
31 // Constraints / Behavior
32 public float MaxVelocity;
33 protected float AccelerationRate;
38 public virtual int Width
43 public virtual int Height
48 public Actor(SuperPolarity newGame)
57 public virtual void Initialize(Vector2 position)
64 Children = new List<Actor>();
66 Velocity = new Vector2(0, 0);
67 Acceleration = new Vector2(0, 0);
70 AccelerationRate = 10;
75 BoxTexture = new Texture2D(game.GraphicsDevice, 1, 1);
76 BoxTexture.SetData(new Color[] { Color.White });
81 protected void InitBox()
83 Box = new Rectangle((int)(Position.X - BoxDimensions.X), (int)(Position.Y - BoxDimensions.X), (int)(BoxDimensions.X + BoxDimensions.X + BoxDimensions.W), (int)(BoxDimensions.Y + BoxDimensions.Y + BoxDimensions.Z));
86 public void AutoDeccelerate(GameTime gameTime)
88 if (Acceleration.X == 0 && Velocity.X > 0)
90 if (AccelerationRate * gameTime.ElapsedGameTime.TotalSeconds > Velocity.X)
97 Acceleration.X = -AccelerationRate;
101 if (Acceleration.X == 0 && Velocity.X < 0)
103 if (-AccelerationRate * gameTime.ElapsedGameTime.TotalSeconds < Velocity.X)
110 Acceleration.X = AccelerationRate;
114 if (Acceleration.Y == 0 && Velocity.Y > 0)
116 if (AccelerationRate * gameTime.ElapsedGameTime.TotalSeconds > Velocity.Y)
123 Acceleration.Y = -AccelerationRate;
127 if (Acceleration.Y == 0 && Velocity.Y < 0)
129 if (-AccelerationRate * gameTime.ElapsedGameTime.TotalSeconds < Velocity.Y)
136 Acceleration.Y = AccelerationRate;
141 public virtual void Update(GameTime gameTime)
149 protected virtual void UpdateBox()
151 Box.X = (int)(Position.X - BoxDimensions.X);
152 Box.Y = (int)(Position.Y - BoxDimensions.Y);
155 public virtual void Move(GameTime gameTime)
157 AutoDeccelerate(gameTime);
159 Velocity.X = Velocity.X + Acceleration.X * (float)gameTime.ElapsedGameTime.TotalSeconds;
160 Velocity.Y = Velocity.Y + Acceleration.Y * (float)gameTime.ElapsedGameTime.TotalSeconds;
162 if (Velocity.X > MaxVelocity)
164 Velocity.X = MaxVelocity;
167 if (Velocity.X < -MaxVelocity)
169 Velocity.X = -MaxVelocity;
172 if (Velocity.Y > MaxVelocity)
174 Velocity.Y = MaxVelocity;
177 if (Velocity.Y < -MaxVelocity)
179 Velocity.Y = -MaxVelocity;
182 Position.X = Position.X + Velocity.X;
183 Position.Y = Position.Y + Velocity.Y;
186 public void ChangeAngle()
188 if (Math.Abs(Velocity.Y) <= 0.1 && Math.Abs(Velocity.X) <= 0.1)
192 Angle = (float)Math.Atan2(Velocity.Y, Velocity.X);
195 public virtual void Draw(SpriteBatch spriteBatch)
199 // TODO: Check what's up with the null children.
200 if (Children == null)
204 for (var i = Children.Count - 1; i >= 0; i--)
207 child.Draw(spriteBatch);
210 //spriteBatch.Draw(BoxTexture, Box, new Color(255, 0, 255, 25));
215 for (var i = Children.Count; i > 0; i--)
217 var actor = Children[i - 1];
218 if (actor.Position.X < -SuperPolarity.OutlierBounds || actor.Position.Y < -SuperPolarity.OutlierBounds ||
219 actor.Position.X > game.GraphicsDevice.Viewport.Width + SuperPolarity.OutlierBounds ||
220 actor.Position.Y > game.GraphicsDevice.Viewport.Height + SuperPolarity.OutlierBounds)
222 Children.Remove(actor);
227 public virtual void Collide(Actor other, Rectangle collision)
231 protected virtual void Die()
236 public virtual void CleanUp()