Cloud layer.
This commit is contained in:
62
elements/cloud.go
Normal file
62
elements/cloud.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package elements
|
||||
|
||||
import (
|
||||
"math"
|
||||
"mover/assets"
|
||||
"mover/gamedata"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
)
|
||||
|
||||
type Cloud struct {
|
||||
Sprite *ebiten.Image
|
||||
position gamedata.Coordinates
|
||||
angle float64
|
||||
velocity float64
|
||||
Alpha float64
|
||||
}
|
||||
|
||||
func NewCloud(a gamedata.Area, angle, velocity float64) *Cloud {
|
||||
c := &Cloud{
|
||||
Sprite: ebiten.NewImage(a.Width, a.Height),
|
||||
angle: angle, //rand.Float64() * (math.Pi * 2),
|
||||
velocity: velocity,
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Cloud) Update() error {
|
||||
|
||||
c.position.X += c.velocity * math.Cos(c.angle)
|
||||
c.position.Y += c.velocity * math.Sin(c.angle)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cloud) Draw() {
|
||||
c.Sprite.Clear()
|
||||
//c.Sprite.Fill(color.RGBA{R: 0xff, G: 0xff, B: 0xff, A: 0xff})
|
||||
//c.Sprite.Fill(color.White)
|
||||
|
||||
cloudsprite := assets.ImageBank[assets.Cloud]
|
||||
|
||||
spritex := cloudsprite.Bounds().Dx()
|
||||
spritey := cloudsprite.Bounds().Dy()
|
||||
|
||||
cloudx := c.Sprite.Bounds().Dx()
|
||||
cloudy := c.Sprite.Bounds().Dy()
|
||||
|
||||
scalex := float64(cloudx) / float64(spritex)
|
||||
scaley := float64(cloudy) / float64(spritey)
|
||||
|
||||
op := &ebiten.DrawImageOptions{}
|
||||
op.GeoM.Scale(scalex, scaley)
|
||||
c.Sprite.DrawImage(assets.ImageBank[assets.Cloud], op)
|
||||
}
|
||||
|
||||
func (c *Cloud) SetPosition(p gamedata.Coordinates) {
|
||||
c.position = p
|
||||
}
|
||||
|
||||
func (c *Cloud) GetPosition() gamedata.Coordinates {
|
||||
return c.position
|
||||
}
|
||||
@@ -23,4 +23,5 @@ type Enemies interface {
|
||||
ExplosionInitiated() bool
|
||||
SetExplosionInitiated()
|
||||
Health() int
|
||||
MaxHealth() int
|
||||
}
|
||||
|
||||
@@ -163,5 +163,11 @@ func (f *FlyEye) SetExplosionInitiated() {
|
||||
}
|
||||
|
||||
func (f *FlyEye) Health() int {
|
||||
//health bars reserved for special enemies, flyeye is a one
|
||||
//hitter so returning zero ensure no health bar is rendered
|
||||
return 0
|
||||
}
|
||||
|
||||
func (f *FlyEye) MaxHealth() int {
|
||||
return 1
|
||||
}
|
||||
|
||||
@@ -9,6 +9,10 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
)
|
||||
|
||||
const (
|
||||
FG_MAXHEALTH = 100
|
||||
)
|
||||
|
||||
type FlyGoblin struct {
|
||||
Sprite *ebiten.Image
|
||||
Maks *ebiten.Image
|
||||
@@ -18,10 +22,8 @@ type FlyGoblin struct {
|
||||
state gamedata.EnemyState
|
||||
cycle int
|
||||
health int
|
||||
dyingcount int
|
||||
damageduration int
|
||||
right bool
|
||||
hit bool
|
||||
touched bool
|
||||
toggle bool
|
||||
sploding bool
|
||||
@@ -33,7 +35,7 @@ func NewFlyGoblin() *FlyGoblin {
|
||||
Sprite: ebiten.NewImage(96, 96),
|
||||
Maks: ebiten.NewImage(96, 96),
|
||||
MaksDest: ebiten.NewImage(96, 96),
|
||||
health: 100,
|
||||
health: FG_MAXHEALTH,
|
||||
damageduration: 0,
|
||||
}
|
||||
fg.Maks.Fill(color.White)
|
||||
@@ -176,3 +178,7 @@ func (f *FlyGoblin) SetExplosionInitiated() {
|
||||
func (f *FlyGoblin) Health() int {
|
||||
return f.health
|
||||
}
|
||||
|
||||
func (f *FlyGoblin) MaxHealth() int {
|
||||
return FG_MAXHEALTH
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user