Skip to content

Commit

Permalink
Maybe bugs are fixed :)
Browse files Browse the repository at this point in the history
  • Loading branch information
barisbll committed Oct 19, 2023
1 parent ad540b7 commit 98778d2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
14 changes: 13 additions & 1 deletion enemy.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,22 @@ func (e *Enemy) move() {
return
}

isEnemyZombie := true
for _, enemy := range e.hero.enemies {
if enemy.id == e.id {
isEnemyZombie = false
break
}
}

if isEnemyZombie {
e.isDead = true
return
}

if e.currentX == e.hero.x && e.currentY == e.hero.y {
e.isDead = true
e.hero.isDead = true
return
}

xDifference := makePositive(e.currentX - e.hero.x)
Expand Down
18 changes: 10 additions & 8 deletions hero.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func (h *Hero) addBomb(s tcell.Screen, style tcell.Style, clickedX, clickedY int
explodedBomb := h.bombs[0]
h.killTheThingsInTheExplosionArea(s, style, explodedBomb.currentX, explodedBomb.currentY)
explodedBomb.isDead = true
h.bombs = h.bombs[1:]

explosionWaitGroup.Done()
explosionWaitGroup.Wait()
Expand All @@ -140,28 +141,29 @@ func (h *Hero) isNearBomb(bombX, bombY, actorX, actorY, distance int) bool {
return false
}

func (h *Hero) removeIndexFromEnemySlice(idx int) {
h.enemies = append(h.enemies[:idx], h.enemies[idx+1:]...)
}

func (h *Hero) killTheThingsInTheExplosionArea(s tcell.Screen, style tcell.Style, bombX, bombY int) {
if h.isNearBomb(bombX, bombY, h.x, h.y, 2) {
h.isDead = true
s.SetContent(h.x, h.y, DeadEmoji, nil, style)
s.Show()
}

var indexToRemove int = -1
indexToRemove := []int{}
for i, enemy := range h.enemies {

if h.isNearBomb(bombX, bombY, enemy.currentX, enemy.currentY, 5) {
enemy.isDead = true
indexToRemove = i
indexToRemove = append(indexToRemove, i)
s.SetContent(enemy.currentX, enemy.currentY, DeadEmoji, nil, style)
s.Show()
}
}

if indexToRemove != -1 {
// Create a new slice without the element to remove
h.enemies = append(h.enemies[:indexToRemove], h.enemies[indexToRemove+1:]...)
indexToRemove = -1
}
for i := 0; i < len(indexToRemove); i++ {
h.removeIndexFromEnemySlice(indexToRemove[i])
}
}

Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"log"

tcell "github.com/gdamore/tcell/v2"
Expand Down Expand Up @@ -32,7 +33,8 @@ func main() {
maybePanic := recover()
s.Fini()
if maybePanic != nil {
panic(maybePanic)
fmt.Println(maybePanic)
// panic(maybePanic)
}
}
defer quit()
Expand Down

0 comments on commit 98778d2

Please sign in to comment.