Browse Source

Add --spawn flag

This allows users to specify where the player should spawn.
main
Trevor Slocum 7 months ago
parent
commit
639b0b8ab1
  1. 4
      README.md
  2. 1108
      asset/map/m1.tmx
  3. 23
      flags.go
  4. 13
      game/game.go
  5. 6
      go.mod
  6. 12
      go.sum
  7. 8
      system/input_move.go
  8. 2
      system/movement.go
  9. 3
      system/render.go
  10. 2
      system/renderdebug.go

4
README.md

@ -7,6 +7,10 @@ This game was created for the [Metroidvania Month 14 Game Jam](https://itch.io/j @@ -7,6 +7,10 @@ This game was created for the [Metroidvania Month 14 Game Jam](https://itch.io/j
## Play
### Browser
[**Play in your browser**](https://rocketnine.itch.io/monovania?secret=monovania)
### Compile
**Note:** You will need to install the dependencies listed for [your platform](https://github.com/hajimehoshi/ebiten/blob/main/README.md#platforms).

1108
asset/map/m1.tmx

File diff suppressed because it is too large Load Diff

23
flags.go

@ -5,7 +5,11 @@ package main @@ -5,7 +5,11 @@ package main
import (
"flag"
"strconv"
"strings"
"code.rocketnine.space/tslocum/monovania/component"
"code.rocketnine.space/tslocum/monovania/engine"
"code.rocketnine.space/tslocum/monovania/world"
"github.com/hajimehoshi/ebiten/v2"
)
@ -13,8 +17,10 @@ import ( @@ -13,8 +17,10 @@ import (
func parseFlags() {
var (
fullscreen bool
spawn string
)
flag.BoolVar(&fullscreen, "fullscreen", false, "run in fullscreen mode")
flag.StringVar(&spawn, "spawn", "", "spawn X,Y position")
flag.BoolVar(&world.World.CanDoubleJump, "doublejump", false, "start with double jump ability")
flag.BoolVar(&world.World.CanLevitate, "levitate", false, "start with levitate ability")
flag.IntVar(&world.World.Debug, "debug", 0, "print debug information")
@ -23,4 +29,21 @@ func parseFlags() { @@ -23,4 +29,21 @@ func parseFlags() {
if fullscreen {
ebiten.SetFullscreen(true)
}
if spawn != "" {
spawnSplit := strings.Split(spawn, ",")
if len(spawnSplit) == 2 {
spawnX, err := strconv.Atoi(spawnSplit[0])
if err != nil {
panic(err)
}
spawnY, err := strconv.Atoi(spawnSplit[1])
if err != nil {
panic(err)
}
world.World.SpawnX, world.World.SpawnY = float64(spawnX), float64(spawnY)
position := engine.Engine.Component(world.World.Player, component.PositionComponentID).(*component.PositionComponent)
position.X, position.Y = world.World.SpawnX, world.World.SpawnY
}
}
}

13
game/game.go

@ -76,15 +76,16 @@ type game struct { @@ -76,15 +76,16 @@ type game struct {
// NewGame returns a new isometric demo game.
func NewGame() (*game, error) {
g := &game{
camScale: 4,
playerX: 7,
playerY: 14,
op: &ebiten.DrawImageOptions{},
camScale: 4,
playerX: 7,
playerY: 14,
audioContext: audio.NewContext(sampleRate),
op: &ebiten.DrawImageOptions{},
}
g.audioContext = audio.NewContext(sampleRate)
const numEntities = 30000
engine.Engine.Preallocate(numEntities)
// TODO replace with fs embed
g.changeMap("map/m1.tmx")
world.World.Player = entity.NewPlayer(world.World.SpawnX, world.World.SpawnY)

6
go.mod

@ -3,7 +3,7 @@ module code.rocketnine.space/tslocum/monovania @@ -3,7 +3,7 @@ module code.rocketnine.space/tslocum/monovania
go 1.17
require (
code.rocketnine.space/tslocum/gohan v0.0.0-20211208035702-62caf1bdd237
code.rocketnine.space/tslocum/gohan v0.0.0-20211210034951-3c7785e5e57f
github.com/fogleman/ease v0.0.0-20170301025033-8da417bf1776
github.com/hajimehoshi/ebiten/v2 v2.2.3
github.com/lafriks/go-tiled v0.5.0
@ -15,8 +15,8 @@ require ( @@ -15,8 +15,8 @@ require (
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20211204153444-caad923f49f4 // indirect
github.com/hajimehoshi/oto/v2 v2.1.0-alpha.4 // indirect
github.com/jezek/xgb v0.0.0-20210312150743-0e0f116e1240 // indirect
golang.org/x/exp v0.0.0-20211207001050-4f2595aad9e7 // indirect
golang.org/x/exp v0.0.0-20211209182145-6e94b45d164d // indirect
golang.org/x/mobile v0.0.0-20211207041440-4e6c2922fdee // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d // indirect
golang.org/x/sys v0.0.0-20211209171907-798191bca915 // indirect
)

12
go.sum

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
code.rocketnine.space/tslocum/gohan v0.0.0-20211208035702-62caf1bdd237 h1:bkA0C05c44k4jUxBhPHw+OKQzaYiv5xssz12CQ35alI=
code.rocketnine.space/tslocum/gohan v0.0.0-20211208035702-62caf1bdd237/go.mod h1:nOvFBFvFPl5sDtkMy2Fn/7QZcWq5RE98/mK+INLqIWg=
code.rocketnine.space/tslocum/gohan v0.0.0-20211210034951-3c7785e5e57f h1:stxIGII7DonP7xIsUaEthEj5j3JNnMzVek5fK9hRAMU=
code.rocketnine.space/tslocum/gohan v0.0.0-20211210034951-3c7785e5e57f/go.mod h1:nOvFBFvFPl5sDtkMy2Fn/7QZcWq5RE98/mK+INLqIWg=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
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=
@ -38,8 +38,8 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U @@ -38,8 +38,8 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
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-20211207001050-4f2595aad9e7 h1:8+tNCYevFo8rmzPdpdYIPSoKyiJtBzYwQt+yHF+dAm8=
golang.org/x/exp v0.0.0-20211207001050-4f2595aad9e7/go.mod h1:b9TAUYHmRtqA6klRHApnXMnj+OyLce4yF5cZCUbk2ps=
golang.org/x/exp v0.0.0-20211209182145-6e94b45d164d h1:kyDnjigapVz/aaGinVfqN3EK7SGZrOCNjcYuf5to0KE=
golang.org/x/exp v0.0.0-20211209182145-6e94b45d164d/go.mod h1:b9TAUYHmRtqA6klRHApnXMnj+OyLce4yF5cZCUbk2ps=
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=
@ -72,8 +72,8 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w @@ -72,8 +72,8 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/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-20211205182925-97ca703d548d h1:FjkYO/PPp4Wi0EAUOVLxePm7qVW4r4ctbWpURyuOD0E=
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211209171907-798191bca915 h1:P+8mCzuEpyszAT6T42q0sxU+eveBAF/cJ2Kp0x6/8+0=
golang.org/x/sys v0.0.0-20211209171907-798191bca915/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=

8
system/input_move.go

@ -1,11 +1,13 @@ @@ -1,11 +1,13 @@
package system
import (
"log"
"time"
"code.rocketnine.space/tslocum/gohan"
"code.rocketnine.space/tslocum/monovania/asset"
"code.rocketnine.space/tslocum/monovania/component"
"code.rocketnine.space/tslocum/monovania/engine"
"code.rocketnine.space/tslocum/monovania/world"
"github.com/fogleman/ease"
"github.com/hajimehoshi/ebiten/v2"
@ -50,6 +52,12 @@ func (s *playerMoveSystem) Update(ctx *gohan.Context) error { @@ -50,6 +52,12 @@ func (s *playerMoveSystem) Update(ctx *gohan.Context) error {
world.World.NoClip = !world.World.NoClip
return nil
}
if ebiten.IsKeyPressed(ebiten.KeyControl) && inpututil.IsKeyJustPressed(ebiten.KeyX) {
position := engine.Engine.Component(s.player, component.PositionComponentID).(*component.PositionComponent)
world.World.SpawnX, world.World.SpawnY = position.X, position.Y-12
log.Printf("Spawn point set to %.0f,%.0f", world.World.SpawnX, world.World.SpawnY)
return nil
}
moveSpeed := 0.1
maxSpeed := 0.5

2
system/movement.go

@ -258,6 +258,8 @@ func (s *MovementSystem) Update(ctx *gohan.Context) error { @@ -258,6 +258,8 @@ func (s *MovementSystem) Update(ctx *gohan.Context) error {
bullet := ctx.Entity != world.World.Player
// TODO apply left and right X collision adjustments (too large, can hang entirely off edge of cliff)
onLadder := -1
playerRect := image.Rect(int(position.X), int(position.Y), int(position.X)+16, int(position.Y)+16)
for i, rect := range s.ladderRects {

3
system/render.go

@ -68,8 +68,7 @@ func (s *RenderSystem) renderSprite(x float64, y float64, offsetx float64, offse @@ -68,8 +68,7 @@ func (s *RenderSystem) renderSprite(x float64, y float64, offsetx float64, offse
// Skip drawing off-screen tiles.
drawX, drawY := s.levelCoordinatesToScreen(x, y)
padding := float64(TileWidth) * 2
w, h := sprite.Size()
width, height := float64(w), float64(h)
width, height := float64(TileWidth), float64(TileWidth)
left := drawX
right := drawX + width
top := drawY

2
system/renderdebug.go

@ -55,7 +55,7 @@ func (s *RenderDebugTextSystem) Draw(ctx *gohan.Context, screen *ebiten.Image) e @@ -55,7 +55,7 @@ func (s *RenderDebugTextSystem) Draw(ctx *gohan.Context, screen *ebiten.Image) e
s.debugImg.Clear()
s.op.GeoM.Reset()
s.op.GeoM.Scale(2, 2)
ebitenutil.DebugPrint(s.debugImg, fmt.Sprintf("POS %.0f,%.0f\nVEL %.2f,%.2f\nENT %d\nUPD %d\nDRA %d\nTPS %0.0f\nFPS %0.0f", position.X, position.Y, velocity.X, velocity.Y, engine.Engine.ActiveEntities(), engine.Engine.UpdatedEntities(), engine.Engine.DrawnEntities(), ebiten.CurrentTPS(), ebiten.CurrentFPS()))
ebitenutil.DebugPrint(s.debugImg, fmt.Sprintf("POS %.0f,%.0f\nVEL %.2f,%.2f\nENT %d\nUPD %d\nDRA %d\nTPS %0.0f\nFPS %0.0f", position.X, position.Y, velocity.X, velocity.Y, engine.Engine.CurrentEntities(), engine.Engine.CurrentUpdates(), engine.Engine.CurrentDraws(), ebiten.CurrentTPS(), ebiten.CurrentFPS()))
screen.DrawImage(s.debugImg, s.op)
return nil
}

Loading…
Cancel
Save