aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-06-26 00:02:56 +0200
committermetamuffin <metamuffin@disroot.org>2024-06-26 00:02:56 +0200
commitd6d561c7e4f9d65718111a1dd519624b44aeec7f (patch)
tree5e64bc51cd5e4916e5fc90584cc7b2580c8fabd8
parent319fb148582a6b154c85d03ca02e60e7e26e32ef (diff)
downloadhurrycurry-d6d561c7e4f9d65718111a1dd519624b44aeec7f.tar
hurrycurry-d6d561c7e4f9d65718111a1dd519624b44aeec7f.tar.bz2
hurrycurry-d6d561c7e4f9d65718111a1dd519624b44aeec7f.tar.zst
places without tiles collide
-rw-r--r--client/game.gd2
-rw-r--r--test-client/movement.ts34
2 files changed, 21 insertions, 15 deletions
diff --git a/client/game.gd b/client/game.gd
index 51b34544..7e954857 100644
--- a/client/game.gd
+++ b/client/game.gd
@@ -145,7 +145,7 @@ func _process(delta):
func get_tile_collision(pos: Vector2i) -> bool:
var t = tile_by_pos.get(str(pos))
- if t == null: return false
+ if t == null: return true
else: return tile_collide[t[0]]
func get_tile_interactive(pos: Vector2i) -> bool:
diff --git a/test-client/movement.ts b/test-client/movement.ts
index 6c2e573d..38f4b47b 100644
--- a/test-client/movement.ts
+++ b/test-client/movement.ts
@@ -34,24 +34,30 @@ export function player_movement_update(p: PlayerData, dt: number, input: V2) {
}
function collide_player(p: PlayerData, dt: number) {
- for (const [_, tile] of tiles) {
- if (!data.tile_collide[tile.kind]) continue
+ for (let xo = -1; xo <= 1; xo++) {
+ for (let yo = -1; yo <= 1; yo++) {
+ const x = Math.floor(p.x) + xo
+ const y = Math.floor(p.y) + yo
- const d = aabb_point_distance(tile.x, tile.y, tile.x + 1, tile.y + 1, p.x, p.y)
- if (d > PLAYER_SIZE) continue
+ const tile = tiles.get([x, y].toString())
+ if (tile && !data.tile_collide[tile.kind]) continue
- const h = 0.01
- const d_sample_x = aabb_point_distance(tile.x, tile.y, tile.x + 1, tile.y + 1, p.x + h, p.y)
- const d_sample_y = aabb_point_distance(tile.x, tile.y, tile.x + 1, tile.y + 1, p.x, p.y + h)
- const grad_x = (d_sample_x - d) / h
- const grad_y = (d_sample_y - d) / h
+ const d = aabb_point_distance(x, y, x + 1, y + 1, p.x, p.y)
+ if (d > PLAYER_SIZE) continue
- p.x += (PLAYER_SIZE - d) * grad_x
- p.y += (PLAYER_SIZE - d) * grad_y
+ const h = 0.01
+ const d_sample_x = aabb_point_distance(x, y, x + 1, y + 1, p.x + h, p.y)
+ const d_sample_y = aabb_point_distance(x, y, x + 1, y + 1, p.x, p.y + h)
+ const grad_x = (d_sample_x - d) / h
+ const grad_y = (d_sample_y - d) / h
- const vdotn = (grad_x * p.vel.x) + (grad_y * p.vel.y)
- p.vel.x -= grad_x * vdotn
- p.vel.y -= grad_y * vdotn
+ p.x += (PLAYER_SIZE - d) * grad_x
+ p.y += (PLAYER_SIZE - d) * grad_y
+
+ const vdotn = (grad_x * p.vel.x) + (grad_y * p.vel.y)
+ p.vel.x -= grad_x * vdotn
+ p.vel.y -= grad_y * vdotn
+ }
}
for (const [_, player] of players) {