ebiten/example/main.go

66 lines
1.4 KiB
Go
Raw Normal View History

2013-07-05 15:25:45 +02:00
package main
import (
2013-10-14 04:34:58 +02:00
"github.com/hajimehoshi/go-ebiten"
"github.com/hajimehoshi/go-ebiten/example/game/blank"
"github.com/hajimehoshi/go-ebiten/example/game/input"
"github.com/hajimehoshi/go-ebiten/example/game/monochrome"
"github.com/hajimehoshi/go-ebiten/example/game/rects"
"github.com/hajimehoshi/go-ebiten/example/game/rotating"
"github.com/hajimehoshi/go-ebiten/example/game/sprites"
2013-10-18 19:58:00 +02:00
"github.com/hajimehoshi/go-ebiten/example/game/testpattern"
2013-10-14 04:34:58 +02:00
"github.com/hajimehoshi/go-ebiten/ui/cocoa"
2013-07-05 15:25:45 +02:00
"os"
"runtime"
2013-11-23 10:10:15 +01:00
"time"
2013-07-05 15:25:45 +02:00
)
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
gameName := ""
if 2 <= len(os.Args) {
gameName = os.Args[1]
}
var game ebiten.Game
switch gameName {
case "blank":
game = blank.New()
case "input":
game = input.New()
case "monochrome":
game = monochrome.New()
case "rects":
game = rects.New()
2013-10-15 02:12:43 +02:00
default:
fallthrough
2013-07-05 15:25:45 +02:00
case "rotating":
game = rotating.New()
case "sprites":
game = sprites.New()
2013-10-18 19:58:00 +02:00
case "testpattern":
game = testpattern.New()
2013-07-05 15:25:45 +02:00
}
2013-10-15 02:12:43 +02:00
const screenWidth = 256
const screenHeight = 240
2013-07-05 15:25:45 +02:00
const screenScale = 2
2013-10-15 02:12:43 +02:00
const title = "Ebiten Demo"
2013-11-22 18:56:18 +01:00
ui := cocoa.New(screenWidth, screenHeight, screenScale, title)
2013-11-23 10:10:15 +01:00
ui.Start()
ui.InitTextures(game.InitTextures)
frameTime := time.Duration(int64(time.Second) / int64(ebiten.FPS))
tick := time.Tick(frameTime)
2013-11-22 18:56:18 +01:00
for {
2013-11-23 10:10:15 +01:00
ui.PollEvents()
select {
case <-tick:
ui.Update(game.Update)
default:
}
2013-11-22 18:56:18 +01:00
ui.Draw(game.Draw)
2013-10-15 02:12:43 +02:00
}
2013-07-05 15:25:45 +02:00
}