protected override void Initialize() { block = new Grid.Cell[4]; blocks = new Grid.Cell[7, 4]; blocks[0, 3] = new Grid.Cell(5, 0, Color.Red, true); // blocks[0, 0] = new Grid.Cell(5, -1, Color.Red, true); // blocks[0, 1] = new Grid.Cell(5, -2, Color.Red, true); // blocks[0, 2] = new Grid.Cell(5, -3, Color.Red, true); // blocks[1, 0] = new Grid.Cell(5, 0, Color.Red, true); // blocks[1, 1] = new Grid.Cell(6, 0, Color.Red, true); // blocks[1, 2] = new Grid.Cell(5, -1, Color.Red, true); //// blocks[1, 3] = new Grid.Cell(5, -2, Color.Red, true); blocks[2, 0] = new Grid.Cell(5, 0, Color.Red, true); // blocks[2, 1] = new Grid.Cell(5, -1, Color.Red, true); //// blocks[2, 2] = new Grid.Cell(4, -1, Color.Red, true); // blocks[2, 3] = new Grid.Cell(5, -2, Color.Red, true); blocks[3, 0] = new Grid.Cell(5, 0, Color.Red, true); //// blocks[3, 1] = new Grid.Cell(6, 0, Color.Red, true); //// blocks[3, 2] = new Grid.Cell(5, -1, Color.Red, true); blocks[3, 3] = new Grid.Cell(6, -1, Color.Red, true); elapsed = 0; piece.x = 5; piece.y = 0; piece.Color = Color.Red; texture = Content.Load <Texture2D>("tile"); Grid.initGrid(); base.Initialize(); }
private void updateMovement(GameTime gameTime) { foreach (var cell in block) { Grid.DeactivateCell(cell.x, cell.y); } if (kbd.KeyTriggered(Keys.Right) || kbd.isKeyHeldDown(Keys.Right, gameTime)) { Grid.Cell[] oldblock = new Grid.Cell[4]; copyBlock(ref oldblock, ref block); for (int i = 0; i < block.Length; i++) { if (block[i].x < Grid.columns - 1) { block[i].x++; } else { copyBlock(ref block, ref oldblock); break; } if (Grid.checkCollision(block[i])) { copyBlock(ref block, ref oldblock); break; } } } if (kbd.KeyTriggered(Keys.Left) || kbd.isKeyHeldDown(Keys.Left, gameTime)) { Grid.Cell[] oldblock = new Grid.Cell[4]; copyBlock(ref oldblock, ref block); for (int i = 0; i < block.Length; i++) { if (block[i].x > 0) { block[i].x--; } else { copyBlock(ref block, ref oldblock); break; } if (Grid.checkCollision(block[i])) { copyBlock(ref block, ref oldblock); break; } } } kbd.KeyTriggered(Keys.Down); if (kbd.isKeyHeldDown(Keys.Down, gameTime)) { speed = 100; } else { speed = 500; } foreach (var cell in block) { Grid.ActivateCell(cell.x, cell.y, cell.Color); } kbd.updateState(); }