/// <summary> /// Gets a serie of sprites according to movement offsets /// </summary> /// <param name="block">base block</param> /// <param name="movements">wall kicks</param> /// <param name="baseRotation">original rotation</param> /// <param name="iteration">display iteration</param> protected virtual List <Sprite> GetMovementSprites(Data.Block block, Int32[,] movements, Int32 baseRotation, Int32 iteration) { var sprites = new List <Sprite>(); for (Int32 j = 0; j < movements.GetLength(0); j++) { // Grid sprites.Add( new SpriteField(this.Game, _field) { Position = this.Position + SpriteField.GridCellSize * ((_field.Width + 1) * j) * Vector2.UnitX + SpriteField.GridCellSize * ((_field.Height - SpriteField.HiddenRows + 1) * iteration) * Vector2.UnitY, } ); // Block boundary sprites.Add( new Sprite(this.Game) { TextureName = "Graphics/blank", Size = Vector2.One * SpriteField.GridCellSize * block.Width, Position = this.Position + SpriteField.GridCellSize * (2 + (_field.Height - SpriteField.HiddenRows + 1) * iteration) * Vector2.UnitY + SpriteField.GridCellSize * (2 + (_field.Width + 1) * j) * Vector2.UnitX, Opacity = 0.1f, Color = Color.White, } ); // Add base sprite var baseBlock = (Data.Block)block.Clone(); baseBlock.Rotation = baseRotation; sprites.Add( new SpriteFallingBlock(this.Game, new Data.FallingBlock(this.Game, baseBlock, _field, 2, block.Height + 1) ) { Position = this.Position + SpriteField.GridCellSize * ((_field.Height - SpriteField.HiddenRows + 1) * iteration) * Vector2.UnitY + SpriteField.GridCellSize * ((_field.Width + 1) * j) * Vector2.UnitX, Opacity = 0.2f, } ); // Add kicked sprite sprites.Add( new SpriteFallingBlock(this.Game, new Data.FallingBlock(this.Game, (Data.Block)block.Clone(), _field, 2 + movements[j, 0], block.Height + 1 + movements[j, 1]) ) { Position = this.Position + SpriteField.GridCellSize * ((_field.Height - SpriteField.HiddenRows + 1) * iteration) * Vector2.UnitY + SpriteField.GridCellSize * ((_field.Width + 1) * j) * Vector2.UnitX } ); } return(sprites); }
/// <summary> /// Creates a new sprite of a falling block /// </summary> /// <param name="game">Game to bind to</param> /// <param name="source">Data</param> public SpriteBlock(Game game, Data.Block source) : base(game) { _source = source; this.TextureName = "Graphics/blank"; this.Size = (SpriteField.GridCellSize - 1) * Vector2.One; if (_source != null) { this.Color = Data.Block.GetColor(source.Type); _source.OnTypeChanged += new Services.BlockTypeDelegate(_source_OnTypeChanged); } }
/// <summary> /// /// </summary> /// <param name="value"></param> public void SetBlock(Data.Block value) { if (_source != null) { _source.OnTypeChanged -= _source_OnTypeChanged; } _source = value; if (_source == null) { return; } _source.OnTypeChanged += new Services.BlockTypeDelegate(_source_OnTypeChanged); this.Color = Data.Block.GetColor(_source.Type); }