|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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
|
||||
|
||||
|
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?
__________________
A work in progress: Card Game Platform (Status: On Hold) | 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.” |
|
#3
|
|||
|
|||
|
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();
}
}
}
|
|
#4
|
||||
|
||||
|
All you need to do is check the collision coordinates.
Do you have a collision detection algorithm? |
|
#5
|
|||
|
|||
|
i fixed the probleme but thanks anyway
|
|
#6
|
||||
|
||||
|
Quote:
__________________
Miscellaneous Software Viper_SB Developershed E-Support Anyone else play chess? Challenge me Challenge me |
|
#7
|
||||
|
||||
|
Yeah, but I always assumed language-specific problems should be in language-specific forums? Guess I was wrong, then...
|
|
#8
|
||||
|
||||
|
Quote:
![]()
__________________
IE QUOTE | PHP Manual | Google | C/C++ Compiler | Linux Tutorials | General Stuff Game Dev |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Game Development > Half of a rectangle. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|