</Compile>
</ItemGroup>
<ItemGroup>
+ <Folder Include="Fonts\" />
<Folder Include="Sound\" />
</ItemGroup>
<ItemGroup>
<Processor>TextureProcessor</Processor>
</Compile>
</ItemGroup>
+ <ItemGroup>
+ <Compile Include="Graphics\square.png">
+ <Name>square</Name>
+ <Importer>TextureImporter</Importer>
+ <Processor>TextureProcessor</Processor>
+ </Compile>
+ </ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" />
<!--
To modify your build process, add your task inside one of the targets below and uncomment it.
{
ActorFactory.Game = game;
}
+
+ internal static Bullet CreateBullet(Vector2 position, float angle)
+ {
+ Bullet bullet = new Bullet(Game);
+
+ bullet.Initialize(Game.Content.Load<Texture2D>("Graphics\\square"), position);
+
+ bullet.Angle = angle;
+
+ ActorManager.CheckIn(bullet);
+
+ return bullet;
+ }
}
}
{
static class ActorManager
{
+
+ static Game Game;
+ static int OutlierBounds;
static List<Actor> Actors;
static ActorManager()
{
+ OutlierBounds = 100;
Actors = new List<Actor>();
}
static public void Update(GameTime gameTime)
{
CheckActors();
+ CheckOutliers();
foreach (Actor actor in Actors)
{
actor.Update(gameTime);
var dx = other.Position.X - actor.Position.X;
var linearDistance = Math.Sqrt(Math.Pow(dx, 2) + Math.Pow(dy, 2));
var angle = (float) Math.Atan2(dy, dx);
+ var otherAngle = (float)Math.Atan2(-dy, -dx);
if (linearDistance < actor.MagneticRadius || linearDistance < other.MagneticRadius)
{
actor.Magnetize(other, (float)linearDistance, angle);
- other.Magnetize(actor, (float)linearDistance, 90 - angle);
+ other.Magnetize(actor, (float)linearDistance, otherAngle);
}
}
}
+
+ static void CheckOutliers()
+ {
+ for (var i = Actors.Count; i > 0; i--)
+ {
+ var actor = Actors[i-1];
+ if (actor.Position.X < -OutlierBounds || actor.Position.Y < -OutlierBounds ||
+ actor.Position.X > Game.GraphicsDevice.Viewport.Width + OutlierBounds ||
+ actor.Position.Y > Game.GraphicsDevice.Viewport.Height + OutlierBounds)
+ {
+ CheckOut(actor);
+ }
+ }
+ }
+
+ internal static void SetGame(Game game)
+ {
+ Game = game;
+ }
}
}
{
protected Game game;
+ public List<Actor> Children;
+
// Graphics / In-Game
protected Texture2D Texture;
protected Vector2 Origin;
public Vector2 Position;
protected Vector2 Velocity;
protected Vector2 Acceleration;
- protected float Angle;
+ public float Angle;
// Constraints / Behavior
protected float MaxVelocity;
Position = position;
Active = true;
+ Children = new List<Actor>();
+
Origin = new Vector2(Texture.Width / 2, Texture.Height / 2);
Velocity = new Vector2(0, 0);
Acceleration = new Vector2(0, 0);
{
Move(gameTime);
ChangeAngle();
+ CheckOutliers();
}
- public void Move(GameTime gameTime)
+ public virtual void Move(GameTime gameTime)
{
AutoDeccelerate(gameTime);
+ var maxVelocity = MaxVelocity;
+
Velocity.X = Velocity.X + Acceleration.X * (float)gameTime.ElapsedGameTime.TotalSeconds;
Velocity.Y = Velocity.Y + Acceleration.Y * (float)gameTime.ElapsedGameTime.TotalSeconds;
public virtual void Draw(SpriteBatch spriteBatch)
{
+ foreach (Actor child in Children)
+ {
+ child.Draw(spriteBatch);
+ }
+
spriteBatch.Draw(Texture, Position, null, Color.White, Angle, Origin, 1f, SpriteEffects.None, 0f);
}
+
+ void CheckOutliers()
+ {
+ for (var i = Children.Count; i > 0; i--)
+ {
+ var actor = Children[i - 1];
+ if (actor.Position.X < -SuperPolarity.OutlierBounds || actor.Position.Y < -SuperPolarity.OutlierBounds ||
+ actor.Position.X > game.GraphicsDevice.Viewport.Width + SuperPolarity.OutlierBounds ||
+ actor.Position.Y > game.GraphicsDevice.Viewport.Height + SuperPolarity.OutlierBounds)
+ {
+ Children.Remove(actor);
+ }
+ }
+ }
}
}
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+
+namespace SuperPolarity
+{
+ class Bullet : Actor
+ {
+ protected ParticleEngine particleEngine;
+
+ public Bullet(Game newGame)
+ : base(newGame)
+ {
+ }
+
+ ~Bullet()
+ {
+ particleEngine = null;
+ }
+
+ public override void Initialize(Texture2D texture, Vector2 position)
+ {
+ base.Initialize(texture, position);
+ particleEngine = ParticleEffectFactory.CreateBullet(position);
+ }
+
+ public override void Update(GameTime gameTime)
+ {
+ Velocity.X = (float)(MaxVelocity * Math.Cos(Angle));
+ Velocity.Y = (float)(MaxVelocity * Math.Sin(Angle));
+
+ Position += Velocity;
+
+ particleEngine.Update();
+ particleEngine.EmitterLocation = Position;
+ }
+
+ public override void Draw(SpriteBatch spriteBatch)
+ {
+ base.Draw(spriteBatch);
+ particleEngine.Draw(spriteBatch);
+ }
+ }
+}
using System.Collections.Generic;
using System.Linq;
using System.Text;
+using System.Threading;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
{
class MainShip : Ship
{
-
- uint Multiplier;
- uint Lives;
- uint Score;
+
+ public static Color BlueColor;
+ public static Color RedColor;
+
ParticleEngine particleEngine;
+ protected bool Shooting;
+ protected int ShotCooldown;
+
public MainShip(Game newGame) : base(newGame) {}
+ ~MainShip()
+ {
+ particleEngine = null;
+ }
+
public override void Initialize(Texture2D texture, Vector2 position)
{
base.Initialize(texture, position);
+ MainShip.BlueColor = new Color(230, 244, 249);
+ MainShip.RedColor = new Color(255, 234, 241);
+
InitParticleEngine();
SetPolarity(Polarity.Positive);
- Multiplier = 1;
- Lives = 3;
- Score = 0;
+ ShotCooldown = 50;
BindInput();
}
void InitParticleEngine()
{
- List<Texture2D> texturesList = new List<Texture2D>();
- texturesList.Add(game.Content.Load<Texture2D>("Graphics\\circle"));
- texturesList.Add(game.Content.Load<Texture2D>("Graphics\\diamond"));
- texturesList.Add(game.Content.Load<Texture2D>("Graphics\\star"));
-
- particleEngine = new ParticleEngine(texturesList, Position);
+ particleEngine = ParticleEffectFactory.CreatePolarCircle(Position);
}
void BindInput()
InputController.Bind("moveX", HandleHorizontalMovement);
InputController.Bind("moveY", HandleVerticalMovement);
InputController.Bind("changePolarity", HandleChangePolarity);
+ InputController.Bind("shoot", HandleShot);
+ }
+
+ protected void HandleShot(float value)
+ {
+ Children.Add(ActorFactory.CreateBullet(Position, Angle));
+ Shooting = true;
+ Timer t = new Timer(new TimerCallback(UnlockShot));
+ t.Change(ShotCooldown, Timeout.Infinite);
+ }
+
+ protected void UnlockShot(object state)
+ {
+ InputController.Unlock("shoot");
}
protected void HandleChangePolarity(float value)
{
if (polarity == Polarity.Positive)
{
- particleEngine.Color = Color.Red;
+ particleEngine.Color = MainShip.RedColor;
}
else if (polarity == Polarity.Negative)
{
- particleEngine.Color = Color.Blue;
+ particleEngine.Color = MainShip.BlueColor;
}
else
{
particleEngine.EmitterLocation = Position;
particleEngine.Update();
ConstrainToEdges();
+ Shooting = false;
+ }
+
+ public override void Move(GameTime gameTime)
+ {
+ base.Move(gameTime);
+
+ if (Shooting)
+ {
+ if (Velocity.X > ActVelocity)
+ {
+ Velocity.X = ActVelocity;
+ }
+
+ if (Velocity.X < -ActVelocity)
+ {
+ Velocity.X = -ActVelocity;
+ }
+
+ if (Velocity.Y > ActVelocity)
+ {
+ Velocity.Y = ActVelocity;
+ }
+
+ if (Velocity.Y < -ActVelocity)
+ {
+ Velocity.Y = -ActVelocity;
+ }
+ }
}
public override void Magnetize(Ship ship, float distance, float angle)
RepelRadius = 100;
FleeVelocity = 5;
- ActVelocity = 3;
+ ActVelocity = 2;
ChargeVelocity = 1.5f;
CurrentPolarity = Polarity.Neutral;
Magnetizing = false;
{
if (!BlockedKeys.Contains(entry.Key))
{
- Dispatch(entry.Key, 1);
BlockedKeys.Add(entry.Key);
+ Dispatch(entry.Key, 1);
}
keyFired = true;
break;
{
if (!BlockedButtons.Contains(entry.Key))
{
- Dispatch(entry.Key, 1);
BlockedButtons.Add(entry.Key);
+ Dispatch(entry.Key, 1);
}
keyFired = true;
break;
method(value);
}
}
+
+ public static void Unlock(string eventName)
+ {
+ BlockedButtons.Remove(eventName);
+ BlockedKeys.Remove(eventName);
+ }
}
}
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+
+namespace SuperPolarity
+{
+ static class ParticleEffectFactory
+ {
+ static Game Game;
+ static Random random;
+
+ static ParticleEffectFactory()
+ {
+ random = new Random();
+ }
+
+ public static ParticleEngine CreatePolarCircle(Vector2 location)
+ {
+ List<Texture2D> texturesList = new List<Texture2D>();
+
+ //texturesList.Add(Game.Content.Load<Texture2D>("Graphics\\circle"));
+ texturesList.Add(Game.Content.Load<Texture2D>("Graphics\\diamond"));
+ texturesList.Add(Game.Content.Load<Texture2D>("Graphics\\square"));
+
+ ParticleEngine particleEngine = new ParticleEngine(texturesList, location);
+
+ particleEngine.Color = new Color(239, 203, 204);
+ particleEngine.TTL = 10;
+ particleEngine.TTLRandomFactor = 5;
+ particleEngine.ScatterFactor = 40;
+ particleEngine.ParticleCount = 50;
+ particleEngine.StretchFactor = 2.8f;
+
+
+ return particleEngine;
+ }
+
+ public static ParticleEngine CreateBullet(Vector2 location)
+ {
+ List<Texture2D> texturesList = new List<Texture2D>();
+
+ texturesList.Add(Game.Content.Load<Texture2D>("Graphics\\circle"));
+ //texturesList.Add(Game.Content.Load<Texture2D>("Graphics\\diamond"));
+ texturesList.Add(Game.Content.Load<Texture2D>("Graphics\\square"));
+
+ ParticleEngine particleEngine = new ParticleEngine(texturesList, location);
+
+ particleEngine.Color = Color.Gray;
+ particleEngine.TTL = 5;
+ particleEngine.TTLRandomFactor = 5;
+ particleEngine.ScatterFactor = 5;
+ particleEngine.ParticleCount = 10;
+ particleEngine.StretchFactor = 1;
+
+ return particleEngine;
+ }
+
+ internal static void SetGame(Game game)
+ {
+ ParticleEffectFactory.Game = game;
+ }
+ }
+}
{
private Random random;
public Vector2 EmitterLocation { get; set; }
- public Color Color;
+ public Color Color; //TODO: Color list for random colors.
+ public int TTL;
+ public int TTLRandomFactor;
+ public int ScatterFactor;
+ public int ParticleCount;
+ public float StretchFactor;
private List<Particle> particles;
private List<Texture2D> textures;
this.particles = new List<Particle>();
random = new Random();
Color = Color.Red;
+ TTL = 20;
+ TTLRandomFactor = 40;
+ StretchFactor = 1;
}
private Particle GenerateNewParticle()
Vector2 velocity = new Vector2(
1f * (float)(random.NextDouble() * 2 - 1),
1f * (float)(random.NextDouble() * 2 - 1));
+
float angle = 0;
float angularVelocity = 0.1f * (float)(random.NextDouble() * 2 - 1);
Color color = Color;
- float size = (float)random.NextDouble();
+ float size = (float)random.NextDouble() * StretchFactor;
+
+ position.X += random.Next(-ScatterFactor, ScatterFactor);
+ position.Y += random.Next(-ScatterFactor, ScatterFactor);
- int ttl = 20 + random.Next(40);
+ int ttl = TTL + random.Next(TTLRandomFactor);
return new Particle(texture, position, velocity, angle, angularVelocity, color, size, ttl);
}
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Microsoft.Xna.Framework.Graphics;
+
+namespace SuperPolarity
+{
+ class Renderer
+ {
+
+ static List<Actor> Actors;
+
+ static Renderer()
+ {
+ Actors = new List<Actor>();
+ }
+
+ static public void CheckIn(Actor actor)
+ {
+ Actors.Add(actor);
+ }
+
+ static public void CheckOut(Actor actor)
+ {
+ Actors.Remove(actor);
+ }
+
+ static public void Draw(SpriteBatch spriteBatch)
+ {
+ foreach (Actor actor in Actors)
+ {
+ actor.Draw(spriteBatch);
+ }
+ }
+ }
+}
<Compile Include="ActorFactory.cs" />
<Compile Include="ActorManager.cs" />
<Compile Include="Actors\StandardShip.cs" />
+ <Compile Include="Actors\Bullet.cs" />
<Compile Include="InputController.cs" />
<Compile Include="Actors\MainShip.cs" />
<Compile Include="Particle.cs" />
+ <Compile Include="ParticleEffectFactory.cs" />
<Compile Include="ParticleEngine.cs" />
<Compile Include="Actors\Actor.cs" />
<Compile Include="Actors\Ship.cs" />
+ <Compile Include="Renderer.cs" />
<Compile Include="SuperPolarity.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<None Include="Content\Graphics\positive-supercruiser.xnb">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
+ <None Include="Content\Graphics\square.xnb">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
<None Include="Content\Graphics\star.xnb">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
public static GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
+ public static int OutlierBounds;
+
public SuperPolarity()
: base()
{
SuperPolarity.graphics.PreferMultiSampling = true;
Content.RootDirectory = "Content";
ActorFactory.SetGame(this);
+ ParticleEffectFactory.SetGame(this);
+ ActorManager.SetGame(this);
}
/// <summary>
{
base.Initialize();
+ OutlierBounds = 100;
+
InputController.RegisterEventForButton("changePolarity", Buttons.A);
InputController.RegisterEventForKey("changePolarity", Keys.Z);
Vector2 playerPosition = new Vector2(GraphicsDevice.Viewport.TitleSafeArea.X, GraphicsDevice.Viewport.TitleSafeArea.Y + GraphicsDevice.Viewport.TitleSafeArea.Height / 2);
- ActorFactory.CreateShip(Ship.Polarity.Positive, new Vector2(200, 200));
- ActorFactory.CreateShip(Ship.Polarity.Negative, new Vector2(400, 200));
- ActorFactory.CreateMainShip(playerPosition);
+ Renderer.CheckIn(ActorFactory.CreateMainShip(playerPosition));
+ Renderer.CheckIn(ActorFactory.CreateShip(Ship.Polarity.Positive, new Vector2(200, 200)));
+ Renderer.CheckIn(ActorFactory.CreateShip(Ship.Polarity.Negative, new Vector2(400, 200)));
}
/// <summary>
spriteBatch.Begin();
- ActorManager.Draw(spriteBatch);
+ Renderer.Draw(spriteBatch);
spriteBatch.End();
C:\Users\Miau\documents\visual studio 2010\Projects\Super Polarity\Super Polarity\bin\WindowsGL\Debug\Content\Graphics\diamond.xnb
C:\Users\Miau\documents\visual studio 2010\Projects\Super Polarity\Super Polarity\bin\WindowsGL\Debug\Content\Graphics\star.xnb
C:\Users\Miau\documents\visual studio 2010\Projects\Super Polarity\Super Polarity\bin\WindowsGL\Debug\Content\Graphics\negative-ship.xnb
+C:\Users\Miau\documents\visual studio 2010\Projects\Super Polarity\Super Polarity\bin\WindowsGL\Debug\Content\Graphics\square.xnb