I think I found the problem. my tplayership type has two fields, x and y. field x:float, field y:float
when i instance ship:tplayership
and targetship:tplayership
they both instance at those default x and y because they would be 0, since i havent specified a number in their fields. i tested this by putting the x and y fields to 512, 384... and the drawtext coords are in my debug function and it read the same coords for both playershipX and targetshipX. and the Y values as well.
i thought that my function which has image,x,y in it when i called it would make the difference when i called it by changing targetship.x = x and the same for Y.
where x and Y in this function, are the values i give to the function parameters when i call it. the drawship function above. I moved the targetship.x = x out of the If
Keyhit T statement and put it so it sets those values when the function is called. so now that works.
edit
I am doing this to teach myself and understand better the use of lists. Collision detection tests. so that i can put combat in the game. so i was trying to make an enemyship which initiazlized with its own shield and hull, so thats the way i did, to test. I'm sure once ihave the full grasp I can add combat properly
Plus I thought I had types down. I dont want to create a type for every ship in the game...
this function works now with the collision function
HERE IS THE COLLISION FUNCTION
I guess you guys understand why im doing this weird code... just trying to understand things before i go off coding without understanding how everything works with regards to these things.
when i instance ship:tplayership
and targetship:tplayership
they both instance at those default x and y because they would be 0, since i havent specified a number in their fields. i tested this by putting the x and y fields to 512, 384... and the drawtext coords are in my debug function and it read the same coords for both playershipX and targetshipX. and the Y values as well.
i thought that my function which has image,x,y in it when i called it would make the difference when i called it by changing targetship.x = x and the same for Y.
where x and Y in this function, are the values i give to the function parameters when i call it. the drawship function above. I moved the targetship.x = x out of the If
Keyhit T statement and put it so it sets those values when the function is called. so now that works.
edit
I am doing this to teach myself and understand better the use of lists. Collision detection tests. so that i can put combat in the game. so i was trying to make an enemyship which initiazlized with its own shield and hull, so thats the way i did, to test. I'm sure once ihave the full grasp I can add combat properly
Plus I thought I had types down. I dont want to create a type for every ship in the game...
this function works now with the collision function
Function DrawShip( image:timage, x, y ) SetRotation(0) SetColor 255,255,255 SetScale(1.0 *newscale, 1.0*newscale) SetAlpha(1.0) SetBlend(ALPHABLEND) MidHandleImage (image) targetship.x = x targetship.y = y 'draws the ship if the shiplist is empty. Shiplist gets a ship when I press T If ListIsEmpty(targetship.shiplist) = False DrawImage(image, x , y ) DrawText("target shieldpower= "+targetship.shieldpower,ship.x-512,ship.y+150) DrawText("target Hull= "+targetship.hull_strength,ship.x-512,ship.y+170) End If 'adds object to shiplist, other code is just part of my testing If KeyHit(KEY_T) targetship.shiplink = ListAddLast(targetship.shiplist, targetship) targetship.shieldpower = 200 End If End Function
HERE IS THE COLLISION FUNCTION
Function Collision() Local torpedo:ttorpedo = New ttorpedo For torpedo = EachIn torpedo.torplist 'if the list is empty, the torpedo will pass through where targetship.x and and targetship.y 'will be. Because it is just a "bot" and won't move...Otherwise my torps would explode 'even when the ship graphic is gone" 'if the list is empty, then the torpedoes just go on happily. If ListIsEmpty(targetship.shiplist) = False If ImagesCollide(torpedo.photonimage, torpedo.x, torpedo.y,torpedo.frame,targetship.shipimage,targetship.x,targetship.y,0) If targetship.shields = False targetship.hull_strength:-5 Else targetship.shieldpower :- 5 End If 'handle shields If targetship.shieldpower < 5 targetship.shields = False targetship.shieldpower = 0 End If 'basic destroy code If targetship.hull_strength < 5 RemoveLink targetship.shiplink End If 'stupid box i draw so i can see when it flashes when a collision occurs. 'it flashes on and off screen too fast, with just text. DrawText "COLLISION!",50,50 DrawRect 50,50,50,50 PlaySound(torpedoexplosionFx) RemoveLink torpedo.link End If End If Next End Function
I guess you guys understand why im doing this weird code... just trying to understand things before i go off coding without understanding how everything works with regards to these things.