Tetris, in go, why not.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.0 KiB

package lib
import (
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
)
// Implements ebiten.Game
// The game has
type TetrisGame struct {
activeScene Scene
}
func NewGame() (*TetrisGame, error) {
return &TetrisGame{
activeScene: &MainMenuScene{
selections: [1]string{"Quit"},
currentSelectionIndex: 0,
},
}, nil
}
func (g *TetrisGame) Layout(outsideWidth, outsideHeight int) (int, int) {
//TODO: Make this do whatever it is supposed to do : resizing etc
return 640, 480
}
func (g *TetrisGame) Update() error {
//while there are events
var keys []ebiten.Key
keys = inpututil.AppendJustReleasedKeys(keys)
var event GameEvent
if len(keys) > 0 {
event = GameEvent{Type: EventKeyRelease}
} else {
event = GameEvent{Type: EventNoOp}
}
switch g.activeScene.HandleEvent(&event) {
case EndProgram:
return ebiten.Termination
case DoNothing:
return nil
default:
return nil
}
return nil
}
func (g *TetrisGame) Draw(screen *ebiten.Image) {
g.activeScene.Draw(screen)
}