playground and object drawer skeleton

This commit is contained in:
2023-07-06 16:35:14 +02:00
parent 701205ac82
commit 2fcf6f4fdc
11 changed files with 56 additions and 20 deletions

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 226 B

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@@ -29,6 +29,22 @@ func (d *Domain) InitLevel() {
}, },
}, },
}, },
{
ID: "test_object2",
Position: entity.Position{
X: 50,
Y: 50,
Z: 0,
},
Type: entity.ObjectType{
ID: "test_object_type",
Render: entity.Render{
Image: "assets/images/objects/test_object.png",
Width: 30,
Height: 30,
},
},
},
}, },
}, },
}, },

View File

@@ -15,5 +15,30 @@ func (e *Engine) PlaygroundUpdate() {
} }
func (e *Engine) PlaygroundDraw(screen *ebiten.Image) { func (e *Engine) PlaygroundDraw(screen *ebiten.Image) {
e.Domain.GetLevel(e.KContext.CurrentLevel) e.PlaygroundBackgroundDraw(screen)
e.PlaygroundObjectsDraw(screen)
}
func (e *Engine) PlaygroundBackgroundDraw(screen *ebiten.Image) {
playground := e.GetPlayground()
render := playground.Render
screen.DrawImage(e.GetImage(render), &ebiten.DrawImageOptions{})
}
func (e *Engine) PlaygroundObjectsDraw(screen *ebiten.Image) {
playground := e.GetPlayground()
geoM := ebiten.GeoM{}
for _, object := range playground.Objects {
render := object.Type.Render
geoM.Reset()
geoM.Translate(float64(object.Position.X), float64(object.Position.Y))
screen.DrawImage(e.GetImage(render), &ebiten.DrawImageOptions{
GeoM: geoM,
})
}
}
func (e *Engine) GetPlayground() entity.Playground {
level := e.Domain.GetLevel(e.KContext.CurrentLevel)
return level.Playgrounds[e.KContext.CurrentPlayground]
} }

View File

@@ -1,10 +1,11 @@
package entity package entity
type KContext struct { type KContext struct {
ScreenType ScreenType ScreenType ScreenType
ScreenValue string ScreenValue string
CurrentLevel int CurrentLevel int
Players []Player CurrentPlayground int
Players []Player
} }
func (c *KContext) getPrimaryPlayer() Player { func (c *KContext) getPrimaryPlayer() Player {

View File

@@ -14,6 +14,7 @@ type KeyMap struct {
type ScreenSettings struct { type ScreenSettings struct {
Width int Width int
Height int Height int
Scale int
} }
type Settings struct { type Settings struct {

23
main.go
View File

@@ -12,26 +12,19 @@ import (
func main() { func main() {
k := konstructor.Konstructor{ k := konstructor.Konstructor{
EngineWrapper: &engine.EngineWrapper{}, EngineWrapper: &engine.EngineWrapper{},
Domain: &domain.Domain{ Domain: &domain.Domain{},
Context: domain.Context{
PlayerState: domain.PlayerState{
Name: "Player One",
},
User: domain.User{
Name: "John Doe",
},
},
},
KContext: &entity.KContext{ KContext: &entity.KContext{
ScreenType: entity.MenuScreenType, ScreenType: entity.PlaygroundScreenType,
ScreenValue: "MainMenu", ScreenValue: "MainMenu",
CurrentLevel: 0, CurrentLevel: 0,
CurrentPlayground: 0,
}, },
Settings: &entity.Settings{ Settings: &entity.Settings{
Name: "Game", Name: "Game",
Screen: &entity.ScreenSettings{ Screen: &entity.ScreenSettings{
Width: 640, Width: 320,
Height: 480, Height: 240,
Scale: 2,
}, },
KeyMap: entity.KeyMap{ KeyMap: entity.KeyMap{
Up: ebiten.KeyUp, Up: ebiten.KeyUp,