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 TEST_0000
- {
- public class Game1 : Microsoft.Xna.Framework.Game
- {
- GraphicsDeviceManager graphics;
- SpriteBatch spriteBatch;
- Texture2D Player;
- Vector2 PlayerPosition;
- Texture2D Portal;
- Vector2 PortalPosition;
- Rectangle PlayerBoundingBox;
- Rectangle PortalBoundingBox;
- bool Collision;
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- Content.RootDirectory = "Content";
- }
- protected override void Initialize()
- {
- PlayerPosition = new Vector2(100,100);
- PortalPosition = new Vector2(600,100);
- Collision = false;
- 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);
- Portal = Content.Load<Texture2D>("player");
- Player = Content.Load<Texture2D>("player");
- PlayerBoundingBox = new Rectangle ((int)PlayerPosition.X, (int)PlayerPosition.Y , Player.Width , Player.Height );
- PortalBoundingBox = new Rectangle ((int)PortalPosition.X , (int)PortalPosition.Y , Portal.Width , Portal.Height );
- }
- /// <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)
- {
- KeyboardState input = Keyboard.GetState();
- if ( Keyboard.GetState().IsKeyDown(Keys.Escape))
- Exit();
- if ( input.IsKeyDown(Keys.Right))
- PlayerPosition.X += 2;
- if ( input.IsKeyDown(Keys.Left))
- PlayerPosition.X -= 2;
- if ( input.IsKeyDown(Keys.Up))
- PlayerPosition.Y -= 2;
- if ( input.IsKeyDown(Keys.Down))
- PlayerPosition.Y += 2;
- if ( PlayerBoundingBox.Intersects(PortalBoundingBox) )
- {
- Collision = true;
- }
- else{ Collision = false; }
- 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)
- {
- if ( Collision )
- {
- GraphicsDevice.Clear(Color.Orange);
- }
- else { GraphicsDevice.Clear(Color.CornflowerBlue); }
- spriteBatch.Begin();
- PlayerBoundingBox = new Rectangle((int)PlayerPosition.X , (int)PlayerPosition.Y , Player.Width , Player.Height );
- spriteBatch.Draw(Player,PlayerPosition,Color.White);
- spriteBatch.Draw(Portal,PortalBoundingBox,Color.Blue);
- spriteBatch.End();
- base.Draw(gameTime);
- }
- }
- }
Add Comment
Please, Sign In to add comment