Game Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesGame Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old September 2nd, 2006, 09:13 AM
william_nagels william_nagels is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Location: belgium
Posts: 101 william_nagels User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 27 m 7 sec
Reputation Power: 2
Send a message via MSN to william_nagels
Collision detection

hi,
i've made a new program to check if there is a collision.
It works .... but not complety.

It only works if my oval is in the rectangle and then if i move him(rectangle) the colision is detected that isn't right.
It has to detect by his self.
The first thing you think of you read this...ha he just forgot repaint(); nope that isn't true i checked for that can someone please help me. Here is my code


Code:
import java.awt.*;
import java.applet.*;

public class col extends Applet implements Runnable
{
    Image Buffer;
    Graphics gBuffer;
    int x, y;
    boolean mouseInside, collide;
    Rectangle r1, r2;

    public void init()
    {
        Buffer=createImage(size().width,size().height);
        gBuffer=Buffer.getGraphics();
        r1=new Rectangle(110,115,60,50);
        r2=new Rectangle(40,100);
    }

    public void drawStuff()
    {
        gBuffer.setColor(Color.white);

        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.black);

        if(collide)
            r1.y = 0;
    }

    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);


        collide=r1.intersects(r2);

        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){    r1.x++; repaint();
            			try{
                  		   Thread.sleep (20);
			           }
            			   catch (InterruptedException ex){}
			    repaint();
                            } 
                  }


}

Reply With Quote
  #2  
Old September 2nd, 2006, 04:58 PM
FernandoLujan FernandoLujan is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Location: Calgary, AB
Posts: 64 FernandoLujan User rank is Private First Class (20 - 50 Reputation Level)FernandoLujan User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 10 h 33 m 51 sec
Reputation Power: 2
Send a message via MSN to FernandoLujan
Well, I think this is the problem:

You have an oval which is the shape, and then the rectangle, which acts as the collision limits. Meaning, if another object touches the collision limits, a collision will be detected.

If what I think you're saying is correct. Not only should the collision rectangle move, but the oval aswell.

And if what I think is not correct. Sorry :P

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesGame Development > Collision detection


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway