mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-03 22:44:28 +01:00
Implement GameContext.Terminate
This commit is contained in:
parent
70723e1211
commit
d6cd54eba7
@ -35,6 +35,7 @@ type Game interface {
|
|||||||
|
|
||||||
type GameContext interface {
|
type GameContext interface {
|
||||||
InputState() InputState
|
InputState() InputState
|
||||||
|
Terminate()
|
||||||
}
|
}
|
||||||
|
|
||||||
type InputState struct {
|
type InputState struct {
|
||||||
|
60
example/game/terminate/terminate.go
Normal file
60
example/game/terminate/terminate.go
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
// Copyright 2013 Hajime Hoshi
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
|
||||||
|
package terminate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/hajimehoshi/go.ebiten"
|
||||||
|
"github.com/hajimehoshi/go.ebiten/graphics"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Terminate struct {
|
||||||
|
life int
|
||||||
|
}
|
||||||
|
|
||||||
|
func New() *Terminate {
|
||||||
|
return &Terminate{60}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (game *Terminate) ScreenWidth() int {
|
||||||
|
return 256
|
||||||
|
}
|
||||||
|
|
||||||
|
func (game *Terminate) ScreenHeight() int {
|
||||||
|
return 240
|
||||||
|
}
|
||||||
|
|
||||||
|
func (game *Terminate) Fps() int {
|
||||||
|
return 60
|
||||||
|
}
|
||||||
|
|
||||||
|
func (game *Terminate) Init(tf graphics.TextureFactory) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (game *Terminate) Update(context ebiten.GameContext) {
|
||||||
|
game.life--
|
||||||
|
if game.life <= 0 {
|
||||||
|
context.Terminate()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (game *Terminate) Draw(context graphics.Context) {
|
||||||
|
}
|
||||||
|
|
@ -28,6 +28,7 @@ import (
|
|||||||
"github.com/hajimehoshi/go.ebiten/example/game/rects"
|
"github.com/hajimehoshi/go.ebiten/example/game/rects"
|
||||||
"github.com/hajimehoshi/go.ebiten/example/game/rotating"
|
"github.com/hajimehoshi/go.ebiten/example/game/rotating"
|
||||||
"github.com/hajimehoshi/go.ebiten/example/game/sprites"
|
"github.com/hajimehoshi/go.ebiten/example/game/sprites"
|
||||||
|
"github.com/hajimehoshi/go.ebiten/example/game/terminate"
|
||||||
"github.com/hajimehoshi/go.ebiten/ui/glut"
|
"github.com/hajimehoshi/go.ebiten/ui/glut"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -55,6 +56,8 @@ func main() {
|
|||||||
game = rotating.New()
|
game = rotating.New()
|
||||||
case "sprites":
|
case "sprites":
|
||||||
game = sprites.New()
|
game = sprites.New()
|
||||||
|
case "terminate":
|
||||||
|
game = terminate.New()
|
||||||
default:
|
default:
|
||||||
game = rotating.New()
|
game = rotating.New()
|
||||||
}
|
}
|
||||||
|
@ -188,7 +188,11 @@ func Run(game ebiten.Game, screenScale int, title string) {
|
|||||||
}
|
}
|
||||||
<-ch
|
<-ch
|
||||||
}
|
}
|
||||||
|
if gameContext.terminated {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
os.Exit(0)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
C.glutMainLoop()
|
C.glutMainLoop()
|
||||||
@ -196,8 +200,13 @@ func Run(game ebiten.Game, screenScale int, title string) {
|
|||||||
|
|
||||||
type GameContext struct {
|
type GameContext struct {
|
||||||
inputState ebiten.InputState
|
inputState ebiten.InputState
|
||||||
|
terminated bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (context *GameContext) InputState() ebiten.InputState {
|
func (context *GameContext) InputState() ebiten.InputState {
|
||||||
return context.inputState
|
return context.inputState
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (context *GameContext) Terminate() {
|
||||||
|
context.terminated = true
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user