mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
Create game package
This commit is contained in:
parent
d54c484165
commit
d87df4979c
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
@ -16,11 +16,8 @@ package main
|
||||
import "C"
|
||||
import (
|
||||
"github.com/hajimehoshi/go.ebiten"
|
||||
"github.com/hajimehoshi/go.ebiten/example/game"
|
||||
"github.com/hajimehoshi/go.ebiten/graphics"
|
||||
"github.com/hajimehoshi/go.ebiten/graphics/matrix"
|
||||
"image"
|
||||
"image/color"
|
||||
_ "image/png"
|
||||
"os"
|
||||
"runtime"
|
||||
"unsafe"
|
||||
@ -92,52 +89,12 @@ func (ui *GlutUI) Run(device graphics.Device) {
|
||||
C.glutMainLoop()
|
||||
}
|
||||
|
||||
type DemoGame struct {
|
||||
ebitenTexture graphics.Texture
|
||||
x int
|
||||
}
|
||||
|
||||
func (game *DemoGame) Init(tf graphics.TextureFactory) {
|
||||
file, err := os.Open("ebiten.png")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
img, _, err := image.Decode(file)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
game.ebitenTexture = tf.NewTextureFromImage(img)
|
||||
}
|
||||
|
||||
func (game *DemoGame) Update() {
|
||||
game.x++
|
||||
}
|
||||
|
||||
func (game *DemoGame) Draw(g graphics.GraphicsContext, offscreen graphics.Texture) {
|
||||
g.Fill(&color.RGBA{R: 128, G: 128, B: 255, A: 255})
|
||||
|
||||
geometryMatrix := matrix.IdentityGeometry()
|
||||
tx, ty := float64(game.ebitenTexture.Width), float64(game.ebitenTexture.Height)
|
||||
geometryMatrix.Translate(-tx/2, -ty/2)
|
||||
geometryMatrix.Rotate(float64(game.x) / 60)
|
||||
geometryMatrix.Translate(tx/2, ty/2)
|
||||
centerX, centerY := float64(offscreen.Width) / 2, float64(offscreen.Height) / 2
|
||||
geometryMatrix.Translate(centerX - tx/2, centerY - ty/2)
|
||||
g.DrawTexture(game.ebitenTexture.ID,
|
||||
0, 0, int(tx), int(ty),
|
||||
geometryMatrix,
|
||||
matrix.IdentityColor())
|
||||
}
|
||||
|
||||
func main() {
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
|
||||
game := &DemoGame{}
|
||||
game := game.NewRotatingImage()
|
||||
currentUI = &GlutUI{}
|
||||
currentUI.Init()
|
||||
|
||||
ebiten.OpenGLRun(game, currentUI)
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user