mirror of
https://github.com/genxium/DelayNoMore
synced 2025-10-09 08:36:52 +00:00
Added simple map for calibration.
This commit is contained in:
@@ -85,7 +85,9 @@ type Game struct {
|
||||
|
||||
func NewGame() *Game {
|
||||
|
||||
stageDiscreteW, stageDiscreteH, stageTileW, stageTileH, playerPosMap, barrierMap, err := parseStage("richsoil")
|
||||
stageName := "simple" // Use this for calibration
|
||||
// stageName := "richsoil"
|
||||
stageDiscreteW, stageDiscreteH, stageTileW, stageTileH, playerPosMap, barrierMap, err := parseStage(stageName)
|
||||
if nil != err {
|
||||
panic(err)
|
||||
}
|
||||
|
@@ -35,17 +35,17 @@ func NewWorldColliderDisplay(game *Game, stageDiscreteW, stageDiscreteH, stageTi
|
||||
spaceOffsetX := float64(spaceW) * 0.5
|
||||
spaceOffsetY := float64(spaceH) * 0.5
|
||||
|
||||
// TODO: Move collider y-axis transformation to a "dnmshared"
|
||||
playerColliderRadius := float64(12) // hardcoded
|
||||
space := resolv.NewSpace(int(spaceW), int(spaceH), int(stageTileW), int(stageTileH))
|
||||
for _, player := range playerList {
|
||||
playerCollider := resolv.NewObject(player.X+spaceOffsetX, player.Y+spaceOffsetY, playerColliderRadius*2, playerColliderRadius*2, "Player")
|
||||
playerCollider := resolv.NewObject(player.X+spaceOffsetX, -player.Y+spaceOffsetY, playerColliderRadius*2, playerColliderRadius*2, "Player")
|
||||
playerColliderShape := resolv.NewCircle(0, 0, playerColliderRadius*2)
|
||||
playerCollider.SetShape(playerColliderShape)
|
||||
Logger.Info("player shape added:", zap.Any("shape", playerColliderShape))
|
||||
space.Add(playerCollider)
|
||||
}
|
||||
|
||||
|
||||
barrierLocalId := 0
|
||||
for _, barrier := range barrierList {
|
||||
var w float64 = 0
|
||||
@@ -66,12 +66,12 @@ func NewWorldColliderDisplay(game *Game, stageDiscreteW, stageDiscreteH, stageTi
|
||||
}
|
||||
|
||||
barrierColliderShape := resolv.NewConvexPolygon()
|
||||
for i := len(barrier.Points)-1; i >= 0; i-- {
|
||||
for i := 0; i < len(barrier.Points); i++ {
|
||||
p := barrier.Points[i]
|
||||
barrierColliderShape.AddPoints(p.X, p.Y)
|
||||
}
|
||||
|
||||
barrierCollider := resolv.NewObject(barrier.Anchor.X+spaceOffsetX, barrier.Anchor.Y+spaceOffsetY, w, h, "Barrier")
|
||||
barrierCollider := resolv.NewObject(barrier.Anchor.X+spaceOffsetX, -barrier.Anchor.Y+spaceOffsetY, w, h, "Barrier")
|
||||
barrierCollider.SetShape(barrierColliderShape)
|
||||
|
||||
Logger.Info("barrier shape added:", zap.Any("barrierLocalId", barrierLocalId), zap.Any("shape", barrierColliderShape))
|
||||
@@ -98,7 +98,7 @@ func (world *WorldColliderDisplay) Draw(screen *ebiten.Image) {
|
||||
ebitenutil.DrawRect(screen, o.X, o.Y, o.W, o.H, drawColor)
|
||||
}
|
||||
|
||||
world.Game.DebugDraw(screen, world.Space)
|
||||
// world.Game.DebugDraw(screen, world.Space)
|
||||
|
||||
if world.Game.ShowHelpText {
|
||||
|
||||
|
@@ -1,170 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image/color"
|
||||
"strconv"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
|
||||
"github.com/solarlune/resolv"
|
||||
)
|
||||
|
||||
type WorldLineTest struct {
|
||||
Game *Game
|
||||
Space *resolv.Space
|
||||
Player *resolv.Object
|
||||
}
|
||||
|
||||
func NewWorldLineTest(game *Game) *WorldLineTest {
|
||||
w := &WorldLineTest{Game: game}
|
||||
w.Init()
|
||||
return w
|
||||
}
|
||||
|
||||
func (world *WorldLineTest) Init() {
|
||||
|
||||
gw := float64(world.Game.Width)
|
||||
gh := float64(world.Game.Height)
|
||||
|
||||
cellSize := 8
|
||||
|
||||
world.Space = resolv.NewSpace(int(gw), int(gh), cellSize, cellSize)
|
||||
|
||||
// Construct geometry
|
||||
geometry := []*resolv.Object{
|
||||
|
||||
resolv.NewObject(0, 0, 16, gh),
|
||||
resolv.NewObject(gw-16, 0, 16, gh),
|
||||
resolv.NewObject(0, 0, gw, 16),
|
||||
resolv.NewObject(0, gh-24, gw, 32),
|
||||
resolv.NewObject(0, gh-24, gw, 32),
|
||||
|
||||
resolv.NewObject(200, -160, 16, gh),
|
||||
}
|
||||
|
||||
world.Space.Add(geometry...)
|
||||
|
||||
for _, o := range world.Space.Objects() {
|
||||
o.AddTags("solid")
|
||||
}
|
||||
|
||||
world.Player = resolv.NewObject(160, 160, 16, 16)
|
||||
world.Player.AddTags("player")
|
||||
world.Space.Add(world.Player)
|
||||
|
||||
}
|
||||
|
||||
func (world *WorldLineTest) Update() {
|
||||
|
||||
dx, dy := 0.0, 0.0
|
||||
moveSpd := 2.0
|
||||
|
||||
if ebiten.IsKeyPressed(ebiten.KeyW) {
|
||||
dy = -moveSpd
|
||||
}
|
||||
|
||||
if ebiten.IsKeyPressed(ebiten.KeyS) {
|
||||
dy += moveSpd
|
||||
}
|
||||
|
||||
if ebiten.IsKeyPressed(ebiten.KeyA) {
|
||||
dx = -moveSpd
|
||||
}
|
||||
|
||||
if ebiten.IsKeyPressed(ebiten.KeyD) {
|
||||
dx += moveSpd
|
||||
}
|
||||
|
||||
if col := world.Player.Check(dx, 0, "solid"); col != nil {
|
||||
dx = col.ContactWithObject(col.Objects[0]).X()
|
||||
}
|
||||
|
||||
world.Player.X += dx
|
||||
|
||||
if col := world.Player.Check(0, dy, "solid"); col != nil {
|
||||
dy = col.ContactWithObject(col.Objects[0]).Y()
|
||||
}
|
||||
|
||||
world.Player.Y += dy
|
||||
|
||||
world.Player.Update()
|
||||
|
||||
}
|
||||
|
||||
func (world *WorldLineTest) Draw(screen *ebiten.Image) {
|
||||
|
||||
for _, o := range world.Space.Objects() {
|
||||
drawColor := color.RGBA{60, 60, 60, 255}
|
||||
if o.HasTags("player") {
|
||||
drawColor = color.RGBA{0, 255, 0, 255}
|
||||
}
|
||||
ebitenutil.DrawRect(screen, o.X, o.Y, o.W, o.H, drawColor)
|
||||
}
|
||||
|
||||
mouseX, mouseY := ebiten.CursorPosition()
|
||||
|
||||
mx, my := world.Space.WorldToSpace(float64(mouseX), float64(mouseY))
|
||||
|
||||
cx, cy := world.Player.CellPosition()
|
||||
|
||||
sightLine := world.Space.CellsInLine(cx, cy, mx, my)
|
||||
|
||||
interrupted := false
|
||||
|
||||
for i, cell := range sightLine {
|
||||
|
||||
if i == 0 { // Skip the beginning because that's the player
|
||||
continue
|
||||
}
|
||||
|
||||
drawColor := color.RGBA{255, 255, 0, 255}
|
||||
|
||||
// if interrupted {
|
||||
// drawColor = color.RGBA{0, 0, 255, 255}
|
||||
// }
|
||||
|
||||
if !interrupted && cell.ContainsTags("solid") {
|
||||
drawColor = color.RGBA{255, 0, 0, 255}
|
||||
interrupted = true
|
||||
}
|
||||
|
||||
ebitenutil.DrawRect(screen,
|
||||
float64(cell.X*world.Space.CellWidth),
|
||||
float64(cell.Y*world.Space.CellHeight),
|
||||
float64(world.Space.CellWidth),
|
||||
float64(world.Space.CellHeight),
|
||||
drawColor)
|
||||
|
||||
if interrupted {
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if world.Game.Debug {
|
||||
world.Game.DebugDraw(screen, world.Space)
|
||||
}
|
||||
|
||||
if world.Game.ShowHelpText {
|
||||
|
||||
world.Game.DrawText(screen, 16, 16,
|
||||
"~ Line of sight test ~",
|
||||
"WASD keys: Move player",
|
||||
"Mouse: Hover over impassible objects",
|
||||
"to get the closest wall to the player.",
|
||||
fmt.Sprintf("Mouse X: %d, Mouse Y: %d", mouseX, mouseY),
|
||||
"Clear line of sight: "+strconv.FormatBool(!interrupted),
|
||||
"",
|
||||
"F1: Toggle Debug View",
|
||||
"F2: Show / Hide help text",
|
||||
"R: Restart world",
|
||||
"E: Next world",
|
||||
"Q: Previous world",
|
||||
fmt.Sprintf("%d FPS (frames per second)", int(ebiten.CurrentFPS())),
|
||||
fmt.Sprintf("%d TPS (ticks per second)", int(ebiten.CurrentTPS())),
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user