mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Change Game.Update
This commit is contained in:
parent
86b2157b68
commit
b969c15ecf
@ -24,17 +24,12 @@ import (
|
||||
"github.com/hajimehoshi/go.ebiten/graphics"
|
||||
)
|
||||
|
||||
type TapInfo struct {
|
||||
X int
|
||||
Y int
|
||||
}
|
||||
|
||||
type Game interface {
|
||||
ScreenWidth() int
|
||||
ScreenHeight() int
|
||||
Fps() int
|
||||
Init(tf graphics.TextureFactory)
|
||||
Update(input InputState)
|
||||
Update()
|
||||
Draw(g graphics.Context, offscreen graphics.Texture)
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,6 @@
|
||||
package blank
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/go.ebiten"
|
||||
"github.com/hajimehoshi/go.ebiten/graphics"
|
||||
)
|
||||
|
||||
@ -47,7 +46,7 @@ func (game *Blank) Fps() int {
|
||||
func (game *Blank) Init(tf graphics.TextureFactory) {
|
||||
}
|
||||
|
||||
func (game *Blank) Update(input ebiten.InputState) {
|
||||
func (game *Blank) Update() {
|
||||
}
|
||||
|
||||
func (game *Blank) Draw(g graphics.Context, offscreen graphics.Texture) {
|
||||
|
@ -21,7 +21,6 @@
|
||||
package monochrome
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/go.ebiten"
|
||||
"github.com/hajimehoshi/go.ebiten/graphics"
|
||||
"github.com/hajimehoshi/go.ebiten/graphics/matrix"
|
||||
"image"
|
||||
@ -115,7 +114,7 @@ func (game *Monochrome) update() {
|
||||
}
|
||||
}
|
||||
|
||||
func (game *Monochrome) Update(input ebiten.InputState) {
|
||||
func (game *Monochrome) Update() {
|
||||
game.ch <- true
|
||||
<-game.ch
|
||||
}
|
||||
|
@ -21,7 +21,6 @@
|
||||
package rects
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/go.ebiten"
|
||||
"github.com/hajimehoshi/go.ebiten/graphics"
|
||||
"github.com/hajimehoshi/go.ebiten/graphics/matrix"
|
||||
"image/color"
|
||||
@ -53,7 +52,7 @@ func (game *Rects) Init(tf graphics.TextureFactory) {
|
||||
game.rectsTexture = tf.NewTexture(game.ScreenWidth(), game.ScreenHeight())
|
||||
}
|
||||
|
||||
func (game *Rects) Update(input ebiten.InputState) {
|
||||
func (game *Rects) Update() {
|
||||
}
|
||||
|
||||
func (game *Rects) Draw(g graphics.Context, offscreen graphics.Texture) {
|
||||
|
@ -21,7 +21,6 @@
|
||||
package rotating
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/go.ebiten"
|
||||
"github.com/hajimehoshi/go.ebiten/graphics"
|
||||
"github.com/hajimehoshi/go.ebiten/graphics/matrix"
|
||||
"image"
|
||||
@ -68,7 +67,7 @@ func (game *Rotating) Init(tf graphics.TextureFactory) {
|
||||
}
|
||||
}
|
||||
|
||||
func (game *Rotating) Update(input ebiten.InputState) {
|
||||
func (game *Rotating) Update() {
|
||||
game.x++
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,6 @@
|
||||
package sprites
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/go.ebiten"
|
||||
"github.com/hajimehoshi/go.ebiten/graphics"
|
||||
"github.com/hajimehoshi/go.ebiten/graphics/matrix"
|
||||
"image"
|
||||
@ -125,7 +124,7 @@ func (game *Sprites) Init(tf graphics.TextureFactory) {
|
||||
}
|
||||
}
|
||||
|
||||
func (game *Sprites) Update(input ebiten.InputState) {
|
||||
func (game *Sprites) Update() {
|
||||
for _, sprite := range game.sprites {
|
||||
sprite.Update()
|
||||
}
|
||||
|
@ -165,8 +165,16 @@ func main() {
|
||||
game = rotating.New()
|
||||
}
|
||||
|
||||
screenScale := 2
|
||||
currentUI = NewGlutUI(game.ScreenWidth(), game.ScreenHeight(), screenScale)
|
||||
const screenScale = 2
|
||||
currentUI = NewGlutUI(game.ScreenWidth(), game.ScreenHeight(),
|
||||
screenScale)
|
||||
|
||||
graphicsDevice := opengl.NewDevice(
|
||||
game.ScreenWidth(), game.ScreenHeight(), screenScale,
|
||||
currentUI.updating)
|
||||
|
||||
game.Init(graphicsDevice.TextureFactory())
|
||||
draw := graphicsDevice.Drawing()
|
||||
|
||||
input := make(chan ebiten.InputState)
|
||||
go func() {
|
||||
@ -188,23 +196,15 @@ func main() {
|
||||
}
|
||||
}()
|
||||
|
||||
graphicsDevice := opengl.NewDevice(
|
||||
game.ScreenWidth(), game.ScreenHeight(), screenScale,
|
||||
currentUI.updating)
|
||||
|
||||
game.Init(graphicsDevice.TextureFactory())
|
||||
draw := graphicsDevice.Drawing()
|
||||
|
||||
go func() {
|
||||
frameTime := time.Duration(int64(time.Second) / int64(game.Fps()))
|
||||
frameTime := time.Duration(
|
||||
int64(time.Second) / int64(game.Fps()))
|
||||
update := time.Tick(frameTime)
|
||||
inputState := ebiten.InputState{}
|
||||
for {
|
||||
select {
|
||||
case inputState = <-input:
|
||||
case <-input:
|
||||
case <-update:
|
||||
game.Update(inputState)
|
||||
inputState = ebiten.InputState{}
|
||||
game.Update()
|
||||
case drawing := <-draw:
|
||||
ch := make(chan interface{})
|
||||
drawing <- func(g graphics.Context, offscreen graphics.Texture) {
|
||||
|
Loading…
Reference in New Issue
Block a user