Added bias towards picking tiles further away (hearts/stars) or closer (monsters) when difficulty increases.
Added minimum distance (from player) for spawning things.
This commit is contained in:
parent
ad8a540af2
commit
45b64a46ec
30
level.go
30
level.go
@ -2,6 +2,7 @@ package tins2021
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"sort"
|
||||
|
||||
"opslag.de/schobers/geom"
|
||||
)
|
||||
@ -126,14 +127,30 @@ func (l *Level) Randomize(difficulty int, stars int) {
|
||||
for pos := range l.Tiles {
|
||||
positions = append(positions, pos)
|
||||
}
|
||||
distances := l.Tiles.Distances(l.Player)
|
||||
sort.Slice(positions, func(i, j int) bool {
|
||||
return distances[positions[i]] < distances[positions[j]]
|
||||
})
|
||||
pick := func(bias int) geom.Point { // bias towards far away [0..100]
|
||||
if bias > 100 {
|
||||
bias = 100
|
||||
}
|
||||
if bias < 0 {
|
||||
bias = 0
|
||||
}
|
||||
n := len(positions)
|
||||
const min = 4
|
||||
from := min + bias*(n-min)/(2*(n-min)) // never pick first
|
||||
return positions[from+rand.Intn(n-from)]
|
||||
}
|
||||
|
||||
flip := difficulty * len(l.Tiles) / 200
|
||||
if flip > len(l.Tiles)/2 {
|
||||
flip = len(l.Tiles) / 2
|
||||
}
|
||||
for ; flip > 0; flip-- {
|
||||
for {
|
||||
i := rand.Intn(len(positions))
|
||||
pos := positions[i]
|
||||
pos := pick(0)
|
||||
if l.Tiles[pos].Inversed {
|
||||
continue
|
||||
}
|
||||
@ -146,8 +163,7 @@ func (l *Level) Randomize(difficulty int, stars int) {
|
||||
}
|
||||
l.Stars = stars
|
||||
for stars > 0 {
|
||||
i := rand.Intn(len(positions))
|
||||
pos := positions[i]
|
||||
pos := pick(difficulty)
|
||||
if l.Tiles[pos].Occupied() {
|
||||
continue
|
||||
}
|
||||
@ -156,8 +172,7 @@ func (l *Level) Randomize(difficulty int, stars int) {
|
||||
}
|
||||
hearts := 1 + (100-difficulty)/50 // [3..1] (only difficulty has 3 hearts)
|
||||
for hearts > 0 {
|
||||
i := rand.Intn(len(positions))
|
||||
pos := positions[i]
|
||||
pos := pick(difficulty)
|
||||
if l.Tiles[pos].Occupied() {
|
||||
continue
|
||||
}
|
||||
@ -168,8 +183,7 @@ func (l *Level) Randomize(difficulty int, stars int) {
|
||||
minRandomMonster := (100-difficulty)*80/100 + 10 // [90..10]
|
||||
minChaserMonster := (100-difficulty)*50/100 + 50 // [100..50]
|
||||
for monsters > 0 {
|
||||
i := rand.Intn(len(positions))
|
||||
pos := positions[i]
|
||||
pos := pick(100 - difficulty)
|
||||
curr := l.Monsters[pos]
|
||||
if l.Tiles[pos].Occupied() || curr != nil {
|
||||
continue
|
||||
|
Loading…
Reference in New Issue
Block a user