public override int use(PlayerBase user, WorldBase world, Vector2 location, GameTime time, BinaryInputManager inputManager) { base.use(user, world, location, time, inputManager); bool showUse = true; foreach (UsableEntity ue in user.world.useableEntities) { if (ue is EntityRopeSegment && ue.getUseBounds().Intersects(user.getCollisionBox())) { EntityRopeSegment currentRopeSegment = (EntityRopeSegment)ue; int numRecoveredRopes = 0; while (currentRopeSegment.child != null) { world.killEntity(currentRopeSegment); numRecoveredRopes++; currentRopeSegment = currentRopeSegment.child; } world.killEntity(currentRopeSegment); world.addEntity(new ItemDropEntity(user.location, world, new Item_Rope((int)((float)numRecoveredRopes * .75f)))); break; } if (ue is EntityBetterRopeSegment && ue.getUseBounds().Intersects(user.getCollisionBox())) { showUse = false; EntityBetterRopeSegment currentRopeSegment = (EntityBetterRopeSegment)ue; int numRecoveredRopes = 0; while (currentRopeSegment.child != null) { world.killEntity(currentRopeSegment); numRecoveredRopes++; currentRopeSegment = currentRopeSegment.child; } currentRopeSegment = (EntityBetterRopeSegment)ue; while (currentRopeSegment.parent != null) { world.killEntity(currentRopeSegment); numRecoveredRopes++; currentRopeSegment = currentRopeSegment.parent; } world.killEntity(currentRopeSegment); world.addEntity(new ItemDropEntity(user.location, world, new Item_Rope((int)((float)numRecoveredRopes * .75f)))); break; } } if (showUse) { user.speechManager.addSpeechBubble(Game1.texture_item_rope); } return(0); }
public override int use(PlayerBase user, WorldBase world, Vector2 location, GameTime time, BinaryInputManager inputManager) { base.use(user, world, location, time, inputManager); Item_Rope item_rope = (Item_Rope)user.inventory.getItemOfType(new Item_Rope(1)); if (!prevOrigin.Equals(user.location) || !prevTarget.Equals(location)) { //recalculate the grappling hook trajectory hookWouldBeAnchored = false; ropeIntermediaryPoints.Clear(); hookWouldBeAnchoredAt = 0; ropeThatWouldBeConsumed = 0; if (item_rope != null) { Vector2 position = user.location + new Vector2(0, -5); Vector2 velocity = Vector2.Normalize(location - user.location) * 25; float ropeIncrementDistance = 2.5f; ropeIntermediaryPoints.Add(position); int ropeCount = item_rope.uses; for (int i = 0; i < ropeCount * 2 + 10; i++) { TileType tileIn = world.getBlock(position); if (tileIn != null) { velocity += new Vector2(0, .5f) * ropeIncrementDistance; velocity *= .975f; position += velocity * ropeIncrementDistance; ropeIntermediaryPoints.Add(position); if (tileIn.tags.Contains(TagReferencer.SOLID) && !hookWouldBeAnchored) { hookWouldBeAnchored = true; hookWouldBeAnchoredAt = i + 1; ropeThatWouldBeConsumed = hookWouldBeAnchoredAt / 2; ropeSegmentsInGreen = ropeCount * 2; } } else { //the rope has extended off the map; simply stop calculating. break; } } } } if (!inputManager.isDown() && inputManager.wasDown() && item_rope != null) { if (hookWouldBeAnchored && ropeThatWouldBeConsumed <= item_rope.uses) { EntityBetterRopeSegment previousRopeSegment = new EntityBetterRopeSegment(ropeIntermediaryPoints[0], world, null); previousRopeSegment.isAnchor = true; world.addEntity(previousRopeSegment); EntityBetterRopeSegment nthRopeSegment = null; for (int i = 1; i < hookWouldBeAnchoredAt; i++) { nthRopeSegment = new EntityBetterRopeSegment(ropeIntermediaryPoints[i], world, previousRopeSegment); previousRopeSegment.child = nthRopeSegment; world.addEntity(nthRopeSegment); previousRopeSegment = nthRopeSegment; } previousRopeSegment.isAnchor = true; user.inventory.consume(item_rope, ropeThatWouldBeConsumed); SoundManager.getSound("grappling-hook").playWithVariance(0, .2f, 0, SoundType.MONSTER); } else { //do a flash? } } drawing = inputManager.isDown(); if (inputManager.isDown() && !inputManager.wasDown() && item_rope == null) { user.speechManager.addSpeechBubble(new SpeechBubble(Game1.texture_item_rope)); } prevOrigin = user.location; prevTarget = location; return(0); }