mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-03 22:44:28 +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 {
|
if y < 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if fieldBlockNumX <= y {
|
if fieldBlockNumY <= y {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return f.blocks[x][y] != BlockTypeNone
|
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
|
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 {
|
func (f *Field) RotatePieceRight(piece *Piece, x, y int, angle Angle) Angle {
|
||||||
if f.collides(piece, x, y, angle.RotateRight()) {
|
if f.collides(piece, x, y, angle.RotateRight()) {
|
||||||
return angle
|
return angle
|
||||||
|
@ -36,9 +36,8 @@ const fieldWidth = blockWidth * fieldBlockNumX
|
|||||||
const fieldHeight = blockHeight * fieldBlockNumY
|
const fieldHeight = blockHeight * fieldBlockNumY
|
||||||
|
|
||||||
func (s *GameScene) choosePiece() *Piece {
|
func (s *GameScene) choosePiece() *Piece {
|
||||||
//num := NormalBlockTypeNum
|
num := NormalBlockTypeNum
|
||||||
//blockType := BlockType(s.rand.Intn(num) + 1)
|
blockType := BlockType(s.rand.Intn(num) + 1)
|
||||||
blockType := BlockType1
|
|
||||||
return Pieces[blockType]
|
return Pieces[blockType]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,18 +54,24 @@ func (s *GameScene) Update(state *GameState) {
|
|||||||
s.currentPiece, s.currentPieceX, s.currentPieceY,
|
s.currentPiece, s.currentPieceX, s.currentPieceY,
|
||||||
s.currentPieceAngle)
|
s.currentPieceAngle)
|
||||||
}
|
}
|
||||||
l := state.Input.StateForKey(ui.KeyLeft)
|
if l := state.Input.StateForKey(ui.KeyLeft);
|
||||||
if l == 1 || (10 <= l && l % 2 == 0) {
|
l == 1 || (10 <= l && l % 2 == 0) {
|
||||||
s.currentPieceX = s.field.MovePieceToLeft(
|
s.currentPieceX = s.field.MovePieceToLeft(
|
||||||
s.currentPiece, s.currentPieceX, s.currentPieceY,
|
s.currentPiece, s.currentPieceX, s.currentPieceY,
|
||||||
s.currentPieceAngle)
|
s.currentPieceAngle)
|
||||||
}
|
}
|
||||||
r := state.Input.StateForKey(ui.KeyRight)
|
if r := state.Input.StateForKey(ui.KeyRight);
|
||||||
if r == 1 || (10 <= r && r % 2 == 0) {
|
r == 1 || (10 <= r && r % 2 == 0) {
|
||||||
s.currentPieceX = s.field.MovePieceToRight(
|
s.currentPieceX = s.field.MovePieceToRight(
|
||||||
s.currentPiece, s.currentPieceX, s.currentPieceY,
|
s.currentPiece, s.currentPieceX, s.currentPieceY,
|
||||||
s.currentPieceAngle)
|
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) {
|
func (s *GameScene) Draw(context graphics.Context) {
|
||||||
|
@ -136,8 +136,8 @@ var cocoaKeyCodeToKey = map[int]ui.Key{
|
|||||||
49: ui.KeySpace,
|
49: ui.KeySpace,
|
||||||
123: ui.KeyLeft,
|
123: ui.KeyLeft,
|
||||||
124: ui.KeyRight,
|
124: ui.KeyRight,
|
||||||
125: ui.KeyUp,
|
125: ui.KeyDown,
|
||||||
126: ui.KeyDown,
|
126: ui.KeyUp,
|
||||||
}
|
}
|
||||||
|
|
||||||
//export ebiten_KeyDown
|
//export ebiten_KeyDown
|
||||||
|
Loading…
Reference in New Issue
Block a user