attempt to optimize collision
it's actually worse
This commit is contained in:
@ -567,12 +567,8 @@ end
|
||||
|
||||
function hurtbox(ship)
|
||||
local h = ship.hurt
|
||||
return {
|
||||
x=ship.x + h.x_off,
|
||||
y=ship.y + h.y_off,
|
||||
width=h.width,
|
||||
height=h.height
|
||||
}
|
||||
local x1,y1 = ship.x + h.x_off, ship.y+h.y_off
|
||||
return {x1, y1, x1+h.width, y1+h.height}
|
||||
end
|
||||
|
||||
function ship_m:maybe_shoot(gun)
|
||||
@ -1356,14 +1352,14 @@ end
|
||||
-->8
|
||||
-- collisions
|
||||
|
||||
-- box: x, y, width, height
|
||||
|
||||
function collides(box1, box2)
|
||||
return not (
|
||||
box1.x>box2.x+box2.width
|
||||
or box1.y>box2.y+box2.height
|
||||
or box1.x+box1.width<box2.x
|
||||
or box1.y+box1.height<box2.y)
|
||||
-- box: x1, y1, x2, y2
|
||||
function collides(b1, b2)
|
||||
-- x1, y1, x2, y2
|
||||
return
|
||||
b1[1]<=b2[3]
|
||||
and b1[2]<=b2[4]
|
||||
and b1[3]>=b2[1]
|
||||
and b1[4]>=b2[2]
|
||||
end
|
||||
|
||||
collider = mknew{
|
||||
@ -1384,10 +1380,10 @@ collider = mknew{
|
||||
}
|
||||
|
||||
function collider_indexes(box)
|
||||
local ret = {}
|
||||
for x = box.x\8, (box.x+box.width)\8 do
|
||||
for y = box.y\8, (box.y+box.height)\8 do
|
||||
add(ret, x+256*y)
|
||||
local ret, ylo, yhi = {}, box[2]\8, box[4]\8
|
||||
for x = box[1]\8, box[3]\8 do
|
||||
for y = ylo, yhi do
|
||||
add(ret, x+(y<<8))
|
||||
end
|
||||
end
|
||||
return ret
|
||||
|
Reference in New Issue
Block a user