Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Net;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- namespace Ghosts
- {
- public class Game1 : Game
- {
- GraphicsDeviceManager graphics;
- SpriteBatch spriteBatch;
- Texture2D Ghost;
- Texture2D Background;
- int posX, posY;
- Random random;
- int GhostColor;
- float GhostTime = 0;
- float GhostSleep = 2f;
- Rectangle posOfGhost;
- int WhiteScore = 0;
- int OtherScore = 0;
- bool isGhostVisible = false;
- List<Color> GhostColors = new List<Color>() { Color.White, Color.Red, Color.Blue };
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- Content.RootDirectory = "Content";
- graphics.PreferredBackBufferWidth = 800;
- graphics.PreferredBackBufferHeight = 600;
- IsMouseVisible = true;
- Window.AllowUserResizing = true;
- }
- protected override void Initialize()
- {
- random = new Random();
- base.Initialize();
- }
- protected override void LoadContent()
- {
- spriteBatch = new SpriteBatch(GraphicsDevice);
- Background = Content.Load<Texture2D>("street");
- Ghost = Content.Load<Texture2D>("ghost");
- }
- protected override void UnloadContent()
- {
- }
- protected override void Update(GameTime gameTime)
- {
- var keyboard = new KeyboardState();
- var mouseState = Mouse.GetState();
- var position1 = new Point(mouseState.X, mouseState.Y);
- GhostTime += (float)gameTime.ElapsedGameTime.TotalSeconds;
- if (Keyboard.GetState().IsKeyDown(Keys.Escape))
- Exit();
- if (GhostTime >= GhostSleep || isGhostVisible == false && mouseState.LeftButton == ButtonState.Released)
- {
- posX = random.Next(50, GraphicsDevice.Viewport.Width - 50);
- posY = random.Next(50, GraphicsDevice.Viewport.Height - 50);
- GhostColor = random.Next(0, 3);
- isGhostVisible = true;
- GhostTime = 0;
- }
- if (posOfGhost.Contains(position1) && isGhostVisible == true && mouseState.LeftButton == ButtonState.Pressed)
- {
- if (GhostColor == 0)
- WhiteScore++;
- else
- OtherScore++;
- Window.Title = "Białe duszki: " + WhiteScore + " Inne duszki: " + OtherScore;
- isGhostVisible = false;
- }
- base.Update(gameTime);
- }
- protected override void Draw(GameTime gameTime)
- {
- GraphicsDevice.Clear(Color.CornflowerBlue);
- spriteBatch.Begin();
- spriteBatch.Draw(Background, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height),Color.White);
- spriteBatch.Draw(Ghost, new Rectangle(posX, posY, 50, 50), GhostColors[GhostColor]);
- posOfGhost = new Rectangle(posX, posY, 50, 50);
- spriteBatch.End();
- base.Draw(gameTime);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement