c# - rectangle list what is the syntax check for collision using intersect -
i how detect collision lists of rectangles.
rectanlge player; list<rectangle> blockhitbox = new list<rectangle>();
i don't know proper syntax for.
blockhitbox.intersect<>();
the code should detect if rectangle hit boxes collide player hit box.
my goal make room small rectangles player cant pass through them need detect more 1 collision @ time ( corners)
you can use intersectswith
method of rectangle
object so:
var commonsize = new size(100, 100); var player = new rectangle(new point(0,0), commonsize); var blockhitbox = new list<rectangle> { new rectangle(new point(0, 100), commonsize), // 1 not collide new rectangle(new point(100, 0), commonsize), // 1 not collide new rectangle(new point(0, 99), commonsize) // 1 collide }; bool collision = blockhitbox.any(item => item.intersectswith(player));
Comments
Post a Comment