Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using System.Collections.Generic;
- namespace Coins
- {
- public class Game1 : Game
- {
- GraphicsDeviceManager graphics;
- SpriteBatch spriteBatch;
- Texture2D background, coins, unknown;
- Rectangle[] coinsRec;
- Rectangle[] coinsCut;
- Rectangle question;
- Color[] coinsColor;
- MouseState ms;
- Point pms;
- int coinscount;
- int coinWidth = 50, coinHeight = 50, coinWidthCut = 100, coinHeightCut = 100;
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- Content.RootDirectory = "Content";
- this.IsMouseVisible = true;
- graphics.PreferredBackBufferWidth = 800;
- graphics.PreferredBackBufferHeight = 800;
- }
- protected override void Initialize()
- {
- coinsRec = new Rectangle[8];
- coinsCut = new Rectangle[8];
- coinsColor = new Color[8];
- question = new Rectangle(25,25,100,100);
- coinscount = 0;
- for(int i = 0; i < 2; i++)
- {
- for(int j = 0; j < 4; j++)
- {
- coinsRec[coinscount] = new Rectangle(0+25, coinscount*55+150, coinWidth, coinHeight);
- coinsCut[coinscount] = new Rectangle(j*100, i*100, coinWidthCut, coinHeightCut);
- coinsColor[coinscount] = Color.White;
- coinscount += 1;
- }
- }
- base.Initialize();
- }
- protected override void LoadContent()
- {
- spriteBatch = new SpriteBatch(GraphicsDevice);
- background = Content.Load<Texture2D>("background");
- coins = Content.Load<Texture2D>("numbers");
- unknown = Content.Load<Texture2D>("question");
- }
- protected override void UnloadContent()
- {
- }
- protected override void Update(GameTime gameTime)
- {
- ms = Mouse.GetState();
- pms = new Point(ms.X, ms.Y);
- if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
- this.Exit();
- for(int i = 0; i < 8; i++)
- {
- if (coinsRec[i].Contains(pms))
- {
- coinsColor[i] = Color.Red;
- break;
- }
- else coinsColor[i] = Color.White;
- }
- base.Update(gameTime);
- }
- protected override void Draw(GameTime gameTime)
- {
- GraphicsDevice.Clear(Color.CornflowerBlue);
- spriteBatch.Begin();
- spriteBatch.Draw(unknown, question, Color.White);
- for(int i = 0; i<8; i++)
- {
- spriteBatch.Draw(coins, coinsRec[i], coinsCut[i], coinsColor[i]);
- }
- spriteBatch.End();
- base.Draw(gameTime);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement