Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Game1.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Audio;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.GamerServices;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Microsoft.Xna.Framework.Media;
- namespace Xbox360Game1
- {
- /// <summary>
- /// This is the main type for your game
- /// </summary>
- public class Game1 : Microsoft.Xna.Framework.Game
- {
- GraphicsDeviceManager graphics;
- SpriteBatch spriteBatch;
- public Ship ship;
- public List<Projectile> LiveProjectiles;
- public Texture2D Bullet;
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- Content.RootDirectory = "Content";
- graphics.PreferredBackBufferWidth = 880;
- graphics.PreferredBackBufferHeight = 520;
- graphics.PreferMultiSampling = true;
- graphics.ApplyChanges();
- }
- protected override void Initialize()
- {
- // TODO: Add your initialization logic here
- base.Initialize();
- }
- protected override void LoadContent()
- {
- spriteBatch = new SpriteBatch(GraphicsDevice);
- ship = new Ship();
- ship.ShipTexture = Content.Load<Texture2D>("RocketShip");
- ship.Rotation = 0.0f;
- ship.Position = new Vector2(
- graphics.GraphicsDevice.Viewport.Width / 2,
- graphics.GraphicsDevice.Viewport.Height / 2);
- LiveProjectiles = new List<Projectile>();
- Bullet = Content.Load<Texture2D>("Bullet");
- }
- protected override void UnloadContent()
- {
- Content.Unload();
- Content.Dispose();
- }
- protected override void Update(GameTime gameTime)
- {
- // Allows the game to exit
- //if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
- //this.Exit();
- GamePadState gamePadState = GamePad.GetState(PlayerIndex.One);
- if (gamePadState.DPad.Left == ButtonState.Pressed)
- ship.Position.X -= 2.5f;
- if (gamePadState.DPad.Right == ButtonState.Pressed)
- ship.Position.X += 2.5f;
- if (gamePadState.DPad.Up == ButtonState.Pressed)
- ship.Position.Y -= 2.5f;
- if (gamePadState.DPad.Down == ButtonState.Pressed)
- ship.Position.Y += 2.5f;
- if (gamePadState.Buttons.RightShoulder == ButtonState.Pressed)
- ship.Rotation += 0.1f;
- if (gamePadState.Buttons.LeftShoulder == ButtonState.Pressed)
- ship.Rotation -= 0.1f;
- if (gamePadState.Triggers.Right >= 0.95f)
- {
- Projectile bullet = new Projectile();
- bullet.Position = ship.Position;
- bullet.Velocity =
- Vector2.Transform(new Vector2(0, -1 * 15),
- Matrix.CreateRotationZ(ship.Rotation - MathHelper.ToRadians(46)));
- LiveProjectiles.Add(bullet);
- }
- base.Update(gameTime);
- }
- protected override void Draw(GameTime gameTime)
- {
- GraphicsDevice.Clear(Color.CornflowerBlue);
- spriteBatch.Begin();
- for (int i = 0; i < LiveProjectiles.Count; i++)
- {
- spriteBatch.Draw(Bullet, LiveProjectiles[i].Position, null, Color.White, 0f,
- new Vector2(Bullet.Width / 2, Bullet.Height / 2), 0.2f, SpriteEffects.None, 0);
- }
- spriteBatch.Draw(ship.ShipTexture, ship.Position, null, Color.White, ship.Rotation,
- new Vector2(
- ship.ShipTexture.Width / 2,
- ship.ShipTexture.Height / 2), 0.35f, SpriteEffects.None, 0);
- spriteBatch.End();
- base.Draw(gameTime);
- }
- }
- }
- //Ship.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework;
- namespace Xbox360Game1
- {
- public class Ship
- {
- public Texture2D ShipTexture;
- public Vector2 Position;
- public Single Rotation;
- }
- }
- //Projectile.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.Xna.Framework;
- namespace Xbox360Game1
- {
- class Projectile
- {
- public Vector2 Position;
- public Vector2 Velocity;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement