Ugh i totally forgot about this one.
Anyways, here is my quick take on it. I provide collision detection, also inside the ellipse, with my konvex shape collision function.
Works awesome mostly, but likes to fail to notice collision when the ellipse is too small. I guess my function is not the best with integers, or maybe the too many bounding points are the problem... i have only used this with boxes before... i don't know right now, play around with it if you will.
sync on : backdrop on
sync rate 50
//Shape vs Point collision initialize
type konv
Xpos as integer
Ypos as integer
endtype
global dim konvexPoints(36) as konv
//Scene setup
Player_X# = screen width()/2
Player_Y# = screen height()-100
Laser_X# = screen width()/2
Laser_Y# = 200
Laser_Width# = 50
Laser_Length# = 100
do
//Player control
if leftkey()=1 then dec Player_X#, 2
if rightkey()=1 then inc Player_X#, 2
if upkey()=1 then dec Player_Y#, 2
if downkey()=1 then inc Player_Y#, 2
//Laser control
if inkey$()="a" then dec Laser_X#, 2
if inkey$()="d" then inc Laser_X#, 2
if inkey$()="w" then dec Laser_Y#, 2
if inkey$()="s" then inc Laser_Y#, 2
if inkey$()="q" then dec Laser_Angle#, 3
if inkey$()="e" then inc Laser_Angle#, 3
Laser_Angle# = wrapvalue(Laser_Angle#)
if inkey$()="r" then inc Laser_Width#, 2
if inkey$()="f" then dec Laser_Width#, 2
if Laser_Width#<10 then Laser_Width#=10
if inkey$()="t" then inc Laser_Length#, 4
if inkey$()="g" then dec Laser_Length#, 4
if Laser_Length#<10 then Laser_Length#=10
//Laser
for t=1 to 360
diam# = cos(t) * (Laser_Length#-Laser_Width#)
x = newxvalue( newxvalue( Laser_X#, Laser_Angle#, diam# ), t+Laser_Angle#, Laser_Width# )
y = newzvalue( newzvalue( Laser_Y#, Laser_Angle#, diam# ), t+Laser_Angle#, Laser_Width# )
dot x,y
t#=t : if t#/20 = t/20 then konvexPoints(t/20).Xpos = x : konvexPoints(t/20).Ypos = y
next t
`Collision test
if KONVEX_COLL( 18 , Player_X#-8,Player_Y#-8 ) or KONVEX_COLL( 18 , Player_X#+8,Player_Y#-8 ) or KONVEX_COLL( 18 , Player_X#+8,Player_Y#+8 ) or KONVEX_COLL( 18 , Player_X#-8,Player_Y#+8 )
ink rgb(255,0,0),1
else
ink rgb(255,255,255),1
endif
//Player
circle Player_X#,Player_Y#, 8
sync
loop
//Konvex shape vs. point collision detection
`You fill up konvexPoints().Xpos and konvexPoints().Ypos with point coordinates, which points all make up a konvex shape.
`Important, you need to go the same direction all the way when defining the shape, otherwise the function won't work.
`(if i remember correctly, you go from left to the right...)
`Then you call this function. POINTNUM means the total number of points in the konvex shape, the other two parameters are the X&Y coordinates of the point what may or may not collide with the shape
`On collision, the function gives 1 as a result!
function KONVEX_COLL( POINTNUM as integer , bulletX as integer , bulletY as integer )
collisionChance = 0
for t=1 to POINTNUM
limitLTsubject = t-1 : if limitLTsubject = 0 then limitLTsubject = POINTNUM
limitLT# = 180 + atanfull( konvexPoints(limitLTsubject).Xpos - konvexPoints(t).Xpos , konvexPoints(limitLTsubject).Ypos - konvexPoints(t).Ypos )
limitRTsubject = t+1 : if limitRTsubject > POINTNUM then limitRTsubject = 1
limitRT# = 180 + atanfull( konvexPoints(limitRTsubject).Xpos - konvexPoints(t).Xpos , konvexPoints(limitRTsubject).Ypos - konvexPoints(t).Ypos )
bulletAngle# = 180 + atanfull( bulletX - konvexPoints(t).Xpos , bulletY - konvexPoints(t).Ypos )
if bulletAngle# <= limitLT# and bulletAngle# >= limitRT#
inc collisionChance
else
if limitLT# > limitRT#+180 or limitLT#+180 < limitRT#
if bulletAngle# >= 0 and bulletAngle# <= limitLT#
inc collisionChance
else
if bulletAngle# <= 360 and bulletAngle# >= limitRT# then inc collisionChance
endif
else
if bulletAngle# > limitLT# and bulletAngle# < limitRT# then inc collisionChance
endif
endif
next t
if collisionChance >= POINTNUM then konvexColl = 1 else konvexColl = 0
endfunction konvexColl
-In.Dev.X: A unique heavy story based shoot'em ~35%
-CoreFleet: An underground commander unit based RTS ~15%
-TailsVSEggman: An Sonic themed RTS under development for idea presentation to Sega ~15%