Created
February 3, 2015 18:44
-
-
Save hamoungh/e0a4a6ff571d60c5b085 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#region Using Statements | |
using System; | |
using System.Collections.Generic; | |
using Microsoft.Xna.Framework; | |
using Microsoft.Xna.Framework.Content; | |
using Microsoft.Xna.Framework.Graphics; | |
using Microsoft.Xna.Framework.Input; | |
using Microsoft.Xna.Framework.Storage; | |
using Microsoft.Xna.Framework.GamerServices; | |
using ShipFighterClasses; | |
#endregion | |
namespace GameName9 | |
{ | |
/// <summary> | |
/// This is the main type for your game | |
/// </summary> | |
public class Game1 : Game | |
{ | |
GraphicsDeviceManager graphics; | |
SpriteBatch spriteBatch; | |
Player background; | |
Random random; | |
Player[] blueEnemies; | |
Player playerShip; | |
public Game1() | |
: base() | |
{ | |
graphics = new GraphicsDeviceManager(this); | |
Content.RootDirectory = "Content"; | |
} | |
protected override void Initialize() | |
{ | |
random = new Random(); | |
blueEnemies = new Player[7]; | |
base.Initialize(); | |
} | |
/// <summary> | |
/// LoadContent will be called once per game and is the place to load | |
/// all of your content. | |
/// </summary> | |
protected override void LoadContent() | |
{ | |
// Create a new SpriteBatch, which can be used to draw textures. | |
spriteBatch = new SpriteBatch(GraphicsDevice); | |
background = new Player(Content.Load<Texture2D>("spaceBackground"), | |
Vector2.Zero, | |
Vector2.Zero, | |
false, | |
1f); | |
for (int i = 0; i < blueEnemies.Length; i++) { | |
blueEnemies[i] = new Player(Content.Load<Texture2D>("blueEnemy"), | |
new Vector2(random.Next(100,700), random.Next(100,300)), | |
new Vector2(random.Next(-100, 100), random.Next(-100, 100)), | |
true, | |
1f); | |
} | |
playerShip = new Player(Content.Load<Texture2D>("shipSprite"), | |
new Vector2(100, 100), | |
new Vector2(70, 70), | |
true, | |
1f); | |
} | |
/// <summary> | |
/// UnloadContent will be called once per game and is the place to unload | |
/// all content. | |
/// </summary> | |
protected override void UnloadContent() | |
{ | |
// TODO: Unload any non ContentManager content here | |
} | |
/// <summary> | |
/// Allows the game to run logic such as updating the world, | |
/// checking for collisions, gathering input, and playing audio. | |
/// </summary> | |
/// <param name="gameTime">Provides a snapshot of timing values.</param> | |
protected override void Update(GameTime gameTime) | |
{ | |
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) | |
Exit(); | |
UpdateInput(); | |
playerShip.Update(gameTime,GraphicsDevice); | |
for(int i=0;i<blueEnemies.Length;i++){ | |
blueEnemies[i].Update(gameTime); | |
bool collided=blueEnemies[i].CollisionSprite(playerShip); | |
if (collided) | |
{ | |
blueEnemies[i].Alive = false; | |
} | |
base.Update(gameTime); | |
} | |
} | |
private void UpdateInput() | |
{ | |
bool keyPressed = false; | |
KeyboardState keyState = Keyboard.GetState(); | |
if (keyState.IsKeyDown(Keys.Up)) | |
{ | |
playerShip.Up(); | |
keyPressed = true; | |
} | |
// other keys | |
if (!keyPressed) | |
{ | |
playerShip.Idle(); | |
} | |
} | |
/// <summary> | |
/// This is called when the game should draw itself. | |
/// </summary> | |
/// <param name="gameTime">Provides a snapshot of timing values.</param> | |
protected override void Draw(GameTime gameTime) | |
{ | |
GraphicsDevice.Clear(Color.CornflowerBlue); | |
spriteBatch.Begin(); | |
background.Draw(spriteBatch); | |
for (int i = 0; i < blueEnemies.Length; i++) | |
{ | |
blueEnemies[i].Draw(spriteBatch); | |
} | |
playerShip.Draw(spriteBatch); | |
spriteBatch.End(); | |
base.Draw(gameTime); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment