Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified ScrollingShooter.suo
Binary file not shown.
65 changes: 56 additions & 9 deletions ScrollingShooter/ScrollingShooter/Enemies/Cobalt.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using System;

namespace ScrollingShooter
{
Expand All @@ -14,9 +15,10 @@ public class Cobalt : Enemy
Texture2D spritesheet;
Vector2 position;
Rectangle spriteBounds;
float delay;

/// <summary>
/// The bounding rectangle of the Dart
/// The bounding rectangle of the Cobalt
/// </summary>
public override Rectangle Bounds
{
Expand Down Expand Up @@ -50,26 +52,35 @@ public override void Update(float elapsedTime)
// Sense the player's position
PlayerShip player = ScrollingShooterGame.Game.player;
Vector2 playerPosition = new Vector2(player.Bounds.Center.X, player.Bounds.Center.Y);
delay += elapsedTime;

// Get a vector from our position to the player's position
Vector2 toPlayer = playerPosition - this.position;

//Sense the player from longer away but move slower.
if (toPlayer.LengthSquared() < 80000)
if (toPlayer.LengthSquared() < 160000)
{
if (toPlayer.LengthSquared() < 10000)
{
if (delay > .5f)
{
//Player is close fire weapons
Vector2 travel = position;
travel.X += Bounds.Width / 2;
travel.Y += Bounds.Height / 2;
ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.CobaltBomb, travel);
delay = 0;
}
}
// We sense the player's ship!
// Get a normalized steering vector
toPlayer.Normalize();

// Steer towards them!
this.position += toPlayer * elapsedTime * 50;

}
if (toPlayer.LengthSquared() < 10000)
{
//Player is close fire weapons
//Thinking of some type of pulse wave from the ship

}

}

/// <summary>
Expand All @@ -79,8 +90,44 @@ public override void Update(float elapsedTime)
/// <param name="spriteBatch">An already initialized SpriteBatch, ready for Draw() commands</param>
public override void Draw(float elapsedTime, SpriteBatch spriteBatch)
{
spriteBatch.Draw(spritesheet, Bounds, spriteBounds, Color.White);
PlayerShip player = ScrollingShooterGame.Game.player;
Vector2 playerPosition = new Vector2(player.Bounds.Center.X, player.Bounds.Center.Y);
Vector2 toPlayer = playerPosition - this.position;
double angle = (2 * Math.PI) - Math.Atan2(toPlayer.X, toPlayer.Y);
if (toPlayer.LengthSquared() < 90000)
{
spriteBatch.Draw(spritesheet, Bounds, spriteBounds, Color.White, (float)angle, new Vector2(Bounds.Width / 2, Bounds.Height / 2), SpriteEffects.None, 1f);
}
else
spriteBatch.Draw(spritesheet, Bounds, spriteBounds, Color.White);
}

}
public class CobaltBomb : Projectile
{
/// <summary>
/// Creates a new blimp bullet
/// </summary>
/// <param name="content">A ContentManager to load content from</param>
/// <param name="position">A position on the screen</param>
public CobaltBomb(uint id, ContentManager content, Vector2 position)
: base(id)
{
this.spriteSheet = content.Load<Texture2D>("Spritesheets/newsh(.shp.000000");

this.spriteBounds = new Rectangle(48, 197, 13, 11);

this.position = position;

// Sense the player's position
PlayerShip player = ScrollingShooterGame.Game.player;
Vector2 playerPosition = new Vector2(player.Bounds.Center.X, player.Bounds.Center.Y);

// Get a vector from our position to the player's position
Vector2 toPlayer = playerPosition - this.position;

velocity = toPlayer;

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@ public Projectile CreateProjectile(ProjectileType projectileType, Vector2 positi
projectile = new blueBeam(id, content, position);
break;

case ProjectileType.CobaltBomb:
projectile = new CobaltBomb(id, content, position);
break;

//This method doesn't fit the trishield very well, so this code is a bit poor in quality.
case ProjectileType.TrishieldBall:
for (int i = 0; i < 2; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public enum ProjectileType
GenericEnemyBullet = 109,
DroneLaser = 110,
RGSabot = 111,
CobaltBomb=112,
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion ScrollingShooter/ScrollingShooter/ScrollingShooterGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected override void LoadContent()
}
tilemap.Scrolling = true;

GameObjectManager.CreateEnemy(EnemyType.Dart, new Vector2(200, 200));
GameObjectManager.CreateEnemy(EnemyType.Cobalt, new Vector2(200, 200));
}

/// <summary>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.