graphics for demo game
This commit is contained in:
+83
-6
@@ -268,12 +268,14 @@ func drawCharacter(dst *ebiten.Image, g *Game, c *runtimeChar) {
|
||||
w := c.def.W
|
||||
h := c.def.H
|
||||
if w == 0 {
|
||||
w = 14
|
||||
w = 24
|
||||
}
|
||||
if h == 0 {
|
||||
h = 26
|
||||
h = 56
|
||||
}
|
||||
if c.def.Sprite != "" {
|
||||
// Try the real sprite first. Only fall through to the stylized
|
||||
// placeholder when no actual art is on disk.
|
||||
if c.def.Sprite != "" && !g.loaded.isPlaceholder(c.def.Sprite) {
|
||||
img := g.loaded.image(g.AssetManager, c.def.Sprite)
|
||||
sw, sh := img.Bounds().Dx(), img.Bounds().Dy()
|
||||
if sw > 0 && sh > 0 {
|
||||
@@ -284,9 +286,84 @@ func drawCharacter(dst *ebiten.Image, g *Game, c *runtimeChar) {
|
||||
return
|
||||
}
|
||||
}
|
||||
col := color.RGBA{200, 200, 200, 255}
|
||||
// Touch the asset cache so isPlaceholder is populated for later frames.
|
||||
if c.def.Sprite != "" {
|
||||
_ = g.loaded.image(g.AssetManager, c.def.Sprite)
|
||||
}
|
||||
x := c.pos.X - w/2
|
||||
y := c.pos.Y - h
|
||||
bodyCol := color.RGBA{200, 200, 200, 255}
|
||||
if rgba, ok := c.def.SpeechColor.(color.RGBA); ok {
|
||||
col = rgba
|
||||
bodyCol = rgba
|
||||
}
|
||||
if w > h {
|
||||
drawQuadrupedPlaceholder(dst, x, y, w, h, bodyCol)
|
||||
} else {
|
||||
drawHumanoidPlaceholder(dst, x, y, w, h, bodyCol)
|
||||
}
|
||||
vector.DrawFilledRect(dst, float32(c.pos.X-w/2), float32(c.pos.Y-h), float32(w), float32(h), col, false)
|
||||
}
|
||||
|
||||
func drawHumanoidPlaceholder(dst *ebiten.Image, x, y, w, h float64, body color.RGBA) {
|
||||
pants := color.RGBA{40, 50, 90, 255}
|
||||
skin := color.RGBA{245, 200, 155, 255}
|
||||
outline := color.RGBA{20, 20, 30, 255}
|
||||
|
||||
headR := h * 0.14
|
||||
headCY := y + headR + 1
|
||||
|
||||
// pants / legs — two narrow strips
|
||||
pantsTop := y + h*0.62
|
||||
pantsH := h - (pantsTop - y) - 1
|
||||
legW := w * 0.36
|
||||
vector.DrawFilledRect(dst, float32(x+w*0.08), float32(pantsTop), float32(legW), float32(pantsH), pants, false)
|
||||
vector.DrawFilledRect(dst, float32(x+w*0.56), float32(pantsTop), float32(legW), float32(pantsH), pants, false)
|
||||
|
||||
// torso — full-width rect, shirt color
|
||||
torsoTop := headCY + headR
|
||||
torsoH := pantsTop - torsoTop
|
||||
vector.DrawFilledRect(dst, float32(x), float32(torsoTop), float32(w), float32(torsoH), body, false)
|
||||
vector.StrokeRect(dst, float32(x), float32(torsoTop), float32(w), float32(torsoH), 1, outline, false)
|
||||
|
||||
// head — circle in skin tone
|
||||
vector.DrawFilledCircle(dst, float32(x+w/2), float32(headCY), float32(headR), skin, true)
|
||||
|
||||
// feet — short dark blobs at the very bottom
|
||||
footH := 2.0
|
||||
vector.DrawFilledRect(dst, float32(x+w*0.05), float32(y+h-footH), float32(legW+2), float32(footH), outline, false)
|
||||
vector.DrawFilledRect(dst, float32(x+w*0.55), float32(y+h-footH), float32(legW+2), float32(footH), outline, false)
|
||||
}
|
||||
|
||||
func drawQuadrupedPlaceholder(dst *ebiten.Image, x, y, w, h float64, body color.RGBA) {
|
||||
outline := color.RGBA{20, 20, 30, 255}
|
||||
dark := color.RGBA{
|
||||
R: body.R / 2, G: body.G / 2, B: body.B / 2, A: 255,
|
||||
}
|
||||
|
||||
// body
|
||||
bodyY := y + h*0.30
|
||||
bodyH := h * 0.65
|
||||
vector.DrawFilledRect(dst, float32(x), float32(bodyY), float32(w*0.78), float32(bodyH), body, false)
|
||||
|
||||
// head — circle on the right
|
||||
headR := h * 0.30
|
||||
headCX := x + w - headR
|
||||
headCY := y + h*0.50
|
||||
vector.DrawFilledCircle(dst, float32(headCX), float32(headCY), float32(headR), body, true)
|
||||
|
||||
// ears — two triangles approximated as small rects
|
||||
earW := w * 0.07
|
||||
earH := h * 0.30
|
||||
vector.DrawFilledRect(dst, float32(headCX-headR*0.7), float32(y), float32(earW), float32(earH), body, false)
|
||||
vector.DrawFilledRect(dst, float32(headCX+headR*0.4), float32(y), float32(earW), float32(earH), body, false)
|
||||
|
||||
// eye — dark dot
|
||||
vector.DrawFilledCircle(dst, float32(headCX+headR*0.25), float32(headCY-1), 1.2, outline, true)
|
||||
|
||||
// tail — small dark line stub on the left
|
||||
vector.DrawFilledRect(dst, float32(x-w*0.04), float32(bodyY+1), float32(w*0.08), 2, dark, false)
|
||||
|
||||
// legs — two short bars at the bottom
|
||||
legW := w * 0.07
|
||||
vector.DrawFilledRect(dst, float32(x+w*0.10), float32(y+h-3), float32(legW), 3, dark, false)
|
||||
vector.DrawFilledRect(dst, float32(x+w*0.55), float32(y+h-3), float32(legW), 3, dark, false)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user