diff --git a/TODO.md b/TODO.md index 005f412..1e8c089 100644 --- a/TODO.md +++ b/TODO.md @@ -8,8 +8,8 @@ - [ ] Change layout when playing in portrait mode. - [X] Fix wobble animation. - [ ] Add more unit tests? -- [ ] Fix z-fighting of monsters. -- [ ] Add exploding animation of monsters. +- [X] Fix z-fighting of monsters. +- [X] Add exploding animation of monsters. - [ ] Add audio settings (music & sound volume). - [X] Hearts must be saved as well for resume. - [ ] Add demo mode. diff --git a/cmd/tins2021/levelcontroller.go b/cmd/tins2021/levelcontroller.go index 844aa7c..c076af2 100644 --- a/cmd/tins2021/levelcontroller.go +++ b/cmd/tins2021/levelcontroller.go @@ -338,22 +338,29 @@ func (r levelController) Render(ctx ui.Context) { renderer.DrawTexturePoint(player, playerPosition.Add(centerTopSquare)) } - for pos, monsterType := range r.Level.Monsters { - tile := r.Level.Tiles[pos] - if tile == nil { - continue - } - texture := monsterTextures[monsterType.Type()] - _, platformPos := positionOfTile(pos) - if target, ok := r.Level.MonsterTargets[pos]; ok { - _, targetPlatformPos := positionOfTile(target) - dt := float32(r.MovingMonsters.Frame(pos)) / 50. - delta := targetPlatformPos.Sub(platformPos) - curve := geom.PtF32(0, .6*geom.Sin32(dt*geom.Pi)*textureWidth) - interpolatedPos := platformPos.Add(delta.Mul(dt)).Sub(curve) - texture.Draw(renderer, interpolatedPos.Add(propOffset), r.Animations["monster"].Frame(pos)) - } else { - texture.Draw(renderer, platformPos.Add(propOffset), r.Animations["monster"].Frame(pos)) + for y := r.Level.Bounds.Min.Y; y < r.Level.Bounds.Max.Y; y++ { + for x := r.Level.Bounds.Min.X; x < r.Level.Bounds.Max.X; x++ { + pos := geom.Pt(x, y) + monsterType, ok := r.Level.Monsters[pos] + if !ok { + continue + } + tile := r.Level.Tiles[pos] + if tile == nil { + continue + } + texture := monsterTextures[monsterType.Type()] + _, platformPos := positionOfTile(pos) + if target, ok := r.Level.MonsterTargets[pos]; ok { + _, targetPlatformPos := positionOfTile(target) + dt := float32(r.MovingMonsters.Frame(pos)) / 50. + delta := targetPlatformPos.Sub(platformPos) + curve := geom.PtF32(0, .6*geom.Sin32(dt*geom.Pi)*textureWidth) + interpolatedPos := platformPos.Add(delta.Mul(dt)).Sub(curve) + texture.Draw(renderer, interpolatedPos.Add(propOffset), r.Animations["monster"].Frame(pos)) + } else { + texture.Draw(renderer, platformPos.Add(propOffset), r.Animations["monster"].Frame(pos)) + } } }