Browse Source

Upgrade depdendencies

This fixes a game crash when playing via browser.
main v1.1.1
Trevor Slocum 4 months ago
parent
commit
17ad15ea5a
  1. 3
      CHANGELOG
  2. 19
      component/actor.go
  3. 24
      component/creepbullet.go
  4. 23
      component/playerbullet.go
  5. 21
      component/position.go
  6. 21
      component/rail.go
  7. 19
      component/sprite.go
  8. 21
      component/velocity.go
  9. 21
      component/weapon.go
  10. 4
      ecs/ecs.go
  11. 30
      entity/creepbullet.go
  12. 12
      entity/player.go
  13. 30
      entity/playerbullet.go
  14. 35
      game/game.go
  15. 21
      go.mod
  16. 78
      go.sum
  17. 18
      system/camera.go
  18. 125
      system/creep.go
  19. 57
      system/input_fire.go
  20. 23
      system/input_move.go
  21. 18
      system/input_profile.go
  22. 105
      system/movement.go
  23. 21
      system/populate.go
  24. 21
      system/powerscan.go
  25. 32
      system/render.go
  26. 25
      system/renderdebug.go
  27. 20
      system/renderhud.go
  28. 21
      system/tax.go
  29. 21
      system/tick.go
  30. 14
      world/world.go

3
CHANGELOG

@ -1,3 +1,6 @@
v1.1.1
- Fixed game crash when playing via browser
v1.1.0
- Fixed bulldozer
- Fixed tax system (now collected per citizen)

19
component/actor.go

@ -2,12 +2,9 @@ package component
import (
"math/rand"
. "code.rocketnine.space/tslocum/citylimits/ecs"
"code.rocketnine.space/tslocum/gohan"
)
type ActorComponent struct {
type Actor struct {
Type int
Active bool
@ -31,17 +28,3 @@ const (
CreepMediumRock
CreepLargeRock
)
var ActorComponentID = ECS.NewComponentID()
func (p *ActorComponent) ComponentID() gohan.ComponentID {
return ActorComponentID
}
func Creep(ctx *gohan.Context) *ActorComponent {
c, ok := ctx.Component(ActorComponentID).(*ActorComponent)
if !ok {
return nil
}
return c
}

24
component/creepbullet.go

@ -1,24 +0,0 @@
package component
import (
. "code.rocketnine.space/tslocum/citylimits/ecs"
"code.rocketnine.space/tslocum/gohan"
)
type CreepBulletComponent struct {
Invulnerable bool // Invulnerable to hazards
}
var CreepBulletComponentID = ECS.NewComponentID()
func (p *CreepBulletComponent) ComponentID() gohan.ComponentID {
return CreepBulletComponentID
}
func CreepBullet(ctx *gohan.Context) *CreepBulletComponent {
c, ok := ctx.Component(CreepBulletComponentID).(*CreepBulletComponent)
if !ok {
return nil
}
return c
}

23
component/playerbullet.go

@ -1,23 +0,0 @@
package component
import (
. "code.rocketnine.space/tslocum/citylimits/ecs"
"code.rocketnine.space/tslocum/gohan"
)
type PlayerBulletComponent struct {
}
var PlayerBulletComponentID = ECS.NewComponentID()
func (p *PlayerBulletComponent) ComponentID() gohan.ComponentID {
return PlayerBulletComponentID
}
func PlayerBullet(ctx *gohan.Context) *PlayerBulletComponent {
c, ok := ctx.Component(PlayerBulletComponentID).(*PlayerBulletComponent)
if !ok {
return nil
}
return c
}

21
component/position.go

@ -1,24 +1,5 @@
package component
import (
. "code.rocketnine.space/tslocum/citylimits/ecs"
"code.rocketnine.space/tslocum/gohan"
)
type PositionComponent struct {
type Position struct {
X, Y float64
}
var PositionComponentID = ECS.NewComponentID()
func (p *PositionComponent) ComponentID() gohan.ComponentID {
return PositionComponentID
}
func Position(ctx *gohan.Context) *PositionComponent {
c, ok := ctx.Component(PositionComponentID).(*PositionComponent)
if !ok {
return nil
}
return c
}

21
component/rail.go

@ -1,23 +1,4 @@
package component
import (
. "code.rocketnine.space/tslocum/citylimits/ecs"
"code.rocketnine.space/tslocum/gohan"
)
type RailComponent struct {
}
var RailComponentID = ECS.NewComponentID()
func (p *RailComponent) ComponentID() gohan.ComponentID {
return RailComponentID
}
func Rail(ctx *gohan.Context) *RailComponent {
c, ok := ctx.Component(RailComponentID).(*RailComponent)
if !ok {
return nil
}
return c
type Rail struct {
}

19
component/sprite.go

@ -3,13 +3,10 @@ package component
import (
"time"
. "code.rocketnine.space/tslocum/citylimits/ecs"
"code.rocketnine.space/tslocum/gohan"
"github.com/hajimehoshi/ebiten/v2"
)
type SpriteComponent struct {
type Sprite struct {
Image *ebiten.Image
HorizontalFlip bool
VerticalFlip bool
@ -31,17 +28,3 @@ type SpriteComponent struct {
OverrideColorScale bool
ColorScale float64
}
var SpriteComponentID = ECS.NewComponentID()
func (p *SpriteComponent) ComponentID() gohan.ComponentID {
return SpriteComponentID
}
func Sprite(ctx *gohan.Context) *SpriteComponent {
c, ok := ctx.Component(SpriteComponentID).(*SpriteComponent)
if !ok {
return nil
}
return c
}

21
component/velocity.go

@ -1,24 +1,5 @@
package component
import (
. "code.rocketnine.space/tslocum/citylimits/ecs"
"code.rocketnine.space/tslocum/gohan"
)
type VelocityComponent struct {
type Velocity struct {
X, Y float64
}
var VelocityComponentID = ECS.NewComponentID()
func (c *VelocityComponent) ComponentID() gohan.ComponentID {
return VelocityComponentID
}
func Velocity(ctx *gohan.Context) *VelocityComponent {
c, ok := ctx.Component(VelocityComponentID).(*VelocityComponent)
if !ok {
return nil
}
return c
}

21
component/weapon.go

@ -1,11 +1,6 @@
package component
import (
. "code.rocketnine.space/tslocum/citylimits/ecs"
"code.rocketnine.space/tslocum/gohan"
)
type WeaponComponent struct {
type Weapon struct {
Equipped bool
Damage int
@ -16,17 +11,3 @@ type WeaponComponent struct {
BulletSpeed float64
}
var WeaponComponentID = ECS.NewComponentID()
func (p *WeaponComponent) ComponentID() gohan.ComponentID {
return WeaponComponentID
}
func Weapon(ctx *gohan.Context) *WeaponComponent {
c, ok := ctx.Component(WeaponComponentID).(*WeaponComponent)
if !ok {
return nil
}
return c
}

4
ecs/ecs.go

@ -1,5 +1 @@
package ecs
import "code.rocketnine.space/tslocum/gohan"
var ECS = gohan.NewWorld()

30
entity/creepbullet.go

@ -1,30 +0,0 @@
package entity
import (
"code.rocketnine.space/tslocum/citylimits/asset"
"code.rocketnine.space/tslocum/citylimits/component"
. "code.rocketnine.space/tslocum/citylimits/ecs"
"code.rocketnine.space/tslocum/gohan"
)
func NewCreepBullet(x, y, xSpeed, ySpeed float64) gohan.Entity {
bullet := ECS.NewEntity()
ECS.AddComponent(bullet, &component.PositionComponent{
X: x,
Y: y,
})
ECS.AddComponent(bullet, &component.VelocityComponent{
X: xSpeed,
Y: ySpeed,
})
ECS.AddComponent(bullet, &component.SpriteComponent{
Image: asset.ImgWhiteSquare,
})
ECS.AddComponent(bullet, &component.CreepBulletComponent{})
return bullet
}

12
entity/player.go

@ -2,23 +2,21 @@ package entity
import (
"code.rocketnine.space/tslocum/citylimits/component"
. "code.rocketnine.space/tslocum/citylimits/ecs"
"code.rocketnine.space/tslocum/gohan"
)
func NewPlayer() gohan.Entity {
player := ECS.NewEntity()
player := gohan.NewEntity()
ECS.AddComponent(player, &component.PositionComponent{})
player.AddComponent(&component.Position{})
ECS.AddComponent(player, &component.VelocityComponent{})
player.AddComponent(&component.Velocity{})
weapon := &component.WeaponComponent{
player.AddComponent(&component.Weapon{
Damage: 1,
FireRate: 144 / 16,
BulletSpeed: 8,
}
ECS.AddComponent(player, weapon)
})
return player
}

30
entity/playerbullet.go

@ -1,30 +0,0 @@
package entity
import (
"code.rocketnine.space/tslocum/citylimits/asset"
"code.rocketnine.space/tslocum/citylimits/component"
. "code.rocketnine.space/tslocum/citylimits/ecs"
"code.rocketnine.space/tslocum/gohan"
)
func NewPlayerBullet(x, y, xSpeed, ySpeed float64) gohan.Entity {
bullet := ECS.NewEntity()
ECS.AddComponent(bullet, &component.PositionComponent{
X: x,
Y: y,
})
ECS.AddComponent(bullet, &component.VelocityComponent{
X: xSpeed,
Y: ySpeed,
})
ECS.AddComponent(bullet, &component.SpriteComponent{
Image: asset.ImgBlackSquare,
})
ECS.AddComponent(bullet, &component.PlayerBulletComponent{})
return bullet
}

35
game/game.go

@ -6,10 +6,11 @@ import (
"os"
"sync"
"code.rocketnine.space/tslocum/gohan"
"code.rocketnine.space/tslocum/citylimits/entity"
"code.rocketnine.space/tslocum/citylimits/asset"
. "code.rocketnine.space/tslocum/citylimits/ecs"
"code.rocketnine.space/tslocum/citylimits/system"
"code.rocketnine.space/tslocum/citylimits/world"
"github.com/hajimehoshi/ebiten/v2"
@ -54,7 +55,7 @@ func NewGame() (*game, error) {
}
const numEntities = 30000
ECS.Preallocate(numEntities)
gohan.Preallocate(numEntities)
return g, nil
}
@ -223,7 +224,7 @@ func (g *game) Update() error {
world.World.GameOver = false
}
err := ECS.Update()
err := gohan.Update()
if err != nil {
return err
}
@ -334,35 +335,31 @@ func (g *game) Draw(screen *ebiten.Image) {
}
world.World.EnvironmentSprites = drawn
err := ECS.Draw(screen)
err := gohan.Draw(screen)
if err != nil {
panic(err)
}
}
func (g *game) addSystems() {
ecs := ECS
// Simulation systems.
ecs.AddSystem(system.NewTickSystem())
ecs.AddSystem(system.NewPowerScanSystem())
ecs.AddSystem(system.NewPopulateSystem())
ecs.AddSystem(system.NewTaxSystem())
gohan.AddSystem(system.NewTickSystem())
gohan.AddSystem(system.NewPowerScanSystem())
gohan.AddSystem(system.NewPopulateSystem())
gohan.AddSystem(system.NewTaxSystem())
// Input systems.
g.movementSystem = system.NewMovementSystem()
ecs.AddSystem(system.NewPlayerMoveSystem(world.World.Player, g.movementSystem))
ecs.AddSystem(system.NewplayerFireSystem())
ecs.AddSystem(g.movementSystem)
gohan.AddSystem(system.NewPlayerMoveSystem(world.World.Player, g.movementSystem))
gohan.AddSystem(g.movementSystem)
// Render systems.
ecs.AddSystem(system.NewCreepSystem())
ecs.AddSystem(system.NewCameraSystem())
gohan.AddSystem(system.NewCameraSystem())
g.renderSystem = system.NewRenderSystem()
ecs.AddSystem(g.renderSystem)
ecs.AddSystem(system.NewRenderHudSystem())
ecs.AddSystem(system.NewRenderDebugTextSystem(world.World.Player))
ecs.AddSystem(system.NewProfileSystem(world.World.Player))
gohan.AddSystem(g.renderSystem)
gohan.AddSystem(system.NewRenderHudSystem())
gohan.AddSystem(system.NewRenderDebugTextSystem(world.World.Player))
gohan.AddSystem(system.NewProfileSystem(world.World.Player))
}
func (g *game) loadAssets() error {

21
go.mod

@ -3,24 +3,25 @@ module code.rocketnine.space/tslocum/citylimits
go 1.17
require (
code.rocketnine.space/tslocum/gohan v0.0.0-20220106015515-0231e09ad78e
code.rocketnine.space/tslocum/gohan v1.0.0
github.com/beefsack/go-astar v0.0.0-20200827232313-4ecf9e304482
github.com/hajimehoshi/ebiten/v2 v2.2.4
github.com/hajimehoshi/ebiten/v2 v2.3.6
github.com/lafriks/go-tiled v0.7.0
golang.org/x/image v0.0.0-20211028202545-6944b10bf410
golang.org/x/image v0.0.0-20220617043117-41969df76e82
golang.org/x/text v0.3.7
)
require (
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20211213063430-748e38ca8aec // indirect
github.com/hajimehoshi/oto/v2 v2.1.0-alpha.5 // indirect
github.com/jezek/xgb v0.0.0-20210312150743-0e0f116e1240 // indirect
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20220712193148-63cf1f4ef61f // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/hajimehoshi/oto/v2 v2.1.0 // indirect
github.com/jezek/xgb v1.0.1 // indirect
github.com/jfreymuth/oggvorbis v1.0.3 // indirect
github.com/jfreymuth/vorbis v1.0.2 // indirect
golang.org/x/exp v0.0.0-20220128181451-c853b6ddb95e // indirect
golang.org/x/mobile v0.0.0-20220112015953-858099ff7816 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 // indirect
golang.org/x/exp/shiny v0.0.0-20220713135740-79cabaa25d75 // indirect
golang.org/x/mobile v0.0.0-20220518205345-8578da9835fd // indirect
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
)
replace github.com/lafriks/go-tiled => github.com/tslocum/go-tiled v0.7.1-0.20220129040705-2d2dec486bd9

78
go.sum

@ -1,31 +1,38 @@
code.rocketnine.space/tslocum/gohan v0.0.0-20220106015515-0231e09ad78e h1:n/4oueA0I1ilZpFGLlaCqaEDTX658fVQDtRkahdUDUI=
code.rocketnine.space/tslocum/gohan v0.0.0-20220106015515-0231e09ad78e/go.mod h1:nOvFBFvFPl5sDtkMy2Fn/7QZcWq5RE98/mK+INLqIWg=
code.rocketnine.space/tslocum/gohan v1.0.0 h1:WBcJq7nVfmr1EB8bew6xWlB5Q1714yWJ3a9/q6aBBrY=
code.rocketnine.space/tslocum/gohan v1.0.0/go.mod h1:12yOt5Ygl/RVwnnZSVZRuS1W6gCaHJgezcvg8+THk10=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/beefsack/go-astar v0.0.0-20200827232313-4ecf9e304482 h1:p4g4uok3+r6Tg6fxXEQUAcMAX/WdK6WhkQW9s0jaT7k=
github.com/beefsack/go-astar v0.0.0-20200827232313-4ecf9e304482/go.mod h1:Cu3t5VeqE8kXjUBeNXWQprfuaP5UCIc5ggGjgMx9KFc=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210727001814-0db043d8d5be/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20211213063430-748e38ca8aec h1:3FLiRYO6PlQFDpUU7OEFlWgjGD1jnBIVSJ5SYRWk+9c=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20211213063430-748e38ca8aec/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/hajimehoshi/bitmapfont/v2 v2.1.3/go.mod h1:2BnYrkTQGThpr/CY6LorYtt/zEPNzvE/ND69CRTaHMs=
github.com/hajimehoshi/ebiten/v2 v2.2.4 h1:/+qrmbv+W6scgVWwQJ7IyiI2z4y8QM2n0JDHStNC+Ns=
github.com/hajimehoshi/ebiten/v2 v2.2.4/go.mod h1:olKl/qqhMBBAm2oI7Zy292nCtE+nitlmYKNF3UpbFn0=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20220320163800-277f93cfa958/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20220712193148-63cf1f4ef61f h1:w3h343WgVLKLITcSpwecCDcq0FO8pAv6A/UG86hhFtY=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20220712193148-63cf1f4ef61f/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
github.com/hajimehoshi/bitmapfont/v2 v2.2.0/go.mod h1:Llj2wTYXMuCTJEw2ATNIO6HbFPOoBYPs08qLdFAxOsQ=
github.com/hajimehoshi/ebiten/v2 v2.3.6 h1:fCKwCcC838uyuwJrJgL5tOOJqRVmrFalyvlDXsIaZ2g=
github.com/hajimehoshi/ebiten/v2 v2.3.6/go.mod h1:vxwpo0q0oSi1cIll0Q3Ui33TVZgeHuFVYzIRk7FwuVk=
github.com/hajimehoshi/file2byteslice v0.0.0-20210813153925-5340248a8f41/go.mod h1:CqqAHp7Dk/AqQiwuhV1yT2334qbA/tFWQW0MD2dGqUE=
github.com/hajimehoshi/go-mp3 v0.3.2/go.mod h1:qMJj/CSDxx6CGHiZeCgbiq2DSUkbK0UbtXShQcnfyMM=
github.com/hajimehoshi/go-mp3 v0.3.3/go.mod h1:qMJj/CSDxx6CGHiZeCgbiq2DSUkbK0UbtXShQcnfyMM=
github.com/hajimehoshi/oto v0.6.1/go.mod h1:0QXGEkbuJRohbJaxr7ZQSxnju7hEhseiPx2hrh6raOI=
github.com/hajimehoshi/oto/v2 v2.1.0-alpha.2/go.mod h1:rUKQmwMkqmRxe+IAof9+tuYA2ofm8cAWXFmSfzDN8vQ=
github.com/hajimehoshi/oto/v2 v2.1.0-alpha.5 h1:AwLKf51fpOTVIBxgQUvNokmj/IaYMYsqJQBh6wif1c8=
github.com/hajimehoshi/oto/v2 v2.1.0-alpha.5/go.mod h1:rUKQmwMkqmRxe+IAof9+tuYA2ofm8cAWXFmSfzDN8vQ=
github.com/hajimehoshi/oto/v2 v2.1.0 h1:/h+UkbKzhD7xBHOQlWgKUplBPZ+J4DK3P2Y7g2UF1X4=
github.com/hajimehoshi/oto/v2 v2.1.0/go.mod h1:9i0oYbpJ8BhVGkXDKdXKfFthX1JUNfXjeTp944W8TGM=
github.com/jakecoffman/cp v1.1.0/go.mod h1:JjY/Fp6d8E1CHnu74gWNnU0+b9VzEdUVPoJxg2PsTQg=
github.com/jezek/xgb v0.0.0-20210312150743-0e0f116e1240 h1:dy+DS31tGEGCsZzB45HmJJNHjur8GDgtRNX9U7HnSX4=
github.com/jezek/xgb v0.0.0-20210312150743-0e0f116e1240/go.mod h1:3P4UH/k22rXyHIJD2w4h2XMqPX4Of/eySEZq9L6wqc4=
github.com/jezek/xgb v1.0.0/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk=
github.com/jezek/xgb v1.0.1 h1:YUGhxps0aR7J2Xplbs23OHnV1mWaxFVcOl9b+1RQkt8=
github.com/jezek/xgb v1.0.1/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk=
github.com/jfreymuth/oggvorbis v1.0.3 h1:MLNGGyhOMiVcvea9Dp5+gbs2SAwqwQbtrWnonYa0M0Y=
github.com/jfreymuth/oggvorbis v1.0.3/go.mod h1:1U4pqWmghcoVsCJJ4fRBKv9peUJMBHixthRlBeD6uII=
github.com/jfreymuth/vorbis v1.0.2 h1:m1xH6+ZI4thH927pgKD8JOH4eaGRm18rEE9/0WKjvNE=
github.com/jfreymuth/vorbis v1.0.2/go.mod h1:DoftRo4AznKnShRl1GxiTFCseHr4zR9BN3TWXyuzrqQ=
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@ -33,49 +40,53 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tslocum/go-tiled v0.7.1-0.20220129040705-2d2dec486bd9 h1:Uf42chMg2Cp5/qZkb9QIPzXgn9jM6Mv2Wp5tOIpVDcY=
github.com/tslocum/go-tiled v0.7.1-0.20220129040705-2d2dec486bd9/go.mod h1:xy+4iO8AKWpFNBWeqBqnq+Cb3Oirm5oin/irP/jPx6A=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4=
golang.org/x/exp v0.0.0-20220128181451-c853b6ddb95e h1:FmsvSkPHPBTboKvYBUtHbHvkQGxq+XSrqPXKDQf2W3s=
golang.org/x/exp v0.0.0-20220128181451-c853b6ddb95e/go.mod h1:M50CtfS+xv2iy/epuEazynj250ScQ0/DOjcsin9UE8k=
golang.org/x/exp/shiny v0.0.0-20220713135740-79cabaa25d75 h1:+tvDaVUVC7xUhwmi3B/tvmqManNx24wRIWsXvvnkb8Q=
golang.org/x/exp/shiny v0.0.0-20220713135740-79cabaa25d75/go.mod h1:VjAR7z0ngyATZTELrBSkxOOHhhlnVUxDye4mcjx5h/8=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190703141733-d6a02ce849c9/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/image v0.0.0-20211028202545-6944b10bf410 h1:hTftEOvwiOq2+O8k2D5/Q7COC7k5Qcrgc2TFURJYnvQ=
golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/image v0.0.0-20220321031419-a8550c1d254a/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/image v0.0.0-20220617043117-41969df76e82 h1:KpZB5pUSBvrHltNEdK/tw0xlPeD13M6M6aGP32gKqiw=
golang.org/x/image v0.0.0-20220617043117-41969df76e82/go.mod h1:doUCurBvlfPMKfmIpRIywoHmhN3VyhnoFDbvIEWF4hY=
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/mobile v0.0.0-20190415191353-3e0bab5405d6/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
golang.org/x/mobile v0.0.0-20210902104108-5d9a33257ab5/go.mod h1:c4YKU3ZylDmvbw+H/PSvm42vhdWbuxCzbonauEAP9B8=
golang.org/x/mobile v0.0.0-20220112015953-858099ff7816 h1:jhDgkcu3yQ4tasBZ+1YwDmK7eFmuVf1w1k+NGGGxfmE=
golang.org/x/mobile v0.0.0-20220112015953-858099ff7816/go.mod h1:pe2sM7Uk+2Su1y7u/6Z8KJ24D7lepUjFZbhFOrmDfuQ=
golang.org/x/mobile v0.0.0-20220518205345-8578da9835fd h1:x1GptNaTtxPAlTVIAJk61fuXg0y17h09DTxyb+VNC/k=
golang.org/x/mobile v0.0.0-20220518205345-8578da9835fd/go.mod h1:pe2sM7Uk+2Su1y7u/6Z8KJ24D7lepUjFZbhFOrmDfuQ=
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f h1:Ax0t5p6N38Ga0dThY21weqDEyz2oklo4IvDkpigvkD8=
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190429190828-d89cdac9e872/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210917161153-d61c044b1678/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 h1:XDXtA5hveEEV8JB2l7nhMTp3t3cHp9ZpwcdjqyEWLlo=
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
@ -85,12 +96,13 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.6/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
golang.org/x/tools v0.1.8-0.20211022200916-316ba0b74098/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

18
system/camera.go

@ -10,6 +10,8 @@ import (
const CameraMoveSpeed = 0.132
type CameraSystem struct {
Position *component.Position
Weapon *component.Weapon
}
func NewCameraSystem() *CameraSystem {
@ -17,18 +19,8 @@ func NewCameraSystem() *CameraSystem {
return s
}
func (_ *CameraSystem) Needs() []gohan.ComponentID {
return []gohan.ComponentID{
component.WeaponComponentID,
component.PositionComponentID,
}
}
func (_ *CameraSystem) Uses() []gohan.ComponentID {
return nil
}
func (s *CameraSystem) Update(ctx *gohan.Context) error {
func (s *CameraSystem) Update(e gohan.Entity) error {
if !world.World.GameStarted || world.World.GameOver {
return nil
}
@ -38,6 +30,6 @@ func (s *CameraSystem) Update(ctx *gohan.Context) error {
return nil
}
func (_ *CameraSystem) Draw(_ *gohan.Context, screen *ebiten.Image) error {
return gohan.ErrSystemWithoutDraw
func (_ *CameraSystem) Draw(_ gohan.Entity, screen *ebiten.Image) error {
return gohan.ErrUnregister
}

125
system/creep.go

@ -1,125 +0,0 @@
package system
import (
"code.rocketnine.space/tslocum/citylimits/component"
. "code.rocketnine.space/tslocum/citylimits/ecs"
"code.rocketnine.space/tslocum/citylimits/entity"
"code.rocketnine.space/tslocum/citylimits/world"
"code.rocketnine.space/tslocum/gohan"
"github.com/hajimehoshi/ebiten/v2"
)
// pause time, screen X, screen Y
type CreepSystem struct {
}
func NewCreepSystem() *CreepSystem {
s := &CreepSystem{}
return s
}
func (_ *CreepSystem) Needs() []gohan.ComponentID {
return []gohan.ComponentID{
component.ActorComponentID,
component.PositionComponentID,
}
}
func (_ *CreepSystem) Uses() []gohan.ComponentID {
return []gohan.ComponentID{
component.WeaponComponentID,
}
}
func (s *CreepSystem) Update(ctx *gohan.Context) error {
if !world.World.GameStarted {
return nil
}
creep := component.Creep(ctx)
position := component.Position(ctx)
if creep.Health <= 0 {
for i, e := range world.World.CreepEntities {
if e == ctx.Entity {
world.World.CreepRects = append(world.World.CreepRects[:i], world.World.CreepRects[i+1:]...)
world.World.CreepEntities = append(world.World.CreepEntities[:i], world.World.CreepEntities[i+1:]...)
ctx.RemoveEntity()
return nil
}
}
}
// Skip inactive creeps.
sx, sy := world.LevelCoordinatesToScreen(position.X, position.Y)
inactive := sx < 0 || sy < 0 || sx > 640 || sy > 480
if creep.Active != !inactive {
creep.Active = !inactive
}
if inactive {
return nil
}
l := len(creep.Movements)
if l > creep.Movement {
if creep.MovementTicks == 0 {
m := creep.Movements[creep.Movement]
position.X, position.Y = m[0], m[1]
creep.Movement++
creep.MovementTicks = int(m[2])
}
creep.MovementTicks--
}
randVelocity := func() (float64, float64) {
for {
vx := creep.Rand.Float64()*0.5 + (0.5 - creep.Rand.Float64())
vy := creep.Rand.Float64()*0.5 + (0.5 - creep.Rand.Float64())
if vx > 0.5 || vx < -0.5 || vy > 0.5 || vy < -0.5 {
return vx, vy
}
}
}
if creep.FireTicks == 0 {
for i := 0; i < creep.FireAmount; i++ {
vx, vy := randVelocity()
if creep.Rand.Intn(2) == 0 {
vx *= -1
}
if creep.Rand.Intn(2) == 0 {
vy *= -1
}
entity.NewCreepBullet(position.X, position.Y, vx, vy)
}
creep.FireTicks = creep.FireRate
}
creep.FireTicks--
if creep.DamageTicks > 0 {
creep.DamageTicks--
sprite := ECS.Component(ctx.Entity, component.SpriteComponentID)
if sprite != nil {
sp := sprite.(*component.SpriteComponent)
if creep.DamageTicks > 0 {
if creep.DamageTicks%2 == 0 {
sp.ColorScale = 100
} else {
sp.ColorScale = .01
}
sp.OverrideColorScale = true
} else {
sp.OverrideColorScale = false
}
}
}
return nil
}
func (_ *CreepSystem) Draw(_ *gohan.Context, screen *ebiten.Image) error {
return gohan.ErrSystemWithoutDraw
}

57
system/input_fire.go

@ -1,57 +0,0 @@
package system
import (
"code.rocketnine.space/tslocum/citylimits/component"
"code.rocketnine.space/tslocum/citylimits/entity"
"code.rocketnine.space/tslocum/citylimits/world"
"code.rocketnine.space/tslocum/gohan"
"github.com/hajimehoshi/ebiten/v2"
)
const (
fireSpeed = 1.5
)
type playerFireSystem struct {
}
func NewplayerFireSystem() *playerFireSystem {
return &playerFireSystem{}
}
func (_ *playerFireSystem) Needs() []gohan.ComponentID {
return []gohan.ComponentID{
component.PositionComponentID,
component.VelocityComponentID,
component.WeaponComponentID,
component.SpriteComponentID,
}
}
func (_ *playerFireSystem) Uses() []gohan.ComponentID {
return nil
}
func (s *playerFireSystem) Update(ctx *gohan.Context) error {
if !world.World.GameStarted || world.World.GameOver {
return nil
}
position := component.Position(ctx)
weapon := component.Weapon(ctx)
if ebiten.IsKeyPressed(ebiten.KeyZ) || ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) {
if weapon.NextFire == 0 {
entity.NewPlayerBullet(position.X-8, position.Y-8, 0, -weapon.BulletSpeed)
entity.NewPlayerBullet(position.X+8, position.Y-8, 0, -weapon.BulletSpeed)
weapon.NextFire = weapon.FireRate
}
}
if weapon.NextFire > 0 {
weapon.NextFire--
}
return nil
}
func (s *playerFireSystem) Draw(_ *gohan.Context, _ *ebiten.Image) error {
return gohan.ErrSystemWithoutDraw
}

23
system/input_move.go

@ -18,6 +18,10 @@ import (
)
type playerMoveSystem struct {
Position *component.Position
Velocity *component.Velocity
Weapon *component.Weapon
player gohan.Entity
movement *MovementSystem
lastWalkDirL bool
@ -37,19 +41,6 @@ func NewPlayerMoveSystem(player gohan.Entity, m *MovementSystem) *playerMoveSyst
scrollDragY: -1,
}
}
func (_ *playerMoveSystem) Needs() []gohan.ComponentID {
return []gohan.ComponentID{
component.PositionComponentID,
component.VelocityComponentID,
component.WeaponComponentID,
}
}
func (_ *playerMoveSystem) Uses() []gohan.ComponentID {
return nil
}
func (s *playerMoveSystem) buildStructure(structureType int, tileX int, tileY int, playSound bool) (*world.Structure, error) {
cost := world.StructureCosts[structureType]
if world.World.Funds < cost {
@ -114,7 +105,7 @@ func (s *playerMoveSystem) buildStructure(structureType int, tileX int, tileY in
return structure, err
}
func (s *playerMoveSystem) Update(ctx *gohan.Context) error {
func (s *playerMoveSystem) Update(e gohan.Entity) error {
if ebiten.IsKeyPressed(ebiten.KeyEscape) && !world.World.DisableEsc {
os.Exit(0)
return nil
@ -458,8 +449,8 @@ func (s *playerMoveSystem) Update(ctx *gohan.Context) error {
return nil
}
func (s *playerMoveSystem) Draw(_ *gohan.Context, _ *ebiten.Image) error {
return gohan.ErrSystemWithoutDraw
func (s *playerMoveSystem) Draw(_ gohan.Entity, _ *ebiten.Image) error {
return gohan.ErrUnregister
}
func deltaXY(x1, y1, x2, y2 float64) (dx float64, dy float64) {

18
system/input_profile.go

@ -13,6 +13,8 @@ import (
)
type profileSystem struct {
Weapon *component.Weapon
player gohan.Entity
cpuProfile *os.File
}
@ -23,17 +25,7 @@ func NewProfileSystem(player gohan.Entity) *profileSystem {
}
}
func (s *profileSystem) Needs() []gohan.ComponentID {
return []gohan.ComponentID{
component.WeaponComponentID,
}
}
func (s *profileSystem) Uses() []gohan.ComponentID {
return nil
}
func (s *profileSystem) Update(_ *gohan.Context) error {
func (s *profileSystem) Update(_ gohan.Entity) error {
if ebiten.IsKeyPressed(ebiten.KeyControl) && inpututil.IsKeyJustPressed(ebiten.KeyP) {
if s.cpuProfile == nil {
runtime.SetCPUProfileRate(1000)
@ -63,6 +55,6 @@ func (s *profileSystem) Update(_ *gohan.Context) error {
return nil
}
func (s *profileSystem) Draw(_ *gohan.Context, _ *ebiten.Image) error {
return gohan.ErrSystemWithoutDraw
func (s *profileSystem) Draw(_ gohan.Entity, _ *ebiten.Image) error {
return gohan.ErrUnregister
}

105
system/movement.go

@ -5,7 +5,6 @@ import (
"image/color"
"code.rocketnine.space/tslocum/citylimits/component"
. "code.rocketnine.space/tslocum/citylimits/ecs"
"code.rocketnine.space/tslocum/citylimits/world"
"code.rocketnine.space/tslocum/gohan"
"github.com/hajimehoshi/ebiten/v2"
@ -14,30 +13,28 @@ import (
const rewindThreshold = 1
type MovementSystem struct {
ScreenW, ScreenH float64
Position *component.Position
Velocity *component.Velocity
Weapon *component.Velocity `gohan:"?"`
}
func NewMovementSystem() *MovementSystem {
s := &MovementSystem{
ScreenW: 640,
ScreenH: 480,
}
s := &MovementSystem{}
return s
}
func drawDebugRect(r image.Rectangle, c color.Color, overrideColorScale bool) gohan.Entity {
rectEntity := ECS.NewEntity()
rectEntity := gohan.NewEntity()
rectImg := ebiten.NewImage(r.Dx(), r.Dy())
rectImg.Fill(c)
ECS.AddComponent(rectEntity, &component.PositionComponent{
rectEntity.AddComponent(&component.Position{
X: float64(r.Min.X),
Y: float64(r.Min.Y),
})
ECS.AddComponent(rectEntity, &component.SpriteComponent{
rectEntity.AddComponent(&component.Sprite{
Image: rectImg,
OverrideColorScale: overrideColorScale,
})
@ -45,33 +42,20 @@ func drawDebugRect(r image.Rectangle, c color.Color, overrideColorScale bool) go
return rectEntity
}
func (_ *MovementSystem) Needs() []gohan.ComponentID {
return []gohan.ComponentID{
component.PositionComponentID,
component.VelocityComponentID,
}
}
func (_ *MovementSystem) Uses() []gohan.ComponentID {
return []gohan.ComponentID{
component.WeaponComponentID,
}
}
func (s *MovementSystem) Update(ctx *gohan.Context) error {
func (s *MovementSystem) Update(e gohan.Entity) error {
if !world.World.GameStarted {
return nil
}
if world.World.GameOver && ctx.Entity == world.World.Player {
if world.World.GameOver && e == world.World.Player {
return nil
}
position := component.Position(ctx)
velocity := component.Velocity(ctx)
position := s.Position
velocity := s.Velocity
vx, vy := velocity.X, velocity.Y
if ctx.Entity == world.World.Player && (world.World.NoClip || world.World.Debug != 0) && ebiten.IsKeyPressed(ebiten.KeyShift) {
if e == world.World.Player && (world.World.NoClip || world.World.Debug != 0) && ebiten.IsKeyPressed(ebiten.KeyShift) {
vx, vy = vx*2, vy*2
}
@ -79,7 +63,7 @@ func (s *MovementSystem) Update(ctx *gohan.Context) error {
// Force player to remain within the screen bounds.
// TODO same for bullets
if ctx.Entity == world.World.Player {
if e == world.World.Player {
screenX, screenY := s.levelCoordinatesToScreen(position.X, position.Y)
if screenX < 0 {
diff := screenX / world.World.CamScale
@ -109,66 +93,7 @@ func (s *MovementSystem) Update(ctx *gohan.Context) error {
return nil
}
}
} else if ctx.Entity == world.World.BrokenPieceA || ctx.Entity == world.World.BrokenPieceB {
sprite := ECS.Component(ctx.Entity, component.SpriteComponentID).(*component.SpriteComponent)
if ctx.Entity == world.World.BrokenPieceA {
sprite.Angle -= 0.05
} else {
sprite.Angle += 0.05
}
}
// Check creepBullet collision.
if world.World.NoClip {
return nil
}
bulletSize := 8.0
bulletRect := image.Rect(int(position.X), int(position.Y), int(position.X+bulletSize), int(position.Y+bulletSize))
creepBullet := ECS.Component(ctx.Entity, component.CreepBulletComponentID)
playerBullet := ECS.Component(ctx.Entity, component.PlayerBulletComponentID)
// Check hazard collisions.
if creepBullet != nil || playerBullet != nil {
var invulnerable bool
if creepBullet != nil {
b := creepBullet.(*component.CreepBulletComponent)
invulnerable = b.Invulnerable
}
if !invulnerable {
for _, hazardRect := range world.World.HazardRects {
if bulletRect.Overlaps(hazardRect) {
ctx.RemoveEntity()
return nil
}
}
}
}
if creepBullet != nil {
playerRect := image.Rect(int(world.World.PlayerX), int(world.World.PlayerY), int(world.World.PlayerX+world.World.PlayerWidth), int(world.World.PlayerY+world.World.PlayerHeight))
if bulletRect.Overlaps(playerRect) {
world.World.SetGameOver(velocity.X, velocity.Y)
return nil
}
return nil
}
if playerBullet != nil {
for i, creepRect := range world.World.CreepRects {
if bulletRect.Overlaps(creepRect) {
creep := ECS.Component(world.World.CreepEntities[i], component.ActorComponentID).(*component.ActorComponent)
if creep.Active {
creep.Health--
creep.DamageTicks = 6
ctx.RemoveEntity()
return nil
}
}
}
}
return nil
}
@ -176,6 +101,6 @@ func (s *MovementSystem) levelCoordinatesToScreen(x, y float64) (float64, float6
return (x - world.World.CamX) * world.World.CamScale, (y - world.World.CamY) * world.World.CamScale
}
func (_ *MovementSystem) Draw(_ *gohan.Context, screen *ebiten.Image) error {
return gohan.ErrSystemWithoutDraw
func (_ *MovementSystem) Draw(_ gohan.Entity, screen *ebiten.Image) error {
return gohan.ErrUnregister
}

21
system/populate.go

@ -8,6 +8,9 @@ import (
)
type PopulateSystem struct {
Position *component.Position
Velocity *component.Velocity
Weapon *component.Weapon
}
func NewPopulateSystem() *PopulateSystem {
@ -16,19 +19,7 @@ func NewPopulateSystem() *PopulateSystem {
return s
}
func (s *PopulateSystem) Needs() []gohan.ComponentID {
return []gohan.ComponentID{
component.PositionComponentID,
component.VelocityComponentID,
component.WeaponComponentID,
}
}
func (s *PopulateSystem) Uses() []gohan.ComponentID {
return nil
}
func (s *PopulateSystem) Update(_ *gohan.Context) error {
func (s *PopulateSystem) Update(_ gohan.Entity) error {
if world.World.Paused {
return nil
}
@ -141,6 +132,6 @@ func (s *PopulateSystem) Update(_ *gohan.Context) error {
return nil
}
func (s *PopulateSystem) Draw(ctx *gohan.Context, screen *ebiten.Image) error {
return gohan.ErrSystemWithoutDraw
func (s *PopulateSystem) Draw(_ gohan.Entity, screen *ebiten.Image) error {
return gohan.ErrUnregister
}

21
system/powerscan.go

@ -10,6 +10,9 @@ import (
)
type PowerScanSystem struct {
Position *component.Position
Velocity *component.Velocity
Weapon *component.Weapon
}
func NewPowerScanSystem() *PowerScanSystem {
@ -18,19 +21,7 @@ func NewPowerScanSystem() *PowerScanSystem {
return s
}
func (s *PowerScanSystem) Needs() []gohan.ComponentID {
return []gohan.ComponentID{
component.PositionComponentID,
component.VelocityComponentID,
component.WeaponComponentID,
}
}
func (s *PowerScanSystem) Uses() []gohan.ComponentID {
return nil
}
func (s *PowerScanSystem) Update(_ *gohan.Context) error {
func (s *PowerScanSystem) Update(_ gohan.Entity) error {
if world.World.Paused {
return nil
}
@ -164,6 +155,6 @@ func (s *PowerScanSystem) Update(_ *gohan.Context) error {
return nil
}
func (s *PowerScanSystem) Draw(ctx *gohan.Context, screen *ebiten.Image) error {
return gohan.ErrSystemWithoutDraw
func (s *PowerScanSystem) Draw(e gohan.Entity, screen *ebiten.Image) error {
return gohan.ErrUnregister
}

32
system/render.go

@ -7,7 +7,6 @@ import (
"golang.org/x/image/colornames"
"code.rocketnine.space/tslocum/citylimits/component"
. "code.rocketnine.space/tslocum/citylimits/ecs"
"code.rocketnine.space/tslocum/citylimits/world"
"code.rocketnine.space/tslocum/gohan"
"github.com/hajimehoshi/ebiten/v2"
@ -25,8 +24,8 @@ const (
)
type RenderSystem struct {
ScreenW int
ScreenH int
Position *component.Position
Sprite *component.Sprite
img *ebiten.Image
op *ebiten.DrawImageOptions
@ -38,30 +37,17 @@ type RenderSystem struct {
func NewRenderSystem() *RenderSystem {
s := &RenderSystem{
renderer: ECS.NewEntity(),
renderer: gohan.NewEntity(),
img: ebiten.NewImage(320, 100),
op: &ebiten.DrawImageOptions{},
camScale: 1,
ScreenW: 640,
ScreenH: 480,
}
return s
}
func (s *RenderSystem) Needs() []gohan.ComponentID {
return []gohan.ComponentID{
component.PositionComponentID,
component.SpriteComponentID,
}
}
func (s *RenderSystem) Uses() []gohan.ComponentID {
return nil
}
func (s *RenderSystem) Update(_ *gohan.Context) error {
return gohan.ErrSystemWithoutUpdate
func (s *RenderSystem) Update(_ gohan.Entity) error {
return gohan.ErrUnregister
}
func (s *RenderSystem) levelCoordinatesToScreen(x, y float64) (float64, float64) {
@ -131,17 +117,17 @@ func (s *RenderSystem) renderSprite(x float64, y float64, offsetx float64, offse
return 1
}
func (s *RenderSystem) Draw(ctx *gohan.Context, screen *ebiten.Image) error {
func (s *RenderSystem) Draw(e gohan.Entity, screen *ebiten.Image) error {
if !world.World.GameStarted {
// TODO
if ctx.Entity == world.World.Player {
if e == world.World.Player {
screen.Fill(colornames.Purple)
}
return nil
}
position := component.Position(ctx)
sprite := component.Sprite(ctx)
position := s.Position
sprite := s.Sprite
if sprite.NumFrames > 0 && time.Since(sprite.LastFrame) > sprite.FrameTime {
sprite.Frame++

25
system/renderdebug.go

@ -6,7 +6,6 @@ import (
_ "image/png"
"code.rocketnine.space/tslocum/citylimits/component"
. "code.rocketnine.space/tslocum/citylimits/ecs"
"code.rocketnine.space/tslocum/citylimits/world"
"code.rocketnine.space/tslocum/gohan"
"github.com/hajimehoshi/ebiten/v2"
@ -14,6 +13,10 @@ import (
)
type RenderDebugTextSystem struct {
Position *component.Position
Velocity *component.Velocity
Weapon *component.Weapon
player gohan.Entity
op *ebiten.DrawImageOptions
debugImg *ebiten.Image
@ -29,29 +32,17 @@ func NewRenderDebugTextSystem(player gohan.Entity) *RenderDebugTextSystem {
return s
}
func (s *RenderDebugTextSystem) Needs() []gohan.ComponentID {
return []gohan.ComponentID{
component.PositionComponentID,
component.VelocityComponentID,
component.WeaponComponentID,
}
}
func (s *RenderDebugTextSystem) Uses() []gohan.ComponentID {
return nil
}
func (s *RenderDebugTextSystem) Update(_ *gohan.Context) error {
return gohan.ErrSystemWithoutUpdate
func (s *RenderDebugTextSystem) Update(_ gohan.Entity) error {
return gohan.ErrUnregister
}
func (s *RenderDebugTextSystem) Draw(ctx *gohan.Context, screen *ebiten.Image) error {
func (s *RenderDebugTextSystem) Draw(e gohan.Entity, screen *ebiten.Image) error {
if world.World.Debug <= 0 {
return nil
}
s.debugImg.Fill(color.RGBA{0, 0, 0, 80})
ebitenutil.DebugPrintAt(s.debugImg, fmt.Sprintf("ENV %d\nENT %d\nUPD %d\nDRA %d\nTPS %0.0f\nFPS %0.0f", world.World.EnvironmentSprites, ECS.CurrentEntities(), ECS.CurrentUpdates(), ECS.CurrentDraws(), ebiten.CurrentTPS(), ebiten.CurrentFPS()), 2, 0)
ebitenutil.DebugPrintAt(s.debugImg, fmt.Sprintf("ENV %d\nENT %d\nUPD %d\nDRA %d\nTPS %0.0f\nFPS %0.0f", world.World.EnvironmentSprites, gohan.CurrentEntities(), gohan.CurrentUpdates(), gohan.CurrentDraws(), ebiten.CurrentTPS(), ebiten.CurrentFPS())