public override void bonkY(Vector2 newPos) { bonk(newPos); if (vel.Y > 0) { Point from = ChunkMap.blockIndices(pos + new Vector2(-0.5F, 0.5F) * dimen); Point to = ChunkMap.blockIndices(pos + new Vector2(0.5F, 0.5F) * dimen); bool allRubber = true; for (int i = from.X; i <= to.X; i++) { for (int j = from.Y; j <= to.Y; j++) { Tile tile = Runner.map.getTile(new Point(i, j), getLayer(zPos)); if (tile.tileType != Tile.type.Rubber) { allRubber = false; goto loopEnd; } } } loopEnd: if (allRubber) { vel.Y *= -0.9F; return; } } vel.Y = 0; }
public override void update(float deltaTime) { base.update(deltaTime); Player player = Runner.player; crushTimer += deltaTime * 2; float extend = dimen.Y / 2 - crusherDimen.Y / 2; float amount = crushAmount(); topCrush = new Vector2(pos.X, extend * amount); bottomCrush = new Vector2(pos.X, ChunkMap.mapHeight() - extend * amount); if (collidesWith(player, topCrush, crusherDimen)) // collides with top crusher { Runner.player.vel = Vector2.UnitY * 20; Runner.player.die(); } else if (collidesWith(player, bottomCrush, crusherDimen)) // collides with top crusher { Runner.player.vel = -Vector2.UnitY * 20; Runner.player.die(); } else if (collidesWith(player) && !collidesWith(player, pos, new Vector2(dimen.X, bottomCrush.Y - topCrush.Y))) // collides with arm { Runner.player.vel = Vector2.UnitX * 20 * Math.Sign(player.pos.X - pos.X); Runner.player.die(); } Point from = ChunkMap.blockIndices(topCrush - crusherDimen / 2); Point to = ChunkMap.blockIndices(topCrush + crusherDimen / 2); int layer = getLayer(); for (int x = from.X; x <= to.X; x++) { for (int y = from.Y; y <= to.Y; y++) { Vector2 blockPos = new Vector2(x, y); Runner.map.removeBlock(blockPos, new Vector2(10, 10), layer); } } from = ChunkMap.blockIndices(bottomCrush - crusherDimen / 2); to = ChunkMap.blockIndices(bottomCrush + crusherDimen / 2); for (int x = from.X; x <= to.X; x++) { for (int y = from.Y; y <= to.Y; y++) { Vector2 blockPos = new Vector2(x, y); Runner.map.removeBlock(blockPos, new Vector2(10, -10), layer); } } if ((int)crushTimer > crushInc + 1) { crushInc = (int)crushTimer; //SoundPlayer.play("Explosion", 0.1F); } }
public void checkOclusion() { Camera camera = Runner.camera; Vector2 diff = dimen / 2 * camera.scaleAt(zPos); Vector2 tl = camera.toScreen(pos, zPos) - diff; Vector2 br = tl + diff * 2; frontPercentOcluded = 0; midPercentOcluded = 0; if (getLayer() == 2) { return; } Point from = ChunkMap.blockIndices(camera.toWorld(tl, 0)); Point to = ChunkMap.blockIndices(camera.toWorld(br, 0)); int blockCount = (to.X - from.X + 1) * (to.Y - from.Y + 1); for (int i = from.X; i <= to.X; i++) { for (int j = from.Y; j <= to.Y; j++) { Tile.type tileType = Runner.map.getTile(new Point(i, j), 2).tileType; if (!Tile.nonFullBlock.Contains(tileType) && !Tile.transparent.Contains(tileType)) { frontPercentOcluded += 1F / blockCount; } } } if (getLayer() == 1) { return; } from = ChunkMap.blockIndices(camera.toWorld(tl, -1)); to = ChunkMap.blockIndices(camera.toWorld(br, -1)); blockCount = (to.X - from.X + 1) * (to.Y - from.Y + 1); for (int i = from.X; i <= to.X; i++) { for (int j = from.Y; j <= to.Y; j++) { Tile.type tileType = Runner.map.getTile(new Point(i, j), 1).tileType; if (!Tile.nonFullBlock.Contains(tileType) && !Tile.transparent.Contains(tileType)) { midPercentOcluded += 1F / blockCount; } } } }
public void collideTouching() // includes inside blocks TODO: dont? { Vector2 diff = dimen / 2 + Vector2.One * 0.2F; Point from = ChunkMap.blockIndices(pos - diff); Point to = ChunkMap.blockIndices(pos + diff); for (int i = from.X; i <= to.X; i++) { for (int j = from.Y; j <= to.Y; j++) { Tile tile = Runner.map.getTile(new Point(i, j), getLayer(zPos)); if (tile.tileType != Tile.type.Air) { collideTouching(tile); } } } }
public void collideInsides() { Vector2 diff = dimen / 2; Point from = ChunkMap.blockIndices(pos - diff); Point to = ChunkMap.blockIndices(pos + diff); for (int i = from.X; i <= to.X; i++) { for (int j = from.Y; j <= to.Y; j++) { Tile tile = Runner.map.getTile(new Point(i, j), getLayer(zPos)); if (tile.tileType != Tile.type.Air) { collideInside(tile); } } } }
public void removeBlock(Vector2 position, Vector2 vel, int layer) { Point blockInd = ChunkMap.blockIndices(position); var(blockX, blockY) = blockInd; Point block = new Point(Util.intMod(blockInd.X, Chunk.chunkSize), Util.intMod(blockInd.Y, Chunk.chunkSize)); var(x, y) = block; if (blockX < 0 || blockX >= mapWidth() || blockY < 0 || blockY >= mapHeight()) { return; } if (chunks.Keys.Contains(chunkIndices(position))) { Tile[,,] tiles = getChunk(position).tiles; Tile tile = tiles[x, y, layer]; if (tile.tileType == Tile.type.Air) { return; } Vector2 pos = tiles[x, y, 0].pos; Camera camera = Runner.camera; Vector2 diff = camera.screenCenter / (camera.scale * camera.farMult(layer - 2)); if (Util.between(pos, camera.pos - diff, camera.pos + diff)) // checks if on-screen before creating particle { Runner.particles[layer].Add(new BlockParticle(tile, vel)); } tiles[x, y, layer] = new Tile(Tile.type.Air, pos, layer); } int ID = (int)Tile.type.Air; Chunk.mapData[layer][blockX, blockY] = ID; }
public Point pointAt(Vector2 mousePos) { return(ChunkMap.blockIndices(Runner.camera.toWorld(mousePos, editLayer - 2))); }