Skip to content

Commit

Permalink
vmars: fix hardcoded start position on sim reload
Browse files Browse the repository at this point in the history
  • Loading branch information
bobertlo committed Nov 17, 2024
1 parent d26b166 commit df807f0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
26 changes: 19 additions & 7 deletions cmd/vmars/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import (
)

type Game struct {
sim gmars.ReportingSimulator
rec gmars.StateRecorder
running bool
finished bool
speedStep int
counter int
sim gmars.ReportingSimulator
config gmars.SimulatorConfig
fixedStart int
rec gmars.StateRecorder
running bool
finished bool
speedStep int
counter int
}

func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
Expand All @@ -42,7 +44,17 @@ func (g *Game) handleInput() {
} else if inpututil.IsKeyJustPressed(ebiten.KeyR) {
g.sim.Reset()
g.sim.SpawnWarrior(0, 0)
g.sim.SpawnWarrior(1, gmars.Address(rand.Intn(7000)+200))

w2start := g.fixedStart
if w2start == 0 {
minStart := 2 * g.config.Length
maxStart := g.config.CoreSize - g.config.Length - 1
startRange := maxStart - minStart
w2start = rand.Intn(int(startRange)+1) + int(minStart)
}

g.sim.SpawnWarrior(1, gmars.Address(w2start))

g.finished = false
} else if inpututil.IsKeyJustPressed(ebiten.KeyDown) {
g.slowDown()
Expand Down
8 changes: 5 additions & 3 deletions cmd/vmars/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,11 @@ func main() {
sim.SpawnWarrior(1, gmars.Address(w2start))

game := &Game{
sim: sim,
rec: *rec,
speedStep: defaultSpeedStep,
sim: sim,
config: config,
rec: *rec,
speedStep: defaultSpeedStep,
fixedStart: *fixedFlag,
}

ebiten.SetWindowSize(screenWidth, screenHeight)
Expand Down

0 comments on commit df807f0

Please sign in to comment.