Added second (bigger) level.
Level is automatically scaled to available space.
This commit is contained in:
parent
3d4df7e956
commit
efea350ae9
@ -151,7 +151,7 @@ func (g *game) loadAssets() error {
|
|||||||
log.Printf("Loaded %d textures.\n", len(g.ctx.Textures))
|
log.Printf("Loaded %d textures.\n", len(g.ctx.Textures))
|
||||||
|
|
||||||
log.Println("Loading levels...")
|
log.Println("Loading levels...")
|
||||||
err = g.loadLevels("1")
|
err = g.loadLevels("1", "2")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ type mainMenu struct {
|
|||||||
func (m *mainMenu) Enter(ctx *Context) error {
|
func (m *mainMenu) Enter(ctx *Context) error {
|
||||||
m.ctx = ctx
|
m.ctx = ctx
|
||||||
m.Init()
|
m.Init()
|
||||||
m.Add("Play", func() { m.ctx.Navigation.playLevel("1") })
|
m.Add("Play", func() { m.ctx.Navigation.playLevel("2") })
|
||||||
m.Add("Settings", func() { m.ctx.Navigation.changeSettings() })
|
m.Add("Settings", func() { m.ctx.Navigation.changeSettings() })
|
||||||
m.Add("Quit", func() { m.ctx.Navigation.quit() })
|
m.Add("Quit", func() { m.ctx.Navigation.quit() })
|
||||||
return nil
|
return nil
|
||||||
|
@ -13,7 +13,8 @@ import (
|
|||||||
type playLevel struct {
|
type playLevel struct {
|
||||||
alui.ControlBase
|
alui.ControlBase
|
||||||
|
|
||||||
ctx *Context
|
ctx *Context
|
||||||
|
init bool
|
||||||
|
|
||||||
menu *alui.Menu
|
menu *alui.Menu
|
||||||
showMenu bool
|
showMenu bool
|
||||||
@ -84,16 +85,13 @@ func (l *playLevel) Enter(ctx *Context) error {
|
|||||||
l.menu.Add("Quit to desktop", func() { l.ctx.Navigation.quit() })
|
l.menu.Add("Quit to desktop", func() { l.ctx.Navigation.quit() })
|
||||||
l.menu.OnEscape = func() { l.showMenu = false }
|
l.menu.OnEscape = func() { l.showMenu = false }
|
||||||
|
|
||||||
|
l.init = true
|
||||||
l.state.Init(l.ctx, l.name)
|
l.state.Init(l.ctx, l.name)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *playLevel) Leave() {}
|
func (l *playLevel) Leave() {}
|
||||||
|
|
||||||
func (l *playLevel) posToScreen(p geom.Point) geom.PointF32 {
|
|
||||||
return l.posToScreenF32(p.ToF32(), 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *playLevel) posToScreenF32(p geom.PointF32, z float32) geom.PointF32 {
|
func (l *playLevel) posToScreenF32(p geom.PointF32, z float32) geom.PointF32 {
|
||||||
pos := l.posToCabinet(p.Add2D(.5, .5)).Add2D(0, z)
|
pos := l.posToCabinet(p.Add2D(.5, .5)).Add2D(0, z)
|
||||||
return pos.Mul(l.scale).Add(l.offset)
|
return pos.Mul(l.scale).Add(l.offset)
|
||||||
@ -118,13 +116,32 @@ func (l *playLevel) posToCabinet(p geom.PointF32) geom.PointF32 {
|
|||||||
// Offset between vertical tiles: -25,40
|
// Offset between vertical tiles: -25,40
|
||||||
|
|
||||||
func (l *playLevel) Layout(ctx *alui.Context, bounds geom.RectangleF32) {
|
func (l *playLevel) Layout(ctx *alui.Context, bounds geom.RectangleF32) {
|
||||||
l.scale = bounds.Dy() / 1080
|
if l.init {
|
||||||
l.offset = geom.PointF32{}
|
l.scale = 1
|
||||||
|
l.offset = geom.PointF32{}
|
||||||
|
|
||||||
level := l.state.Level()
|
level := l.state.Level()
|
||||||
tilesCenter := l.posToScreenF32(geom.PtF32(.5*float32(level.width), .5*float32(level.height)), 0)
|
var contentCenter = l.posToScreenF32(geom.PtF32(.5*float32(level.width), .5*float32(level.height)), 0)
|
||||||
center := bounds.Center()
|
var content = geom.RectF32(contentCenter.X, contentCenter.Y, contentCenter.X, contentCenter.Y)
|
||||||
l.offset = geom.PtF32(center.X-tilesCenter.X, center.Y-tilesCenter.Y)
|
for idx, tile := range l.state.Level().tiles {
|
||||||
|
if tile == tileNothing || tile == tileInvalid {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
pos := level.idxToPos(idx).ToF32()
|
||||||
|
bottomLeft := l.posToScreenF32(pos.Add2D(-1.5, 1.5), 100)
|
||||||
|
content.Min = geom.MinPtF32(content.Min, bottomLeft)
|
||||||
|
content.Max = geom.MaxPtF32(content.Max, bottomLeft)
|
||||||
|
topRight := l.posToScreenF32(pos.Add2D(1.5, -1.5), 0)
|
||||||
|
content.Min = geom.MinPtF32(content.Min, topRight)
|
||||||
|
content.Max = geom.MaxPtF32(content.Max, topRight)
|
||||||
|
}
|
||||||
|
l.scale = geom.Min32(bounds.Dx()/content.Dx(), bounds.Dy()/content.Dy())
|
||||||
|
|
||||||
|
contentCenter = content.Center().Mul(l.scale)
|
||||||
|
center := bounds.Center()
|
||||||
|
l.offset = geom.PtF32(center.X-contentCenter.X, center.Y-contentCenter.Y)
|
||||||
|
l.init = false
|
||||||
|
}
|
||||||
|
|
||||||
l.state.Tick(l.ctx.Tick)
|
l.state.Tick(l.ctx.Tick)
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,9 @@ type playLevelState struct {
|
|||||||
func (s *playLevelState) Entities() []*entity {
|
func (s *playLevelState) Entities() []*entity {
|
||||||
var entities []*entity
|
var entities []*entity
|
||||||
entities = append(entities, s.player)
|
entities = append(entities, s.player)
|
||||||
entities = append(entities, s.villain)
|
if s.villain != nil {
|
||||||
|
entities = append(entities, s.villain)
|
||||||
|
}
|
||||||
entities = append(entities, s.bricks...)
|
entities = append(entities, s.bricks...)
|
||||||
return entities
|
return entities
|
||||||
}
|
}
|
||||||
|
13
cmd/krampus19/res/levels/level2.txt
Normal file
13
cmd/krampus19/res/levels/level2.txt
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
level:
|
||||||
|
._._._._._._._._._._._._._._._._._._._._
|
||||||
|
._._._._._#_#_#_._._._._._._._._._._._._
|
||||||
|
._._._._._#B#_#_._._._._._._._._._._._._
|
||||||
|
._._._._._#_#_#B._._._._._._._._._._._._
|
||||||
|
._._._#_#_#B#_#B#_._._._._._._._._._._._
|
||||||
|
._._._#_._#_._._#_._._._._#X#_~_~_~_#_._
|
||||||
|
._#_#_#_._#_._._#_._._._._._._._~_~_#_._
|
||||||
|
._#_#B#_#_#B#_#_#_#_#_#_#_#_#_#_~_#_#_._
|
||||||
|
._._._._._#_._._._#_._#@._._._._#_#_._._
|
||||||
|
._._._._._#_#_#_#_#_._._._._._._._._._._
|
||||||
|
._._._._._._._._._._._._._._._._._._._._
|
||||||
|
:level
|
Loading…
Reference in New Issue
Block a user