[java] Java 1.1, Collision detection and fliping image

Started by
3 comments, last by farhanx 19 years, 10 months ago
hi every one|! i am facing some problem , i am at the end of my webgame but i am facing some problems. 1) i have sprites with 1 direction(left) , i want to flip them (right)on keyboard event.I know its easy in java 1.2 and so on but i want to make this game in java 1.1 so it will work on all pc without any problem. If some one know how i can do this then please guide me 2)i am using pathagoras theorm for detection, like dist=(int)Math.sqrt((PlayerX-(DogX))*(PlayerX-(DogX))+(PlayerY-200)*(PlayerY-200)); here Dog is the enemy , problem is this when dog hit and move forward and when i forward my self again before reaching to dog''s middle portion it collides....... it seems like player is hitting with dog even there is a big space between them while when both faces infront of each other then it hits without a space problem (means correctly). How can i control this any got any idea??? these problems are becoming wall for me to make a good webgame.. Thanks in advance Farhan
Things has been changed but the just the way it is....
Advertisement
I think you can flip images by just using drawImage(theImage,x,y,-width,height,null)

Notice the "-"!
If this doesn't work, get the pixels with a pixelGrabber, flip them, put them back into animage using a MemoryImageSource.

Wherefore is the "200" in your formula?
(By the way,it is pythagoras)

-edit:forgot a parameter in drawImage

[edited by - koroljov on June 11, 2004 8:56:39 AM]
Why do my programs never work on other computers?
Thanks for reply , i am using -(width) rightnow to flip the image but its not working perfectly it changes the X position and i think its all because of it what i am facing, actully when i move left or right by using minus width it doesnt place the image on same position while X-Y is both same in left and right place....maybe thats why its not collides with other object on same position.

I dont know how i can grap these pixels can u little be more specific to guide me or any code...

Thanks to correct me about pathagoras i mean pythagoras
Things has been changed but the just the way it is....
Yes it changes the X position. Try this: drawImage(theImg, x+width, y, -width, null). If that doesn''t work I''ll post pixelgrabber code.
Why do my programs never work on other computers?
Thanks alot man , your one line has made my whole game cool , now collision detection are going fine as how it should be , and flipping images too.

thanks champs
Things has been changed but the just the way it is....

This topic is closed to new replies.

Advertisement