This demo shows the use of the
jt_vectors library to implement a version of
Spacewar!, one of the first computer games ever created. Orbital movement and complex collision detection of irregular shapes is demonstrated.
See the
Pointing the Way to Vectors article for background information and discussion of the techniques used.
Line 281: "for(h in ourshape.hull)" of check collision proc:
"[code]proc/check_collision()
// check ship-sun collision
// note this is simple check if ship is too close to sun
if(pos.Magnitude2() < 576) // 24**2
explode(1)
del(src)
// check ship-ship collision
// will check to see if any of our ship's vertices are inside the other ship
// note this is not sufficient to test for collision, but other ship will also
// test the same thing against us, which is sufficient
var/mob/ship/S
for(S in orange(1,src)) // look within 1 tile for ship objects
break
if(!S) // no other ship in range, so end
return
var/vector/h
var/vector/offset = pos.SubVector(S.pos)
// this is the shape of the other ship (on it's current heading)
var/shape/othershape = S.shapes[S.heading_state]
// this is the shape of our ship
var/shape/ourshape = shapes[heading_state]
var/hit = FALSE
// check each of our hull vertices
// see if they lie inside the hull shape of the other ship
for(h in ourshape.hull)
h = h.AddVector(offset)
if(othershape.pointInShape(h))
hit = TRUE
break
if(hit) // we found a collision, blow up both ships
explode()
S.explode()
del(S)
del(src)[/code]"
Checking out this demo for potential ideas in a space game.