shield arcs

BlitzMax Forums/BlitzMax Beginners Area/shield arcs

Cruis.In(Posted 2006) [#1]
ok this is a good one.

I have a ship. it has four shield arcs, fore,left,right,aft
_
( A )
--

the shield arcs are semi circle graphics like the two brackets there, as I turn my ship, would would i get those to draw around my ship in a circle? So that they can remain the correct perspective. this has me stumped, i cant even approach it beyond setting rotation to the ships angle, but this rotates the graphic only, which makes the shield arcs rotate all over of course.

its just hard to figure, I mean the nose of my ship rotates around in a nice circle, which is what id like the shield arcs to do...


WendellM(Posted 2006) [#2]
My first thought would be to use masking (or alpha transparency for a smoother look) and draw the ship and four shield arcs with five separate images. When they're loaded with AutoMidHandle and superimposed at the same coordinates, you get something like this:



The images all share the same center, so they all rotate around the same point together.

Here's a zip with code and sample images to test that it works: ship_shield.zip (I got a little carried away jazzing up the drab artwork with a pulsating front shield <g>):




Cruis.In(Posted 2006) [#3]
cool. does it maintain separate shield arcs though? as in arcs with their own power? they might not go where they are supposed to if i rotate my ship, but at startup they are in position, and act as an individual shield, and each has its own hit points, and collision detection for each of course.


tonyg(Posted 2006) [#4]
Have a type field in TShip pointing to a TShield type or has an array with the shield data.


ImaginaryHuman(Posted 2006) [#5]
You just need to have a `handle offset for each of the parts and then SetRotation() before you draw the ship and the arcs should deal with the whole thing. Set the handle for each arc so that it's centered on the ship.


Cruis.In(Posted 2006) [#6]
heeh thanks angeldaniel. I did figure this out and had just come to post about it. But had I not, you posted the solution so thanks anyway.

since my ship is at the centre i experimented first with setting theimage handle at gwidth and gheight /2 but thats just rotates the arc around the borders of the screen, and would never place them where they should be, (right next to the ship)

so then I did ,
setimagehandle(x + imagewidth(shipimage)/2


same for the Y, and they are drawn already where they should be and rotated by the ships angle so I had that covered, and voila.

edit: I think that's it, doesn't look right now hheehe*(that I am looking at it again), will check when I get home and edit here to let ya know for sure.
confusing myself :)


ImaginaryHuman(Posted 2006) [#7]
It depends on whether each of your shield arcs is drawn in its correct position within a square image, ie the left shield arc is on the left side of a square image and the right arc is on the right side, so that the centers of ALL five images (the ship and the 4 arcs) are all the same. Then you just rotate them together. You don't set the handle of the arcs to anything to do with the ship. You just do automidhandle or set the handle to the center, presuming the ship image and the arc images are all the same size squares on top of each other. Then rotating will rotate together. If your arcs are stored as narrow thin images then you will need to set the handle so that when they appear to be in the right position, their center is offset to one side of the arc image so it still is where the center of the ship is.


Cruis.In(Posted 2006) [#8]
each arc is actually a separate individually loaded image. they are not all in one image. otherwise i couldnt do collision detection for a particular shield.


Cruis.In(Posted 2006) [#9]
after more fiddling i dont think I quite have it.

	'handle shield arc gfx by centre of ship
		'SetImageHandle(shield_front, ImageWidth(shipimage)/2 -5, ImageHeight(shipimage)/2)
		'SetImageHandle(shield_aft, ImageWidth(shipimage)/2 - 5, ImageHeight(shipimage)/2 - 105)
		'SetImageHandle(shield_left, ImageWidth(shipimage)/2, ImageHeight(shipimage)/2 - 15)
		'SetImageHandle(shield_right, ImageWidth(shipimage)/2 - 100, ImageHeight(shipimage)/2 - 15)

		
	 '	SetImageHandle(shield_front, 50, 50)
	'	SetImageHandle(shield_aft,50,50)
	'	SetImageHandle(shield_left, 50,50 )
	'	SetImageHandle(shield_right, 50,50 )

		'SetAlpha 0.0
		'draw shield arcs around player ship
		DrawImage shield_front,(x -ImageWidth(shipimage)/2) ,(y - ImageHeight(shipimage)/2)  
		DrawImage shield_aft,  x , y 
		DrawImage shield_left, x  , y
		DrawImage shield_right,x , y 


thats what ive been working with, thing is getting each arc in the right x and why positions and getting them to rotate properly. I had them in the right positions before, and rotating fine, but when I rotated my ship, the graphics stayed true, but the collision was awry.

this is one ill have to do through trial and error myself :)

the above is the result of endless variations ive tried, but u can see what im working with. Placing, and handling.

SetImageHandle(shield_front, ImageWidth(shield_front)/2,(ImageHeight(shield_front)+30)  )
		SetImageHandle(shield_aft,50,50)
		SetImageHandle(shield_left, 50,50 )
		SetImageHandle(shield_right, 50,50 )

		'SetAlpha 0.0
		'draw shield arcs around player ship
		DrawImage shield_front, x,  y  
		DrawImage shield_aft,   x , y 
		DrawImage shield_left,  x , y
		DrawImage shield_right, x , y 


ok above im trying to correct one at a time, starting with front shield. so without setting the +30 on the Y value in setimagehandle of front shield, the front arc appears of course in the centre of the ship, so I want to move it up a bit. so I put in -30, to go up as in to the top of the screen you subtract from the Y value, but oddly enough this causes it(the graphic to go DOWN), and I have to + 30 to get it to go up. This is where my collision is gone awry, something is opposited for some reason.

adjusting the X and Y of where the shield arc is drawn doesnt work because then it throws off the rotation. wont rotate the way they should.


Cruis.In(Posted 2006) [#10]

It depends on whether each of your shield arcs is drawn in its correct position within a square image, ie the left shield arc is on the left side of a square image and the right arc is on the right side, so that the centers of ALL five images (the ship and the 4 arcs) are all the same. Then you just rotate them together. You don't set the handle of the arcs to anything to do with the ship. You just do automidhandle or set the handle to the center, presuming the ship image and the arc images are all the same size squares on top of each other. Then rotating will rotate together. If your arcs are stored as narrow thin images then you will need to set the handle so that when they appear to be in the right position, their center is offset to one side of the arc image so it still is where the center of the ship is.


its the latter, the arcs are like -----> ( )
for top left bottom and right, and the image its on is as thin as the arc, no square. easier you think if i did the square? would that still go well for a ship any size?

If your arcs are stored as narrow thin images then you will need to set the handle so that when they appear to be in the right position, their center is offset to one side of the arc image so it still is where the center of the ship is.


this is the part i dont understand how to do. I understand what you mean by offsetting the centre to one side (left or right, bottom or top of the arc, depending on which arc) but not the part " so it is still where the centre of the ship is."


ImaginaryHuman(Posted 2006) [#11]
What is the dimensions of the left and right shield arc images?
What is the dimensions of the top and bottom shield arc images?
What is the dimensions of the ship image?

Since you aren't using square shield arc images, and since the arc within its image is not at the edge of a square but rather just the arc by itself, you have TWO levels of offsets to add to the handle.

Let's deal with the LEFT shield arc. The handle has to be the distance from the top left corner of the shield arc across and down to the center of the ship. You might understand it better if you FIRST create a handle that is centered on the shield arc. So if your shield arc image is, say, 10 width by 50 height, the handle would be 5,25. This centers on the shield arc. Then you need the difference between that position and the center of the ship. Let's say you want the center of the left shield arc to be 50 pixels to the left of the ship, you now add 50 to the handle position for the arc. so it would be 5+50,25 = 55,25.

You do the same with the right arc except now you subtract 50 from x instead of add it.

For the top arc find the middle of the arc image, then add the distance from the ship center to the y handle for the arc, e.g. 25,5+50

Then do the same for the bottom arc but subtract the difference between the ship center and the arc center ie 25,5-50

Then when you do the rotate thing they should all rotate around the ship center as if you have rods going out in a + formation from the ship center, attached to the center of each arc.

SetImageHandle(shield_front, ImageWidth(shield_front)/2,(ImageHeight(shield_front)/2)+50)

SetImageHandle(shield_aft,ImageWidth(shield_aft)/2,(ImageHeight(shield_aft)/2)-50)

SetImageHandle(shield_left, (ImageWidth(shield_left)/2)+50, ImageHeight(shield_left)/2)

SetImageHandle(shield_right, (ImageWidth(shield_right)/2)-50,ImageHeight(shield_right)/2)

                'SetAlpha 0.0
                'draw shield arcs around player ship
                DrawImage shield_front, x,  y  
                DrawImage shield_aft,   x , y 
                DrawImage shield_left,  x , y
                DrawImage shield_right, x , y 

I think that should work.

Bare in mind that you only need to set the image handles ONCE upon loading the images, you don't have to set them every time you draw them.

Also if you put the handle setting into a function, you could pass a `closeness` value which is your `50` or whatever, which you can call any number of times with different values to animate the shield arcs moving closer to or further away from the ship, or reacting to an impact, etc. You also might want to use floats e.g. 50.0


Cruis.In(Posted 2006) [#12]
so before they are loaded only , i thought it only affected drawing commands.

btw the dimensions for each arc are the same. basically you could say its one arc, just each in a different direction, for starboard,port,aft, etc...

of course your code there works perfect, as in the shield arcs are placed perfectly together to a T, and rotate well. However I have realised some of my ways I tested it works too.

What is happening however is I place an enemyship above me, and have him fire, and no matter what direction I have turned, thus turning my arcs, it always takes power from the front shield.

same with if i place an enemy below and rotate, it always takes from the rear shield.

i think the problem might lay with the fact that all of the arcs are drawn at the ships x and y, and the collision is checking at the ships X and Y for each arc image.
I tried adding in the numerical offset appropriately 50, -50 to each one, but it didn't entirely correct it.

also its interesting to see that in the imagehandle, one specifies a -50 or +50 value for an x or y coordinate but it moves opposite along the coordinate plane than how it should.

but putting offset in the drawing to position the arcs where they should be instead offset in the image handle, makes it so that i never can set a correct handle to get the arcs to rotate how they should, so by adjusting the drawing x and y they end up correctly positioned but without rotating the way i want them too.


Cruis.In(Posted 2006) [#13]


thats it now

and this is how a shield arc looks.



tonyg(Posted 2006) [#14]
You should be able to extract a small but full working example of the front/rear shield issue and post it.


Cruis.In(Posted 2006) [#15]
do you mean do up an independent piece of code which can be run to demonstrate the problem or post the working code I am having an issue with?

because the issue now is with the collision, they rotate and are placed correctly, but the handle or the fact that each arch is drawn at ship x and y is causing a problem.

before i started going about making the shield arcs rotate correctly, i had them behaving correctly with collision, by drawing them around the ship, and giving the collision function the coords of where the arcs are drawn, the problem came with rotating.

the thing is i have do
drawimage x + anything, Y + anything

i cant find where i should set the handle for the arcs so that they rotate correctly, so while doing the above sets them right with collision everything, rotation is off.


tonyg(Posted 2006) [#16]
do you mean do up an independent piece of code which can be run to demonstrate the problem or post the working code I am having an issue with?


Yes.


Cruis.In(Posted 2006) [#17]
yes to which one? lol


Cruis.In(Posted 2006) [#18]
after some more stuff, i feel the solution is simple, and what we/I was trying to do before should work.

my ship is located at the center of the screen.
however getting the player ship,x and y and drawing text to the screen it says 0,0

setting the X handle of the respective shield arc to the center is the first correct step. Then you can rotate each arc around the ship in a perfect circle similar to how the ship's nose or stern rotates in a perfect circle, by setting the Y handle of each arc to be the centre of the ship graphic.

the difficulty, or problem comes with setting that. setting the y handle to be ship.y which would be the center of the ship doesn't work, because that is the same to setting the Y value to 0, which has no effect so the arc just spins in an axis at the center of the arc itself. setting the Y handle with a number like 50 or so, puts an axis for the arc to rotate at, AT 50, and it rotates around that imaginary axis perfectly.

so unless I can figure out how to set the Y handle of each arc image to be the ships center, so it rotates on a virtual axis being the ships center, then it;ll never work.


tonyg(Posted 2006) [#19]
yes to which one? lol

Take your pick as it's difficult to know what you're after from text.
Anyway, I'd have used WendellM's suggestion from earlier.


Cruis.In(Posted 2006) [#20]
the thing is, with the player able to be multiple ships of different, sizes, drawing a shield image for each is alot.

maybe ill just make a line for the shield and alpha it, :)


Cruis.In(Posted 2006) [#21]
ive done it wendel's way. as i suspected the problem remains. while the placing of the arcs around the ship, and there rotation to keep the arcs in perspective, front shield arc @ front of ship as you rotate, the collision doesnt work.

its because each image is drawn at ship.x ship.y
when the collision works for each arc, i draw the shields arcs at offsets of the ship x and y.
drawimage ship.x, ship.y-50
for example is for the front shield to put it at the front of the ship.

but i cant get the shield arcs to rotate and keep perspective, when i draw the images that way.


bradford6(Posted 2006) [#22]
use sin and cos.


Cruis.In(Posted 2006) [#23]
to get the arcs to move in a circular motion, to keep the front arc, at the front area of the ship, and likewise for the rest respectively?


bradford6(Posted 2006) [#24]
yes


bradford6(Posted 2006) [#25]
here is an example

The shield arcs are in the move method. I just added them so it is quite crude but it should give you an idea.




ImaginaryHuman(Posted 2006) [#26]
To make the arcs move with the ship all you need to do is set the handles, then you should call SetRotation (rotate?) before drawing all 5 images, to the angle you want.


Cruis.In(Posted 2006) [#27]
yeah that works for that. but collision for each image is like this

checking enemy missile, x y, frame against one of the arcs, x, y,0

using imagescollide. problem is the x and y for the arcs is looking to the ships x and y for each arc. so it isn't hitting the correct arc when you turn to present a different arc.


Cruis.In(Posted 2006) [#28]
that works too brad. places them nice, rotates nice but not for collision.


bradford6(Posted 2006) [#29]
At this point Cruis, I think you need to post some working code. Isolate the problem and post something that shows the problem occuring.

Thanks.


Jesse(Posted 2006) [#30]
see if this can help you. I used your shield sample to code this. you might want to play with the image handle offsets to get the right connections.



Cruis.In(Posted 2006) [#31]
one more thing, if you had to add collision checking for each of those shield arcs, with an independent power level for each, what sort of collision checking and coordinates would you add.

Having tried each way suggested in this thread, and my initial ideas, rotation and placement of the shield. (like your shield distance, where the arcs are from the ship) the remaining problem, is im proper collision detection for each arc.

everytime i offset the coordinates of where each arc is drawn I apply that to the x and y coordinates in the collision check.

Here is the collision function.

'============================================================
'collision detection for shield arcs around the player ship.
'============================================================
Function coll_shieldarcs()
	For Local etorpedo:ettorpedo = EachIn ettorpedo.list
		If ImagesCollide(etorpedo.photonimage, etorpedo.x, etorpedo.y,etorpedo.frame,shield_front,ship.x,ship.y,0)
				'handle shields
				If ship.fore_shield_power < 5
					ship.foreshields = False
				Else
					ship.fore_shield_power :- 5
					texplosions.create(etorpedo.x,etorpedo.y,15)
				End If 
				
				'remove torpedo object when it hits, play shield hit effect.
				RemoveLink etorpedo.link
				PlaySound(Shieldhit)
		End If 
	
	
		If ImagesCollide(etorpedo.photonimage, etorpedo.x, etorpedo.y,etorpedo.frame,shield_right,ship.x,ship.y,0)
				'handle shields
				If ship.right_shield_power < 5
					ship.rightshields = False
				Else
					ship.right_shield_power :- 5
					texplosions.create(etorpedo.x,etorpedo.y,15)
				End If 
				
				'remove torpedo object when it hits, play shield hit effect.
				RemoveLink etorpedo.link
				PlaySound(Shieldhit)
		End If 
	
	
		If ImagesCollide(etorpedo.photonimage, etorpedo.x, etorpedo.y,etorpedo.frame,shield_aft,ship.x,ship.y,0)
				'handle shields
				If ship.aft_shield_power < 5
					ship.aftshields = False
				Else
					ship.aft_shield_power :- 5
					texplosions.create(etorpedo.x,etorpedo.y,15)
				End If 
				
				'remove torpedo object when it hits, play shield hit effect.
				RemoveLink etorpedo.link
				PlaySound(Shieldhit)
		End If 
	
	
		If ImagesCollide(etorpedo.photonimage, etorpedo.x, etorpedo.y,etorpedo.frame,shield_left,ship.x,ship.y,0)
				'handle shields
				If ship.left_shield_power < 5
					ship.leftshields = False
				Else
					ship.left_shield_power :- 5
					texplosions.create(etorpedo.x,etorpedo.y,15)
				End If 
				
				'remove torpedo object when it hits, play shield hit effect.
				RemoveLink etorpedo.link
				PlaySound(Shieldhit)
		End If 
	Next
End Function



Cruis.In(Posted 2006) [#32]
failing that, ill send the entire code to anyone, and highlight where my shield images are drawn, and the collision function, see if you can see why collision would be awry even though the graphics for the arcs are placed correctly, rotated correctly, and the collision checking has the correct coordinates of each placed shield arc.


Jesse(Posted 2006) [#33]
if you want to email me the code, I'll look at it tomorrow and I'll try to help you with what I can.


Cruis.In(Posted 2006) [#34]
ok

let me put it back where it is before all the changes.


Cruis.In(Posted 2006) [#35]
im wondering if i should make each shield an object. so it can have its on x and y coordinate.

as you can see my foreshield is the first shield arc being checked in collision. ive just now realised that as I turn the ship, no matter where I specify to check for the other shield arcs, the enemy torpedo is always impacting at where I am checking for the front shield arc.

I believed(am I wrong) the way I am doing my code, is if a torpedo was hitting the right shield, it would check for the right shield arc graphics x and y position. because the functions if imagescollide, is checking specific images and their coordinates... so if a torpedo goes to collide with a different image, it should't have to worry about the coordinates it was checking for the fore shield arc, because you've turned that arc out of the way of the torpedo, and it should now be striking the arc that is facing.

this is why i feel turning each arc into an instanced object would solve the problem, because it'll be checking each image, with its own set of coordinates and not checking each shield image at the one set of coordinates being ship.x and ship.y


Cruis.In(Posted 2006) [#36]
ive emailed the code to your address jesse, along with all graphics/sounds.

anyone else would like it?


Jesse(Posted 2006) [#37]
I figure it out, you are reseting your rotation angle back to 0 before collition testing. eventhough you are displaying the ship rotated you are testing the shields at zero degrees that is why it always collides with the the same shield at the same spot. here is what I did to solve the broblem:


hope that helps.


Jesse(Posted 2006) [#38]
I just realized tha imagescollide won't work with two images rotating at different angles. Does anybody know how to do this with another native command?


Jesse(Posted 2006) [#39]
I searched and I found. Next time I will search before asking. the correct command is imagescollide2.


Cruis.In(Posted 2006) [#40]
since you said you solved the problem already, I havent read it yet, that is good news.

I knew the problem was with the collision code reason being, everyones code worked right, it just frigged up when it came to collision, but the order of the checking wasn't wrong either, meaning If EndIF, If End if, there was nothing wrong with that, it worked for other things. I saw that what was happening was in this case, the front shield was being checked for collision first, and if you rotated, the torpedo would still collide in the area where the front shield WOULD be, if it had not rotated, it was easy to see as you could see the torpedoes go past the other shields slightly, but as you turned slowly watching the torpedo as you came back to face your front shield at it, you would realise the exact place the collision is occuring even when the front shield does not face, is AT the front shield coordinates.

I did the other approach I said I would do, and created T shield. Which has 4 shield arcs which are instanced. I placed two shield arcs to test. Front and Rear. So they rotate and place properly(though no exactly properly as this is just for test) Then I put the exact same collision code from coll_shieldarcs in there, this time when checking for collision with the front shield arc, i use the front shield arcs objects graphics which is shield_front.png and the front shield arc coordinates with fshield.FrontX, fshield.FrontY, and the checks work perfectly. The front shields are hit, the rear is hit, and the etc etc...

here is what I did.
please do not worry with the terrible coding stuff for this type. I was just conjuring it up quickly to test my theory the objects would work, once I tested the collision for each object.

'shields
Type tshield 

Rem
Field frontX = ship.x '- 25
Field frontY = ship.y '- 50
Field aftX = ship.x
Field aftY = ship.y
Field rightX = ship.x
Field rightY = ship.y
Field LeftX = ship.x
Field leftY = ship.y
End Rem

Field shield_front:timage = LoadImage("graphics\shield_front.png")
Field shield_aft:timage   = LoadImage("graphics\shield_aft.png")
Field shield_left:timage  = LoadImage("graphics\shield_left.png")
Field shield_right:timage = LoadImage("graphics\shield_right.png")


	Function create()		
		Local fshield:tshield = New tshield
		Local ashield:tshield = New tshield
		Local rshield:tshield = New tshield
		Local lshield:tshield = New tshield
		
		'set handle for arcs
		SetImageHandle(ashield.shield_aft,ImageWidth(shield_aft)/2, -ImageHeight(ship.shipimage))
		SetImageHandle(lshield.shield_left,ImageWidth(ship.shipimage)/2, ImageHeight(ship.shipimage))
		SetImageHandle(rshield.shield_right,-ImageWidth(ship.shipimage)/2, ImageHeight(ship.shipimage))
	    SetImageHandle(fshield.shield_front,ImageWidth(shield_front)/2, ImageHeight(ship.shipimage))
	
		
		'draw shield arcs
		SetRotation ship.angle
		DrawImage fshield.shield_front, ship.x,ship.y
		DrawImage ashield.shield_aft, ship.x,ship.y
		DrawImage lshield.shield_left, ship.x,ship.y
		DrawImage rshield.shield_right,ship.x,ship.y
	
			
		'collision for each arc respectively
		For Local etorpedo:ettorpedo = EachIn ettorpedo.list 
			If ImagesCollide(etorpedo.photonimage, etorpedo.x, etorpedo.y,etorpedo.frame,fshield.shield_front,ship.x,ship.y,0)
				'handle shields
				If ship.fore_shield_power < 5
					ship.foreshields = False
				Else
					ship.fore_shield_power :- 5
					texplosions.create(etorpedo.x,etorpedo.y,15)
				End If 
				
				'remove torpedo object when it hits, play shield hit effect.
				RemoveLink etorpedo.link
				PlaySound(Shieldhit)
			End If 
		
		
			If ImagesCollide(etorpedo.photonimage, etorpedo.x, etorpedo.y,etorpedo.frame,rshield.shield_right,ship.x,ship.y,0)
				'handle shields
				If ship.right_shield_power < 5
					ship.rightshields = False
				Else
					ship.right_shield_power :- 5
					texplosions.create(etorpedo.x,etorpedo.y,15)
				End If 
				
				'remove torpedo object when it hits, play shield hit effect.
				RemoveLink etorpedo.link
				PlaySound(Shieldhit)
			End If 
		
		
			If ImagesCollide(etorpedo.photonimage, etorpedo.x, etorpedo.y,etorpedo.frame,ashield.shield_aft,ship.x,ship.y,0)
				'handle shields
				If ship.aft_shield_power < 5
					ship.aftshields = False
				Else
					ship.aft_shield_power :- 5
					texplosions.create(etorpedo.x,etorpedo.y,15)
				End If 
				
				'remove torpedo object when it hits, play shield hit effect.
				RemoveLink etorpedo.link
				PlaySound(Shieldhit)
			End If 
		
		
			If ImagesCollide(etorpedo.photonimage, etorpedo.x, etorpedo.y,etorpedo.frame,lshield.shield_left,ship.x,ship.y,0)
				'handle shields
				If ship.left_shield_power < 5
					ship.leftshields = False
				Else
					ship.left_shield_power :- 5
					texplosions.create(etorpedo.x,etorpedo.y,15)
				End If 
				
				'remove torpedo object when it hits, play shield hit effect.
				RemoveLink etorpedo.link
				PlaySound(Shieldhit)
			End If 
		
		Next	
	End Function
End Type



thanks for help guys :)


Cruis.In(Posted 2006) [#41]
is the imagescollide2 question related to me? do i need to use it?

i didnt know you had to test between rotations, the only parameters asked for are, for images of the two things, x and y and frame...

the first way is simple, adding it as OOP adds nothign IMO, which do you think is best? In fact the way it will work now with it properly working, shields recharge, take damage and disappear/fail when energy to them is depleted.


Jesse(Posted 2006) [#42]
The code above is fine with imagescollide as long as the noncircular image is set to the proper rotation before any collition test is done. but for collition testing two images with their own angle of rotation you need to use imagescollide2.

I was looking at your code above and it doesn't seem as it would work. you are still colliding with the top shield only. and it will keep on happening as long as the proper angle is not set before collition is tested.
yes visually it looks like it is turnig because you set the rotation to the correct angle before displaying but you set rotation back to 0 before displaying other stuf such as text and other images. so by the time you get to the collition test, rotation is set to 0 and your collition test become inacurate.
if you look at the code I edited, the only thing I did was add the rotation instruction to work with imagescollide, Because the test needed to be done with the image at the appropriate angle of rotation.

In your case I recomend using imagescollide2 if you don't understand the principle of imagescollide. that should solve your problem.


Cruis.In(Posted 2006) [#43]
you mean i dont have to set the rotation of the torpedo in the collision function if i use imagescollide2?

and you said that my OOP way wouldn't work because the same problem exists. I agree with you, the problem should exist, as I have done nothing different. I place the arcs, i rotate them and i test each at ship.x and ship.y but Im telling you it works. Each shield is hit, and in the correct location. Perhaps making each a different object helps. Where as before the image was just a drawn image, this is an object, and object given the image of its respective arc.


Jesse(Posted 2006) [#44]

you mean i dont have to set the rotation of the torpedo in the collision function if i use imagescollide2?


that is correct.

I agree with you, the problem should exist, as I have done nothing different. I place the arcs, i rotate them and i test each at ship.x and ship.y but Im telling you it works.


the only explanation I can come out with on why it works is that you are rotating, displaying and then testing the collision before resetting the rotation back to 0. That would solve the problem for that issue. on the other hand you have to be careful that all of your collision detections happen in that order and that you are not colliding two independently rotated images. against each other because that would become up to 100% inaccurate. there is no guessing here. It either works correctly or it doesn't. if you don't know why it does, you need to analyse your code because it might fail when you least expect it.