From e4c0edeacb2c5829f864e116b68f6cad175141b3 Mon Sep 17 00:00:00 2001 From: davidovski Date: Mon, 22 Apr 2024 17:54:21 +0100 Subject: paper-style art --- objects.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'objects.go') diff --git a/objects.go b/objects.go index 2d14855..88aa8ea 100644 --- a/objects.go +++ b/objects.go @@ -133,11 +133,23 @@ func (o * GameObject) HasCollision(tilemap Tilemap, others []*GameObject, dir Di return false } -func DrawObject(o * GameObject, screen *ebiten.Image, tilemap Tilemap) { +func ShadowDraw(screen *ebiten.Image, image *ebiten.Image, x, y float32, alpha float32) { op := &ebiten.DrawImageOptions{} - op.ColorScale.ScaleAlpha(o.alpha) - op.GeoM.Translate(float64(o.x), float64(o.y)) - screen.DrawImage(o.image, op) + if alpha > 0{ + op = &ebiten.DrawImageOptions{} + op.ColorScale.ScaleAlpha(alpha) + op.ColorScale.Scale(0, 0, 0, 1); + op.GeoM.Translate(float64(x+shadowOffset), float64(y + shadowOffset)) + screen.DrawImage(image, op) + } + op = &ebiten.DrawImageOptions{} + op.ColorScale.ScaleAlpha(alpha) + op.GeoM.Translate(float64(x), float64(y)) + screen.DrawImage(image, op) +} + +func DrawObject(o * GameObject, screen *ebiten.Image, tilemap Tilemap) { + ShadowDraw(screen, o.image, o.x, o.y, o.alpha) if o.highlight { vector.StrokeRect(screen, o.x, o.y, float32(o.image.Bounds().Dx()), float32(o.image.Bounds().Dy()), hightlightBorder, color.RGBA{255, 100, 100, 255}, false) -- cgit v1.2.1