twin-stick-ebiten-tutorial/step-1/game.go

34 lines
827 B
Go

package main
import (
"github.com/hajimehoshi/ebiten/v2"
"golang.org/x/image/colornames"
)
// Game represents a twin-stick shooter game.
type Game struct {
}
// NewGame returns a new Game.
func NewGame() *Game {
return &Game{}
}
// Layout is called by ebiten when the game starts, and every time the game state is updated.
func (g *Game) Layout(width, height int) (int, int) {
// Scale the size of the screen to support high-DPI displays.
s := ebiten.DeviceScaleFactor()
return int(s * float64(width)), int(s * float64(height))
}
// Update is called by ebiten to update the game state.
func (g *Game) Update() error {
return nil
}
// Draw is called by ebiten to draw the game onto the screen.
func (g *Game) Draw(screen *ebiten.Image) {
// Fill the screen with a solid color.
screen.Fill(colornames.Darkgreen)
}