Skip to content

Instantly share code, notes, and snippets.

@SpaceShot
Created June 28, 2011 01:32
Show Gist options
  • Save SpaceShot/1050287 to your computer and use it in GitHub Desktop.
Save SpaceShot/1050287 to your computer and use it in GitHub Desktop.
Game1 class
/// <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);
gridTexture = Content.Load<Texture2D>("GridTemplate");
obstacle = Content.Load<Texture2D>("pillar200");
scoreFont = Content.Load<SpriteFont>("ScoreFont");
enemyTexture = Content.Load<Texture2D>("FighterToken");
playersToken.Texture = Content.Load<Texture2D>("FighterToken");
Random random = new Random();
int enemyCount = random.Next(1, 7);
for (int i = 1; i <= enemyCount ; i++)
{
Token enemy = new Token { Position = new Vector2(300.0f + (i * 50.0f), 300.0f + (i * 50.0f)), Health = 20, Texture = enemyTexture };
enemies.Add(enemy);
}
}
/// <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)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
KeyboardState keyState = Keyboard.GetState();
if (keyState.IsKeyUp(Keys.Down) && lastKeyState.IsKeyDown(Keys.Down))
{
// key is down
int x = 4;
}
lastKeyState = keyState;
base.Update(gameTime);
}
/// <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.Tan);
// TODO: Add your drawing code here
spriteBatch.Begin();
spriteBatch.Draw(obstacle, obstaclePosition, Color.White);
for (int i = 0; i < graphics.GraphicsDevice.Viewport.Width; i += 50)
{
for (int j = 0; j < graphics.GraphicsDevice.Viewport.Height; j+= 50)
{
spriteBatch.Draw(gridTexture, new Vector2(i, j), Color.Gray);
}
}
spriteBatch.DrawString(scoreFont, "Player Health: " + playersToken.Health.ToString(), new Vector2(50.0f, 50.0f), Color.Red);
spriteBatch.DrawString(scoreFont, "Enemy Health: " + enemyHealth.ToString(), new Vector2(50.0f, 400.0f), Color.Red);
foreach (Token enemy in enemies)
{
if (enemy.Health > 0)
{
spriteBatch.Draw(enemy.Texture, enemy.Position, Color.White);
}
else
{
spriteBatch.Draw(enemy.Texture, enemy.Position, Color.Red);
}
}
spriteBatch.Draw(playersToken.Texture, playersToken.Position, Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment