mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
examples/blocks: Reduce members from GameScene
This commit is contained in:
parent
507fc7cbbb
commit
fb4343af21
@ -127,7 +127,6 @@ func drawTextBoxContent(r *ebiten.Image, content string, x, y, width int) {
|
|||||||
|
|
||||||
type GameScene struct {
|
type GameScene struct {
|
||||||
field *Field
|
field *Field
|
||||||
rand *rand.Rand
|
|
||||||
currentPiece *Piece
|
currentPiece *Piece
|
||||||
currentPieceX int
|
currentPieceX int
|
||||||
currentPieceY int
|
currentPieceY int
|
||||||
@ -135,16 +134,18 @@ type GameScene struct {
|
|||||||
currentPieceAngle Angle
|
currentPieceAngle Angle
|
||||||
nextPiece *Piece
|
nextPiece *Piece
|
||||||
landingCount int
|
landingCount int
|
||||||
currentFrame int
|
|
||||||
score int
|
score int
|
||||||
lines int
|
lines int
|
||||||
gameover bool
|
gameover bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
}
|
||||||
|
|
||||||
func NewGameScene() *GameScene {
|
func NewGameScene() *GameScene {
|
||||||
return &GameScene{
|
return &GameScene{
|
||||||
field: &Field{},
|
field: &Field{},
|
||||||
rand: rand.New(rand.NewSource(time.Now().UnixNano())),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,7 +181,7 @@ const (
|
|||||||
|
|
||||||
func (s *GameScene) choosePiece() *Piece {
|
func (s *GameScene) choosePiece() *Piece {
|
||||||
num := int(BlockTypeMax)
|
num := int(BlockTypeMax)
|
||||||
blockType := BlockType(s.rand.Intn(num) + 1)
|
blockType := BlockType(rand.Intn(num) + 1)
|
||||||
return Pieces[blockType]
|
return Pieces[blockType]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,8 +226,6 @@ func (s *GameScene) Update(state *GameState) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
s.currentFrame++
|
|
||||||
|
|
||||||
const maxLandingCount = ebiten.FPS
|
const maxLandingCount = ebiten.FPS
|
||||||
if s.currentPiece == nil {
|
if s.currentPiece == nil {
|
||||||
s.initCurrentPiece(s.choosePiece())
|
s.initCurrentPiece(s.choosePiece())
|
||||||
|
Loading…
Reference in New Issue
Block a user