EngineWrapper, engine via interfaces
This commit is contained in:
25
konstructor/engine/engine.wrapper.go
Normal file
25
konstructor/engine/engine.wrapper.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package engine
|
||||||
|
|
||||||
|
import (
|
||||||
|
"game/konstructor/entity"
|
||||||
|
|
||||||
|
"github.com/hajimehoshi/ebiten"
|
||||||
|
)
|
||||||
|
|
||||||
|
type EngineWrapper struct {
|
||||||
|
Engine Engine
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ew *EngineWrapper) Init(options entity.EngineOptions) {
|
||||||
|
ew.Engine = Engine{
|
||||||
|
KContext: &options.KContext,
|
||||||
|
Domain: options.Domain,
|
||||||
|
Settings: &options.Settings,
|
||||||
|
}
|
||||||
|
ebiten.SetWindowSize(options.Settings.Screen.Width, options.Settings.Screen.Height)
|
||||||
|
ebiten.SetWindowTitle(options.Settings.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ew *EngineWrapper) Run() {
|
||||||
|
ebiten.RunGame(&ew.Engine)
|
||||||
|
}
|
||||||
37
konstructor/entity/entity.engine.go
Normal file
37
konstructor/entity/entity.engine.go
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package entity
|
||||||
|
|
||||||
|
type EngineInterface interface {
|
||||||
|
ClearKeyPresed()
|
||||||
|
UpPressed() bool
|
||||||
|
DownPressed() bool
|
||||||
|
RightPressed() bool
|
||||||
|
LeftPressed() bool
|
||||||
|
Action0Pressed() bool
|
||||||
|
Action1Pressed() bool
|
||||||
|
Action2Pressed() bool
|
||||||
|
Action3Pressed() bool
|
||||||
|
ScreenTypeIs(name string) bool
|
||||||
|
Update(screen any) error
|
||||||
|
Draw(screen any)
|
||||||
|
AddToInventory(item *Item)
|
||||||
|
RemoveFromInventory(item *Item)
|
||||||
|
UseInventoryItem(item *Item)
|
||||||
|
DialogDraw(screen any)
|
||||||
|
DialogUpdate()
|
||||||
|
MenuDraw(screen any)
|
||||||
|
MenuUpdate()
|
||||||
|
PlaygroundDraw(screen any)
|
||||||
|
PlaygroundUpdate()
|
||||||
|
}
|
||||||
|
|
||||||
|
type EngineOptions struct {
|
||||||
|
Engine EngineInterface
|
||||||
|
Domain DomainInterface
|
||||||
|
KContext KContext
|
||||||
|
Settings Settings
|
||||||
|
}
|
||||||
|
|
||||||
|
type EngineWrapperInterface interface {
|
||||||
|
Init(options EngineOptions)
|
||||||
|
Run()
|
||||||
|
}
|
||||||
@@ -1,33 +1,22 @@
|
|||||||
package konstructor
|
package konstructor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"game/konstructor/engine"
|
|
||||||
"game/konstructor/entity"
|
"game/konstructor/entity"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Konstructor struct {
|
type Konstructor struct {
|
||||||
Domain entity.DomainInterface
|
Domain entity.DomainInterface
|
||||||
Settings *entity.Settings
|
Settings entity.Settings
|
||||||
KContext *entity.KContext
|
KContext *entity.KContext
|
||||||
|
EngineWrapper entity.EngineWrapperInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k Konstructor) Init() {
|
func (k Konstructor) Init() {
|
||||||
k.Domain.Init()
|
k.Domain.Init()
|
||||||
k.SetWindow()
|
k.EngineWrapper.Init(entity.EngineOptions{
|
||||||
k.Run()
|
KContext: *k.KContext,
|
||||||
}
|
|
||||||
|
|
||||||
func (k Konstructor) SetWindow() {
|
|
||||||
ebiten.SetWindowSize(k.Settings.Screen.Width, k.Settings.Screen.Height)
|
|
||||||
ebiten.SetWindowTitle(k.Settings.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (k Konstructor) Run() {
|
|
||||||
ebiten.RunGame(&engine.Engine{
|
|
||||||
KContext: k.KContext,
|
|
||||||
Domain: k.Domain,
|
Domain: k.Domain,
|
||||||
Settings: k.Settings,
|
Settings: k.Settings,
|
||||||
})
|
})
|
||||||
|
k.EngineWrapper.Run()
|
||||||
}
|
}
|
||||||
|
|||||||
39
main.go
39
main.go
@@ -3,13 +3,34 @@ package main
|
|||||||
import (
|
import (
|
||||||
"game/domain"
|
"game/domain"
|
||||||
"game/konstructor"
|
"game/konstructor"
|
||||||
|
"game/konstructor/engine"
|
||||||
"game/konstructor/entity"
|
"game/konstructor/entity"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten"
|
"github.com/hajimehoshi/ebiten"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
|
s := entity.Settings{
|
||||||
|
Name: "Game",
|
||||||
|
Screen: &entity.ScreenSettings{
|
||||||
|
Width: 640,
|
||||||
|
Height: 480,
|
||||||
|
},
|
||||||
|
KeyMap: entity.KeyMap{
|
||||||
|
Up: ebiten.KeyUp,
|
||||||
|
Down: ebiten.KeyDown,
|
||||||
|
Right: ebiten.KeyRight,
|
||||||
|
Left: ebiten.KeyLeft,
|
||||||
|
Action0: ebiten.KeySpace,
|
||||||
|
Action1: ebiten.KeyAlt,
|
||||||
|
Action2: ebiten.KeyControl,
|
||||||
|
Action3: ebiten.KeyEscape,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
k := konstructor.Konstructor{
|
k := konstructor.Konstructor{
|
||||||
|
EngineWrapper: &engine.EngineWrapper{},
|
||||||
KContext: &entity.KContext{
|
KContext: &entity.KContext{
|
||||||
Screen: entity.KContextScreen{
|
Screen: entity.KContextScreen{
|
||||||
Type: "menu",
|
Type: "menu",
|
||||||
@@ -27,23 +48,7 @@ func main() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Settings: &entity.Settings{
|
Settings: s,
|
||||||
Name: "Game",
|
|
||||||
Screen: &entity.ScreenSettings{
|
|
||||||
Width: 640,
|
|
||||||
Height: 480,
|
|
||||||
},
|
|
||||||
KeyMap: entity.KeyMap{
|
|
||||||
Up: ebiten.KeyUp,
|
|
||||||
Down: ebiten.KeyDown,
|
|
||||||
Right: ebiten.KeyRight,
|
|
||||||
Left: ebiten.KeyLeft,
|
|
||||||
Action0: ebiten.KeySpace,
|
|
||||||
Action1: ebiten.KeyAlt,
|
|
||||||
Action2: ebiten.KeyControl,
|
|
||||||
Action3: ebiten.KeyEscape,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
k.Init()
|
k.Init()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user