mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-24 09:52:03 +01:00
Remove Game.ScreenWidth/Height
This commit is contained in:
parent
129532692d
commit
62e8755b64
@ -29,14 +29,14 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Game interface {
|
type Game interface {
|
||||||
ScreenWidth() int
|
|
||||||
ScreenHeight() int
|
|
||||||
Init(tf graphics.TextureFactory)
|
Init(tf graphics.TextureFactory)
|
||||||
Update(context GameContext)
|
Update(context GameContext)
|
||||||
Draw(context graphics.Context)
|
Draw(context graphics.Context)
|
||||||
}
|
}
|
||||||
|
|
||||||
type GameContext interface {
|
type GameContext interface {
|
||||||
|
ScreenWidth() int
|
||||||
|
ScreenHeight() int
|
||||||
InputState() InputState
|
InputState() InputState
|
||||||
Terminate()
|
Terminate()
|
||||||
}
|
}
|
||||||
|
@ -32,14 +32,6 @@ func New() *Blank {
|
|||||||
return &Blank{}
|
return &Blank{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (game *Blank) ScreenWidth() int {
|
|
||||||
return 256
|
|
||||||
}
|
|
||||||
|
|
||||||
func (game *Blank) ScreenHeight() int {
|
|
||||||
return 240
|
|
||||||
}
|
|
||||||
|
|
||||||
func (game *Blank) Init(tf graphics.TextureFactory) {
|
func (game *Blank) Init(tf graphics.TextureFactory) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,14 +39,6 @@ func New() *Input {
|
|||||||
return &Input{}
|
return &Input{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (game *Input) ScreenWidth() int {
|
|
||||||
return 256
|
|
||||||
}
|
|
||||||
|
|
||||||
func (game *Input) ScreenHeight() int {
|
|
||||||
return 240
|
|
||||||
}
|
|
||||||
|
|
||||||
func (game *Input) Init(tf graphics.TextureFactory) {
|
func (game *Input) Init(tf graphics.TextureFactory) {
|
||||||
file, err := os.Open("images/text.png")
|
file, err := os.Open("images/text.png")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -34,23 +34,17 @@ type Monochrome struct {
|
|||||||
ebitenTexture graphics.Texture
|
ebitenTexture graphics.Texture
|
||||||
ch chan bool
|
ch chan bool
|
||||||
colorMatrix matrix.Color
|
colorMatrix matrix.Color
|
||||||
|
geometryMatrix matrix.Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() *Monochrome {
|
func New() *Monochrome {
|
||||||
return &Monochrome{
|
return &Monochrome{
|
||||||
ch: make(chan bool),
|
ch: make(chan bool),
|
||||||
colorMatrix: matrix.IdentityColor(),
|
colorMatrix: matrix.IdentityColor(),
|
||||||
|
geometryMatrix: matrix.IdentityGeometry(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (game *Monochrome) ScreenWidth() int {
|
|
||||||
return 256
|
|
||||||
}
|
|
||||||
|
|
||||||
func (game *Monochrome) ScreenHeight() int {
|
|
||||||
return 240
|
|
||||||
}
|
|
||||||
|
|
||||||
func (game *Monochrome) Init(tf graphics.TextureFactory) {
|
func (game *Monochrome) Init(tf graphics.TextureFactory) {
|
||||||
file, err := os.Open("images/ebiten.png")
|
file, err := os.Open("images/ebiten.png")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -114,15 +108,16 @@ func (game *Monochrome) update() {
|
|||||||
func (game *Monochrome) Update(context ebiten.GameContext) {
|
func (game *Monochrome) Update(context ebiten.GameContext) {
|
||||||
game.ch <- true
|
game.ch <- true
|
||||||
<-game.ch
|
<-game.ch
|
||||||
|
|
||||||
|
game.geometryMatrix = matrix.IdentityGeometry()
|
||||||
|
tx := context.ScreenWidth()/2 - game.ebitenTexture.Width()/2
|
||||||
|
ty := context.ScreenHeight()/2 - game.ebitenTexture.Height()/2
|
||||||
|
game.geometryMatrix.Translate(float64(tx), float64(ty))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (game *Monochrome) Draw(g graphics.Context) {
|
func (game *Monochrome) Draw(g graphics.Context) {
|
||||||
g.Fill(&color.RGBA{R: 128, G: 128, B: 255, A: 255})
|
g.Fill(&color.RGBA{R: 128, G: 128, B: 255, A: 255})
|
||||||
|
|
||||||
geometryMatrix := matrix.IdentityGeometry()
|
|
||||||
tx := game.ScreenWidth()/2 - game.ebitenTexture.Width()/2
|
|
||||||
ty := game.ScreenHeight()/2 - game.ebitenTexture.Height()/2
|
|
||||||
geometryMatrix.Translate(float64(tx), float64(ty))
|
|
||||||
g.DrawTexture(game.ebitenTexture.ID(),
|
g.DrawTexture(game.ebitenTexture.ID(),
|
||||||
geometryMatrix, game.colorMatrix)
|
game.geometryMatrix, game.colorMatrix)
|
||||||
}
|
}
|
||||||
|
@ -31,44 +31,38 @@ import (
|
|||||||
|
|
||||||
type Rects struct {
|
type Rects struct {
|
||||||
rectsTexture graphics.Texture
|
rectsTexture graphics.Texture
|
||||||
|
rect *graphics.Rect
|
||||||
|
rectColor *color.RGBA
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() *Rects {
|
func New() *Rects {
|
||||||
return &Rects{}
|
return &Rects{
|
||||||
}
|
rect: &graphics.Rect{},
|
||||||
|
rectColor: &color.RGBA{},
|
||||||
func (game *Rects) ScreenWidth() int {
|
}
|
||||||
return 256
|
|
||||||
}
|
|
||||||
|
|
||||||
func (game *Rects) ScreenHeight() int {
|
|
||||||
return 240
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (game *Rects) Init(tf graphics.TextureFactory) {
|
func (game *Rects) Init(tf graphics.TextureFactory) {
|
||||||
game.rectsTexture = tf.NewTexture(game.ScreenWidth(), game.ScreenHeight())
|
// TODO: fix
|
||||||
|
game.rectsTexture = tf.NewTexture(256, 240)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (game *Rects) Update(context ebiten.GameContext) {
|
func (game *Rects) Update(context ebiten.GameContext) {
|
||||||
|
game.rect.X = rand.Intn(context.ScreenWidth())
|
||||||
|
game.rect.Y = rand.Intn(context.ScreenHeight())
|
||||||
|
game.rect.Width = rand.Intn(context.ScreenWidth() - game.rect.X)
|
||||||
|
game.rect.Height = rand.Intn(context.ScreenHeight() - game.rect.Y)
|
||||||
|
|
||||||
|
game.rectColor.R = uint8(rand.Intn(256))
|
||||||
|
game.rectColor.G = uint8(rand.Intn(256))
|
||||||
|
game.rectColor.B = uint8(rand.Intn(256))
|
||||||
|
game.rectColor.A = uint8(rand.Intn(256))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (game *Rects) Draw(g graphics.Context) {
|
func (game *Rects) Draw(g graphics.Context) {
|
||||||
g.SetOffscreen(game.rectsTexture.ID())
|
g.SetOffscreen(game.rectsTexture.ID())
|
||||||
|
|
||||||
x := rand.Intn(game.ScreenWidth())
|
g.DrawRect(*game.rect, game.rectColor)
|
||||||
y := rand.Intn(game.ScreenHeight())
|
|
||||||
width := rand.Intn(game.ScreenWidth() - x)
|
|
||||||
height := rand.Intn(game.ScreenHeight() - y)
|
|
||||||
|
|
||||||
red := uint8(rand.Intn(256))
|
|
||||||
green := uint8(rand.Intn(256))
|
|
||||||
blue := uint8(rand.Intn(256))
|
|
||||||
alpha := uint8(rand.Intn(256))
|
|
||||||
|
|
||||||
g.DrawRect(
|
|
||||||
graphics.Rect{x, y, width, height},
|
|
||||||
&color.RGBA{red, green, blue, alpha},
|
|
||||||
)
|
|
||||||
|
|
||||||
g.SetOffscreen(g.Screen().ID())
|
g.SetOffscreen(g.Screen().ID())
|
||||||
g.DrawTexture(game.rectsTexture.ID(),
|
g.DrawTexture(game.rectsTexture.ID(),
|
||||||
|
@ -34,20 +34,13 @@ import (
|
|||||||
type Rotating struct {
|
type Rotating struct {
|
||||||
ebitenTexture graphics.Texture
|
ebitenTexture graphics.Texture
|
||||||
x int
|
x int
|
||||||
|
geometryMatrix matrix.Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() *Rotating {
|
func New() *Rotating {
|
||||||
return &Rotating{}
|
return &Rotating{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (game *Rotating) ScreenWidth() int {
|
|
||||||
return 256
|
|
||||||
}
|
|
||||||
|
|
||||||
func (game *Rotating) ScreenHeight() int {
|
|
||||||
return 240
|
|
||||||
}
|
|
||||||
|
|
||||||
func (game *Rotating) Init(tf graphics.TextureFactory) {
|
func (game *Rotating) Init(tf graphics.TextureFactory) {
|
||||||
file, err := os.Open("images/ebiten.png")
|
file, err := os.Open("images/ebiten.png")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -66,21 +59,20 @@ func (game *Rotating) Init(tf graphics.TextureFactory) {
|
|||||||
|
|
||||||
func (game *Rotating) Update(context ebiten.GameContext) {
|
func (game *Rotating) Update(context ebiten.GameContext) {
|
||||||
game.x++
|
game.x++
|
||||||
|
|
||||||
|
game.geometryMatrix = matrix.IdentityGeometry()
|
||||||
|
tx, ty := float64(game.ebitenTexture.Width()), float64(game.ebitenTexture.Height())
|
||||||
|
game.geometryMatrix.Translate(-tx/2, -ty/2)
|
||||||
|
game.geometryMatrix.Rotate(float64(game.x) * 2 * math.Pi / float64(ebiten.FPS*10))
|
||||||
|
game.geometryMatrix.Translate(tx/2, ty/2)
|
||||||
|
centerX := float64(context.ScreenWidth()) / 2
|
||||||
|
centerY := float64(context.ScreenHeight()) / 2
|
||||||
|
game.geometryMatrix.Translate(centerX-tx/2, centerY-ty/2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (game *Rotating) Draw(g graphics.Context) {
|
func (game *Rotating) Draw(g graphics.Context) {
|
||||||
g.Fill(&color.RGBA{R: 128, G: 128, B: 255, A: 255})
|
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) * 2 * math.Pi / float64(ebiten.FPS*10))
|
|
||||||
geometryMatrix.Translate(tx/2, ty/2)
|
|
||||||
centerX := float64(game.ScreenWidth()) / 2
|
|
||||||
centerY := float64(game.ScreenHeight()) / 2
|
|
||||||
geometryMatrix.Translate(centerX-tx/2, centerY-ty/2)
|
|
||||||
|
|
||||||
g.DrawTexture(game.ebitenTexture.ID(),
|
g.DrawTexture(game.ebitenTexture.ID(),
|
||||||
geometryMatrix,
|
game.geometryMatrix,
|
||||||
matrix.IdentityColor())
|
matrix.IdentityColor())
|
||||||
}
|
}
|
||||||
|
@ -88,14 +88,6 @@ func New() *Sprites {
|
|||||||
return &Sprites{}
|
return &Sprites{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (game *Sprites) ScreenWidth() int {
|
|
||||||
return 256
|
|
||||||
}
|
|
||||||
|
|
||||||
func (game *Sprites) ScreenHeight() int {
|
|
||||||
return 240
|
|
||||||
}
|
|
||||||
|
|
||||||
func (game *Sprites) Init(tf graphics.TextureFactory) {
|
func (game *Sprites) Init(tf graphics.TextureFactory) {
|
||||||
file, err := os.Open("images/ebiten.png")
|
file, err := os.Open("images/ebiten.png")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -112,9 +104,10 @@ func (game *Sprites) Init(tf graphics.TextureFactory) {
|
|||||||
}
|
}
|
||||||
game.sprites = []*Sprite{}
|
game.sprites = []*Sprite{}
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 100; i++ {
|
||||||
|
// TODO: fix
|
||||||
sprite := newSprite(
|
sprite := newSprite(
|
||||||
game.ScreenWidth(),
|
256,
|
||||||
game.ScreenHeight(),
|
240,
|
||||||
game.ebitenTexture.Width(),
|
game.ebitenTexture.Width(),
|
||||||
game.ebitenTexture.Height())
|
game.ebitenTexture.Height())
|
||||||
game.sprites = append(game.sprites, sprite)
|
game.sprites = append(game.sprites, sprite)
|
||||||
|
@ -33,14 +33,6 @@ func New() *Terminate {
|
|||||||
return &Terminate{60}
|
return &Terminate{60}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (game *Terminate) ScreenWidth() int {
|
|
||||||
return 256
|
|
||||||
}
|
|
||||||
|
|
||||||
func (game *Terminate) ScreenHeight() int {
|
|
||||||
return 240
|
|
||||||
}
|
|
||||||
|
|
||||||
func (game *Terminate) Init(tf graphics.TextureFactory) {
|
func (game *Terminate) Init(tf graphics.TextureFactory) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,5 +63,5 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const screenScale = 2
|
const screenScale = 2
|
||||||
glut.Run(game, screenScale, "Ebiten Demo")
|
glut.Run(game, 256, 240, screenScale, "Ebiten Demo")
|
||||||
}
|
}
|
||||||
|
@ -42,12 +42,9 @@ type Context struct {
|
|||||||
screenScale int
|
screenScale int
|
||||||
textures map[graphics.TextureID]*Texture
|
textures map[graphics.TextureID]*Texture
|
||||||
currentOffscreen *Texture
|
currentOffscreen *Texture
|
||||||
projectionMatrix [16]float32
|
|
||||||
currentShaderProgram C.GLuint
|
|
||||||
mainFramebufferTexture *Texture
|
mainFramebufferTexture *Texture
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method should be called on the UI thread.
|
|
||||||
func newContext(screenWidth, screenHeight, screenScale int) *Context {
|
func newContext(screenWidth, screenHeight, screenScale int) *Context {
|
||||||
context := &Context{
|
context := &Context{
|
||||||
screenWidth: screenWidth,
|
screenWidth: screenWidth,
|
||||||
@ -126,7 +123,6 @@ func (context *Context) DrawRect(rect graphics.Rect, clr color.Color) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
C.glUseProgram(0)
|
C.glUseProgram(0)
|
||||||
context.currentShaderProgram = 0
|
|
||||||
C.glDisable(C.GL_TEXTURE_2D)
|
C.glDisable(C.GL_TEXTURE_2D)
|
||||||
C.glEnableClientState(C.GL_VERTEX_ARRAY)
|
C.glEnableClientState(C.GL_VERTEX_ARRAY)
|
||||||
C.glEnableClientState(C.GL_COLOR_ARRAY)
|
C.glEnableClientState(C.GL_COLOR_ARRAY)
|
||||||
@ -161,11 +157,11 @@ func (context *Context) DrawTextureParts(
|
|||||||
panic("invalid texture ID")
|
panic("invalid texture ID")
|
||||||
}
|
}
|
||||||
|
|
||||||
context.setShaderProgram(geometryMatrix, colorMatrix)
|
shaderProgram := context.setShaderProgram(geometryMatrix, colorMatrix)
|
||||||
C.glBindTexture(C.GL_TEXTURE_2D, texture.id)
|
C.glBindTexture(C.GL_TEXTURE_2D, texture.id)
|
||||||
|
|
||||||
vertexAttrLocation := getAttributeLocation(context.currentShaderProgram, "vertex")
|
vertexAttrLocation := getAttributeLocation(shaderProgram, "vertex")
|
||||||
textureAttrLocation := getAttributeLocation(context.currentShaderProgram, "texture")
|
textureAttrLocation := getAttributeLocation(shaderProgram, "texture")
|
||||||
|
|
||||||
C.glEnableClientState(C.GL_VERTEX_ARRAY)
|
C.glEnableClientState(C.GL_VERTEX_ARRAY)
|
||||||
C.glEnableClientState(C.GL_TEXTURE_COORD_ARRAY)
|
C.glEnableClientState(C.GL_TEXTURE_COORD_ARRAY)
|
||||||
@ -220,10 +216,11 @@ func (context *Context) SetOffscreen(textureID graphics.TextureID) {
|
|||||||
texture.framebuffer = createFramebuffer(texture.id)
|
texture.framebuffer = createFramebuffer(texture.id)
|
||||||
}
|
}
|
||||||
context.setOffscreen(texture)
|
context.setOffscreen(texture)
|
||||||
context.currentOffscreen = texture
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (context *Context) setOffscreen(texture *Texture) {
|
func (context *Context) setOffscreen(texture *Texture) {
|
||||||
|
context.currentOffscreen = texture
|
||||||
|
|
||||||
C.glFlush()
|
C.glFlush()
|
||||||
|
|
||||||
C.glBindFramebuffer(C.GL_FRAMEBUFFER, texture.framebuffer)
|
C.glBindFramebuffer(C.GL_FRAMEBUFFER, texture.framebuffer)
|
||||||
@ -235,6 +232,18 @@ func (context *Context) setOffscreen(texture *Texture) {
|
|||||||
|
|
||||||
C.glViewport(0, 0, C.GLsizei(abs(texture.textureWidth)),
|
C.glViewport(0, 0, C.GLsizei(abs(texture.textureWidth)),
|
||||||
C.GLsizei(abs(texture.textureHeight)))
|
C.GLsizei(abs(texture.textureHeight)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (context *Context) resetOffscreen() {
|
||||||
|
context.setOffscreen(context.mainFramebufferTexture)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (context *Context) flush() {
|
||||||
|
C.glFlush()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (context *Context) projectionMatrix() [16]float32 {
|
||||||
|
texture := context.currentOffscreen
|
||||||
|
|
||||||
var e11, e22, e41, e42 float32
|
var e11, e22, e41, e42 float32
|
||||||
if texture != context.mainFramebufferTexture {
|
if texture != context.mainFramebufferTexture {
|
||||||
@ -250,7 +259,7 @@ func (context *Context) setOffscreen(texture *Texture) {
|
|||||||
e42 = -1 + height/float32(texture.textureHeight)*2
|
e42 = -1 + height/float32(texture.textureHeight)*2
|
||||||
}
|
}
|
||||||
|
|
||||||
context.projectionMatrix = [...]float32{
|
return [...]float32{
|
||||||
e11, 0, 0, 0,
|
e11, 0, 0, 0,
|
||||||
0, e22, 0, 0,
|
0, e22, 0, 0,
|
||||||
0, 0, 1, 0,
|
0, 0, 1, 0,
|
||||||
@ -258,20 +267,8 @@ func (context *Context) setOffscreen(texture *Texture) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (context *Context) resetOffscreen() {
|
|
||||||
context.setOffscreen(context.mainFramebufferTexture)
|
|
||||||
context.currentOffscreen = context.mainFramebufferTexture
|
|
||||||
}
|
|
||||||
|
|
||||||
// This method should be called on the UI thread.
|
|
||||||
func (context *Context) flush() {
|
|
||||||
C.glFlush()
|
|
||||||
}
|
|
||||||
|
|
||||||
// This method should be called on the UI thread.
|
|
||||||
func (context *Context) setShaderProgram(
|
func (context *Context) setShaderProgram(
|
||||||
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) {
|
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) (program C.GLuint) {
|
||||||
program := C.GLuint(0)
|
|
||||||
if colorMatrix.IsIdentity() {
|
if colorMatrix.IsIdentity() {
|
||||||
program = regularShaderProgram
|
program = regularShaderProgram
|
||||||
} else {
|
} else {
|
||||||
@ -279,11 +276,11 @@ func (context *Context) setShaderProgram(
|
|||||||
}
|
}
|
||||||
// TODO: cache and skip?
|
// TODO: cache and skip?
|
||||||
C.glUseProgram(program)
|
C.glUseProgram(program)
|
||||||
context.currentShaderProgram = program
|
|
||||||
|
|
||||||
|
projectionMatrix := context.projectionMatrix()
|
||||||
C.glUniformMatrix4fv(getUniformLocation(program, "projection_matrix"),
|
C.glUniformMatrix4fv(getUniformLocation(program, "projection_matrix"),
|
||||||
1, C.GL_FALSE,
|
1, C.GL_FALSE,
|
||||||
(*C.GLfloat)(&context.projectionMatrix[0]))
|
(*C.GLfloat)(&projectionMatrix[0]))
|
||||||
|
|
||||||
a := float32(geometryMatrix.Elements[0][0])
|
a := float32(geometryMatrix.Elements[0][0])
|
||||||
b := float32(geometryMatrix.Elements[0][1])
|
b := float32(geometryMatrix.Elements[0][1])
|
||||||
@ -328,6 +325,8 @@ func (context *Context) setShaderProgram(
|
|||||||
}
|
}
|
||||||
C.glUniform4fv(getUniformLocation(program, "color_matrix_translation"),
|
C.glUniform4fv(getUniformLocation(program, "color_matrix_translation"),
|
||||||
1, (*C.GLfloat)(&glColorMatrixTranslation[0]))
|
1, (*C.GLfloat)(&glColorMatrixTranslation[0]))
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func createFramebuffer(textureID C.GLuint) C.GLuint {
|
func createFramebuffer(textureID C.GLuint) C.GLuint {
|
||||||
|
@ -135,10 +135,7 @@ func new(screenWidth, screenHeight, screenScale int, title string) *GlutUI {
|
|||||||
return ui
|
return ui
|
||||||
}
|
}
|
||||||
|
|
||||||
func Run(game ebiten.Game, screenScale int, title string) {
|
func Run(game ebiten.Game, screenWidth, screenHeight, screenScale int, title string) {
|
||||||
screenWidth := game.ScreenWidth()
|
|
||||||
screenHeight := game.ScreenHeight()
|
|
||||||
|
|
||||||
ui := new(screenWidth, screenHeight, screenScale, title)
|
ui := new(screenWidth, screenHeight, screenScale, title)
|
||||||
currentUI = ui
|
currentUI = ui
|
||||||
|
|
||||||
@ -175,6 +172,8 @@ func Run(game ebiten.Game, screenScale int, title string) {
|
|||||||
int64(time.Second) / int64(ebiten.FPS))
|
int64(time.Second) / int64(ebiten.FPS))
|
||||||
tick := time.Tick(frameTime)
|
tick := time.Tick(frameTime)
|
||||||
gameContext := &GameContext{
|
gameContext := &GameContext{
|
||||||
|
screenWidth: screenWidth,
|
||||||
|
screenHeight: screenHeight,
|
||||||
inputState: ebiten.InputState{-1, -1},
|
inputState: ebiten.InputState{-1, -1},
|
||||||
}
|
}
|
||||||
for {
|
for {
|
||||||
@ -196,10 +195,20 @@ func Run(game ebiten.Game, screenScale int, title string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GameContext struct {
|
type GameContext struct {
|
||||||
|
screenWidth int
|
||||||
|
screenHeight int
|
||||||
inputState ebiten.InputState
|
inputState ebiten.InputState
|
||||||
terminated bool
|
terminated bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (context *GameContext) ScreenWidth() int {
|
||||||
|
return context.screenWidth
|
||||||
|
}
|
||||||
|
|
||||||
|
func (context *GameContext) ScreenHeight() int {
|
||||||
|
return context.screenHeight
|
||||||
|
}
|
||||||
|
|
||||||
func (context *GameContext) InputState() ebiten.InputState {
|
func (context *GameContext) InputState() ebiten.InputState {
|
||||||
return context.inputState
|
return context.inputState
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user