Fixed monster z-fighting.

This commit is contained in:
Sander Schobers 2021-08-14 09:46:38 +02:00
parent 17008871ce
commit 24db632470
2 changed files with 25 additions and 18 deletions

View File

@ -8,8 +8,8 @@
- [ ] Change layout when playing in portrait mode. - [ ] Change layout when playing in portrait mode.
- [X] Fix wobble animation. - [X] Fix wobble animation.
- [ ] Add more unit tests? - [ ] Add more unit tests?
- [ ] Fix z-fighting of monsters. - [X] Fix z-fighting of monsters.
- [ ] Add exploding animation of monsters. - [X] Add exploding animation of monsters.
- [ ] Add audio settings (music & sound volume). - [ ] Add audio settings (music & sound volume).
- [X] Hearts must be saved as well for resume. - [X] Hearts must be saved as well for resume.
- [ ] Add demo mode. - [ ] Add demo mode.

View File

@ -338,22 +338,29 @@ func (r levelController) Render(ctx ui.Context) {
renderer.DrawTexturePoint(player, playerPosition.Add(centerTopSquare)) renderer.DrawTexturePoint(player, playerPosition.Add(centerTopSquare))
} }
for pos, monsterType := range r.Level.Monsters { for y := r.Level.Bounds.Min.Y; y < r.Level.Bounds.Max.Y; y++ {
tile := r.Level.Tiles[pos] for x := r.Level.Bounds.Min.X; x < r.Level.Bounds.Max.X; x++ {
if tile == nil { pos := geom.Pt(x, y)
continue monsterType, ok := r.Level.Monsters[pos]
} if !ok {
texture := monsterTextures[monsterType.Type()] continue
_, platformPos := positionOfTile(pos) }
if target, ok := r.Level.MonsterTargets[pos]; ok { tile := r.Level.Tiles[pos]
_, targetPlatformPos := positionOfTile(target) if tile == nil {
dt := float32(r.MovingMonsters.Frame(pos)) / 50. continue
delta := targetPlatformPos.Sub(platformPos) }
curve := geom.PtF32(0, .6*geom.Sin32(dt*geom.Pi)*textureWidth) texture := monsterTextures[monsterType.Type()]
interpolatedPos := platformPos.Add(delta.Mul(dt)).Sub(curve) _, platformPos := positionOfTile(pos)
texture.Draw(renderer, interpolatedPos.Add(propOffset), r.Animations["monster"].Frame(pos)) if target, ok := r.Level.MonsterTargets[pos]; ok {
} else { _, targetPlatformPos := positionOfTile(target)
texture.Draw(renderer, platformPos.Add(propOffset), r.Animations["monster"].Frame(pos)) 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))
}
} }
} }