Advertisement
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;
- using Microsoft.Xna.Framework.Net;
- using Microsoft.Xna.Framework.Storage;
- namespace Assignment_1_faces
- {
- public class Game1 : Microsoft.Xna.Framework.Game
- {
- GraphicsDeviceManager graphics;
- SpriteBatch spriteBatch;
- #region Game World
- Texture2D smileyFace;
- Texture2D normalFace;
- Texture2D sadFace;
- Texture2D normalFace2;
- Rectangle faceY;
- Rectangle faceX;
- Rectangle faceB;
- Rectangle faceA;
- Rectangle happyRect;
- Rectangle normalRect;
- Rectangle normal2Rect;
- Rectangle sadRect;
- SpriteFont score;
- SpriteFont runCount;
- SpriteFont scoreNumber;
- SpriteFont runCountNumber;
- int scorePoint = 0;
- int runPoint = 0;
- int startPos;
- // SoundEffect point;
- // SoundEffect resetPoint;
- // SoundEffect gameOver;
- GamePadState oldPad1;
- Random rand = new Random();
- #endregion
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- Content.RootDirectory = "Content";
- }
- protected override void Initialize()
- {
- faceY = new Rectangle (350, 50, 100, 150);
- faceX = new Rectangle(100, 200, 100, 150);
- faceB = new Rectangle(600, 200, 100, 150);
- faceA = new Rectangle(350, 400, 100, 150);
- base.Initialize();
- }
- protected override void LoadContent()
- {
- spriteBatch = new SpriteBatch(GraphicsDevice);
- score = this.Content.Load<SpriteFont>("score");
- scoreNumber = this.Content.Load<SpriteFont>("scoreNumber");
- runCount = this.Content.Load<SpriteFont>("runCount");
- runCountNumber = this.Content.Load<SpriteFont>("runCountNumber");
- smileyFace = this.Content.Load<Texture2D>("hFace");
- normalFace = this.Content.Load<Texture2D>("nFace");
- normalFace2 = this.Content.Load<Texture2D>("nFace2");
- sadFace = this.Content.Load<Texture2D>("sFace");
- //point = this.Content.Load<SoundEffect>("ting");
- //resetPoint = this.Content.Load<SoundEffect>("snare");
- //gameOver = this.Content.Load<SoundEffect>("top");
- }
- protected override void UnloadContent()
- {
- }
- protected override void Update(GameTime gameTime)
- {
- if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
- this.Exit();
- /*GamePadState pad1 = GamePad.GetState(PlayerIndex.One);
- if (pad1.Buttons.Start == ButtonState.Released
- && oldPad1.Buttons.Start == ButtonState.Pressed)
- */
- startPos = rand.Next(1, 5);
- if (startPos == 1)
- {
- happyRect = faceY;
- sadRect = faceX;
- normalRect = faceB;
- normal2Rect = faceA;
- }
- if (startPos == 2)
- {
- happyRect = faceX;
- normalRect = faceB;
- normal2Rect = faceA;
- sadRect = faceY;
- }
- if (startPos == 3)
- {
- happyRect = faceB;
- normalRect = faceA;
- normal2Rect = faceY;
- sadRect = faceX;
- }
- if (startPos == 4)
- {
- happyRect = faceA;
- normalRect = faceY;
- normal2Rect = faceX;
- sadRect = faceB;
- }
- //oldPad1 = pad1;
- base.Update(gameTime);
- }
- protected override void Draw(GameTime gameTime)
- {
- GraphicsDevice.Clear(Color.YellowGreen);
- Vector2 nowVector1 = new Vector2(15, 15);
- Vector2 nowVector2 = new Vector2(15, 50);
- spriteBatch.Begin();
- spriteBatch.DrawString(
- scoreNumber,
- scorePoint.ToString(),
- new Vector2(115, 15),
- Color.Red);
- spriteBatch.DrawString(
- runCountNumber,
- runPoint.ToString(),
- new Vector2(145, 50),
- Color.Blue);
- spriteBatch.DrawString(score, "Score: ",
- nowVector1, Color.Red);
- spriteBatch.DrawString(runCount, "Run Count: ",
- nowVector2, Color.Blue);
- spriteBatch.Draw(smileyFace, happyRect, Color.White);
- spriteBatch.Draw(normalFace, normalRect, Color.White);
- spriteBatch.Draw(normalFace, normal2Rect, Color.White);
- spriteBatch.Draw(sadFace, sadRect, Color.White);
- spriteBatch.End();
- base.Draw(gameTime);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement