Add title screen
This commit is contained in:
parent
26e546f405
commit
0cc953339b
|
@ -0,0 +1,58 @@
|
|||
package asset
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"image"
|
||||
|
||||
_ "image/jpeg"
|
||||
|
||||
"code.rocketnine.space/tslocum/gas-station-sim/world"
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
)
|
||||
|
||||
//go:embed image
|
||||
var fs embed.FS
|
||||
|
||||
var (
|
||||
ImageInterior = interiorImage()
|
||||
ImageExterior = exteriorImage()
|
||||
)
|
||||
|
||||
func interiorImage() *ebiten.Image {
|
||||
img := LoadImage("image/interior.jpg")
|
||||
|
||||
n := ebiten.NewImage(world.ScreenWidth, world.ScreenHeight)
|
||||
op := &ebiten.DrawImageOptions{}
|
||||
op.GeoM.Scale(0.64, 0.64)
|
||||
op.GeoM.Translate(-42, -42)
|
||||
n.DrawImage(img, op)
|
||||
|
||||
return n
|
||||
}
|
||||
|
||||
func exteriorImage() *ebiten.Image {
|
||||
img := LoadImage("image/exterior.jpg")
|
||||
|
||||
n := ebiten.NewImage(world.ScreenWidth, world.ScreenHeight)
|
||||
op := &ebiten.DrawImageOptions{}
|
||||
op.GeoM.Scale(0.9, 0.9)
|
||||
op.GeoM.Translate(-23, -2)
|
||||
n.DrawImage(img, op)
|
||||
|
||||
return n
|
||||
}
|
||||
|
||||
func LoadImage(p string) *ebiten.Image {
|
||||
f, err := fs.Open(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
baseImg, _, err := image.Decode(f)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return ebiten.NewImageFromImage(baseImg)
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 41 KiB |
Binary file not shown.
After Width: | Height: | Size: 186 KiB |
18
game/game.go
18
game/game.go
|
@ -3,6 +3,7 @@ package game
|
|||
import (
|
||||
"log"
|
||||
|
||||
"code.rocketnine.space/tslocum/gas-station-sim/asset"
|
||||
"code.rocketnine.space/tslocum/gas-station-sim/entity"
|
||||
"code.rocketnine.space/tslocum/gas-station-sim/system"
|
||||
"code.rocketnine.space/tslocum/gas-station-sim/world"
|
||||
|
@ -18,32 +19,27 @@ const shaderSrc = `
|
|||
package main
|
||||
|
||||
func Fragment(position vec4, tex vec2, color vec4) vec4 {
|
||||
xCol := int(position.x) % int(2) == int(0)
|
||||
yCol := int(position.y) % int(2) == int(0)
|
||||
|
||||
clr := imageSrc0UnsafeAt(tex)
|
||||
brightness := max(max(clr.r, clr.g), clr.b)
|
||||
|
||||
if brightness > 0.75 {
|
||||
return vec4(1, 1, 1, 1)
|
||||
} else if brightness > 0.5 {
|
||||
xCol := int(position.x) % int(2) == int(0)
|
||||
yCol := int(position.y) % int(2) == int(0)
|
||||
|
||||
if (!xCol && yCol) {
|
||||
return vec4(0, 0, 0, 1)
|
||||
} else {
|
||||
return vec4(1, 1, 1, 1)
|
||||
}
|
||||
} else if brightness > 0.25 {
|
||||
xCol := int(position.x) % int(2) == int(0)
|
||||
yCol := int(position.y) % int(2) == int(0)
|
||||
|
||||
if (xCol && yCol) || (!xCol && !yCol) {
|
||||
return vec4(1, 1, 1, 1)
|
||||
} else {
|
||||
return vec4(0, 0, 0, 1)
|
||||
}
|
||||
} else if brightness > 0.001 {
|
||||
xCol := int(position.x) % int(2) == int(0)
|
||||
yCol := int(position.y) % int(2) == int(0)
|
||||
|
||||
} else if brightness > 0.075 {
|
||||
if (xCol && yCol) {
|
||||
return vec4(1, 1, 1, 1)
|
||||
} else {
|
||||
|
@ -90,6 +86,8 @@ func (g *Game) Update() error {
|
|||
func (g *Game) Draw(screen *ebiten.Image) {
|
||||
//g.target.Clear()
|
||||
|
||||
g.target.DrawImage(asset.ImageExterior, nil)
|
||||
|
||||
err := gohan.Draw(g.target)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package system
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
|
||||
|
||||
"code.rocketnine.space/tslocum/gas-station-sim/world"
|
||||
"code.rocketnine.space/tslocum/gohan"
|
||||
|
@ -9,8 +9,9 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
gradientWidth = 128
|
||||
gradientHeight = 64
|
||||
introText = "Gas Station\n Simulator"
|
||||
introTextWidth = 6*len(introText) - 2
|
||||
introTextHeight = 50
|
||||
)
|
||||
|
||||
type Render struct {
|
||||
|
@ -21,17 +22,22 @@ type Render struct {
|
|||
|
||||
func (r *Render) Update(e gohan.Entity) error {
|
||||
if r.i == nil {
|
||||
r.i = ebiten.NewImage(gradientWidth, gradientHeight)
|
||||
for y := 0; y < 64; y++ {
|
||||
img := ebiten.NewImage(introTextWidth, introTextHeight)
|
||||
for i := 0; i < 4; i++ { // Draw four times to increase shadow effect
|
||||
ebitenutil.DebugPrintAt(img, introText, -1, -3)
|
||||
}
|
||||
|
||||
r.i = ebiten.NewImage(introTextWidth*2, introTextHeight*2)
|
||||
/*for y := 0; y < 64; y++ {
|
||||
for x := 0; x < 128; x++ {
|
||||
vx := x
|
||||
if vx == 0 {
|
||||
vx = 1
|
||||
}
|
||||
brightness := uint8(float64(255) * (float64(vx) / gradientWidth))
|
||||
brightness := uint8(float64(255) * (float64(x) / gradientWidth))
|
||||
r.i.Set(x, y, color.RGBA{brightness, brightness, brightness, 255})
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
op := &ebiten.DrawImageOptions{}
|
||||
op.GeoM.Scale(2, 2)
|
||||
r.i.DrawImage(img, op)
|
||||
|
||||
r.dx, r.dy = 1, 1
|
||||
return nil
|
||||
|
@ -40,10 +46,10 @@ func (r *Render) Update(e gohan.Entity) error {
|
|||
r.x += r.dx
|
||||
r.y += r.dy
|
||||
|
||||
if r.x == 0 || r.x == world.ScreenWidth-gradientWidth {
|
||||
if r.x == 0 || r.x == float64(world.ScreenWidth-introTextWidth) {
|
||||
r.dx *= -1
|
||||
}
|
||||
if r.y == 0 || r.y == world.ScreenHeight-gradientHeight {
|
||||
if r.y == 0 || r.y == float64(world.ScreenHeight-introTextHeight) {
|
||||
r.dy *= -1
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue