IEnumerator ControlledByBlock(Blocks.Block block, IEnumerator processor) { SpecialStateBlock = block; yield return(SpecialState(processor)); SpecialStateBlock = null; }
public void TestBlocks() { //Arrange Blocks.Block b1 = new Blocks.Block("Primal Red", 155, 039, 039); Blocks.Block b2 = new Blocks.Block("Verdant Green", 083, 175, 020); //Act Blocks blocks = new Blocks(); //Assert Assert.AreEqual(b1.Color, blocks.Standard[0].Color); Assert.AreEqual(b2.Color, blocks.Standard[blocks.Standard.Count - 1].Color); }
/// <summary> /// Sets a <see cref="Block"/> in the position /// </summary> /// <param name="x">X pos of the block</param> /// <param name="y">Y pos of the block</param> /// <param name="z">Z pos of the block</param> /// <param name="block"><see cref="Block"/> to set</param> /// <param name="chunk"><see cref="Chunk"/> to set the block in</param> /// <param name="replacesBlocks">Can it replace blocks</param> public static void SetBlock(int x, int y, int z, Blocks.Block block, Chunk chunk, bool replacesBlocks = false) { //* corrects the x, y, z pos of the so that the block is placed in the correct position x -= chunk.chunkWorldPos.x; y -= chunk.chunkWorldPos.y; z -= chunk.chunkWorldPos.z; //* checks that the block is in the chunk and that no block is already their then sets it if (Chunk.InRange(x) && Chunk.InRange(y) && Chunk.InRange(z)) { if (replacesBlocks || chunk.blocks[x, y, z] == null) { chunk.SetBlock(x, y, z, block, false); } } }
public bool IsContactedWith(Blocks.Block block) => contactedBlocks.Contains(block);
/// <summary> /// Checks for collision between ball and block, and changes the behavior of the ball accordingly /// </summary> /// <param name="block">Block for which collision is checked</param> /// <returns>The type of block hit, if no block is hit -1 is returned</returns> public int CheckCollision(Blocks.Block block) { //Points are labeled starting from the top-left corner and continuing clockwise PointF a = new PointF(block.X, block.Y); PointF b = new PointF(block.X + Constants.BLOCK_WIDTH, block.Y); PointF c = new PointF(block.X + Constants.BLOCK_WIDTH, block.Y + Constants.BLOCK_HEIGHT); PointF d = new PointF(block.X, block.Y + Constants.BLOCK_HEIGHT); //Check if the ball is totally away from the block //Line 1 a-b //Line 2 b-c //Line 3 c-d //Line 4 d-a Point Center = new Point(this.Center.X + (int)r, this.Center.Y + (int)r); double d1 = DistanceToLine(Center, a, b); double d2 = DistanceToLine(Center, b, c); double d3 = DistanceToLine(Center, c, d); double d4 = DistanceToLine(Center, d, a); bool WasHit = false; int x = this.Center.X, y = this.Center.Y; bool isSquareBlock = (block is Blocks.SquareBlock); if (d1 <= r && Center.X + r >= a.X && Center.X - r <= b.X) { //Ball hit the top side if (isSquareBlock) { this.velocityY = -Math.Abs(this.velocityY); } WasHit = true; } if (d2 <= r && Center.Y + r >= b.Y && Center.Y - r <= c.Y) { //Ball hit the right side if (isSquareBlock) { this.velocityX = Math.Abs(this.velocityX); } // x += (int)(Constants.DELTA + r); WasHit = true; } if (d3 <= r && Center.X + r >= a.X && Center.X - r <= b.X) { //Ball hit the bottom side if (isSquareBlock) { this.velocityY = Math.Abs(this.velocityY); } WasHit = true; } if (d4 <= r && Center.Y + r >= b.Y && Center.Y - r <= c.Y) { //Ball hit the left side if (isSquareBlock) { this.velocityX = -Math.Abs(this.velocityX); } WasHit = true; } if (WasHit) { HitOnce = true; Move(); Center = new Point(x, y); return(block.WasHit()); } return(-1); }