Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 45 KiB |
After Width: | Height: | Size: 66 KiB |
After Width: | Height: | Size: 72 KiB |
After Width: | Height: | Size: 101 KiB |
After Width: | Height: | Size: 156 KiB |
After Width: | Height: | Size: 123 KiB |
@ -0,0 +1,64 @@
@@ -0,0 +1,64 @@
|
||||
package system |
||||
|
||||
import ( |
||||
_ "image/png" |
||||
|
||||
"code.rocketnine.space/tslocum/monovania/component" |
||||
|
||||
"code.rocketnine.space/tslocum/monovania/asset" |
||||
|
||||
"code.rocketnine.space/tslocum/monovania/world" |
||||
|
||||
"code.rocketnine.space/tslocum/gohan" |
||||
"github.com/hajimehoshi/ebiten/v2" |
||||
) |
||||
|
||||
type RenderBackgroundSystem struct { |
||||
op *ebiten.DrawImageOptions |
||||
} |
||||
|
||||
func NewRenderBackgroundSystem() *RenderBackgroundSystem { |
||||
s := &RenderBackgroundSystem{ |
||||
op: &ebiten.DrawImageOptions{}, |
||||
} |
||||
|
||||
return s |
||||
} |
||||
|
||||
func (s *RenderBackgroundSystem) Matches(entity gohan.Entity) bool { |
||||
return entity == world.World.Player |
||||
} |
||||
|
||||
func (s *RenderBackgroundSystem) Update(_ gohan.Entity) error { |
||||
return gohan.ErrSystemWithoutUpdate |
||||
} |
||||
|
||||
func (s *RenderBackgroundSystem) Draw(entity gohan.Entity, screen *ebiten.Image) error { |
||||
if world.World.GameOver { |
||||
return nil |
||||
} |
||||
|
||||
position := component.Position(world.World.Player) |
||||
|
||||
pctX, pctY := position.X/(512*16), position.Y/(512*16) |
||||
|
||||
scale := (float64(world.World.ScreenH) / float64(asset.ImgBackground1.Bounds().Dy())) * 1.7 |
||||
offsetX, offsetY := float64(asset.ImgBackground1.Bounds().Dx())*pctX, float64(asset.ImgBackground1.Bounds().Dy())*pctY |
||||
|
||||
op := &ebiten.DrawImageOptions{} |
||||
op.GeoM.Scale(scale, scale) |
||||
screen.DrawImage(asset.ImgBackground1, op) |
||||
op = &ebiten.DrawImageOptions{} |
||||
op.GeoM.Scale(scale, scale) |
||||
op.GeoM.Translate(-offsetX*0.5, -offsetY*0.5) |
||||
screen.DrawImage(asset.ImgBackground2, op) |
||||
op = &ebiten.DrawImageOptions{} |
||||
op.GeoM.Scale(scale, scale) |
||||
op.GeoM.Translate(-offsetX*1, -offsetY*0.75) |
||||
screen.DrawImage(asset.ImgBackground3, op) |
||||
op = &ebiten.DrawImageOptions{} |
||||
op.GeoM.Scale(scale, scale) |
||||
op.GeoM.Translate(-offsetX*2, -offsetY) |
||||
screen.DrawImage(asset.ImgBackground4, op) |
||||
return nil |
||||
} |
@ -0,0 +1,65 @@
@@ -0,0 +1,65 @@
|
||||
package system |
||||
|
||||
import ( |
||||
"log" |
||||
"os" |
||||
"path" |
||||
"runtime" |
||||
"runtime/pprof" |
||||
|
||||
"code.rocketnine.space/tslocum/gohan" |
||||
"github.com/hajimehoshi/ebiten/v2" |
||||
"github.com/hajimehoshi/ebiten/v2/inpututil" |
||||
) |
||||
|
||||
type profileSystem struct { |
||||
player gohan.Entity |
||||
cpuProfile *os.File |
||||
} |
||||
|
||||
func NewProfileSystem(player gohan.Entity) *profileSystem { |
||||
return &profileSystem{ |
||||
player: player, |
||||
} |
||||
} |
||||
|
||||
func (s *profileSystem) Matches(e gohan.Entity) bool { |
||||
return e == s.player |
||||
} |
||||
|
||||
func (s *profileSystem) Update(e gohan.Entity) error { |
||||
if ebiten.IsKeyPressed(ebiten.KeyControl) && inpututil.IsKeyJustPressed(ebiten.KeyP) { |
||||
if s.cpuProfile == nil { |
||||
log.Println("CPU profiling started...") |
||||
|
||||
runtime.SetCPUProfileRate(1000) |
||||
|
||||
homeDir, err := os.UserHomeDir() |
||||
if err != nil { |
||||
return err |
||||
} |
||||
|
||||
s.cpuProfile, err = os.Create(path.Join(homeDir, "monovania.prof")) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
|
||||
err = pprof.StartCPUProfile(s.cpuProfile) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
} else { |
||||
pprof.StopCPUProfile() |
||||
|
||||
s.cpuProfile.Close() |
||||
s.cpuProfile = nil |
||||
|
||||
log.Println("CPU profiling stopped") |
||||
} |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
func (s *profileSystem) Draw(_ gohan.Entity, _ *ebiten.Image) error { |
||||
return gohan.ErrSystemWithoutDraw |
||||
} |