Computer Science Canada

WHATDOTCOLOR!!!!

Author:  Spartan_117 [ Sat May 28, 2005 6:04 pm ]
Post subject:  WHATDOTCOLOR!!!!

In turing i've used what dot colour for simple colision detection, and now i'm using Java. Does anyone kno the command for What Dot Colour in Java?

Thx

Author:  wtd [ Sat May 28, 2005 6:28 pm ]
Post subject: 

Don't work that way in Java. Java has more sophisticated graphics capabilities. Make use of them. Rather than manually testing the color of pixels, keep track of where objects are on the screen, then do the collision detection separate from the graphics stuff entirely.

Author:  Spartan_117 [ Sun May 29, 2005 10:53 am ]
Post subject: 

Thats wut i'm doing, checking positions on screen. Im making the first Mario Bros game and im checking positions for colision detection between enemies and Mario, but for platforms I believe checking positions is a lot more complicated than needed, What dot Colour would work fine to check if mario has landed on a platform or not.

Author:  wtd [ Sun May 29, 2005 11:49 am ]
Post subject: 

The approach I descried offers you flexibility. It's known as MVC: Model-View-Controller. You have code that displays the output and gathers input from the user (the View). You have code that maintains the state of the game, including things like player positions, enemy positions, obstacle positions, etc (the Model). And then you have code that communicates between them, taking a keypress from the View and chaning the Model, for instance (the Controller).

Author:  Spartan_117 [ Sun May 29, 2005 12:08 pm ]
Post subject: 

hmmm...sry, but i'm a little confused, what i was thinking was Mario will have (X1, Y1) and (X2, Y2), and the enemies will have the same, and i can detect collisions. is this wut ur talking about?

Author:  wtd [ Sun May 29, 2005 1:27 pm ]
Post subject: 

Basically, yes. MVC sounds complicated, but a lot of us use it without even realizing it.

Author:  Spartan_117 [ Mon May 30, 2005 3:58 pm ]
Post subject: 

Well i've used MVC, but i'm still in need of what dot colour, so if any one knows how i can check the colour of given co-ordinates in Java, please help. So far i've come accross the PixelGrabber class, but not sure how to use it.

Author:  Martin [ Tue May 31, 2005 9:11 am ]
Post subject: 

Whatdotcolour is a terrible way to do collision detection. If you're making Mario, you'll want there to be invisible blocks. How do you propose you'll do that with whatdotcolour?

Use bounding boxes and check for collisions in the background.

Author:  Spartan_117 [ Tue May 31, 2005 9:36 am ]
Post subject: 

No i'm not using invisible blocks in my game. I'm making Mario Bros. which doesnt have any invisible blocks. I've already spoke to many people for my problem so what dot colour is definately what i'm in need of.

Author:  [Gandalf] [ Wed Jun 01, 2005 9:35 am ]
Post subject: 

Have you ever actually played Mario Brothers? The real one?

First level (if I remebers correctly) *double checked*:
Jump past the fourth underground tunnel pipe thing, then just before the mountain in the background, jump. A box will appear, and a "1 up" will pop out.

You don't call that an invisible block?

*Edit I checked, looks like I haven't lost my Mario touch Very Happy*

*Edit 2 - Well, maybe...*

Author:  Spartan_117 [ Wed Jun 01, 2005 9:48 am ]
Post subject: 

I believe you are talking about super mario. I'm talking about Mario Bros. This is the Mario with one level with pipes at the top. First two levels turtles come out of pipes. In this game you hit the floor with Mario's head from below to knock enemies, instead of jumping on them. Also, i'm sure you remember the POW box or button at the bottom of the screen. Hitting this would knock out all enemies.[/img]

Author:  Spartan_117 [ Wed Jun 01, 2005 9:48 am ]
Post subject: 

I believe you are talking about super mario. I'm talking about Mario Bros. This is the Mario with one level with pipes at the top. First two levels turtles come out of pipes. In this game you hit the floor with Mario's head from below to knock enemies, instead of jumping on them. Also, i'm sure you remember the POW box or button at the bottom of the screen. Hitting this would knock out all enemies.

Author:  1of42 [ Wed Jun 01, 2005 3:19 pm ]
Post subject: 

I think that's basically quibbling. The other posters on this thread are correct - it is better by far to use the coordinates of the various objects to do collision detection.

Whatdotcolour is a very limited method in the long run, and worse, it teaches you bad habits.

Author:  Hikaru79 [ Wed Jun 01, 2005 7:29 pm ]
Post subject: 

Spartan, take our word for it. We're not saying whatdotcolour will not WORK. It surely will, for some very limited purposes. However, we are saying it is NOT THE RIGHT SOLUTION for the job. The correct solution, as wtd has pointed out, is treating the logic of the game differently from its display. Figure out whether he's collided by always knowing where each object is in a logical format. Not by relying on cheap color tricks. Believe me, it will make your writing and debugging much easier.

They're not just insisting on this approach because they don't know how to answer your question or something. They're trying to steer you in the right direction.

Author:  McKenzie [ Wed Jun 01, 2005 9:57 pm ]
Post subject: 

First off, Mario Bros is a great game for a final project that is very different from Gandalf's Mario (i.e. Super Mario Bro.) Second I'm not sure anyone who has posted knows how to use whatdotcolour in Java. The reality is it a POOR solution that no one can be bothered to look up. Mario Bro. the original has LESS of a reason to use whatdotcolour than Super Mario does.

Author:  Spartan_117 [ Thu Jun 02, 2005 7:11 pm ]
Post subject: 

Ya, i've pretty much forgot about using whatdotcolour. I've already done most collision detection

but if someone knows i'd be curiouos to kno

Author:  Hikaru79 [ Thu Jun 02, 2005 7:23 pm ]
Post subject: 

McKenzie wrote:
Second I'm not sure anyone who has posted knows how to use whatdotcolour in Java.

Well, it's my experience that if someone is given what they think is an easy way, they'll take it. But since Spartan seems to have taken care of it already, there's no harm Smile

There's a "Robot" class in the Java standard library (starting from 1.4.2 and up) that can do this. It has a method, "getPixelColor(int x, int y)" that will return the "Color" object of the corresponding pixel. I think you need to pass a particular Graphics object in as the Screen in the constructor, or else "Robot" will take the entire screen into calculation (since the "Robot" class is meant for doing things involving controlling keyboard/mouse movements for automated demonstrations, etc).

If you can't pass in a Graphics object to the Robot, you can use a particular component's "getLocationOnScreen" method and just subtract the two values to get the co-ordinate relative to the component's top-left corner.

Author:  Spartan_117 [ Fri Jun 03, 2005 8:26 am ]
Post subject: 

Robot eh? interesting name. Well thx ne ways. and dont worry people, Mr. McKenzie already knows i'm not using whatdotcolour for collisions any more.

thx


: