The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Game Development
|
Half of a rectangle.
Discuss Half of a rectangle. in the Game Development forum on Dev Shed. Half of a rectangle. Game Development forum covering non language specific programming - game creation, design, modding, theories and math. A place for developers and gamers of all levels to discuss and debate all things involved in game creation and modding.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

September 2nd, 2006, 03:09 PM
|
|
Contributing User
|
|
Join Date: Aug 2006
Location: belgium
Posts: 116

Time spent in forums: 1 Day 7 h 2 m 45 sec
Reputation Power: 7
|
|
|
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
|

September 2nd, 2006, 03:27 PM
|
 |
<?PHP user_title("gimp"); ?>
|
|
Join Date: Jan 2005
Location: Internet
|
|
|
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
|

September 2nd, 2006, 03:42 PM
|
|
Contributing User
|
|
Join Date: Aug 2006
Location: belgium
Posts: 116

Time spent in forums: 1 Day 7 h 2 m 45 sec
Reputation Power: 7
|
|
|
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();
}
}
}
|

September 2nd, 2006, 06:45 PM
|
 |
<?PHP user_title("gimp"); ?>
|
|
Join Date: Jan 2005
Location: Internet
|
|
|
All you need to do is check the collision coordinates.
Do you have a collision detection algorithm?
|

September 3rd, 2006, 07:02 AM
|
|
Contributing User
|
|
Join Date: Aug 2006
Location: belgium
Posts: 116

Time spent in forums: 1 Day 7 h 2 m 45 sec
Reputation Power: 7
|
|
|
i fixed the probleme but thanks anyway
|

September 3rd, 2006, 11:37 PM
|
 |
Psycho Canadian
|
|
Join Date: Jan 2001
Location: Canada
|
|
Quote: | 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.
|

September 4th, 2006, 07:44 PM
|
 |
<?PHP user_title("gimp"); ?>
|
|
Join Date: Jan 2005
Location: Internet
|
|
|
Yeah, but I always assumed language-specific problems should be in language-specific forums? Guess I was wrong, then...
|

September 4th, 2006, 10:32 PM
|
 |
Only the strong survives!!.
|
|
Join Date: Feb 2003
Location: A World of wonders.
|
|
Quote: | 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 
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|