Guest User

Untitled

a guest
Aug 14th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.52 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.Xna.Framework;
  5. using Microsoft.Xna.Framework.Audio;
  6. using Microsoft.Xna.Framework.Content;
  7. using Microsoft.Xna.Framework.GamerServices;
  8. using Microsoft.Xna.Framework.Graphics;
  9. using Microsoft.Xna.Framework.Input;
  10. using Microsoft.Xna.Framework.Media;
  11.  
  12. namespace WindowsGame2
  13. {
  14.     /// <summary>
  15.     /// This is the main type for your game
  16.     /// </summary>
  17.     public class Game1 : Microsoft.Xna.Framework.Game
  18.     {
  19.         GraphicsDeviceManager graphics;
  20.         SpriteBatch spriteBatch;
  21.         Texture2D dumyTexture;
  22.         Texture2D starTexture;
  23.         Point poz;
  24.         float angle = 0.0f, speed;
  25.         SpriteFont pisava;
  26.         KeyboardState oldKstate;
  27.         float fps, trenutniFps=0, elapsedTime=0;
  28.  
  29.         Point zadniMisak;
  30.         Rectangle premikajoci = new Rectangle(0, 0, 50, 50);
  31.  
  32.         public Game1()
  33.         {
  34.             graphics = new GraphicsDeviceManager(this);
  35.             Content.RootDirectory = "Content";
  36.         }
  37.  
  38.         /// <summary>
  39.         /// Allows the game to perform any initialization it needs to before starting to run.
  40.         /// This is where it can query for any required services and load any non-graphic
  41.         /// related content.  Calling base.Initialize will enumerate through any components
  42.         /// and initialize them as well.
  43.         /// </summary>
  44.         protected override void Initialize()
  45.         {
  46.             // TODO: Add your initialization logic here
  47.             this.IsMouseVisible = true;
  48.             base.Initialize();
  49.         }
  50.  
  51.         /// <summary>
  52.         /// LoadContent will be called once per game and is the place to load
  53.         /// all of your content.
  54.         /// </summary>
  55.         protected override void LoadContent()
  56.         {
  57.             // Create a new SpriteBatch, which can be used to draw textures.
  58.             spriteBatch = new SpriteBatch(GraphicsDevice);
  59.  
  60.             // TODO: use this.Content to load your game content here
  61.             poz = new Point(100, 100);
  62.             speed = 0.01f;
  63.             dumyTexture = new Texture2D(GraphicsDevice, 1, 1);
  64.             dumyTexture.SetData(new Color[] { Color.Wheat });
  65.             pisava = Content.Load<SpriteFont>("pisava");
  66.  
  67.             starTexture = Content.Load<Texture2D>("zvezdica");
  68.         }
  69.  
  70.         /// <summary>
  71.         /// UnloadContent will be called once per game and is the place to unload
  72.         /// all content.
  73.         /// </summary>
  74.         protected override void UnloadContent()
  75.         {
  76.             // TODO: Unload any non ContentManager content here
  77.         }
  78.  
  79.         /// <summary>
  80.         /// Allows the game to run logic such as updating the world,
  81.         /// checking for collisions, gathering input, and playing audio.
  82.         /// </summary>
  83.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  84.         protected override void Update(GameTime gameTime)
  85.         {
  86.             // Allows the game to exit
  87.             if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  88.                 this.Exit();
  89.  
  90.             // TODO: Add your update logic here
  91.             KeyboardState kstate = Keyboard.GetState();
  92.  
  93.             if (kstate.IsKeyDown(Keys.Up))
  94.             {
  95.                 poz.Y -= 1;
  96.             }
  97.             if (kstate.IsKeyDown(Keys.Down))
  98.             {
  99.                 poz.Y += 1;
  100.             }
  101.             if (kstate.IsKeyDown(Keys.Left))
  102.             {
  103.                 poz.X -= 1;
  104.             }
  105.             if ( kstate.IsKeyDown(Keys.Right))
  106.             {
  107.                 poz.X += 1;
  108.             }
  109.  
  110.             //if (oldKstate.IsKeyUp(Keys.Up) && kstate.IsKeyDown(Keys.Up))
  111.             //{
  112.             //    poz.Y -= 10;
  113.             //}
  114.             //if (oldKstate.IsKeyUp(Keys.Down) && kstate.IsKeyDown(Keys.Down))
  115.             //{
  116.             //    poz.Y += 10;
  117.             //}
  118.             //if (oldKstate.IsKeyUp(Keys.Left) && kstate.IsKeyDown(Keys.Left))
  119.             //{
  120.             //    poz.X -= 10;
  121.             //}
  122.             //if (oldKstate.IsKeyUp(Keys.Right) && kstate.IsKeyDown(Keys.Right))
  123.             //{
  124.             //    poz.X += 10;
  125.             //}
  126.             oldKstate = kstate;
  127.  
  128.             MouseState misak = Mouse.GetState();
  129.  
  130.             //if (misak.LeftButton == ButtonState.Pressed)
  131.             //{
  132.             //    poz.X = misak.X;
  133.             //    poz.Y = misak.Y;
  134.             //}
  135.  
  136.             zadniMisak.X = misak.X;
  137.             zadniMisak.Y = misak.Y;
  138.  
  139.  
  140.             speed += 0.001f % 1;
  141.             angle = (angle + speed) % 360;
  142.            
  143.  
  144.             elapsedTime += gameTime.ElapsedGameTime.Milliseconds;
  145.             if (elapsedTime >= 1000)
  146.             {
  147.                 fps = trenutniFps;
  148.                 trenutniFps = 0;
  149.                 elapsedTime = 0;
  150.             }
  151.  
  152.  
  153.             base.Update(gameTime);
  154.         }
  155.  
  156.         /// <summary>
  157.         /// This is called when the game should draw itself.
  158.         /// </summary>
  159.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  160.         protected override void Draw(GameTime gameTime)
  161.         {
  162.             GraphicsDevice.Clear(Color.CornflowerBlue);
  163.  
  164.             // TODO: Add your drawing code here
  165.             spriteBatch.Begin();
  166.             spriteBatch.Draw(dumyTexture, new Rectangle(poz.X, poz.Y, 100, 100), Color.Tomato);
  167.             //spriteBatch.Draw(starTexture, new Rectangle(30, 30, starTexture.Width * 10, starTexture.Height / 100), Color.White);
  168.             //spriteBatch.Draw(starTexture, new Vector2(10, 10), Color.Magenta);
  169.            
  170.             Vector2 location = new Vector2(300, 300);
  171.             Rectangle rect = new Rectangle(0, 0, starTexture.Width, starTexture.Height);
  172.             Vector2 origi = new Vector2(100, 50);
  173.             /*
  174.             spriteBatch.Draw(starTexture, location, rect, Color.White, angle, origi, 1.0f, SpriteEffects.None, 1);
  175.             spriteBatch.DrawString(pisava, "Fps: " + fps.ToString(), new Vector2(10, 10), Color.White);
  176.             */
  177.             Rectangle rect2 = new Rectangle(200, 200, 300, 300);
  178.             if (rect2.Intersects(new Rectangle(poz.X, poz.Y, 100, 100)))
  179.             {
  180.                 spriteBatch.Draw(dumyTexture, rect2, Color.PaleTurquoise);
  181.             }
  182.             else
  183.             {
  184.                 spriteBatch.Draw(dumyTexture, rect2, Color.Black);
  185.             }
  186.  
  187.  
  188.             spriteBatch.End();
  189.             trenutniFps++;
  190.             base.Draw(gameTime);
  191.         }
  192.     }
  193. }
Add Comment
Please, Sign In to add comment