Advertisement
Guest User

cyce

a guest
Oct 14th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.08 KB | None | 0 0
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using Microsoft.Xna.Framework.Input;
  4. using System.Collections.Generic;
  5.  
  6. namespace Coins
  7. {
  8.     public class Game1 : Game
  9.     {
  10.         GraphicsDeviceManager graphics;
  11.         SpriteBatch spriteBatch;
  12.         Texture2D background, coins, unknown;
  13.         Rectangle[] coinsRec;
  14.         Rectangle[] coinsCut;
  15.         Rectangle question;
  16.         Color[] coinsColor;
  17.         MouseState ms;
  18.         Point pms;
  19.         int coinscount;
  20.         int coinWidth = 50, coinHeight = 50, coinWidthCut = 100, coinHeightCut = 100;
  21.  
  22.         public Game1()
  23.         {
  24.             graphics = new GraphicsDeviceManager(this);
  25.             Content.RootDirectory = "Content";
  26.             this.IsMouseVisible = true;
  27.             graphics.PreferredBackBufferWidth = 800;
  28.             graphics.PreferredBackBufferHeight = 800;
  29.  
  30.         }
  31.  
  32.         protected override void Initialize()
  33.         {
  34.             coinsRec = new Rectangle[8];
  35.             coinsCut = new Rectangle[8];
  36.             coinsColor = new Color[8];
  37.             question = new Rectangle(25,25,100,100);
  38.             coinscount = 0;
  39.  
  40.             for(int i = 0; i < 2; i++)
  41.             {
  42.                 for(int j = 0; j < 4; j++)
  43.                 {
  44.                     coinsRec[coinscount] = new Rectangle(0+25, coinscount*55+150, coinWidth, coinHeight);
  45.                     coinsCut[coinscount] = new Rectangle(j*100, i*100, coinWidthCut, coinHeightCut);
  46.                     coinsColor[coinscount] = Color.White;
  47.                     coinscount += 1;
  48.                 }
  49.                
  50.             }
  51.             base.Initialize();
  52.         }
  53.  
  54.         protected override void LoadContent()
  55.         {
  56.             spriteBatch = new SpriteBatch(GraphicsDevice);
  57.             background = Content.Load<Texture2D>("background");
  58.             coins = Content.Load<Texture2D>("numbers");
  59.             unknown = Content.Load<Texture2D>("question");
  60.         }
  61.  
  62.         protected override void UnloadContent()
  63.         {
  64.  
  65.         }
  66.  
  67.         protected override void Update(GameTime gameTime)
  68.         {
  69.             ms = Mouse.GetState();
  70.             pms = new Point(ms.X, ms.Y);
  71.  
  72.             if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  73.                 this.Exit();
  74.  
  75.             for(int i = 0; i < 8; i++)
  76.             {
  77.                 if (coinsRec[i].Contains(pms))
  78.                 {
  79.                     coinsColor[i] = Color.Red;
  80.                     break;
  81.                 }
  82.                 else coinsColor[i] = Color.White;
  83.             }
  84.  
  85.             base.Update(gameTime);
  86.         }
  87.  
  88.         protected override void Draw(GameTime gameTime)
  89.         {
  90.             GraphicsDevice.Clear(Color.CornflowerBlue);
  91.             spriteBatch.Begin();
  92.  
  93.             spriteBatch.Draw(unknown, question, Color.White);
  94.  
  95.             for(int i = 0; i<8; i++)
  96.             {
  97.                 spriteBatch.Draw(coins, coinsRec[i], coinsCut[i], coinsColor[i]);
  98.             }
  99.  
  100.             spriteBatch.End();
  101.             base.Draw(gameTime);
  102.         }
  103.  
  104.     }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement