public virtual void performPhysics(GameTime time) { tileIn = world.getBlock(location); if (tileIn != null && !tileIn.tags.Contains(TagReferencer.WATER)) { impulse += new Vector2(0, .5f * gravityMultiplier); } else { impulse += new Vector2(0, .05f * gravityMultiplier); } velocity += impulse; TileType tileOccupied = world.getBlock(location); TileType tileBelow = world.getBlock(location + new Vector2(0, Chunk.tileDrawWidth)); if (tileOccupied != null) { velocity -= velocity * (1 - tileOccupied.getFrictionMultiplier()) * frictionMultiplier; } if (collideBottom && tileBelow != null) { velocity -= velocity * (1 - tileBelow.getFrictionMultiplier()) * frictionMultiplier; } Vector2 potentialLocation = location + velocity; collideBottom = false; collideLeft = false; collideRight = false; collideTop = false; location = world.tryMove(this, new AABB((potentialLocation.X - width / 2), (potentialLocation.Y - height / 2), (width), (height))).Center; impulse = new Vector2(); if (tileIn != null && tileIn.tags.Contains(TagReferencer.WATER)) { for (int i = 0; i < Math.Floor(velocity.Length() / 3); i++) { world.addEntity(new ParticleBubble(new Vector2(location.X, location.Y + height / 2), world, new Vector2(), 75)); } if (rand.NextDouble() <= .02f) { world.addEntity(new ParticleBubble(location, world, new Vector2(), 75)); } } }
public static void writeDecoration(WorldBase world, Point lowerLeft, Point origin, Point topRight, String name) { using (BinaryWriter writer = new BinaryWriter(File.Open(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Saved Games/MapData", name), FileMode.Create))) { writer.Write(topRight.X - lowerLeft.X + 1); //write decoration width writer.Write(lowerLeft.Y - topRight.Y + 1); //write decoration height writer.Write(origin.X - lowerLeft.X); //write decoration offset x writer.Write(topRight.Y - origin.Y); //write decoration offset y int numWrites = 4; for (int x = lowerLeft.X; x <= topRight.X; x++) { for (int y = topRight.Y; y <= lowerLeft.Y; y++) { if (world.getBlock(new Point(x, y)) == TileTypeReferencer.AIR) { writer.Write(-1); } else { writer.Write(world.getBlock(new Point(x, y)).TILEID); } numWrites++; } } for (int x = lowerLeft.X; x <= topRight.X; x++) { for (int y = topRight.Y; y <= lowerLeft.Y; y++) { TileType type = world.getBackgroundBlock(new Point(x, y)); if (type == null) { writer.Write(-1); } else { writer.Write(type.TILEID); } numWrites++; } } } }
public override int use(PlayerBase user, WorldBase world, Vector2 location, GameTime time, BinaryInputManager inputManager) { int consumed = 0; TileType currentTile = world.getBlock(location); if (currentTile != null && !currentTile.tags.Contains(TagReferencer.Climbeable) && !currentTile.tags.Contains(TagReferencer.Teleporter)) { consumed = 1; world.placeTile(TileTypeReferencer.LADDER, location); } return(consumed); }
public void writeWorld(WorldBase world, String name) { for (int kx = -world.tileGenRadious; kx <= world.tileGenRadious; kx++) { for (int ky = -world.tileGenRadious; ky <= world.tileGenRadious; ky++) { Directory.CreateDirectory(name + "\\"); using (BinaryWriter writer = new BinaryWriter(File.Open(name + "\\" + kx + "-" + ky + ".cnk", FileMode.Create))) { for (int x = 0; x <= Chunk.tilesPerChunk; x++) { for (int y = 0; y <= Chunk.tilesPerChunk; y++) { TileType type = world.getBlock(new Point(Chunk.tilesPerChunk * kx + x, Chunk.tilesPerChunk * ky + y)); if (type != null) { writer.Write(type.TILEID); } else { writer.Write(-1); } } } for (int x = 0; x <= Chunk.tilesPerChunk; x++) { for (int y = 0; y <= Chunk.tilesPerChunk; y++) { TileType type = world.getBackgroundBlock(new Point(Chunk.tilesPerChunk * kx + x, Chunk.tilesPerChunk * ky + y)); if (type != null) { writer.Write(type.TILEID); } else { writer.Write(-1); } } } } } } }
public override int use(PlayerBase user, WorldBase world, Vector2 location, GameTime time, BinaryInputManager inputManager) { if (user is Player) { if (world.getBlock(user.location) != null) { if (world.getBlock(user.location).tags.Contains(TagReferencer.TotemRabbit) && user.inventory.getItemOfType(new Item_Totem_Rabbit(1)) == null) { user.inventory.add(new Item_Totem_Rabbit(1)); replaceKeyedItem(user, new Item_Totem_Rabbit(1)); return(1); } else if (world.getBlock(user.location).tags.Contains(TagReferencer.TotemTaipir) && user.inventory.getItemOfType(new Item_Totem_Tapir(1)) == null) { user.inventory.add(new Item_Totem_Tapir(1)); replaceKeyedItem(user, new Item_Totem_Tapir(1)); return(1); } else if (world.getBlock(user.location).tags.Contains(TagReferencer.TotemCrocodile) && user.inventory.getItemOfType(new Item_Totem_Crocodile(1)) == null) { user.inventory.add(new Item_Totem_Crocodile(1)); replaceKeyedItem(user, new Item_Totem_Crocodile(1)); return(1); } else if (world.getBlock(user.location).tags.Contains(TagReferencer.TotemCondor) && user.inventory.getItemOfType(new Item_Totem_Condor(1)) == null) { user.inventory.add(new Item_Totem_Condor(1)); replaceKeyedItem(user, new Item_Totem_Condor(1)); return(1); } else if (world.getBlock(user.location).tags.Contains(TagReferencer.TotemFalcon) && user.inventory.getItemOfType(new Item_Totem_Falcon(1)) == null) { user.inventory.add(new Item_Totem_Falcon(1)); replaceKeyedItem(user, new Item_Totem_Falcon(1)); return(1); } else { return(0); } } } else if (user is TransformedPlayer) { world.transformPlayer(((TransformedPlayer)user).transformedFrom); return(0); } 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); }
public override void use(PlayerBase user, WorldBase world, Vector2 location, GameTime time, BinaryInputManager manager) { if (manager.click()) { if (charges > 0) { SoundManager.getSound("card-use-" + (level - 1)).playWithVariance(0, .5f, 0, SoundType.MONSTER); Vector2 teleportLoc = new Vector2(); Vector2 preTeleportLoc = user.location; if (location.X < user.location.X) { teleportLoc = new Vector2(user.location.X - level * 2 * Chunk.tileDrawWidth - Chunk.tileDrawWidth * 3, user.location.Y); TileType teleportTo = world.getBlock(teleportLoc); while (teleportTo != null && teleportTo.tags.Contains(TagReferencer.SOLID)) { teleportLoc += new Vector2(Chunk.tileDrawWidth, 0); teleportTo = world.getBlock(teleportLoc); } user.location = teleportLoc; charges--; } else if (location.X > user.location.X) { teleportLoc = new Vector2(user.location.X + level * 2 * Chunk.tileDrawWidth + Chunk.tileDrawWidth * 3, user.location.Y); TileType teleportTo = world.getBlock(teleportLoc); while (teleportTo != null && teleportTo.tags.Contains(TagReferencer.SOLID)) { teleportLoc += new Vector2(-Chunk.tileDrawWidth, 0); teleportTo = world.getBlock(teleportLoc); } user.location = teleportLoc; charges--; } for (int i = 0; i < 7; i++) { ParticleArbitrary teleportParticle = new ParticleArbitrary(preTeleportLoc + (teleportLoc - preTeleportLoc) * (float)i / 7, world, new Vector2(), (int)(75 * (1 - 1f / (i + 1))), ((Player)user).texture_run[0]); if (preTeleportLoc.X < teleportLoc.X) { teleportParticle.flip = true; } teleportParticle.gravityMultiplier = 0; teleportParticle.endColor = teleportParticle.endColor * .01f; world.addEntity(teleportParticle); } if (user.inventory.getItemOfType(new Item_Macuhatil(1)) != null) { for (int i = 0; i < 7; i++) { ParticleArbitrary teleportParticle = new ParticleArbitrary(preTeleportLoc + (teleportLoc - preTeleportLoc) * (float)i / 7 + new Vector2(0, -10), world, new Vector2(), (int)(75 * (1 - 1f / (i + 1))), Game1.texture_item_macuhatil); teleportParticle.gravityMultiplier = -.1f; teleportParticle.endColor = Color.Red; world.addEntity(teleportParticle); EntityMacuhatilSlash macuhatilSlash = new EntityMacuhatilSlash(preTeleportLoc + (teleportLoc - preTeleportLoc) * (float)i / 7, world, user); macuhatilSlash.velocity += Vector2.Normalize(location - user.location) * .1f; world.addEntity(macuhatilSlash); SoundManager.getSound("sword-slash").playWithVariance(-.5f, .4f, 0, SoundType.MONSTER); } } else if (user.inventory.getItemOfType(new Item_Sword(1)) != null) { for (int i = 0; i < 7; i++) { ParticleArbitrary teleportParticle = new ParticleArbitrary(preTeleportLoc + (teleportLoc - preTeleportLoc) * (float)i / 7 + new Vector2(0, -10), world, new Vector2(), (int)(75 * (1 - 1f / (i + 1))), Game1.texture_item_sword); teleportParticle.gravityMultiplier = -.1f; teleportParticle.endColor = Color.Red; world.addEntity(teleportParticle); EntitySwordSlash swordSlash = new EntitySwordSlash(preTeleportLoc + (teleportLoc - preTeleportLoc) * (float)i / 7, world, user); swordSlash.canUnlockWarrior = true; swordSlash.velocity += Vector2.Normalize(location - user.location) * .1f; world.addEntity(swordSlash); SoundManager.getSound("sword-slash").playWithVariance(0f, .4f, 0, SoundType.MONSTER); } } } else { user.speechManager.addSpeechBubble(Game1.texture_item_charmstone); } } else if (manager.isDown()) { if (charges > 0) { Vector2 teleportLoc = new Vector2(); Vector2 preTeleportLoc = user.location; if (location.X < user.location.X) { teleportLoc = new Vector2(user.location.X - level * 2 * Chunk.tileDrawWidth - Chunk.tileDrawWidth * 3, user.location.Y); TileType teleportTo = world.getBlock(teleportLoc); while (teleportTo != null && teleportTo.tags.Contains(TagReferencer.SOLID)) { teleportLoc += new Vector2(Chunk.tileDrawWidth, 0); teleportTo = world.getBlock(teleportLoc); } } else if (location.X > user.location.X) { teleportLoc = new Vector2(user.location.X + level * 2 * Chunk.tileDrawWidth + Chunk.tileDrawWidth * 3, user.location.Y); TileType teleportTo = world.getBlock(teleportLoc); while (teleportTo != null && teleportTo.tags.Contains(TagReferencer.SOLID)) { teleportLoc += new Vector2(-Chunk.tileDrawWidth, 0); teleportTo = world.getBlock(teleportLoc); } } ParticleArbitrary teleportParticle = new ParticleArbitrary(preTeleportLoc + (teleportLoc - preTeleportLoc), world, new Vector2(), 7, ((Player)user).texture_run[0]); if (preTeleportLoc.X < teleportLoc.X) { teleportParticle.flip = true; } teleportParticle.gravityMultiplier = 0; teleportParticle.startColor = Color.Lerp(teleportParticle.startColor, Color.White, .5f); teleportParticle.endColor = teleportParticle.endColor * .01f; world.addEntity(teleportParticle); } } }