Add beach chairs

This commit is contained in:
Trevor Slocum 2022-06-12 21:02:22 -07:00
parent 723f50dad1
commit 2f3ec2cdf2
3 changed files with 48 additions and 2 deletions

View File

@ -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)
}

View File

@ -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

View File

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