mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 12:08:58 +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"
|
"github.com/hajimehoshi/go.ebiten/graphics"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TapInfo struct {
|
|
||||||
X int
|
|
||||||
Y int
|
|
||||||
}
|
|
||||||
|
|
||||||
type Game interface {
|
type Game interface {
|
||||||
ScreenWidth() int
|
ScreenWidth() int
|
||||||
ScreenHeight() int
|
ScreenHeight() int
|
||||||
Fps() int
|
Fps() int
|
||||||
Init(tf graphics.TextureFactory)
|
Init(tf graphics.TextureFactory)
|
||||||
Update(input InputState)
|
Update()
|
||||||
Draw(g graphics.Context, offscreen graphics.Texture)
|
Draw(g graphics.Context, offscreen graphics.Texture)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
package blank
|
package blank
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/hajimehoshi/go.ebiten"
|
|
||||||
"github.com/hajimehoshi/go.ebiten/graphics"
|
"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) 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) {
|
func (game *Blank) Draw(g graphics.Context, offscreen graphics.Texture) {
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
package monochrome
|
package monochrome
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/hajimehoshi/go.ebiten"
|
|
||||||
"github.com/hajimehoshi/go.ebiten/graphics"
|
"github.com/hajimehoshi/go.ebiten/graphics"
|
||||||
"github.com/hajimehoshi/go.ebiten/graphics/matrix"
|
"github.com/hajimehoshi/go.ebiten/graphics/matrix"
|
||||||
"image"
|
"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 <- true
|
||||||
<-game.ch
|
<-game.ch
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
package rects
|
package rects
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/hajimehoshi/go.ebiten"
|
|
||||||
"github.com/hajimehoshi/go.ebiten/graphics"
|
"github.com/hajimehoshi/go.ebiten/graphics"
|
||||||
"github.com/hajimehoshi/go.ebiten/graphics/matrix"
|
"github.com/hajimehoshi/go.ebiten/graphics/matrix"
|
||||||
"image/color"
|
"image/color"
|
||||||
@ -53,7 +52,7 @@ func (game *Rects) Init(tf graphics.TextureFactory) {
|
|||||||
game.rectsTexture = tf.NewTexture(game.ScreenWidth(), game.ScreenHeight())
|
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) {
|
func (game *Rects) Draw(g graphics.Context, offscreen graphics.Texture) {
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
package rotating
|
package rotating
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/hajimehoshi/go.ebiten"
|
|
||||||
"github.com/hajimehoshi/go.ebiten/graphics"
|
"github.com/hajimehoshi/go.ebiten/graphics"
|
||||||
"github.com/hajimehoshi/go.ebiten/graphics/matrix"
|
"github.com/hajimehoshi/go.ebiten/graphics/matrix"
|
||||||
"image"
|
"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++
|
game.x++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
package sprites
|
package sprites
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/hajimehoshi/go.ebiten"
|
|
||||||
"github.com/hajimehoshi/go.ebiten/graphics"
|
"github.com/hajimehoshi/go.ebiten/graphics"
|
||||||
"github.com/hajimehoshi/go.ebiten/graphics/matrix"
|
"github.com/hajimehoshi/go.ebiten/graphics/matrix"
|
||||||
"image"
|
"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 {
|
for _, sprite := range game.sprites {
|
||||||
sprite.Update()
|
sprite.Update()
|
||||||
}
|
}
|
||||||
|
@ -165,8 +165,16 @@ func main() {
|
|||||||
game = rotating.New()
|
game = rotating.New()
|
||||||
}
|
}
|
||||||
|
|
||||||
screenScale := 2
|
const screenScale = 2
|
||||||
currentUI = NewGlutUI(game.ScreenWidth(), game.ScreenHeight(), screenScale)
|
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)
|
input := make(chan ebiten.InputState)
|
||||||
go func() {
|
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() {
|
go func() {
|
||||||
frameTime := time.Duration(int64(time.Second) / int64(game.Fps()))
|
frameTime := time.Duration(
|
||||||
|
int64(time.Second) / int64(game.Fps()))
|
||||||
update := time.Tick(frameTime)
|
update := time.Tick(frameTime)
|
||||||
inputState := ebiten.InputState{}
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case inputState = <-input:
|
case <-input:
|
||||||
case <-update:
|
case <-update:
|
||||||
game.Update(inputState)
|
game.Update()
|
||||||
inputState = ebiten.InputState{}
|
|
||||||
case drawing := <-draw:
|
case drawing := <-draw:
|
||||||
ch := make(chan interface{})
|
ch := make(chan interface{})
|
||||||
drawing <- func(g graphics.Context, offscreen graphics.Texture) {
|
drawing <- func(g graphics.Context, offscreen graphics.Texture) {
|
||||||
|
Loading…
Reference in New Issue
Block a user