collision question

BlitzMax Forums/BlitzMax Beginners Area/collision question

Cruis.In(Posted 2006) [#1]
can I check for a collision between a drawnline using
drawline

and an image?


Dreamora(Posted 2006) [#2]
no

Rect (-> area) or Image only


Cruis.In(Posted 2006) [#3]
so how would I create a laser weapon then?


tonyg(Posted 2006) [#4]
Pure guess here...
You have your start point (e.g. shipx, shipy)
You know your target point (perhaps mousex(),mousey())
Use atan2 to get the angle and work out how to 'setrotate' to point to that target.
Then use drawimagerect with that rotation.
It might then be possible to check the rotated, drawimagerect'ed image with your other images.
No idea whether it'll work though.


Cruis.In(Posted 2006) [#5]
ok ill try it, ill let you know when i leave work.


Jesse(Posted 2006) [#6]
I never done that either but wouldn't it be easy to just create a lazer light image and then use collideimage to check for collition?


Cruis.In(Posted 2006) [#7]
drawimagerect needs an image supplied, isn't like drawrect.


tonyg(Posted 2006) [#8]
Yes, that's right.


Cruis.In(Posted 2006) [#9]
well what Im doing now, is i did a line about 300pixels long, random the colours its drawn with along the orange scale, to make it an orange laser. and setting the handle of the image to be the bottom, so the line is drawn from the bottom when i fire, and the top of course is 300 pixels ahead. so voila, laser type weapon, but the collision is awry this way :).


H&K(Posted 2006) [#10]
Read each pixel in the path of the laser, and stop when the pixel is different to the normal back colour. Then at the pixel before the change you know that you are about to hit something

http://www.blitzbasic.com/Community/posts.php?topic=49893#558158 (ReadPixel link)


tonyg(Posted 2006) [#11]
... or create a small segment of the orange (or, better, greyscale) laser as an image.


Dreamora(Posted 2006) [#12]
Or just go through all pixels and do a colliderect with a 1x1 rect (ie the pixel of the line) and look if this one collides. This can be done x steps in front or back, as you like and need it and due to 1x1 it is very fast

Reading each pixel is no solution in BM at the moment as all solutions so far grab something.


H&K(Posted 2006) [#13]
Edit. Mistake sorry


Cruis.In(Posted 2006) [#14]
thanks guys? HK you sorry means mistake in advice?

dreamora, what you said sounds, good but a little confusing.

tonyg, ill try that. but if i make it so that the part nearest the ship when firing is grey wont it look like not appearing to be fired from the ship. i will post a screenshot of me firing several laser beams when I get home.

@ work now.


H&K(Posted 2006) [#15]
HK you sorry means mistake in advice?

If the mistake was in the advice I would have edited the advice. The sorry was because I critised Dream, then realised that is was me not understanding, I had thought he was just paraphrasing my advice, then when I read it again I realised what he ment


Cruis.In(Posted 2006) [#16]
here is the screen shot



looks better in the game... when its running, not as horrible as it looks there.

for the collision code, i set the handle back to 0.0 so when the beginning of the laser touches the target it should disappear. but funny thing, the laser just becomes really fady before disappearing, when it collides with its target.


tonyg(Posted 2006) [#17]
tonyg, ill try that. but if i make it so that the part nearest the ship when firing is grey wont it look like not appearing to be fired from the ship.

not sure what you mean but have the image greyscale and use setcolor to make it orange, blue, red whatever.