Game and Ball Hit problem

Hello everyone, I am working on a game and was wondering if I could get some help. I have a ball that bounces around in a box, and place one small ball in the applet. I want to create an effect that when the ball that is moving comes into connect with the static ball, the moving ball bounces in the opposite direction. I used this:
if(x_pos - 100 < 2 & y_pos - 100 < 2 || 100-x_pos < 2 && 100 - y_pos < 2)
where x_pos and y_pos are for the moving ball, and 100 is the radius of the static ball. Should I use the Pythagoras theorem to do it?
Thank You In Advance for any help.

Use java.awt.Shape and its contains() method. It's a standard collision detection idiom.

Similar Messages

  • X-Fi Gamer and 5:1 problems on ga

    Hi,?Just to clarify something, I seem to have a problem with my new x-fi gamer soundcard:?Maybe its just the way it is: I have run the wizard sound works ok on all speakers in windows when Im playing a game in game mode:?Like in planetside and bf242: I get sound out of all speakers the problem is I only get sounds of my gun firing from the center speaker only? this seems a bit of a waste if I only hear main sounds from the center speaker and the 2 other front speakers pick ambient sounds gun fire from other players?in the distance very strange?Is there something I need to in the control panel in windows?I have EAX enabled on both games aswell?Many thanks.Message Edited by unicronuk on 02-08-200706:3 AM

    your own gun from the center speaker is pretty standard. And correct in the surround mapping.
    As for enemy fire. There should definately be action taking place behind you if enemy gunfire is behind you. You are hearing everything else in surround though? If so, it must be as designed. =/

  • I am making code to try to make a game and my problem is that my code......

    I am making code to try to make a game and my problem is that my code
    will not let it change the hit everytime so im getting the first guy to hit 1 then next hits 8 and so on and always repeats.
    Another problem is that I would like it to attack with out me telling it how much times to attack. I am using Object oriented programming.
    Here is the code for my objects:
    import java.lang.*;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.util.Random;
    import static java.lang.Math.*;
    import java.awt.*;
    import java.awt.color.*;
    class rockCrab {
         //Wounding formula
         double sL = 70;                                   // my Strength Level
         double bP = 1;                                   // bonus for prayer (is 1 times prayer bonus)
         double aB = 0;                                 // equipment stats
         double eS = (sL * bP) + 3;                         // effective strength
         double bD = floor(1.3 + (eS/10) + (aB/80) + ((eS*aB)/640));     // my base damage
         //Attack formula
         double aL = 50;                                   // my Attack Level
         double eD = 1;                                   // enemy's Defence
         double eA = aL / eD;                              // effective Attack
         double eB = 0;                                   // equipment bonus'
         double bA = ((eA/10) * (eB/10));                    // base attack
         //The hit formula
         double fA = random() * bA;
         double fH = random() * bD;
         double done = rint(fH - fA);
         //health formula
         double health = floor(10 + sL/10 * aL/10);
         rockCrab() {
         void attack() {
              health = floor(10 + sL/10 * aL/10);
              double done = rint(fH - fA);
              fA = random() * bA;
              fH = random() * bD;
              done = rint(fH - fA);
              System.out.println("Rockcrab hit" +done);
    import java.lang.*;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.util.Random;
    import static java.lang.Math.*;
    import java.awt.*;
    import java.awt.color.*;
    class self {
         //Wounding formula
         double sL = 1;                                   // my Strength Level
         double bP = 1;                                   // bonus for prayer (is 1 times prayer bonus)
         double aB = 0;                                 // equipment stats
         double eS = (sL * bP) + 3;                         // effective strength
         double bD = floor(1.3 + (eS/10) + (aB/80) + ((eS*aB)/640));     // my base damage
         //Attack formula
         double aL = 1;                                   // my Attack Level
         double eD = 1;                                   // enemy's Defence
         double eA = aL / eD;                              // effective Attack
         double eB = 0;                                   // equipment bonus'
         double bA = ((eA/10) * (eB/10));                    // base attack
         //The hit formula
         double fA = random() * bA;
         double fH = random() * bD;
         double done = rint(fH - fA);
         //health formula
         double health = floor(10 + sL/10 * aL/10);
         self() {
         void attack() {
              health = floor(10 + sL/10 * aL/10);
              fA = random() * bA;
              fH = random() * bD;
              done = rint(fH - fA);
              System.out.println("You hit" +done);
    }Here is the main code that writes what the objects do:
    class fight {
         public static void main(String[] args) {
              self instance1 = new self();
              rockCrab instance2 = new rockCrab();
              instance2.health = instance2.health - instance1.done;
              System.out.println("You hit: " +instance1.done);
              System.out.println("rockCrabs health: " + instance2.health);
              instance1.health = instance1.health - instance2.done;
              System.out.println("RockCrab hit: " +instance2.done);
              System.out.println("rockCrabs health: " + instance1.health);
              instance2.health = instance2.health - instance1.done;
              System.out.println("You hit: " +instance1.done);
              System.out.println("rockCrabs health: " + instance2.health);
              instance1.health = instance1.health - instance2.done;
              System.out.println("RockCrab hit: " +instance2.done);
              System.out.println("rockCrabs health: " + instance1.health);
              instance2.health = instance2.health - instance1.done;
              System.out.println("You hit: " +instance1.done);
              System.out.println("rockCrabs health: " + instance2.health);
              instance1.health = instance1.health - instance2.done;
              System.out.println("RockCrab hit: " +instance2.done);
              System.out.println("rockCrabs health: " + instance1.health);
              instance2.health = instance2.health - instance1.done;
              System.out.println("You hit: " +instance1.done);
              System.out.println("rockCrabs health: " + instance2.health);
              instance1.health = instance1.health - instance2.done;
              System.out.println("RockCrab hit: " +instance2.done);
              System.out.println("rockCrabs health: " + instance1.health);
    }when the code is run it says something like this:
    you hit 1
    RockCrabs health is 9
    RockCrab hit 7
    your health is 38
    you hit 1
    RockCrabs health is 8
    RockCrab hit 7
    your health is 31
    you hit 1
    RockCrabs health is 7
    RockCrab hit 7
    your health is 24
    you hit 1
    RockCrabs health is 6
    RockCrab hit 7
    your health is 17
    my point is whatever some one hits it always repeats that
    my expected output would have to be something like
    you hit 1
    RockCrabs health is 9
    RockCrab hit 9
    your health is 37
    you hit 3
    RockCrabs health is 6
    RockCrab hit 4
    your health is 33
    you hit 2
    RockCrabs health is 4
    RockCrab hit 7
    your health is 26
    you hit 3
    RockCrabs health is 1
    RockCrab hit 6
    your health is 20
    Edited by: rade134 on Jun 4, 2009 10:58 AM

    [_Crosspost_|http://forums.sun.com/thread.jspa?threadID=5390217] I'm locking.

  • What are the problems associated with Minecraft game and Apple computers

    What are the problems with Minecraft game and Apple computers.  I've read that the two are incompatible.

    You have a very limited amount of time before night falls and the monsters might come out. You have to HOLD DOWN the mouse button to hit things to change them. Hit the earth to dig a cave. Hit a tree repeatedly to get wood.
    A two button mouse is superior, because a lot of actions require a left click. <-- OH That is why they say it is not compatible!
    It is compatible, you just need to left click sometimes!

  • HT5137 I made a purchase with my debit card on The Simpson Tapped out game, And now my game won't open. It just kicks me out every time I click on it. How do I fix this problem with out deleting my app?

    I made a purchase with my debit card on The Simpson Tapped out game, And now my game won't open. It just kicks me out every time I click on it. How do I fix this problem with out deleting my app?

    Personally, I would never use a debit card online, for security reasons.  If your card gets hacked its your money that is stolen.  At least with a credit card it is the card providers money that is stolen.
    Anyway,  I would delete the app and re-install.  If you paid for the app in the first place you will be able to re-install free of charge.  Also, the app should allow the in-app purchase to happen again as it should recognise that you have already purchased it previously.
    Finally, it might be that the 3G doesnt have as much ram as more recent models of iphone and you may have applications running in the background that are preventing the app to function with the in-app purchase unless you shut down any apps eating all you memory that are running in the background.  Shut-down these apps (and the simpson tap out app) by exiting to your home screen and double-tapping the home button to show what apps are running in the background.  press and hold any of the open apps until it starts shaking.  close all the apps down.  exit then re-launch the app.
    good luck.

  • Im worried about the battery percentage while play a game on my iphone 4s.so that,i decided to play a games and charging at the same time.is it problem on my battery ? im to worried.please give a conclusion.

    Im too worried about the battery percentage while playing a game on my iphone 4s.so that,i decided to play a games and charging at the same time.im too worried for my battery problem on the future.please give a conclusion.

    It is perfectly fine to use the phone while charging it.

  • My iphone3g its ben having a lot of problems i it will not lock i open a game and it will go to im  ipod im probly going to get a new one but i would like to know what is rong

    my iphone3 its ben havin g a lot of problems it will not lock i open a game and
    it will go to ipod  im going to get a new one but i would like to know what is rong with it

    Yeah, and it didn't work.
    I had problems when I updated to iOS 5 (lost all my apps - a few of my friends had the same problem) and when there was an update to iOS 4 (camera wouldn't work). The iOS 5 issue was sorted by backup (but I lost the app data) but for the iOS 4 issue I had to return my iPod to get a new one.

  • I already purchase a game and kind a deleted it when i finished playing the whole game. Now my problem is i'm trying to download it again and its asking to pay for it again. What should i do?

    I already purchase a game and kind a deleted it when i finished playing the whole game. Now my problem is i'm trying to download it again and its asking to pay for it again. What should i do?

    I did that already i can download the game but it still asking me to pay for every level even thou i pay already for the whole thing.

  • Hello, I have a problem. Help me to solve it. The first time I want to buy the game and asks me to answer a security question that I do not remember. Discard them please that I introduced them to

    Hello, I have a problem. Help me to solve it. The first time I want to buy the game and asks me to answer a security question that I do not remember. Discard them please that I introduced them to

    See Kappy's great User Tips.
    See my User Tip for some help: Some Solutions for Resetting Forgotten Security Questions: Apple Support Communities https://discussions.apple.com/docs/DOC-4551
    Rescue email address and how to reset Apple ID security questions
    http://support.apple.com/kb/HT5312
    Send Apple an email request for help at: Apple - Support - iTunes Store - Contact Us http://www.apple.com/emea/support/itunes/contact.html
    Call Apple Support in your country: Customer Service: Contacting Apple for support and service http://support.apple.com/kb/HE57
     Cheers, Tom

  • I'm attempting to install cs6 and after hitting install the following message appeared: installer failed to initialize. please download adobe support advisor to detect the problem. well that has been discontinued...

    i'm attempting to install cs6 and after hitting install the following message appeared: installer failed to initialize. please download adobe support advisor to detect the problem. well that has been discontinued...

    rename OOBE Folder to OOBE.old.
    to find OOBE:
    64 bit OS: Program Files x86\Common Files\Adobe\OOBE
    32 bit OS: Program Files \Common Files\Adobe\OOBE

  • I purchased dungeon hunter alliance from the app store and accidentally hit the x button instead of the installed button to install the game how do I install the game now

    Can someone help me, I purchased the game dungeon hunter alliance froom the app store and accidentally hit the x button instead of the install button so now how can I install the game to my computer macbook

    Hi ...
    You accidentally "hid" the purchase ..
    Follow the instructions here.  Mac App Store: Hiding and unhiding purchases
    Once the app is available ...
    How to re download apps from the Mac App Store:
    Open the App Store. From the menu bar click Store > Sign In
    Click Purchases from the top of the App Store window.
    Select which apps you want to re download. Then right or control click where you see Installed  then click Install.
    Make sure and use the same Apple ID used for the original purchase.

  • HT1567 i can not download free games and movies on my 8gb ipod and how can i fixe that problem

    I used to download games and movies on my 8gb ipod touch and all of the sudden it stop and i can't download anymore, i would like to know how can i fixe that problem.

    Need more information. What happens when you try? Error messages?

  • Details:  i can not buy any thing from the app store and any thing from in side any games pls fix my problem urgent and as soon

    Details:
    Hi i can not buy any thing from the app store and any thing from in side any games pls fix my problem urgent and as soon
    Note this is second email pls answer and fix my problem
    <Email Edited by Host>

    These are public forums, you are not talking to iTunes Support here (most of the people here, including myself, are fellow users) - I've asked the hosts to remove your email address from your post
    If you are getting a message to contact iTunes support then you can do so via this page and ask them why the message is appearing (we won't know why) : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption
    If it's a different problem ... ?

  • I have ipad 2 16gb wifi, recently it starts autorestart and crashs out of games and apps, more than 20 times aday- tried to restore, updated to the latest 7.0.4 but still the same problem

    i have ipad 2 16gb wifi, since 3 months it started to autorestart and crash out of games and apps, more than 20 times aday- tried to restore-install as new ipad- soft and hard reset-, updated to the latest 7.0.4 but still the same problem
    plz help....

    Vinayaka-
    After all you've tried, Dah*veed is probably right about needing warranty assistance.
    But first check to be sure Settings-Airplane Mode is set to OFF, and Settings-WiFi-WiFi is set to ON.
    Try unplugging your WiFi router for a few seconds.  Then reset the iPad's network.  Go to Settings-General-Reset-Reset Network Settings.  You will need to reconnect to your WiFi.
    Fred

  • Here.  Hi I buy pack but the problem is you already purchased in-app purchased but it hasn't been downloaded pls fix it for me and I buy before 15 days pack 19,99 and 4,99 and the same problem  in game world strike

    Hi I buy pack but the problem is you already purchased in-app purchased but it hasn't been downloaded pls fix it for me and I buy before 15 days pack 19,99 and 4,99 and the same problem want or were can I fit it pls

    The e-mail for World Strike support is: [email protected]
    You need to contact them with your questions.

Maybe you are looking for

  • MacBook Pro 10.4.9 Mail Search option not working!

    When a key word or email address is entered into the search pain of mac mail, it produces 0 results every time, even when I have an email open containing the exact key word or email address. Another thread suggested running a downloadable Etresoft re

  • Apps appearing in $$$ and not £££

    Hi all, My first post here! I have a UK i-phone straight from O2, no unlocking nothing. Just noticed that my I-Phone apps store has now turned itself American! Have checked with friends that their's are still in sterling currency. Anyone got any idea

  • Link opened in an IFRAME abandons the page

    A certain page on my site uses an iframe to link to a page in another domain. My page loads properly and displays the content from the remote domain in the iframe that I expect to see. Problem comes whenever I click on any link within the iframe. The

  • License Problem after formating Hard Drive

    Hello, I'm french, so my english isn't very good, I'm sorry for this. I have got a problem with my Adobe Photoshop Elements 8 license. My Grandfather bought this software 5month ago and installed it in his computer. He lend me the CD and I installed

  • Adobe Audition 3.0 Problems

    Kind of Long - Windows XP SP3 I play guitar and bass guitar, and want to record them. I have my guitar connected to a ZOOM G1N Multi FX Pedal. The OUTPUT cable from the pedal is then connected to my computer at the LINE IN jack. My headphones come fr