Spawning radi

This commit is contained in:
2025-09-21 08:24:28 +02:00
parent e8d99dd002
commit 0e89b8be70
3 changed files with 63 additions and 43 deletions

View File

@@ -3,34 +3,35 @@ package zombie
import (
"bytes"
"fmt"
"image"
"log"
"time"
"github.com/hajimehoshi/ebiten/v2"
"gitlab.com/kbr4/9heroja/collision"
"gitlab.com/kbr4/9heroja/configuration"
"gitlab.com/kbr4/9heroja/resources"
"image"
"log"
"time"
)
const WalkSpeedMs = 10
var (
zombieImage *ebiten.Image
walkTicker *time.Ticker
animationTicker *time.Ticker
zombieImage *ebiten.Image
)
type Zombie struct {
step int
direction configuration.Direction
IsWalking bool
X float64
Y float64
OffsetX float64
OffsetY float64
WhereToGoX float64
WhereToGoY float64
IsDead bool
step int
direction configuration.Direction
IsWalking bool
X float64
Y float64
OffsetX float64
OffsetY float64
WhereToGoX float64
WhereToGoY float64
IsDead bool
walkTicker *time.Ticker
animationTicker *time.Ticker
}
type spritePosition struct {
@@ -77,8 +78,6 @@ func init() {
log.Fatal(err)
}
zombieImage = ebiten.NewImageFromImage(img)
walkTicker = time.NewTicker(WalkSpeedMs * time.Millisecond)
animationTicker = time.NewTicker(WalkSpeedMs * 5 * time.Millisecond) // Adjust the speed of animation frames
}
func NewZombie() *Zombie {
@@ -87,11 +86,13 @@ func NewZombie() *Zombie {
IsWalking: false,
IsDead: false,
}
zombie.walkTicker = time.NewTicker(WalkSpeedMs * time.Millisecond)
zombie.animationTicker = time.NewTicker(WalkSpeedMs * 10 * time.Millisecond) // Adjust the speed of animation frames
go func() {
for {
select {
case <-walkTicker.C:
case <-zombie.walkTicker.C:
if zombie.IsWalking {
// Move the zombie towards its target position
if zombie.X < zombie.WhereToGoX {
@@ -112,7 +113,7 @@ func NewZombie() *Zombie {
go func() {
for {
select {
case <-animationTicker.C:
case <-zombie.animationTicker.C:
if zombie.IsWalking {
zombie.step++
if zombie.step > 3 {
@@ -129,7 +130,7 @@ func NewZombie() *Zombie {
func (z *Zombie) Walk() {
if !z.IsWalking {
walkTicker.Reset(WalkSpeedMs * time.Millisecond)
z.walkTicker.Reset(WalkSpeedMs * time.Millisecond)
z.IsWalking = true
}