mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Drop a piece
This commit is contained in:
parent
631b226b5b
commit
2ac027c452
@ -20,7 +20,7 @@ func (f *Field) IsBlocked(x, y int) bool {
|
||||
if y < 0 {
|
||||
return false
|
||||
}
|
||||
if fieldBlockNumX <= y {
|
||||
if fieldBlockNumY <= y {
|
||||
return true
|
||||
}
|
||||
return f.blocks[x][y] != BlockTypeNone
|
||||
@ -44,6 +44,13 @@ func (f *Field) MovePieceToRight(piece *Piece, x, y int, angle Angle) int {
|
||||
return x + 1
|
||||
}
|
||||
|
||||
func (f *Field) DropPiece(piece *Piece, x, y int, angle Angle) int {
|
||||
if f.collides(piece, x, y+1, angle) {
|
||||
return y
|
||||
}
|
||||
return y + 1
|
||||
}
|
||||
|
||||
func (f *Field) RotatePieceRight(piece *Piece, x, y int, angle Angle) Angle {
|
||||
if f.collides(piece, x, y, angle.RotateRight()) {
|
||||
return angle
|
||||
|
@ -36,9 +36,8 @@ const fieldWidth = blockWidth * fieldBlockNumX
|
||||
const fieldHeight = blockHeight * fieldBlockNumY
|
||||
|
||||
func (s *GameScene) choosePiece() *Piece {
|
||||
//num := NormalBlockTypeNum
|
||||
//blockType := BlockType(s.rand.Intn(num) + 1)
|
||||
blockType := BlockType1
|
||||
num := NormalBlockTypeNum
|
||||
blockType := BlockType(s.rand.Intn(num) + 1)
|
||||
return Pieces[blockType]
|
||||
}
|
||||
|
||||
@ -55,18 +54,24 @@ func (s *GameScene) Update(state *GameState) {
|
||||
s.currentPiece, s.currentPieceX, s.currentPieceY,
|
||||
s.currentPieceAngle)
|
||||
}
|
||||
l := state.Input.StateForKey(ui.KeyLeft)
|
||||
if l == 1 || (10 <= l && l % 2 == 0) {
|
||||
if l := state.Input.StateForKey(ui.KeyLeft);
|
||||
l == 1 || (10 <= l && l % 2 == 0) {
|
||||
s.currentPieceX = s.field.MovePieceToLeft(
|
||||
s.currentPiece, s.currentPieceX, s.currentPieceY,
|
||||
s.currentPieceAngle)
|
||||
}
|
||||
r := state.Input.StateForKey(ui.KeyRight)
|
||||
if r == 1 || (10 <= r && r % 2 == 0) {
|
||||
if r := state.Input.StateForKey(ui.KeyRight);
|
||||
r == 1 || (10 <= r && r % 2 == 0) {
|
||||
s.currentPieceX = s.field.MovePieceToRight(
|
||||
s.currentPiece, s.currentPieceX, s.currentPieceY,
|
||||
s.currentPieceAngle)
|
||||
}
|
||||
if d := state.Input.StateForKey(ui.KeyDown);
|
||||
(d - 1) % 2 == 0 {
|
||||
s.currentPieceY = s.field.DropPiece(
|
||||
s.currentPiece, s.currentPieceX, s.currentPieceY,
|
||||
s.currentPieceAngle)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *GameScene) Draw(context graphics.Context) {
|
||||
|
@ -136,8 +136,8 @@ var cocoaKeyCodeToKey = map[int]ui.Key{
|
||||
49: ui.KeySpace,
|
||||
123: ui.KeyLeft,
|
||||
124: ui.KeyRight,
|
||||
125: ui.KeyUp,
|
||||
126: ui.KeyDown,
|
||||
125: ui.KeyDown,
|
||||
126: ui.KeyUp,
|
||||
}
|
||||
|
||||
//export ebiten_KeyDown
|
||||
|
Loading…
Reference in New Issue
Block a user