mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Implement rotating left (blocks)
This commit is contained in:
parent
6efb806cc2
commit
5f0bc87402
@ -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() {
|
||||
|
@ -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
|
||||
|
@ -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 (
|
||||
|
Loading…
Reference in New Issue
Block a user