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) {
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

@@ -4,6 +4,7 @@ type KContext struct {
ScreenType ScreenType
ScreenValue string
CurrentLevel int
CurrentPlayground int
Players []Player
}

View File

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

19
main.go
View File

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