Slapping in the mix.
This commit is contained in:
@@ -3,6 +3,7 @@ package elements
|
||||
import (
|
||||
"client/gamedata"
|
||||
"image/color"
|
||||
"math"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
)
|
||||
@@ -11,6 +12,7 @@ type Block struct {
|
||||
Sprite *ebiten.Image
|
||||
cycle int
|
||||
position gamedata.Coordinates
|
||||
target gamedata.Coordinates
|
||||
hit bool
|
||||
}
|
||||
|
||||
@@ -22,6 +24,17 @@ func NewBlock() *Block {
|
||||
}
|
||||
|
||||
func (b *Block) Update() {
|
||||
|
||||
dx := b.target.X - b.position.X
|
||||
dy := b.target.Y - b.position.Y
|
||||
|
||||
delta := math.Sqrt(dx*dx + dy*dy)
|
||||
angle := math.Atan2(dy, dx)
|
||||
if delta > 0.5 {
|
||||
b.position.X += delta * math.Cos(angle) / 2
|
||||
b.position.Y += delta * math.Sin(angle) / 2
|
||||
}
|
||||
|
||||
b.cycle++
|
||||
}
|
||||
|
||||
@@ -42,6 +55,14 @@ func (b *Block) GetPosition() gamedata.Coordinates {
|
||||
return b.position
|
||||
}
|
||||
|
||||
func (b *Block) SetTargetPosition(pos gamedata.Coordinates) {
|
||||
b.target = pos
|
||||
}
|
||||
|
||||
func (b *Block) GetTargetosition() gamedata.Coordinates {
|
||||
return b.target
|
||||
}
|
||||
|
||||
func (b *Block) SetHit(hit bool) {
|
||||
b.hit = hit
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user