/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Note: use this.Content to load your game contents here // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // Create needed input components inputManager = new InputComponent(this, true, true, false, false); //Loads all the sprites planeSprite = new GameSprite(Content.Load<Texture2D>("plane"), 1, 3, 0, 0.5); //Create Game objects planeObject = new GameObject(planeSprite, Window.ClientBounds.Width / 2 - planeSprite.Width / 2, Window.ClientBounds.Height - planeSprite.Height); }
// Remember to draw objects public List<GameObject> generateGameSet() { solutionObjectReplica = null; currentGameSet.Clear(); gameObjectPosition.Clear(); int xSpacing = 5; var set = Content.LoadContent<Texture2D>("Level1\\" + getRandomGameSet()); List<string> contentName = new List<string>(); foreach (string s in set.Keys) contentName.Add(s); List<int> contentRand = genRandomNumberList(0, contentName.Count); // Create solution object GameSprite solutionSprite = new GameSprite(set[contentName[contentRand[0]]], 1, 1, 0, 0); // Create selection objects GameSprite selectionSprite1 = new GameSprite(set[contentName[contentRand[1]]], 1, 1, 0, 0); GameSprite selectionSprite2 = new GameSprite(set[contentName[contentRand[2]]], 1, 1, 0, 0); GameSprite selectionSprite3 = new GameSprite(set[contentName[contentRand[3]]], 1, 1, 0, 0); // GameSprite selectionSprite4 = new GameSprite(set1["yellow_ball"] , 1, 1, 0, 0); // Store positions. These are namely 2 on the left, 2 on the right gameObjectPosition.Add(new Vector2(0, xSpacing)); //top left gameObjectPosition.Add(new Vector2(0, solutionSprite.Height * 4)); // bottom left gameObjectPosition.Add(new Vector2(Window.ClientBounds.Width - solutionSprite.Width, 0)); // top right gameObjectPosition.Add(new Vector2(Window.ClientBounds.Width - solutionSprite.Width, solutionSprite.Height * 4)); //btm right // Generate position placement choices randomly List<int> randPosn = new List<int>(); while (randPosn.Count != gameObjectPosition.Count) { int choice = rand.Next(0, gameObjectPosition.Count); if (!randPosn.Contains(choice)) randPosn.Add(choice); } // Create solution object GameObject solutionObj = new GameObject(solutionSprite, gameObjectPosition[randPosn[0]]); solutionObj.isSolutionObject = true; // Create a replica of the solution object for display purposes only solutionObjectReplica = new GameObject(solutionSprite, Window.ClientBounds.Width / 2, 0); // left hand side GameObject selectionObject1 = new GameObject(selectionSprite1, gameObjectPosition[randPosn[1]]); GameObject selectionObject2 = new GameObject(selectionSprite2, gameObjectPosition[randPosn[2]]); // right hand side GameObject selectionObject3 = new GameObject(selectionSprite3, gameObjectPosition[randPosn[3]]); // Add to current game set currentGameSet.Add(solutionObj); //Solution is always the first currentGameSet.Add(selectionObject1); currentGameSet.Add(selectionObject2); currentGameSet.Add(selectionObject3); return currentGameSet; }
/// <summary> /// Checks for a collision with the specified GameObject /// </summary> /// <param name="otherObject">The object to check</param> /// <returns>Returns null if he object is dead</returns> public bool Collision(GameObject otherObject) { //Checks for a collision between this object and the other specified object if (IsDead() == false && otherObject.IsDead() == false) { return boundingRect.Intersects(otherObject.boundingRect); } else { return false; } }