Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 MyGames
- {
- /// <summary>
- /// This is the main type for your game
- /// </summary>
- public class SpaceInvader : Game
- {
- private readonly GraphicsDeviceManager graphics_;
- private KeyboardState oldKeyboardState_;
- private KeyboardState newKeyboardState_;
- private SpriteBatch spriteBatch_;
- private Ship playerShip_;
- public SpaceInvader()
- {
- graphics_ = new GraphicsDeviceManager(this);
- Content.RootDirectory = "Content";
- // Set device frame rate to 60 fps.
- TargetElapsedTime = TimeSpan.FromSeconds(1 / 60.0);
- graphics_.PreferredBackBufferWidth = 480;
- graphics_.PreferredBackBufferHeight = 268;
- }
- protected override void Initialize()
- {
- playerShip_ = new Ship(new Vector2(Window.ClientBounds.Width / 2, Window.ClientBounds.Height - 150), new Vector2(10,10));
- base.Initialize();
- }
- protected override void LoadContent()
- {
- // Create a new SpriteBatch, which can be used to draw textures.
- spriteBatch_ = new SpriteBatch(GraphicsDevice);
- playerShip_.LoadContent(Content);
- }
- protected override void UnloadContent()
- {
- // TODO: Unload any non ContentManager content here
- }
- protected override void Update(GameTime gameTime)
- {
- newKeyboardState_ = Keyboard.GetState();
- // Allows the game to exit
- if (newKeyboardState_.IsKeyDown(Keys.Escape))
- Exit();
- // TODO: Add your update logic here
- playerShip_.Update(Window, newKeyboardState_, oldKeyboardState_);
- base.Update(gameTime);
- }
- protected override void Draw(GameTime gameTime)
- {
- if (oldKeyboardState_.IsKeyDown(Keys.F) && newKeyboardState_.IsKeyUp(Keys.F))
- graphics_.ToggleFullScreen();
- graphics_.GraphicsDevice.Clear(Color.CornflowerBlue);
- //set rendering back to the back buffer
- // Draw the sprite.
- spriteBatch_.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);
- playerShip_.Draw(spriteBatch_);
- spriteBatch_.End();
- base.Draw(gameTime);
- oldKeyboardState_ = newKeyboardState_;
- }
- }
- }
- using (SpaceInvader game = new SpaceInvader())
- {
- game.Run();
- }
- SpaceInvader game = new SpaceInvader();
- game.Run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement