#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Location
    belgium
    Posts
    116
    Rep Power
    8

    Half of a rectangle.


    OK look here is my problem:
    I'm working on a school program.
    There is a rolling ball and a rectangle.
    (height of the applet = 400 , width =400)
    how can i find out if the ball hits above the half of the rectangle or under the half.
    please help me.

    William
  2. #2
  3. <?PHP user_title("gimp"); ?>
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2005
    Location
    Internet
    Posts
    7,652
    Rep Power
    6084
    First, I think you just posted this.
    Second, you might want to post this in a language-specific forum next time, probably java? Can a mod move this there?
    Third, aren't you supposed to be doing homework with your brain, a book, a compiler, and an API? We don't really like homework questions here. We can prod you in the right direction if we see that you have put some effort into this. What do you have so far?
    Chat Server Project & Tutorial | WiFi-remote-control sailboat (building) | Joke Thread
    “Rational thinkers deplore the excesses of democracy; it abuses the individual and elevates the mob. The death of Socrates was its finest fruit.”
    Use XXX in a comment to flag something that is bogus but works. Use FIXME to flag something that is bogus and broken. Use TODO to leave yourself reminders. Calling a program finished before all these points are checked off is lazy.
    -Partial Credit: Sun

    If I ask you to redescribe your problem, it's because when you describe issues in detail, you often get a *click* and you suddenly know the solutions.
    Ches Koblents
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Location
    belgium
    Posts
    116
    Rep Power
    8

    i got this


    I'm pretty far already but i just keep getting the same error.
    It's a boolean probleme:
    the boolean always changes to 'heenschuin = true' i really don't get it .

    btw the language is java (applets....)
    this is my code


    Code:
    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    import java.awt.Event.*;
    public class col extends Applet implements Runnable
    {
        Image Buffer;
        Graphics gBuffer;
        int x, y;
        boolean mouseInside, collide, onderdeel1;
        boolean heen, terug;
        boolean heenschuin, terugschuin;
        Rectangle r1, r2;
        Rectangle bots1,bots2; 
    
        public void init()
        {
            Buffer=createImage(size().width,size().height);
            gBuffer=Buffer.getGraphics();
            r1=new Rectangle(110,115,10,10);
            r2=new Rectangle(0,0,25,50);
            bots1=new Rectangle(0,0,25,25);
            heen = true;
    	terug = false;
            heenschuin = false;
    	terugschuin = false;
            onderdeel1 = false;
    
        }
    
        public void drawStuff()
        {
            gBuffer.setColor(Color.black);
    
            gBuffer.fillRect(0,0,size().width,size().height);
    
            gBuffer.setColor(Color.red);
            gBuffer.fillOval(r1.x, r1.y, r1.width, r1.height);
    
            gBuffer.setColor(Color.blue);
    
            gBuffer.fillRect(r2.x, r2.y, r2.width, r2.height);
            gBuffer.setColor(Color.yellow);
            gBuffer.fillRect(r2.x, r2.y, bots1.width, bots1.height);
            gBuffer.setColor(Color.black);
    
        }
    
        public boolean mouseEnter(Event evt,int x,int y)
        {
            mouseInside=true;
            repaint();
    
            return true;
        }
    
        public boolean mouseExit(Event evt,int x,int y)
        {
            mouseInside=false ;
            repaint();
    
            return true;
        }
    
        public boolean mouseMove(Event evt,int x,int y)
        {
            this.x=x;
            this.y=y;
            r2.move(x-r2.width/2, y-r2.height/2);
            drawStuff();
    
            repaint();
            return true;
        }
    
        public void update(Graphics g)
        {
            paint(g);
        }
    
        public void paint(Graphics g)
        {
            drawStuff();
            g.drawImage (Buffer,0,0, this);
        }
    public void start(){
          		   Thread tbal = new Thread (this);
                       tbal.start(); 
                       }
    public void run (){
          		while (true){ 
    		            collide=r2.intersects(r1); 
     		            onderdeel1=bots1.intersects(r1);   
                                if (collide){
                                            if(onderdeel1){
                                                          terug = false;
    						      heen  = true;
                                                          collide=false;
                                                          heenschuin = false;
    	                                              terugschuin = false;
    	                                              onderdeel1 =false;
                                                          }
                                            else{
                                            terug = false;
    					heen  = false;
                                            collide=false;
                                            heenschuin = true;
    	                                terugschuin = false;
    	                                onderdeel1 =false;
                                                 }
                                             }
    			   else{}
                        
    		if(heen && collide==false){
    			if ( r1.x >400){
                                          heen = false; terug = true;
    			              }
    		        else{
                                r1.x=r1.x+2;
                                }
                                              }
    		if(heenschuin && collide==false){
    			r1.x = r1.x+2;
    			r1.y = r1.y+2;
                            }
    		if(terug && collide== false){
    			if ( r1.x <10){
                                          heen = true; 
                                          terug = false;
    			              }
    		        else{
                                r1.x=r1.x-2;
                                }
                            }
    		if(terugschuin && collide== false){
    			r1.x = r1.x-2;
    			r1.y = r1.y+2;
                            }	
     repaint();
                			try{
                      		   Thread.sleep (20);
    			           }
                			   catch (InterruptedException ex){}
    			    repaint();
                                } 
                      }
                                            }
  6. #4
  7. <?PHP user_title("gimp"); ?>
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2005
    Location
    Internet
    Posts
    7,652
    Rep Power
    6084
    All you need to do is check the collision coordinates.

    Do you have a collision detection algorithm?
    Chat Server Project & Tutorial | WiFi-remote-control sailboat (building) | Joke Thread
    “Rational thinkers deplore the excesses of democracy; it abuses the individual and elevates the mob. The death of Socrates was its finest fruit.”
    Use XXX in a comment to flag something that is bogus but works. Use FIXME to flag something that is bogus and broken. Use TODO to leave yourself reminders. Calling a program finished before all these points are checked off is lazy.
    -Partial Credit: Sun

    If I ask you to redescribe your problem, it's because when you describe issues in detail, you often get a *click* and you suddenly know the solutions.
    Ches Koblents
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Location
    belgium
    Posts
    116
    Rep Power
    8
    i fixed the probleme but thanks anyway
  10. #6
  11. Psycho Canadian
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Jan 2001
    Location
    Canada
    Posts
    4,846
    Rep Power
    635
    Originally Posted by gimp
    First, I think you just posted this.
    Second, you might want to post this in a language-specific forum next time, probably java? Can a mod move this there?
    Third, aren't you supposed to be doing homework with your brain, a book, a compiler, and an API? We don't really like homework questions here. We can prod you in the right direction if we see that you have put some effort into this. What do you have so far?
    FYI gimp that is the whole point of this forum, for questions like this.
  12. #7
  13. <?PHP user_title("gimp"); ?>
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2005
    Location
    Internet
    Posts
    7,652
    Rep Power
    6084
    Yeah, but I always assumed language-specific problems should be in language-specific forums? Guess I was wrong, then...
    Chat Server Project & Tutorial | WiFi-remote-control sailboat (building) | Joke Thread
    “Rational thinkers deplore the excesses of democracy; it abuses the individual and elevates the mob. The death of Socrates was its finest fruit.”
    Use XXX in a comment to flag something that is bogus but works. Use FIXME to flag something that is bogus and broken. Use TODO to leave yourself reminders. Calling a program finished before all these points are checked off is lazy.
    -Partial Credit: Sun

    If I ask you to redescribe your problem, it's because when you describe issues in detail, you often get a *click* and you suddenly know the solutions.
    Ches Koblents
  14. #8
  15. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,583
    Rep Power
    407
    Originally Posted by Viper_SB
    FYI gimp that is the whole point of this forum, for questions like this.
    Not for nothing.. but the post did sound like a language spacific problem though

IMN logo majestic logo threadwatch logo seochat tools logo