well, a very wierd problem


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 1 of 1

Thread: well, a very wierd problem

Threaded View

  1. #1
    Join Date
    Mar 2003
    Posts
    8

    Unhappy well, a very wierd problem

    hi i'm new in these forums,

    and i have a very wierd problem in my very first java game-applet.

    well, it is a shooting game(i dont really like shooting games but they are easier to program)
    and the problem occurs not when compiling nor activating, but when your bullet approches an enemy spacecraft.....

    till now it worked 100%. i had a little spaceship that it's y was constant and the x varies by the mouse, you could shoot by left clicking, and they were enemies(though they werent affected by your shots..)

    the enemies were contained in a Point array, that contained their coordinates.(by the way it was a single-class program, and i know i'm not getting the best of object oriented programming)

    to detect collision between the enemies and your bullet(only one bullet can be active at the same time)
    i created a new int method used to calculate the distance between two points by using Pythagoras' technique(written in the tutorial "java by example" section 5 page 8 i think)

    which is
    (int)Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));

    ...by the way, my JCreator didnt listed that method in that list on the left, very odd.

    now the main problem is that when you shoot an enemy, one of the following will happen :

    1.the enemy will be destroyed as i programmed it to.
    2.the enemy will be destroyed only if i'll shoot it a pixel or two left to its center(almost always on the leftmost enemy)
    3.the enemy could not be killed
    4.when i hit the side of the enemy(especially on its right side), the enemy beside it destroyed istead of itself....

    i used the same distance calculation for ALL of the enemies(i used a for loop), and i know my numbers are correct(the maximum distance of collision).

    you might think that this problem was something that i made up, but i SWEAR it true....

    can you help????

    and i also attached the full code(commented) in a txt file.

    n.b. i'm using JDK 1.4 on winxp home edition

    nick
    Attached Files Attached Files
    I wonder how poisoned Java tastes like....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center