move KeyMap to Settings
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (e *Engine) WatchKeyPress() {
|
func (e *Engine) WatchKeyPress() {
|
||||||
values := reflect.ValueOf(e.KeyMap)
|
values := reflect.ValueOf(e.Settings.KeyMap)
|
||||||
|
|
||||||
for i := 0; i < values.NumField(); i++ {
|
for i := 0; i < values.NumField(); i++ {
|
||||||
key := values.Field(i).Interface().(ebiten.Key)
|
key := values.Field(i).Interface().(ebiten.Key)
|
||||||
@@ -25,33 +25,33 @@ func (e *Engine) ClearKeyPresed() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *Engine) UpPressed() bool {
|
func (e *Engine) UpPressed() bool {
|
||||||
return e.PressedKey == e.KeyMap.Up
|
return e.PressedKey == e.Settings.KeyMap.Up
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Engine) DownPressed() bool {
|
func (e *Engine) DownPressed() bool {
|
||||||
return e.PressedKey == e.KeyMap.Down
|
return e.PressedKey == e.Settings.KeyMap.Down
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Engine) RightPressed() bool {
|
func (e *Engine) RightPressed() bool {
|
||||||
return e.PressedKey == e.KeyMap.Right
|
return e.PressedKey == e.Settings.KeyMap.Right
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Engine) LeftPressed() bool {
|
func (e *Engine) LeftPressed() bool {
|
||||||
return e.PressedKey == e.KeyMap.Left
|
return e.PressedKey == e.Settings.KeyMap.Left
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Engine) Action0Pressed() bool {
|
func (e *Engine) Action0Pressed() bool {
|
||||||
return e.PressedKey == e.KeyMap.Action0
|
return e.PressedKey == e.Settings.KeyMap.Action0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Engine) Action1Pressed() bool {
|
func (e *Engine) Action1Pressed() bool {
|
||||||
return e.PressedKey == e.KeyMap.Action1
|
return e.PressedKey == e.Settings.KeyMap.Action1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Engine) Action2Pressed() bool {
|
func (e *Engine) Action2Pressed() bool {
|
||||||
return e.PressedKey == e.KeyMap.Action2
|
return e.PressedKey == e.Settings.KeyMap.Action2
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Engine) Action3Pressed() bool {
|
func (e *Engine) Action3Pressed() bool {
|
||||||
return e.PressedKey == e.KeyMap.Action3
|
return e.PressedKey == e.Settings.KeyMap.Action3
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ type Engine struct {
|
|||||||
Domain entity.DomainInterface
|
Domain entity.DomainInterface
|
||||||
Settings *entity.Settings
|
Settings *entity.Settings
|
||||||
KContext *entity.KContext
|
KContext *entity.KContext
|
||||||
KeyMap entity.KeyMap
|
|
||||||
PressedKey ebiten.Key
|
PressedKey ebiten.Key
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
package entity
|
|
||||||
|
|
||||||
import "github.com/hajimehoshi/ebiten"
|
|
||||||
|
|
||||||
type KeyMap struct {
|
|
||||||
Up ebiten.Key
|
|
||||||
Down ebiten.Key
|
|
||||||
Right ebiten.Key
|
|
||||||
Left ebiten.Key
|
|
||||||
Action0 ebiten.Key
|
|
||||||
Action1 ebiten.Key
|
|
||||||
Action2 ebiten.Key
|
|
||||||
Action3 ebiten.Key
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,18 @@
|
|||||||
package entity
|
package entity
|
||||||
|
|
||||||
|
import "github.com/hajimehoshi/ebiten"
|
||||||
|
|
||||||
|
type KeyMap struct {
|
||||||
|
Up ebiten.Key
|
||||||
|
Down ebiten.Key
|
||||||
|
Right ebiten.Key
|
||||||
|
Left ebiten.Key
|
||||||
|
Action0 ebiten.Key
|
||||||
|
Action1 ebiten.Key
|
||||||
|
Action2 ebiten.Key
|
||||||
|
Action3 ebiten.Key
|
||||||
|
}
|
||||||
|
|
||||||
type ScreenSettings struct {
|
type ScreenSettings struct {
|
||||||
Width int
|
Width int
|
||||||
Height int
|
Height int
|
||||||
@@ -8,4 +21,5 @@ type ScreenSettings struct {
|
|||||||
type Settings struct {
|
type Settings struct {
|
||||||
Name string
|
Name string
|
||||||
Screen *ScreenSettings
|
Screen *ScreenSettings
|
||||||
|
KeyMap *KeyMap
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
|
|
||||||
type Konstructor struct {
|
type Konstructor struct {
|
||||||
Domain entity.DomainInterface
|
Domain entity.DomainInterface
|
||||||
KeyMap entity.KeyMap
|
|
||||||
Settings *entity.Settings
|
Settings *entity.Settings
|
||||||
KContext *entity.KContext
|
KContext *entity.KContext
|
||||||
}
|
}
|
||||||
@@ -29,7 +28,6 @@ func (k Konstructor) Run() {
|
|||||||
ebiten.RunGame(&engine.Engine{
|
ebiten.RunGame(&engine.Engine{
|
||||||
KContext: k.KContext,
|
KContext: k.KContext,
|
||||||
Domain: k.Domain,
|
Domain: k.Domain,
|
||||||
KeyMap: k.KeyMap,
|
|
||||||
Settings: k.Settings,
|
Settings: k.Settings,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
20
main.go
20
main.go
@@ -27,22 +27,22 @@ func main() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
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,
|
|
||||||
},
|
|
||||||
Settings: &entity.Settings{
|
Settings: &entity.Settings{
|
||||||
Name: "Game",
|
Name: "Game",
|
||||||
Screen: &entity.ScreenSettings{
|
Screen: &entity.ScreenSettings{
|
||||||
Width: 640,
|
Width: 640,
|
||||||
Height: 480,
|
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