diff --git a/asset/asset.go b/asset/asset.go index 307bc91..0e8089a 100644 --- a/asset/asset.go +++ b/asset/asset.go @@ -204,3 +204,11 @@ var allTrash = []*ebiten.Image{ func TrashImage() *ebiten.Image { return allTrash[rand.Intn(3)] } + +func BeachChairTop(c int) *ebiten.Image { + return FishTileXY(13+c, 0) +} + +func BeachChairBottom(c int) *ebiten.Image { + return FishTileXY(13+c, 1) +} diff --git a/game/game.go b/game/game.go index bfffaca..49b6158 100644 --- a/game/game.go +++ b/game/game.go @@ -99,7 +99,7 @@ func (g *game) Update() error { } world.World.Player.With(func(position *component.Position) { - position.X, position.Y = float64(rand.Intn(world.ScreenWidth/2)), world.ScreenHeight-system.TileWidth-float64(rand.Intn(100)) + position.X, position.Y = float64(rand.Intn(world.ScreenWidth/2)), world.ScreenHeight-system.TileWidth*2 }) world.World.CamX, world.World.CamY = 0, 0 diff --git a/world/section.go b/world/section.go index 395fd9a..09628f6 100644 --- a/world/section.go +++ b/world/section.go @@ -182,7 +182,7 @@ func (s *Section) Regenerate(lastShoreDepth int) { // Generate buildings. // TODO bag of random buildings - addBuildings := rand.Intn(14) + addBuildings := rand.Intn(4) for j := 0; j < addBuildings; j++ { specialBuilding := rand.Intn(4) == 0 @@ -236,6 +236,44 @@ func (s *Section) Regenerate(lastShoreDepth int) { break } } + + // Generate decorations. + const decorations = 4 + for i := 0; i < decorations; i++ { + for attempt := 0; attempt < attempts; attempt++ { + tx, ty := rand.Intn(SectionWidth/16), int(float64(rand.Intn(s.ShoreDepth-2))) + if !s.tileAvailable(tx, ty, false) || !s.tileAvailable(tx, ty+1, false) || !s.tileAvailable(tx-1, ty, false) || !s.tileAvailable(tx+1, ty, false) || !s.tileAvailable(tx-1, ty+1, false) || !s.tileAvailable(tx+1, ty+1, false) { + continue + } + + c := rand.Intn(8) + for j := 0; j < 2; j++ { + x, y := s.X+float64(tx)*16, s.Y+float64(ty+j)*16 + + e := gohan.NewEntity() + + e.AddComponent(&component.Position{ + X: x, + Y: y, + Z: level.LayerBuilding, + }) + + img := asset.BeachChairTop(c) + if j == 1 { + img = asset.BeachChairBottom(c) + } + + e.AddComponent(&component.Sprite{ + Image: img, + }) + + s.TileOccupied[ty+j][tx] = true + + s.Entities = append(s.Entities, e) + } + break + } + } } func (s *Section) canBuild(tiles [][][2]int, tx, ty int) bool {