2014-12-10 17:59:38 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-12-10 19:50:35 +01:00
|
|
|
"fmt"
|
2014-12-10 17:59:38 +01:00
|
|
|
"github.com/hajimehoshi/ebiten"
|
|
|
|
"github.com/hajimehoshi/ebiten/ebitenutil"
|
|
|
|
"github.com/hajimehoshi/ebiten/runner"
|
|
|
|
"log"
|
|
|
|
"runtime"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
screenWidth = 320
|
|
|
|
screenHeight = 240
|
|
|
|
)
|
|
|
|
|
|
|
|
type Game struct {
|
|
|
|
gameContext ebiten.GameContext
|
|
|
|
canvasRenderTarget ebiten.RenderTargetID
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *Game) Initialize(ga ebiten.GameContext) error {
|
|
|
|
g.gameContext = ga
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *Game) Update() error {
|
|
|
|
// TODO: Implement
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *Game) Draw(gr ebiten.GraphicsContext) error {
|
|
|
|
if g.canvasRenderTarget.IsNil() {
|
|
|
|
var err error
|
|
|
|
g.canvasRenderTarget, err = g.gameContext.NewRenderTargetID(screenWidth, screenHeight, ebiten.FilterNearest)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2014-12-10 20:02:46 +01:00
|
|
|
gr.PushRenderTarget(g.canvasRenderTarget)
|
2014-12-10 17:59:38 +01:00
|
|
|
gr.Fill(0xff, 0xff, 0xff)
|
2014-12-10 20:02:46 +01:00
|
|
|
gr.PopRenderTarget()
|
2014-12-10 17:59:38 +01:00
|
|
|
}
|
|
|
|
ebiten.DrawWhole(gr.RenderTarget(g.canvasRenderTarget), screenWidth, screenHeight, ebiten.GeometryMatrixI(), ebiten.ColorMatrixI())
|
2014-12-10 19:50:35 +01:00
|
|
|
|
|
|
|
mx, my := g.gameContext.CursorPosition()
|
|
|
|
ebitenutil.DebugPrint(g.gameContext, gr, fmt.Sprintf("(%d, %d)", mx, my))
|
2014-12-10 17:59:38 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
runtime.LockOSThread()
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
game := new(Game)
|
|
|
|
if err := runner.Run(game, screenWidth, screenHeight, 2, "Paint (Ebiten Demo)", 60); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|