Bugfix ceiling bump.

This commit is contained in:
Gonzalo Delgado 2024-10-15 08:55:05 -03:00
parent 9387ee1167
commit 562935196d
2 changed files with 15 additions and 8 deletions

View File

@ -111,6 +111,7 @@ function Entity:adjust_for_collisions(old_state, dt, frame)
})
local next_rect = next_state:get_rect()
local ceiling_bump = false
if old_state.grounded and self.vel.y >= 0 then
if
@ -126,9 +127,10 @@ function Entity:adjust_for_collisions(old_state, dt, frame)
or
top_right_tile.solid and helpers.rectangles_overlap(next_rect, top_right_tile.pixel_rect)[2]
) then
next_state.pos.y = top_right_tile.y + top_right_tile.h - self.height/2
next_state.pos.y = top_right_tile.pixel_rect.y + top_right_tile.h + self.height/2
next_state.vel.y = 0
print(frame, "CEILING BUMP!")
ceiling_bump = true
elseif self.vel.y >= 0 and (
bottom_left_tile.solid and helpers.rectangles_overlap(next_rect, bottom_left_tile.pixel_rect)[3]
or
@ -140,12 +142,12 @@ function Entity:adjust_for_collisions(old_state, dt, frame)
end
end
if old_state.vel.x < 0 then
if not ceiling_bump and old_state.vel.x < 0 then
if top_left_tile.solid and helpers.rectangles_overlap(next_rect, top_left_tile.pixel_rect)[2] then
next_state.vel.x = 0
next_state.pos.x = top_left_tile.pixel_rect.x + top_left_tile.pixel_rect.w + next_rect.w/2
end
elseif old_state.vel.x > 0 then
elseif not ceiling_bump and old_state.vel.x > 0 then
if top_right_tile.solid and helpers.rectangles_overlap(next_rect, top_right_tile.pixel_rect)[2] then
next_state.vel.x = 0
next_state.pos.x = top_right_tile.pixel_rect.x - next_rect.w/2

View File

@ -903,6 +903,7 @@ We'll need to check for collisions against solid tiles and adjust the entities p
})
local next_rect = next_state:get_rect()
local ceiling_bump = false
if old_state.grounded and self.vel.y >= 0 then
if
@ -918,9 +919,10 @@ We'll need to check for collisions against solid tiles and adjust the entities p
or
top_right_tile.solid and helpers.rectangles_overlap(next_rect, top_right_tile.pixel_rect)[2]
) then
next_state.pos.y = top_right_tile.y + top_right_tile.h - self.height/2
next_state.pos.y = top_right_tile.pixel_rect.y + top_right_tile.h + self.height/2
next_state.vel.y = 0
print(frame, "CEILING BUMP!")
ceiling_bump = true
elseif self.vel.y >= 0 and (
bottom_left_tile.solid and helpers.rectangles_overlap(next_rect, bottom_left_tile.pixel_rect)[3]
or
@ -932,12 +934,12 @@ We'll need to check for collisions against solid tiles and adjust the entities p
end
end
if old_state.vel.x < 0 then
if not ceiling_bump and old_state.vel.x < 0 then
if top_left_tile.solid and helpers.rectangles_overlap(next_rect, top_left_tile.pixel_rect)[2] then
next_state.vel.x = 0
next_state.pos.x = top_left_tile.pixel_rect.x + top_left_tile.pixel_rect.w + next_rect.w/2
end
elseif old_state.vel.x > 0 then
elseif not ceiling_bump and old_state.vel.x > 0 then
if top_right_tile.solid and helpers.rectangles_overlap(next_rect, top_right_tile.pixel_rect)[2] then
next_state.vel.x = 0
next_state.pos.x = top_right_tile.pixel_rect.x - next_rect.w/2
@ -1389,8 +1391,11 @@ Need something more global, maybe that takes a game state instance or something.
** DONE Fix jump
SCHEDULED: <2024-08-13 mar 11:15-12:00>
** TODO Bugfix ceiling bump teleport
DEADLINE: <2024-10-07 lun>
** DONE Bugfix ceiling bump teleport
SCHEDULED: <2024-10-15 mar 07:00-08:00> DEADLINE: <2024-10-07 lun>
:LOGBOOK:
CLOCK: [2024-10-15 mar 08:41]--[2024-10-15 mar 08:54] => 0:13
:END:
** TODO Try implementing wrap-around with polar coordinates and cosine
DEADLINE: <2024-11-05 mar>