Implement rotating left (blocks)

This commit is contained in:
Hajime Hoshi 2015-01-08 00:50:02 +09:00
parent 6efb806cc2
commit 5f0bc87402
3 changed files with 19 additions and 1 deletions

View File

@ -79,6 +79,13 @@ func (f *Field) RotatePieceRight(piece *Piece, x, y int, angle Angle) Angle {
return angle.RotateRight()
}
func (f *Field) RotatePieceLeft(piece *Piece, x, y int, angle Angle) Angle {
if f.collides(piece, x, y, angle.RotateLeft()) {
return angle
}
return angle.RotateLeft()
}
func (f *Field) AbsorbPiece(piece *Piece, x, y int, angle Angle) {
piece.AbsorbInto(f, x, y, angle)
if f.flushable() {

View File

@ -274,10 +274,14 @@ func (s *GameScene) Update(state *GameState) error {
piece := s.currentPiece
x := s.currentPieceX
y := s.currentPieceY
if state.Input.StateForKey(ebiten.KeySpace) == 1 {
if state.Input.StateForKey(ebiten.KeySpace) == 1 || state.Input.StateForKey(ebiten.KeyX) == 1 {
s.currentPieceAngle = s.field.RotatePieceRight(piece, x, y, angle)
moved = angle != s.currentPieceAngle
}
if state.Input.StateForKey(ebiten.KeyZ) == 1 {
s.currentPieceAngle = s.field.RotatePieceLeft(piece, x, y, angle)
moved = angle != s.currentPieceAngle
}
if l := state.Input.StateForKey(ebiten.KeyLeft); l == 1 || (10 <= l && l%2 == 0) {
s.currentPieceX = s.field.MovePieceToLeft(piece, x, y, angle)
moved = x != s.currentPieceX

View File

@ -45,6 +45,13 @@ func (a Angle) RotateRight() Angle {
return a + 1
}
func (a Angle) RotateLeft() Angle {
if a == Angle0 {
return Angle270
}
return a - 1
}
type BlockType int
const (