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 WindowsGame2
- {
- /// <summary>
- /// This is the main type for your game
- /// </summary>
- public class Game1 : Microsoft.Xna.Framework.Game
- {
- GraphicsDeviceManager graphics;
- SpriteBatch spriteBatch;
- Texture2D dumyTexture;
- Texture2D starTexture;
- Point poz;
- float angle = 0.0f, speed;
- SpriteFont pisava;
- KeyboardState oldKstate;
- float fps, trenutniFps=0, elapsedTime=0;
- Point zadniMisak;
- Rectangle premikajoci = new Rectangle(0, 0, 50, 50);
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- Content.RootDirectory = "Content";
- }
- /// <summary>
- /// Allows the game to perform any initialization it needs to before starting to run.
- /// This is where it can query for any required services and load any non-graphic
- /// related content. Calling base.Initialize will enumerate through any components
- /// and initialize them as well.
- /// </summary>
- protected override void Initialize()
- {
- // TODO: Add your initialization logic here
- this.IsMouseVisible = true;
- 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);
- // TODO: use this.Content to load your game content here
- poz = new Point(100, 100);
- speed = 0.01f;
- dumyTexture = new Texture2D(GraphicsDevice, 1, 1);
- dumyTexture.SetData(new Color[] { Color.Wheat });
- pisava = Content.Load<SpriteFont>("pisava");
- starTexture = Content.Load<Texture2D>("zvezdica");
- }
- /// <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)
- {
- // Allows the game to exit
- if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
- this.Exit();
- // TODO: Add your update logic here
- KeyboardState kstate = Keyboard.GetState();
- if (kstate.IsKeyDown(Keys.Up))
- {
- poz.Y -= 1;
- }
- if (kstate.IsKeyDown(Keys.Down))
- {
- poz.Y += 1;
- }
- if (kstate.IsKeyDown(Keys.Left))
- {
- poz.X -= 1;
- }
- if ( kstate.IsKeyDown(Keys.Right))
- {
- poz.X += 1;
- }
- //if (oldKstate.IsKeyUp(Keys.Up) && kstate.IsKeyDown(Keys.Up))
- //{
- // poz.Y -= 10;
- //}
- //if (oldKstate.IsKeyUp(Keys.Down) && kstate.IsKeyDown(Keys.Down))
- //{
- // poz.Y += 10;
- //}
- //if (oldKstate.IsKeyUp(Keys.Left) && kstate.IsKeyDown(Keys.Left))
- //{
- // poz.X -= 10;
- //}
- //if (oldKstate.IsKeyUp(Keys.Right) && kstate.IsKeyDown(Keys.Right))
- //{
- // poz.X += 10;
- //}
- oldKstate = kstate;
- MouseState misak = Mouse.GetState();
- //if (misak.LeftButton == ButtonState.Pressed)
- //{
- // poz.X = misak.X;
- // poz.Y = misak.Y;
- //}
- zadniMisak.X = misak.X;
- zadniMisak.Y = misak.Y;
- speed += 0.001f % 1;
- angle = (angle + speed) % 360;
- elapsedTime += gameTime.ElapsedGameTime.Milliseconds;
- if (elapsedTime >= 1000)
- {
- fps = trenutniFps;
- trenutniFps = 0;
- elapsedTime = 0;
- }
- 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.CornflowerBlue);
- // TODO: Add your drawing code here
- spriteBatch.Begin();
- spriteBatch.Draw(dumyTexture, new Rectangle(poz.X, poz.Y, 100, 100), Color.Tomato);
- //spriteBatch.Draw(starTexture, new Rectangle(30, 30, starTexture.Width * 10, starTexture.Height / 100), Color.White);
- //spriteBatch.Draw(starTexture, new Vector2(10, 10), Color.Magenta);
- Vector2 location = new Vector2(300, 300);
- Rectangle rect = new Rectangle(0, 0, starTexture.Width, starTexture.Height);
- Vector2 origi = new Vector2(100, 50);
- /*
- spriteBatch.Draw(starTexture, location, rect, Color.White, angle, origi, 1.0f, SpriteEffects.None, 1);
- spriteBatch.DrawString(pisava, "Fps: " + fps.ToString(), new Vector2(10, 10), Color.White);
- */
- Rectangle rect2 = new Rectangle(200, 200, 300, 300);
- if (rect2.Intersects(new Rectangle(poz.X, poz.Y, 100, 100)))
- {
- spriteBatch.Draw(dumyTexture, rect2, Color.PaleTurquoise);
- }
- else
- {
- spriteBatch.Draw(dumyTexture, rect2, Color.Black);
- }
- spriteBatch.End();
- trenutniFps++;
- base.Draw(gameTime);
- }
- }
- }
Add Comment
Please, Sign In to add comment