public static ItemEntity CreateItemEntity(Vector2 position, Vector2 velocity, ItemStack droppedItem, int layer) { ItemEntity i = new ItemEntity(position, velocity, droppedItem); i.Initialize(); i.layer = layer; World.itemEntities.Add(i); return i; }
/// <summary> /// Drops an item on top of the entity. /// </summary> /// <param name="dropItem">the item to drop.</param> public void dropItem(ItemStack dropItem) { ItemEntity.CreateItemEntity(center, velocity, dropItem, layer); }
public bool PickupItem(ItemEntity item) { for (int i = 0; i < inventory.GetLength(0); i++) { if (inventory[i] == null) { inventory[i] = item.itemStack; return true; } else if (inventory[i].item.id == item.item.id) { inventory[i].stackSize += item.itemStack.stackSize; return true; } } return false; }
public void Control(World world) { //Handles input bool keyW = Keyboard.GetState().IsKeyDown(Keys.W); bool keyS = Keyboard.GetState().IsKeyDown(Keys.S); bool keyA = Keyboard.GetState().IsKeyDown(Keys.A); bool keyD = Keyboard.GetState().IsKeyDown(Keys.D); if (keyW) { velocity.Y += -speed; } if (keyS) { velocity.Y += speed; } if (keyA) { velocity.X += -speed; } if (keyD) { velocity.X += speed; } if (Game1.keyPress(Keys.I)) { if (guiInventory.active) { guiInventory.Close(); } else { guiInventory.Open(); } } if (Game1.keyPress(Keys.L)) { world.Save(); } if (Game1.keyPress(Keys.K)) { world.LoadWorldFromFile("strings\\maps\\map1.gff"); } if (Game1.keyPress(Keys.F))//Keyboard.GetState().IsKeyDown(Keys.F)) { ItemEntity.CreateItemEntity(center, Vector2.Zero, new ItemStack(ItemWeapon.CreateItemWeapon(1), 1), 1); } if (Game1.keyPress(Keys.G)) { World.cutscene.StartCutscene(0, this); //CloseDialogue(); } if (Game1.keyPress(Keys.OemTilde)) { world.drawTileDEBUG = !world.drawTileDEBUG; } if (Game1.mouse.LeftClick()) { //Vector2 dPos = (Game1.mouse.positionRelativeWorld - position); //float angleToMouse = (float)Math.Atan2(dPos.X, dPos.Y); Vector2 positionToRotation = Vector2.Transform(new Vector2(center.X, center.Y + 32) - center, Matrix.CreateRotationZ(-angleToMouse)) + center; createHurtBox(this, new Rectangle((int)positionToRotation.X, (int)positionToRotation.Y, 64, 32), new Vector2(center.X, center.Y + 32) - center, damage, 5, -angleToMouse); } if ((keyW && keyS && keyA && keyD) == false) { //if the player is holding none of the movement keys down isFriction = true; //turn off friction } else { isFriction = false; } }