Skip to content

Commit 95ab79f

Browse files
committed
FIX: MTV fix.
ContactSet.MTV works again; it stopped working due to Vector.Dot() not returning the correct dot product. Removing go.mod from examples folder. Updating world platformer example.
1 parent a3a73ff commit 95ab79f

File tree

7 files changed

+141
-137
lines changed

7 files changed

+141
-137
lines changed

examples/go.mod

Lines changed: 0 additions & 15 deletions
This file was deleted.

examples/go.sum

Lines changed: 0 additions & 95 deletions
This file was deleted.

examples/worldPlatformer.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import (
55
"image/color"
66
"math"
77

8-
"github.com/hajimehoshi/ebiten/v2/inpututil"
98
"github.com/tanema/gween"
109
"github.com/tanema/gween/ease"
1110

1211
"github.com/hajimehoshi/ebiten/v2"
13-
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
12+
"github.com/hajimehoshi/ebiten/v2/inpututil"
13+
"github.com/hajimehoshi/ebiten/v2/vector"
1414
"github.com/solarlune/resolv"
1515
)
1616

@@ -113,6 +113,8 @@ func (world *WorldPlatformer) Init() {
113113
rampShape := resolv.NewConvexPolygon(
114114
0, 0,
115115

116+
// Vertices:
117+
116118
0, 0,
117119
2, 0, // The extra 2 pixels here make it so the Player doesn't get stuck for a frame or two when running up the ramp.
118120
ramp.W-2, ramp.H, // Same here; an extra 2 pixels makes it so that dismounting the ramp is nice and easy
@@ -126,8 +128,8 @@ func (world *WorldPlatformer) Init() {
126128

127129
func (world *WorldPlatformer) Update() {
128130

129-
// Platform movement needs to be done first to make sure there's no space between the top and the player's bottom; otherwise, an alternative might
130-
// be to have the platform detect to see if the Player's resting on it, and if so, move the player up manually.
131+
// Floating platform movement needs to be done before the player's movement update to make sure there's no space between its top and the player's bottom;
132+
// otherwise, an alternative might be to have the platform detect to see if the Player's resting on it, and if so, move the player up manually.
131133
y, _, seqDone := world.FloatingPlatformTween.Update(1.0 / 60.0)
132134
world.FloatingPlatform.Y = float64(y)
133135
if seqDone {
@@ -153,12 +155,12 @@ func (world *WorldPlatformer) Update() {
153155

154156
// Horizontal movement is only possible when not wallsliding.
155157
if player.WallSliding == nil {
156-
if ebiten.IsKeyPressed(ebiten.KeyRight) || ebiten.GamepadAxis(0, 0) > 0.1 {
158+
if ebiten.IsKeyPressed(ebiten.KeyRight) || ebiten.GamepadAxisValue(0, 0) > 0.1 {
157159
player.SpeedX += accel
158160
player.FacingRight = true
159161
}
160162

161-
if ebiten.IsKeyPressed(ebiten.KeyLeft) || ebiten.GamepadAxis(0, 0) < -0.1 {
163+
if ebiten.IsKeyPressed(ebiten.KeyLeft) || ebiten.GamepadAxisValue(0, 0) < -0.1 {
162164
player.SpeedX -= accel
163165
player.FacingRight = false
164166
}
@@ -182,7 +184,7 @@ func (world *WorldPlatformer) Update() {
182184
// Check for jumping.
183185
if inpututil.IsKeyJustPressed(ebiten.KeyX) || ebiten.IsGamepadButtonPressed(0, 0) || ebiten.IsGamepadButtonPressed(1, 0) {
184186

185-
if (ebiten.IsKeyPressed(ebiten.KeyDown) || ebiten.GamepadAxis(0, 1) > 0.1 || ebiten.GamepadAxis(1, 1) > 0.1) && player.OnGround != nil && player.OnGround.HasTags("platform") {
187+
if (ebiten.IsKeyPressed(ebiten.KeyDown) || ebiten.GamepadAxisValue(0, 1) > 0.1 || ebiten.GamepadAxisValue(1, 1) > 0.1) && player.OnGround != nil && player.OnGround.HasTags("platform") {
186188

187189
player.IgnorePlatform = player.OnGround
188190

@@ -399,20 +401,18 @@ func (world *WorldPlatformer) Update() {
399401

400402
func (world *WorldPlatformer) Draw(screen *ebiten.Image) {
401403

402-
fmt.Println(world.Space.Objects())
403-
404404
for _, o := range world.Space.Objects() {
405405

406406
if o.HasTags("platform") && o != world.FloatingPlatform {
407407
drawColor := color.RGBA{180, 100, 0, 255}
408-
ebitenutil.DrawRect(screen, o.X, o.Y, o.W, o.H, drawColor)
408+
vector.DrawFilledRect(screen, float32(o.X), float32(o.Y), float32(o.W), float32(o.H), drawColor, false)
409409
} else if o.HasTags("ramp") {
410410
drawColor := color.RGBA{255, 50, 100, 255}
411411
tri := o.Shape.(*resolv.ConvexPolygon)
412412
world.DrawPolygon(screen, tri, drawColor)
413413
} else {
414414
drawColor := color.RGBA{60, 60, 60, 255}
415-
ebitenutil.DrawRect(screen, o.X, o.Y, o.W, o.H, drawColor)
415+
vector.DrawFilledRect(screen, float32(o.X), float32(o.Y), float32(o.W), float32(o.H), drawColor, false)
416416
}
417417

418418
}
@@ -421,15 +421,15 @@ func (world *WorldPlatformer) Draw(screen *ebiten.Image) {
421421
// that the platform would draw under the solid blocks if it's below it. This way, it always draws on top.
422422
o := world.FloatingPlatform
423423
drawColor := color.RGBA{180, 100, 0, 255}
424-
ebitenutil.DrawRect(screen, o.X, o.Y, o.W, o.H, drawColor)
424+
vector.DrawFilledRect(screen, float32(o.X), float32(o.Y), float32(o.W), float32(o.H), drawColor, false)
425425

426426
player := world.Player.Object
427427
playerColor := color.RGBA{0, 255, 60, 255}
428428
if world.Player.OnGround == nil {
429429
// We draw the player as a different color when jumping so we can visually see when he's in the air.
430430
playerColor = color.RGBA{200, 0, 200, 255}
431431
}
432-
ebitenutil.DrawRect(screen, player.X, player.Y, player.W, player.H, playerColor)
432+
vector.DrawFilledRect(screen, float32(player.X), float32(player.Y), float32(player.W), float32(player.H), playerColor, false)
433433

434434
if world.Game.Debug {
435435
world.Game.DebugDraw(screen, world.Space)
@@ -451,8 +451,8 @@ func (world *WorldPlatformer) Draw(screen *ebiten.Image) {
451451
"R: Restart world",
452452
"E: Next world",
453453
"Q: Previous world",
454-
fmt.Sprintf("%d FPS (frames per second)", int(ebiten.CurrentFPS())),
455-
fmt.Sprintf("%d TPS (ticks per second)", int(ebiten.CurrentTPS())),
454+
fmt.Sprintf("%d FPS (frames per second)", int(ebiten.ActualFPS())),
455+
fmt.Sprintf("%d TPS (ticks per second)", int(ebiten.ActualTPS())),
456456
)
457457

458458
}
@@ -462,7 +462,7 @@ func (world *WorldPlatformer) Draw(screen *ebiten.Image) {
462462
func (world *WorldPlatformer) DrawPolygon(screen *ebiten.Image, polygon *resolv.ConvexPolygon, color color.Color) {
463463

464464
for _, line := range polygon.Lines() {
465-
ebitenutil.DrawLine(screen, line.Start.X(), line.Start.Y(), line.End.X(), line.End.Y(), color)
465+
vector.StrokeLine(screen, float32(line.Start.X()), float32(line.Start.Y()), float32(line.End.X()), float32(line.End.Y()), 1, color, false)
466466
}
467467

468468
}

go.mod

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@ module github.com/solarlune/resolv
22

33
go 1.16
44

5-
require github.com/quartercastle/vector v0.1.3
5+
require (
6+
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
7+
github.com/hajimehoshi/ebiten/v2 v2.5.4
8+
github.com/quartercastle/vector v0.1.3
9+
github.com/tanema/gween v0.0.0-20221212145351-621cc8a459d1
10+
golang.org/x/image v0.7.0
11+
)

0 commit comments

Comments
 (0)