/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { #region interface and buttons // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); // Mouse tracking currentSelection = null; MouseState currentState = Mouse.GetState(); //Loop through all the game objects. See if you're overtop of any of them. for (int i = 0; i < world.objects.Count; ++i) { //Check position based on fontsize. if (currentState.X > world.objects[i].position.X && currentState.X < world.objects[i].position.X + spriteDimensions.X && currentState.Y > world.objects[i].position.Y && currentState.Y < world.objects[i].position.Y + spriteDimensions.Y) { currentSelection = world.objects[i]; break; //Forget you! I'll use break statements as much as I want while hacking! } } //Drag and drop interface. This can be fixed with some variables to make it more exact when selecting items. if (currentState.LeftButton == ButtonState.Pressed) { for (int i = 0; i < world.player.inventory.Count; i++) { //Check position based on fontsize. if (currentState.X > 500 + i * this.statsDimensions.X && currentState.X < 500 + i * this.statsDimensions.X + statsDimensions.X && currentState.Y > height - 100 && currentState.Y < height - 100 + statsDimensions.Y) { indexSelected = i; break; //Once again, unnecessary, but good for processer times. } } } else //On release. { if (indexSelected != -1) { //If you're over top of anothe person, (and it's not you, give them that flower). if (currentSelection != null && currentSelection != world.player) { world.player.giveFlower(currentSelection, world.player.inventory[indexSelected]); } //Either way, you don't have it selected. indexSelected = -1; } } //Button Presses KeyboardState currentKeyState = Keyboard.GetState(); Keys[] currentKeysDown = currentKeyState.GetPressedKeys(); //Run logic. world.player.movementX = 0; world.player.movementY = 0; foreach (Keys k in currentKeysDown) { if (k == Keys.W) { world.player.movementY = -1; } else if (k == Keys.S) { world.player.movementY = 1; } else if (k == Keys.A) { world.player.movementX = -1; } else if (k == Keys.D) { world.player.movementX = 1; } } #endregion #region gameLogic world.update(); #endregion base.Update(gameTime); }
public bool doCollision(BaseObject b) { if (b is Flower) { //Add it to your inventory. inventory.Add((b as Flower).color); if (this.controlled == true) { int j = 3; } //Tell the world what you did. world.broadcastAction(new Action(this, this.getFlower, null, new dynamic[] { (b as Flower).color }, 100, 5)); if(b.color == favoriteColor) increaseOwnHappiness(flowerInterest); return true; //Collision is finished. Object is to be removed. } return false; //Collision is finished. Do not remove object. }