Compare commits
10 Commits
7ef126f02b
...
638fb415ec
| Author | SHA1 | Date | |
|---|---|---|---|
| 638fb415ec | |||
| e5c2294f6c | |||
| 6028c5770f | |||
| 73f06f458f | |||
| 75e7f92396 | |||
| 3947c34b4c | |||
| 09959a8932 | |||
| 9a7be89da6 | |||
| 05ec82d8e8 | |||
| 1db9417dbb |
3
Makefile
3
Makefile
@@ -4,4 +4,5 @@ build:
|
||||
go build -o dist/game.exe
|
||||
dep:
|
||||
go mod tidy
|
||||
|
||||
doc:
|
||||
godoc -http=:3000
|
||||
BIN
assets/images/players/default.png
Normal file
BIN
assets/images/players/default.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 214 B |
@@ -1,16 +0,0 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"game/konstructor"
|
||||
"image/color"
|
||||
)
|
||||
|
||||
func GetDefaultFontLayout() konstructor.FontLayout {
|
||||
return konstructor.FontLayout{
|
||||
Path: "assets/fonts/ArcadeClassic.ttf",
|
||||
DPI: 72,
|
||||
Size: 24,
|
||||
Color: color.White,
|
||||
SelectedColor: color.RGBA{R: 255, G: 0, B: 0, A: 100},
|
||||
}
|
||||
}
|
||||
3
go.mod
3
go.mod
@@ -8,9 +8,8 @@ require golang.org/x/text v0.4.0 // indirect
|
||||
|
||||
require (
|
||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200707082815-5321531c36a2 // indirect
|
||||
github.com/hajimehoshi/bitmapfont/v2 v2.2.3
|
||||
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 // indirect
|
||||
golang.org/x/image v0.1.0 // indirect
|
||||
golang.org/x/image v0.1.0
|
||||
golang.org/x/mobile v0.0.0-20210208171126-f462b3930c8f // indirect
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
|
||||
)
|
||||
|
||||
7
go.sum
7
go.sum
@@ -4,9 +4,8 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200707082815-5321531c36a2/go.mod h1:tQ2
|
||||
github.com/gofrs/flock v0.8.0 h1:MSdYClljsF3PbENUUEx85nkWfJSGfzYI9yEBZOJz6CY=
|
||||
github.com/gofrs/flock v0.8.0/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
|
||||
github.com/hajimehoshi/bitmapfont v1.3.0 h1:h6+HJQ+2MKT3lEVEArjVC4/h0qcFXlVsMTGuRijEnVA=
|
||||
github.com/hajimehoshi/bitmapfont v1.3.0/go.mod h1:/Qb7yVjHYNUV4JdqNkPs6BSZwLjKqkZOMIp6jZD0KgE=
|
||||
github.com/hajimehoshi/bitmapfont/v2 v2.2.3 h1:jmq/TMNj352V062Tr5e3hAoipkoxCbY1JWTzor0zNps=
|
||||
github.com/hajimehoshi/bitmapfont/v2 v2.2.3/go.mod h1:sWM8ejdkGSXaQGlZcegMRx4DyEPOWYyXqsBKIs+Yhzk=
|
||||
github.com/hajimehoshi/ebiten v1.12.12 h1:JvmF1bXRa+t+/CcLWxrJCRsdjs2GyBYBSiFAfIqDFlI=
|
||||
github.com/hajimehoshi/ebiten v1.12.12/go.mod h1:1XI25ImVCDPJiXox4h9yK/CvN5sjDYnbF4oZcFzPXHw=
|
||||
github.com/hajimehoshi/file2byteslice v0.0.0-20200812174855-0e5e8a80490e/go.mod h1:CqqAHp7Dk/AqQiwuhV1yT2334qbA/tFWQW0MD2dGqUE=
|
||||
@@ -20,7 +19,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
|
||||
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
@@ -34,7 +32,6 @@ golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9t
|
||||
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
||||
golang.org/x/image v0.0.0-20190703141733-d6a02ce849c9/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/image v0.0.0-20200801110659-972c09e46d76 h1:U7GPaoQyQmX+CBRWXKrvRzWTbd+slqeSh8uARsIyhAw=
|
||||
golang.org/x/image v0.0.0-20200801110659-972c09e46d76/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/image v0.1.0 h1:r8Oj8ZA2Xy12/b5KZYj3tuv7NG/fBz3TwQVvpJ9l8Rk=
|
||||
golang.org/x/image v0.1.0/go.mod h1:iyPr49SD/G/TBxYVB/9RRtGUT5eNbo2u4NamWeQcD5c=
|
||||
@@ -61,11 +58,9 @@ golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190429190828-d89cdac9e872/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200918174421-af09f7315aff h1:1CPUrky56AcgSpxz/KfgzQWzfG09u5YOL8MvPYBlrL8=
|
||||
golang.org/x/sys v0.0.0-20200918174421-af09f7315aff/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
package easy_ebitengine
|
||||
|
||||
import (
|
||||
"game/konstructor"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
)
|
||||
|
||||
func (e *Engine) PlaygroundUpdate() {
|
||||
level := e.Domain.GetLevel(e.KContext.CurrentLevel)
|
||||
e.Domain.Process(konstructor.DomainProcessArgs{
|
||||
Level: &level,
|
||||
KContext: e.KContext,
|
||||
})
|
||||
}
|
||||
|
||||
func (e *Engine) PlaygroundDraw(screen *ebiten.Image) {
|
||||
e.PlaygroundBackgroundDraw(screen)
|
||||
e.PlaygroundPlatformsDraw(screen)
|
||||
e.PlaygroundItemsDraw(screen)
|
||||
e.PlaygroundNPCsDraw(screen)
|
||||
}
|
||||
|
||||
func (e *Engine) PlaygroundBackgroundDraw(screen *ebiten.Image) {
|
||||
playground := e.GetPlayground()
|
||||
render := playground.Render
|
||||
screen.DrawImage(e.GetImage(render), &ebiten.DrawImageOptions{})
|
||||
}
|
||||
|
||||
func (e *Engine) PlaygroundPlatformsDraw(screen *ebiten.Image) {
|
||||
playground := e.GetPlayground()
|
||||
geoM := ebiten.GeoM{}
|
||||
for _, platform := range playground.Platforms {
|
||||
render := platform.Type.Render
|
||||
geoM.Reset()
|
||||
geoM.Translate(float64(platform.Position.X), float64(platform.Position.Y))
|
||||
screen.DrawImage(e.GetImage(render), &ebiten.DrawImageOptions{
|
||||
GeoM: geoM,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Engine) PlaygroundItemsDraw(screen *ebiten.Image) {
|
||||
playground := e.GetPlayground()
|
||||
geoM := ebiten.GeoM{}
|
||||
for _, platform := range playground.Items {
|
||||
render := platform.Type.Render
|
||||
geoM.Reset()
|
||||
geoM.Translate(float64(platform.Position.X), float64(platform.Position.Y))
|
||||
screen.DrawImage(e.GetImage(render), &ebiten.DrawImageOptions{
|
||||
GeoM: geoM,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Engine) PlaygroundNPCsDraw(screen *ebiten.Image) {
|
||||
playground := e.GetPlayground()
|
||||
geoM := ebiten.GeoM{}
|
||||
for _, platform := range playground.NPCs {
|
||||
render := platform.Type.Render
|
||||
geoM.Reset()
|
||||
geoM.Translate(float64(platform.Position.X), float64(platform.Position.Y))
|
||||
screen.DrawImage(e.GetImage(render), &ebiten.DrawImageOptions{
|
||||
GeoM: geoM,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Engine) GetPlayground() konstructor.Playground {
|
||||
level := e.Domain.GetLevel(e.KContext.CurrentLevel)
|
||||
return level.Playgrounds[e.KContext.CurrentPlayground]
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package konstructor
|
||||
|
||||
type DomainBaseFields struct {
|
||||
MenuMap MenuMap
|
||||
DialogMap DialogMap
|
||||
Levels []Level
|
||||
PlatformTypeMap PlatformTypeMap
|
||||
ItemTypeMap ItemTypeMap
|
||||
NPCTypeMap NPCTypeMap
|
||||
}
|
||||
|
||||
type DomainInterface interface {
|
||||
Init()
|
||||
|
||||
GetMenuMap() MenuMap
|
||||
GetMenu(name MenuMapKey) Menu
|
||||
SetMenu(name MenuMapKey, menu Menu)
|
||||
|
||||
GetDialogMap() DialogMap
|
||||
GetDialog(name DialogMapKey) Dialog
|
||||
SetDialog(name DialogMapKey, menu Dialog)
|
||||
|
||||
GetLevels() []Level
|
||||
GetLevel(index int) Level
|
||||
|
||||
GetPlatformTypeMap() PlatformTypeMap
|
||||
GetPlatformType(name PlatformTypeMapKey) PlatformType
|
||||
|
||||
GetItemTypeMap() ItemTypeMap
|
||||
GetItemType(name ItemTypeMapKey) ItemType
|
||||
|
||||
GetNPCTypeMap() NPCTypeMap
|
||||
GetNPCType(name NPCTypeMapKey) NPCType
|
||||
|
||||
AddToInventory(item *Item) bool
|
||||
RemoveFromInventory(item *Item) bool
|
||||
UseInventoryItem(item *Item) bool
|
||||
|
||||
Process(DomainProcessArgs)
|
||||
}
|
||||
|
||||
type DomainProcessArgs struct {
|
||||
Level *Level
|
||||
KContext *KContext
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package konstructor
|
||||
|
||||
type InventoryItem struct {
|
||||
Item Item
|
||||
Used bool
|
||||
Active bool
|
||||
}
|
||||
|
||||
type Inventory struct {
|
||||
Items []InventoryItem
|
||||
}
|
||||
|
||||
type Player struct {
|
||||
ID string
|
||||
Render Render
|
||||
Position Position
|
||||
Inventory Inventory
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package konstructor
|
||||
|
||||
type KeyMap struct {
|
||||
Up any
|
||||
Down any
|
||||
Right any
|
||||
Left any
|
||||
Action0 any
|
||||
Action1 any
|
||||
Action2 any
|
||||
Action3 any
|
||||
}
|
||||
|
||||
type ScreenSettings struct {
|
||||
Width int
|
||||
Height int
|
||||
Scale int
|
||||
}
|
||||
|
||||
type Settings struct {
|
||||
Name string
|
||||
Screen *ScreenSettings
|
||||
KeyMap KeyMap
|
||||
}
|
||||
33
main.go
33
main.go
@@ -1,42 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"game/domain"
|
||||
"game/konstructor"
|
||||
"game/konstructor/engines/easy_ebitengine"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"game/src/domain"
|
||||
"game/src/konstructor"
|
||||
"game/src/konstructor/engines/easy_ebitengine"
|
||||
)
|
||||
|
||||
func main() {
|
||||
k := konstructor.Konstructor{
|
||||
EngineWrapper: &easy_ebitengine.EngineWrapper{},
|
||||
Domain: &domain.Domain{},
|
||||
KContext: &konstructor.KContext{
|
||||
ScreenType: konstructor.PlaygroundScreenType,
|
||||
ActiveMenu: domain.MainMenu,
|
||||
ActiveDialog: domain.DialogTest,
|
||||
CurrentLevel: 0,
|
||||
CurrentPlayground: 0,
|
||||
},
|
||||
Settings: &konstructor.Settings{
|
||||
Name: "Game",
|
||||
Screen: &konstructor.ScreenSettings{
|
||||
Width: 320,
|
||||
Height: 240,
|
||||
Scale: 2,
|
||||
},
|
||||
KeyMap: konstructor.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()
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"game/konstructor"
|
||||
"game/src/konstructor"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -1,7 +1,7 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"game/konstructor"
|
||||
"game/src/konstructor"
|
||||
)
|
||||
|
||||
type Domain struct {
|
||||
@@ -15,5 +15,6 @@ func (d *Domain) Init() {
|
||||
d.InitNPCType()
|
||||
d.InitMenu()
|
||||
d.InitDialog()
|
||||
d.InitPlayer()
|
||||
d.InitLevel()
|
||||
}
|
||||
34
src/domain/font.go
Normal file
34
src/domain/font.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"game/src/konstructor"
|
||||
"image/color"
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultFontName konstructor.FontName = "ArcadeClassic"
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultDPI = 72
|
||||
)
|
||||
|
||||
func GetDefaultFontLayout() konstructor.FontLayout {
|
||||
return konstructor.FontLayout{
|
||||
Path: konstructor.GetFontPath(DefaultFontName),
|
||||
DPI: DefaultDPI,
|
||||
Size: 24,
|
||||
Color: color.White,
|
||||
SelectedColor: color.RGBA{R: 255, G: 0, B: 0, A: 100},
|
||||
}
|
||||
}
|
||||
|
||||
func GetHeaderFontLayout() konstructor.FontLayout {
|
||||
return konstructor.FontLayout{
|
||||
Path: konstructor.GetFontPath(DefaultFontName),
|
||||
DPI: DefaultDPI,
|
||||
Size: 12,
|
||||
Color: color.White,
|
||||
SelectedColor: color.RGBA{R: 255, G: 0, B: 0, A: 100},
|
||||
}
|
||||
}
|
||||
51
src/domain/init.go
Normal file
51
src/domain/init.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"game/src/konstructor"
|
||||
"image/color"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
)
|
||||
|
||||
func (d *Domain) GetInitialKContext() *konstructor.KContext {
|
||||
return &konstructor.KContext{
|
||||
ScreenType: konstructor.PlaygroundScreenType,
|
||||
ActiveMenu: MainMenu,
|
||||
ActiveDialog: DialogTest,
|
||||
CurrentLevel: 0,
|
||||
CurrentPlayground: 0,
|
||||
Multiplayer: false,
|
||||
LiveCount: 3,
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Domain) GetInitialConfig() *konstructor.Config {
|
||||
return &konstructor.Config{
|
||||
Name: "Teletype Adventure",
|
||||
Screen: &konstructor.ScreenConfig{
|
||||
Width: konstructor.VGAResolutionSet.Width,
|
||||
Height: konstructor.VGAResolutionSet.Height,
|
||||
Scale: 2,
|
||||
},
|
||||
Header: &konstructor.HeaderConfig{
|
||||
BackgroundColor: color.RGBA{
|
||||
R: 0,
|
||||
G: 255,
|
||||
B: 0,
|
||||
A: 200,
|
||||
},
|
||||
Height: 20,
|
||||
FontLayout: GetHeaderFontLayout(),
|
||||
},
|
||||
KeyMap: konstructor.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,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package domain
|
||||
|
||||
import "game/konstructor"
|
||||
import "game/src/konstructor"
|
||||
|
||||
func (d *Domain) AddToInventory(item *konstructor.Item) bool {
|
||||
return true
|
||||
@@ -1,6 +1,6 @@
|
||||
package domain
|
||||
|
||||
import "game/konstructor"
|
||||
import "game/src/konstructor"
|
||||
|
||||
const (
|
||||
Level1Playground1 konstructor.PlaygroundID = "level_1_playground_1"
|
||||
@@ -2,7 +2,7 @@ package domain
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"game/konstructor"
|
||||
"game/src/konstructor"
|
||||
"os"
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package domain
|
||||
|
||||
import "game/konstructor"
|
||||
import "game/src/konstructor"
|
||||
|
||||
func (d *Domain) Process(options konstructor.DomainProcessArgs) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package domain
|
||||
|
||||
import "game/konstructor"
|
||||
import "game/src/konstructor"
|
||||
|
||||
const (
|
||||
SwordItemType konstructor.ItemTypeMapKey = "sword"
|
||||
@@ -1,6 +1,6 @@
|
||||
package domain
|
||||
|
||||
import "game/konstructor"
|
||||
import "game/src/konstructor"
|
||||
|
||||
const (
|
||||
TestNPCType konstructor.NPCTypeMapKey = "test_npc"
|
||||
@@ -1,6 +1,6 @@
|
||||
package domain
|
||||
|
||||
import "game/konstructor"
|
||||
import "game/src/konstructor"
|
||||
|
||||
const (
|
||||
TestPlatformType konstructor.PlatformTypeMapKey = "test_platform"
|
||||
38
src/domain/type.player.go
Normal file
38
src/domain/type.player.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package domain
|
||||
|
||||
import "game/src/konstructor"
|
||||
|
||||
const (
|
||||
DefaultPlayerType konstructor.PlayerTypeID = "default"
|
||||
)
|
||||
|
||||
func (d *Domain) InitPlayer() {
|
||||
d.Players = []konstructor.Player{
|
||||
{
|
||||
ID: "default",
|
||||
Type: konstructor.PlayerType{
|
||||
ID: DefaultPlayerType,
|
||||
Render: konstructor.Render{
|
||||
Image: konstructor.GetPlayerTypeImagePath(DefaultPlayerType),
|
||||
},
|
||||
},
|
||||
Position: konstructor.Position{
|
||||
X: 70,
|
||||
Y: 70,
|
||||
Z: 1,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Domain) GetPlayers() []konstructor.Player {
|
||||
return d.Players
|
||||
}
|
||||
|
||||
func (d *Domain) GetPlayer(index int) konstructor.Player {
|
||||
return d.Players[index]
|
||||
}
|
||||
|
||||
func (d *Domain) GetDefaultPlayer() konstructor.Player {
|
||||
return d.Players[0]
|
||||
}
|
||||
81
src/konstructor/config.go
Normal file
81
src/konstructor/config.go
Normal file
@@ -0,0 +1,81 @@
|
||||
package konstructor
|
||||
|
||||
import "image/color"
|
||||
|
||||
// Windows resolution set
|
||||
type ResolutionSet struct {
|
||||
Width int
|
||||
Height int
|
||||
}
|
||||
|
||||
// QVGA resolution set
|
||||
var QVGAResolutionSet = ResolutionSet{
|
||||
Width: 320,
|
||||
Height: 240,
|
||||
}
|
||||
|
||||
// VGA resolution set
|
||||
var VGAResolutionSet = ResolutionSet{
|
||||
Width: 640,
|
||||
Height: 480,
|
||||
}
|
||||
|
||||
// SVGA resolution set
|
||||
var SVGAResolutionSet = ResolutionSet{
|
||||
Width: 800,
|
||||
Height: 600,
|
||||
}
|
||||
|
||||
// XGA resolution set
|
||||
var XGAResolutionSet = ResolutionSet{
|
||||
Width: 1024,
|
||||
Height: 768,
|
||||
}
|
||||
|
||||
// List of resolution sets
|
||||
var ResolutionSets = []ResolutionSet{
|
||||
QVGAResolutionSet,
|
||||
VGAResolutionSet,
|
||||
SVGAResolutionSet,
|
||||
XGAResolutionSet,
|
||||
}
|
||||
|
||||
// Keyboard layout configuration
|
||||
type KeyMap struct {
|
||||
Up any
|
||||
Down any
|
||||
Right any
|
||||
Left any
|
||||
Action0 any
|
||||
Action1 any
|
||||
Action2 any
|
||||
Action3 any
|
||||
}
|
||||
|
||||
// Screen configuration
|
||||
type ScreenConfig struct {
|
||||
Width int
|
||||
Height int
|
||||
Scale int
|
||||
}
|
||||
|
||||
// Header configuration
|
||||
type HeaderConfig struct {
|
||||
BackgroundColor color.Color
|
||||
Height int
|
||||
FontLayout FontLayout
|
||||
}
|
||||
|
||||
// Game configuration
|
||||
type Config struct {
|
||||
Name string
|
||||
Screen *ScreenConfig
|
||||
Header *HeaderConfig
|
||||
KeyMap KeyMap
|
||||
}
|
||||
|
||||
// Set screen resolution config to a resolution set
|
||||
func (c *Config) SetResolution(set ResolutionSet) {
|
||||
c.Screen.Width = set.Width
|
||||
c.Screen.Height = set.Height
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func (e *Engine) WatchKeyPress() {
|
||||
values := reflect.ValueOf(e.Settings.KeyMap)
|
||||
values := reflect.ValueOf(e.Config.KeyMap)
|
||||
|
||||
for i := 0; i < values.NumField(); i++ {
|
||||
key := values.Field(i).Interface().(ebiten.Key)
|
||||
@@ -25,33 +25,33 @@ func (e *Engine) ClearKeyPresed() {
|
||||
}
|
||||
|
||||
func (e *Engine) UpPressed() bool {
|
||||
return e.PressedKey == e.Settings.KeyMap.Up.(ebiten.Key)
|
||||
return e.PressedKey == e.Config.KeyMap.Up.(ebiten.Key)
|
||||
}
|
||||
|
||||
func (e *Engine) DownPressed() bool {
|
||||
return e.PressedKey == e.Settings.KeyMap.Down.(ebiten.Key)
|
||||
return e.PressedKey == e.Config.KeyMap.Down.(ebiten.Key)
|
||||
}
|
||||
|
||||
func (e *Engine) RightPressed() bool {
|
||||
return e.PressedKey == e.Settings.KeyMap.Right.(ebiten.Key)
|
||||
return e.PressedKey == e.Config.KeyMap.Right.(ebiten.Key)
|
||||
}
|
||||
|
||||
func (e *Engine) LeftPressed() bool {
|
||||
return e.PressedKey == e.Settings.KeyMap.Left.(ebiten.Key)
|
||||
return e.PressedKey == e.Config.KeyMap.Left.(ebiten.Key)
|
||||
}
|
||||
|
||||
func (e *Engine) Action0Pressed() bool {
|
||||
return e.PressedKey == e.Settings.KeyMap.Action0.(ebiten.Key)
|
||||
return e.PressedKey == e.Config.KeyMap.Action0.(ebiten.Key)
|
||||
}
|
||||
|
||||
func (e *Engine) Action1Pressed() bool {
|
||||
return e.PressedKey == e.Settings.KeyMap.Action1.(ebiten.Key)
|
||||
return e.PressedKey == e.Config.KeyMap.Action1.(ebiten.Key)
|
||||
}
|
||||
|
||||
func (e *Engine) Action2Pressed() bool {
|
||||
return e.PressedKey == e.Settings.KeyMap.Action2.(ebiten.Key)
|
||||
return e.PressedKey == e.Config.KeyMap.Action2.(ebiten.Key)
|
||||
}
|
||||
|
||||
func (e *Engine) Action3Pressed() bool {
|
||||
return e.PressedKey == e.Settings.KeyMap.Action3.(ebiten.Key)
|
||||
return e.PressedKey == e.Config.KeyMap.Action3.(ebiten.Key)
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package easy_ebitengine
|
||||
|
||||
import (
|
||||
"game/konstructor"
|
||||
"game/src/konstructor"
|
||||
"os"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
@@ -9,13 +9,13 @@ import (
|
||||
|
||||
type Engine struct {
|
||||
Domain konstructor.DomainInterface
|
||||
Settings *konstructor.Settings
|
||||
Config *konstructor.Config
|
||||
KContext *konstructor.KContext
|
||||
PressedKey ebiten.Key
|
||||
}
|
||||
|
||||
func (e *Engine) Layout(outsideWidth, outsideHeight int) (int, int) {
|
||||
return e.Settings.Screen.Width, e.Settings.Screen.Height
|
||||
return e.Config.Screen.Width, e.Config.Screen.Height
|
||||
}
|
||||
|
||||
func (e *Engine) Update(screen *ebiten.Image) error {
|
||||
@@ -1,7 +1,7 @@
|
||||
package easy_ebitengine
|
||||
|
||||
import (
|
||||
"game/konstructor"
|
||||
"game/src/konstructor"
|
||||
"log"
|
||||
|
||||
_ "image/png"
|
||||
@@ -1,7 +1,7 @@
|
||||
package easy_ebitengine
|
||||
|
||||
import (
|
||||
"game/konstructor"
|
||||
"game/src/konstructor"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
)
|
||||
@@ -14,10 +14,10 @@ func (ew *EngineWrapper) Init(options konstructor.EngineArgs) {
|
||||
ew.Engine = Engine{
|
||||
KContext: options.KContext,
|
||||
Domain: options.Domain,
|
||||
Settings: options.Settings,
|
||||
Config: options.Config,
|
||||
}
|
||||
ebiten.SetWindowSize(options.Settings.Screen.Width, options.Settings.Screen.Height)
|
||||
ebiten.SetWindowTitle(options.Settings.Name)
|
||||
ebiten.SetWindowSize(options.Config.Screen.Width, options.Config.Screen.Height)
|
||||
ebiten.SetWindowTitle(options.Config.Name)
|
||||
}
|
||||
|
||||
func (ew *EngineWrapper) Run() {
|
||||
@@ -25,7 +25,7 @@ func (e *Engine) DialogUpdate() {
|
||||
func (e *Engine) DialogDraw(screen *ebiten.Image) {
|
||||
dialog := e.Domain.GetDialog(e.KContext.ActiveDialog)
|
||||
|
||||
face := dialog.Layout.ChoiceFont.GetFontFace()
|
||||
face := dialog.Layout.ChoiceFont.GetFontFace(e.Config.Screen.Scale)
|
||||
|
||||
for i, choice := range dialog.Choices {
|
||||
offset := int(dialog.Layout.ChoiceFont.Size) * (i + 1)
|
||||
@@ -1,7 +1,7 @@
|
||||
package easy_ebitengine
|
||||
|
||||
import (
|
||||
"game/konstructor"
|
||||
"game/src/konstructor"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
)
|
||||
@@ -25,7 +25,7 @@ func (e *Engine) MenuUpdate() {
|
||||
|
||||
func (e *Engine) MenuDraw(screen *ebiten.Image) {
|
||||
menu := e.Domain.GetMenu(e.KContext.ActiveMenu)
|
||||
face := menu.Layout.MenuItemFont.GetFontFace()
|
||||
face := menu.Layout.MenuItemFont.GetFontFace(e.Config.Screen.Scale)
|
||||
|
||||
for i, menu_item := range menu.MenuItems {
|
||||
color := menu.GetMenuItemColor(i)
|
||||
41
src/konstructor/engines/easy_ebitengine/screen.playground.go
Normal file
41
src/konstructor/engines/easy_ebitengine/screen.playground.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package easy_ebitengine
|
||||
|
||||
import (
|
||||
"game/src/konstructor"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
)
|
||||
|
||||
func (e *Engine) PlaygroundUpdate() {
|
||||
level := e.Domain.GetLevel(e.KContext.CurrentLevel)
|
||||
e.Domain.Process(konstructor.DomainProcessArgs{
|
||||
Level: &level,
|
||||
KContext: e.KContext,
|
||||
})
|
||||
}
|
||||
|
||||
func (e *Engine) PlaygroundDraw(screen *ebiten.Image) {
|
||||
e.PlaygroundBackgroundDraw(screen)
|
||||
e.PlaygroundPlatformsDraw(screen)
|
||||
e.PlaygroundItemsDraw(screen)
|
||||
e.PlaygroundNPCsDraw(screen)
|
||||
e.PlaygroundDefaultPlayerDraw(screen)
|
||||
e.PlaygroundHeaderDraw(screen)
|
||||
}
|
||||
|
||||
func (e *Engine) PlaygroundBackgroundDraw(screen *ebiten.Image) {
|
||||
playground := e.GetPlayground()
|
||||
e.PlaygroundAssetDraw(screen, playground.Render, konstructor.Position{})
|
||||
}
|
||||
|
||||
func (e *Engine) GetPlayground() konstructor.Playground {
|
||||
level := e.Domain.GetLevel(e.KContext.CurrentLevel)
|
||||
return level.Playgrounds[e.KContext.CurrentPlayground]
|
||||
}
|
||||
|
||||
func (e *Engine) PlaygroundAssetDraw(screen *ebiten.Image, render konstructor.Render, position konstructor.Position) {
|
||||
geoM := ebiten.GeoM{}
|
||||
geoM.Translate(float64(position.X), float64(position.Y))
|
||||
geoM.Scale(float64(e.Config.Screen.Scale), float64(e.Config.Screen.Scale))
|
||||
screen.DrawImage(e.GetImage(render), &ebiten.DrawImageOptions{GeoM: geoM})
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package easy_ebitengine
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"game/src/konstructor"
|
||||
"image/color"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/text"
|
||||
)
|
||||
|
||||
func (e *Engine) PlaygroundHeaderDraw(screen *ebiten.Image) {
|
||||
e.PlaygroundHeaderBackgroundDraw(screen)
|
||||
e.PlaygroundHeaderTextDraw(screen)
|
||||
}
|
||||
|
||||
func (e *Engine) PlaygroundHeaderBackgroundDraw(screen *ebiten.Image) {
|
||||
background, _ := ebiten.NewImage(e.Config.Screen.Width, e.Config.Header.Height, ebiten.FilterDefault)
|
||||
background.Fill(e.Config.Header.BackgroundColor)
|
||||
geoM := ebiten.GeoM{}
|
||||
geoM.Scale(float64(e.Config.Screen.Scale), float64(e.Config.Screen.Scale))
|
||||
screen.DrawImage(background, &ebiten.DrawImageOptions{GeoM: geoM})
|
||||
}
|
||||
|
||||
func (e *Engine) PlaygroundHeaderTextDraw(screen *ebiten.Image) {
|
||||
face := e.Config.Header.FontLayout.GetFontFace(e.Config.Screen.Scale)
|
||||
header_text := fmt.Sprint(e.Config.Name, " LIVES ", e.KContext.LiveCount, " LEVEL ", e.KContext.CurrentLevel)
|
||||
|
||||
offset := getTopOffset(e.Config)
|
||||
text.Draw(screen, header_text, face, 10, offset, color.Black)
|
||||
}
|
||||
|
||||
func getTopOffset(config *konstructor.Config) int {
|
||||
size := int(config.Header.FontLayout.Size) * config.Screen.Scale
|
||||
height := config.Header.Height * config.Screen.Scale
|
||||
return (height-size)/2 + size
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package easy_ebitengine
|
||||
|
||||
import "github.com/hajimehoshi/ebiten"
|
||||
|
||||
func (e *Engine) PlaygroundItemsDraw(screen *ebiten.Image) {
|
||||
playground := e.GetPlayground()
|
||||
for _, item := range playground.Items {
|
||||
e.PlaygroundAssetDraw(screen, item.Type.Render, item.Position)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package easy_ebitengine
|
||||
|
||||
import "github.com/hajimehoshi/ebiten"
|
||||
|
||||
func (e *Engine) PlaygroundNPCsDraw(screen *ebiten.Image) {
|
||||
playground := e.GetPlayground()
|
||||
for _, npc := range playground.NPCs {
|
||||
e.PlaygroundAssetDraw(screen, npc.Type.Render, npc.Position)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package easy_ebitengine
|
||||
|
||||
import "github.com/hajimehoshi/ebiten"
|
||||
|
||||
func (e *Engine) PlaygroundPlatformsDraw(screen *ebiten.Image) {
|
||||
playground := e.GetPlayground()
|
||||
for _, platform := range playground.Platforms {
|
||||
e.PlaygroundAssetDraw(screen, platform.Type.Render, platform.Position)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package easy_ebitengine
|
||||
|
||||
import "github.com/hajimehoshi/ebiten"
|
||||
|
||||
func (e *Engine) PlaygroundDefaultPlayerDraw(screen *ebiten.Image) {
|
||||
player := e.Domain.GetDefaultPlayer()
|
||||
e.PlaygroundAssetDraw(screen, player.Type.Render, player.Position)
|
||||
}
|
||||
81
src/konstructor/interface.domain.go
Normal file
81
src/konstructor/interface.domain.go
Normal file
@@ -0,0 +1,81 @@
|
||||
package konstructor
|
||||
|
||||
// Base fields for Domain layer.
|
||||
// You need to include this of your game's domain struct
|
||||
type DomainBaseFields struct {
|
||||
MenuMap MenuMap
|
||||
DialogMap DialogMap
|
||||
Levels []Level
|
||||
Players []Player
|
||||
PlatformTypeMap PlatformTypeMap
|
||||
ItemTypeMap ItemTypeMap
|
||||
NPCTypeMap NPCTypeMap
|
||||
}
|
||||
|
||||
// Domain interface.
|
||||
// You need to implement this interface in your game's domain struct
|
||||
type DomainInterface interface {
|
||||
// Domain initialization. This variable will invoke only once when the game starts
|
||||
Init()
|
||||
|
||||
// Return with the default KContext object
|
||||
GetInitialKContext() *KContext
|
||||
// Return with the default config object
|
||||
GetInitialConfig() *Config
|
||||
|
||||
// Return with the menu map
|
||||
GetMenuMap() MenuMap
|
||||
// Return with a specific menu
|
||||
GetMenu(name MenuMapKey) Menu
|
||||
// Owerride a specific menu
|
||||
SetMenu(name MenuMapKey, menu Menu)
|
||||
|
||||
// Return with the dialog map
|
||||
GetDialogMap() DialogMap
|
||||
// Return with a specific dialog
|
||||
GetDialog(name DialogMapKey) Dialog
|
||||
// Override a specific menu
|
||||
SetDialog(name DialogMapKey, menu Dialog)
|
||||
|
||||
// Get levels
|
||||
GetLevels() []Level
|
||||
// Get a specific level
|
||||
GetLevel(index int) Level
|
||||
|
||||
// Get players for multiplayer game
|
||||
GetPlayers() []Player
|
||||
// Get a specific player for multiplayer game
|
||||
GetPlayer(index int) Player
|
||||
// Get the player for simple player game
|
||||
GetDefaultPlayer() Player
|
||||
|
||||
// Return with the platform type map
|
||||
GetPlatformTypeMap() PlatformTypeMap
|
||||
// Return with a specific platform type
|
||||
GetPlatformType(name PlatformTypeMapKey) PlatformType
|
||||
|
||||
// Return with the item type map
|
||||
GetItemTypeMap() ItemTypeMap
|
||||
// Return with a specific item type
|
||||
GetItemType(name ItemTypeMapKey) ItemType
|
||||
|
||||
// Return with the NPC type map
|
||||
GetNPCTypeMap() NPCTypeMap
|
||||
// Return with a specific NPC type
|
||||
GetNPCType(name NPCTypeMapKey) NPCType
|
||||
|
||||
// Add item to inventory
|
||||
AddToInventory(item *Item) bool
|
||||
// Remove item from inventory
|
||||
RemoveFromInventory(item *Item) bool
|
||||
// Use inventory item
|
||||
UseInventoryItem(item *Item) bool
|
||||
|
||||
// Process game flow by Domain layer
|
||||
Process(DomainProcessArgs)
|
||||
}
|
||||
|
||||
type DomainProcessArgs struct {
|
||||
Level *Level
|
||||
KContext *KContext
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
package konstructor
|
||||
|
||||
// Initial arguments of an engine
|
||||
type EngineArgs struct {
|
||||
Domain DomainInterface
|
||||
KContext *KContext
|
||||
Settings *Settings
|
||||
Config *Config
|
||||
}
|
||||
|
||||
// Engine wrapper interface. You need to implement to this for your EntityWrapper, which can run your game engine
|
||||
type EngineWrapperInterface interface {
|
||||
Init(options EngineArgs)
|
||||
Run()
|
||||
@@ -1,18 +1,17 @@
|
||||
package konstructor
|
||||
|
||||
// Framework context (state)
|
||||
type KContext struct {
|
||||
ScreenType ScreenType
|
||||
ActiveMenu MenuMapKey
|
||||
ActiveDialog DialogMapKey
|
||||
CurrentLevel int
|
||||
CurrentPlayground int
|
||||
Players []Player
|
||||
}
|
||||
|
||||
func (c *KContext) getPrimaryPlayer() Player {
|
||||
return c.Players[0]
|
||||
Multiplayer bool
|
||||
LiveCount int
|
||||
}
|
||||
|
||||
// Check the current screen type
|
||||
func (c *KContext) ScreenTypeIs(name ScreenType) bool {
|
||||
return c.ScreenType == name
|
||||
}
|
||||
@@ -1,18 +1,19 @@
|
||||
// Game framework inspired by AGI
|
||||
package konstructor
|
||||
|
||||
// Main struct of framework
|
||||
type Konstructor struct {
|
||||
Domain DomainInterface
|
||||
KContext *KContext
|
||||
Settings *Settings
|
||||
EngineWrapper EngineWrapperInterface
|
||||
}
|
||||
|
||||
// Framework initialization
|
||||
func (k Konstructor) Init() {
|
||||
k.Domain.Init()
|
||||
k.EngineWrapper.Init(EngineArgs{
|
||||
Domain: k.Domain,
|
||||
KContext: k.KContext,
|
||||
Settings: k.Settings,
|
||||
KContext: k.Domain.GetInitialKContext(),
|
||||
Config: k.Domain.GetInitialConfig(),
|
||||
})
|
||||
k.EngineWrapper.Run()
|
||||
}
|
||||
@@ -8,6 +8,10 @@ import (
|
||||
"golang.org/x/image/font/opentype"
|
||||
)
|
||||
|
||||
// Font name type for function input validation
|
||||
type FontName string
|
||||
|
||||
// Font preset
|
||||
type FontLayout struct {
|
||||
Path string
|
||||
DPI float64
|
||||
@@ -17,17 +21,23 @@ type FontLayout struct {
|
||||
cachedFontFace font.Face
|
||||
}
|
||||
|
||||
func (fl *FontLayout) GetFontFace() font.Face {
|
||||
// Get font face from the preset
|
||||
func (fl *FontLayout) GetFontFace(scale int) font.Face {
|
||||
if fl.cachedFontFace != nil {
|
||||
return fl.cachedFontFace
|
||||
}
|
||||
file, _ := ioutil.ReadFile(fl.Path)
|
||||
true_type, _ := opentype.Parse(file)
|
||||
font_face, _ := opentype.NewFace(true_type, &opentype.FaceOptions{
|
||||
Size: fl.DPI,
|
||||
DPI: fl.Size,
|
||||
Size: fl.Size * float64(scale),
|
||||
DPI: fl.DPI,
|
||||
Hinting: font.HintingVertical,
|
||||
})
|
||||
fl.cachedFontFace = font_face
|
||||
return font_face
|
||||
}
|
||||
|
||||
// Helper, which return the path of font
|
||||
func GetFontPath(name FontName) string {
|
||||
return "assets/fonts/" + string(name) + ".ttf"
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"log"
|
||||
)
|
||||
|
||||
// Element render options
|
||||
type Render struct {
|
||||
Image string
|
||||
Width int
|
||||
@@ -15,6 +16,7 @@ type Render struct {
|
||||
cachedImage image.Image
|
||||
}
|
||||
|
||||
// Get image object from image path
|
||||
func (ro *Render) GetImage() image.Image {
|
||||
if ro.cachedImage != nil {
|
||||
return ro.cachedImage
|
||||
@@ -1,21 +1,26 @@
|
||||
package konstructor
|
||||
|
||||
// Object type type for function input validation
|
||||
type ObjectType string
|
||||
|
||||
const (
|
||||
ItemObjectType ObjectType = "item"
|
||||
NPCObjectType ObjectType = "npc"
|
||||
PlatformObjectType ObjectType = "platform"
|
||||
PlayerObjectType ObjectType = "player"
|
||||
)
|
||||
|
||||
// Map of object type's directories
|
||||
type ObjectDirectoryMap map[ObjectType]string
|
||||
|
||||
var ObjectDirectories = ObjectDirectoryMap{
|
||||
ItemObjectType: "items",
|
||||
NPCObjectType: "npcs",
|
||||
PlatformObjectType: "platforms",
|
||||
PlayerObjectType: "players",
|
||||
}
|
||||
|
||||
// Return with the path of a specific object type asset directory
|
||||
func GetObjectDirectory(name ObjectType) string {
|
||||
return "assets/images/" + ObjectDirectories[name] + "/"
|
||||
}
|
||||
@@ -4,17 +4,20 @@ type ItemTypeMapKey string
|
||||
|
||||
type ItemTypeMap map[ItemTypeMapKey]ItemType
|
||||
|
||||
// Type of item
|
||||
type ItemType struct {
|
||||
ID string
|
||||
Render Render
|
||||
}
|
||||
|
||||
// Playground usable item, which can be put in the Inventory
|
||||
type Item struct {
|
||||
ID string
|
||||
Type ItemType
|
||||
Position Position
|
||||
}
|
||||
|
||||
// Helper, which return with the path of a specific item type
|
||||
func GetItemTypeImagePath(name ItemTypeMapKey) string {
|
||||
return GetObjectDirectory(ItemObjectType) + string(name) + ".png"
|
||||
}
|
||||
@@ -15,6 +15,7 @@ type NPC struct {
|
||||
Position Position
|
||||
}
|
||||
|
||||
// Helper, which return with the path of a specific NPC type
|
||||
func GetNPCTypeImagePath(name NPCTypeMapKey) string {
|
||||
return GetObjectDirectory(NPCObjectType) + string(name) + ".png"
|
||||
}
|
||||
@@ -15,6 +15,7 @@ type Platform struct {
|
||||
Position Position
|
||||
}
|
||||
|
||||
// Helper, which return with the path of a specific platform type
|
||||
func GetPlatformTypeImagePath(name PlatformTypeMapKey) string {
|
||||
return GetObjectDirectory(PlatformObjectType) + string(name) + ".png"
|
||||
}
|
||||
33
src/konstructor/object.player.go
Normal file
33
src/konstructor/object.player.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package konstructor
|
||||
|
||||
type PlayerTypeID string
|
||||
|
||||
type InventoryItem struct {
|
||||
Item Item
|
||||
Used bool
|
||||
Active bool
|
||||
}
|
||||
|
||||
// Player inventory
|
||||
type Inventory struct {
|
||||
Items []InventoryItem
|
||||
}
|
||||
|
||||
// Player type
|
||||
type PlayerType struct {
|
||||
ID PlayerTypeID
|
||||
Render Render
|
||||
}
|
||||
|
||||
// Playable character
|
||||
type Player struct {
|
||||
ID string
|
||||
Type PlayerType
|
||||
Position Position
|
||||
Inventory Inventory
|
||||
}
|
||||
|
||||
// Helper, which return with the path of a specific player type
|
||||
func GetPlayerTypeImagePath(name PlayerTypeID) string {
|
||||
return GetObjectDirectory(PlayerObjectType) + string(name) + ".png"
|
||||
}
|
||||
@@ -6,23 +6,27 @@ type DialogMapKey string
|
||||
|
||||
type DialogMap map[DialogMapKey]Dialog
|
||||
|
||||
// Layout of dialog
|
||||
type DialogLayout struct {
|
||||
Render Render
|
||||
ChoiceFont FontLayout
|
||||
}
|
||||
|
||||
// Choicable answer in a dialog (by player)
|
||||
type DialogChoice struct {
|
||||
ID string
|
||||
Label string
|
||||
Handler func()
|
||||
}
|
||||
|
||||
// Dialog between player and NPC
|
||||
type Dialog struct {
|
||||
CurrentSelected int
|
||||
Layout DialogLayout
|
||||
Choices []DialogChoice
|
||||
}
|
||||
|
||||
// Return with color of choice
|
||||
func (dialog *Dialog) GetChoiceColor(i int) color.Color {
|
||||
if dialog.CurrentSelected == i {
|
||||
return dialog.Layout.ChoiceFont.SelectedColor
|
||||
@@ -4,24 +4,29 @@ import "image/color"
|
||||
|
||||
type MenuMapKey string
|
||||
|
||||
// Map of menus
|
||||
type MenuMap map[MenuMapKey]Menu
|
||||
|
||||
// Layout of menu
|
||||
type MenuLayout struct {
|
||||
MenuItemFont FontLayout
|
||||
}
|
||||
|
||||
// Menu item
|
||||
type MenuItem struct {
|
||||
ID string
|
||||
Label string
|
||||
Handler func()
|
||||
}
|
||||
|
||||
// Game menu
|
||||
type Menu struct {
|
||||
CurrentSelected int
|
||||
Layout MenuLayout
|
||||
MenuItems []MenuItem
|
||||
}
|
||||
|
||||
// Return with the color of menu item
|
||||
func (menu *Menu) GetMenuItemColor(i int) color.Color {
|
||||
if menu.CurrentSelected == i {
|
||||
return menu.Layout.MenuItemFont.SelectedColor
|
||||
@@ -1,13 +1,16 @@
|
||||
package konstructor
|
||||
|
||||
// ID of playground for method input validation
|
||||
type PlaygroundID string
|
||||
|
||||
// Position configuration
|
||||
type Position struct {
|
||||
X int
|
||||
Y int
|
||||
Z int
|
||||
}
|
||||
|
||||
// Displayable section of a level
|
||||
type Playground struct {
|
||||
ID PlaygroundID
|
||||
Render Render
|
||||
@@ -16,12 +19,14 @@ type Playground struct {
|
||||
Items []Item
|
||||
}
|
||||
|
||||
// Game level
|
||||
type Level struct {
|
||||
ID string
|
||||
Name string
|
||||
Playgrounds []Playground
|
||||
}
|
||||
|
||||
// Return with the path of a specific playground background
|
||||
func GetPlaygroundImagePath(name PlaygroundID) string {
|
||||
return "assets/images/playgrounds/" + string(name) + ".png"
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package konstructor
|
||||
|
||||
// Type of screen type for method input validation
|
||||
type ScreenType string
|
||||
|
||||
const (
|
||||
Reference in New Issue
Block a user