Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 More efficient method of whatdotcolor?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
jinjin




PostPosted: Sun May 18, 2008 6:39 pm   Post subject: More efficient method of whatdotcolor?

Hi everybody,

I am currently making a fighting game for my Grade 10 ISU and I was hoping to use whatdotcolor for collision detection as it is a very easy method which is great for someone like myself who is currently inexperienced with Turing. However, in my fighting game, there are several pictures that are used for various character movements instead of Turing-drawn graphics. Does this mean that the only way I can use whatdotcolor for my collision detection is if I draw a small dot precisely on the throughout the entire perimeter of each of my pictures? I could do this but it would likely take hours. So, is there any faster/more efficient way of doing this while still using whatdotcolor collision detection? Any help is appreciated. Thanks. Smile
Sponsor
Sponsor
Sponsor
sponsor
Saad




PostPosted: Sun May 18, 2008 6:42 pm   Post subject: Re: More efficient method of whatdotcolor?

Yes there is, what you want to do is use geometrical shapes to represent each object. As a result it becomes simple collision detection between 2 shapes

Collision detection with shapes can be found here

On a another note, Never use whatdotcolor for collision detection. You want both the graphics and the collisions to be independent of each other
isaiahk9




PostPosted: Sun May 18, 2008 6:48 pm   Post subject: RE:More efficient method of whatdotcolor?

If your game involves gravity at all, spare yourself the grief of making boundaries with View.Whatdotcolor. I'm making a fighter game and just maed my boundaries. When gravity is present, View.WhatDotColor won't work for boundaries (character will fall through the boundary and re-appear above it, and eventually just fall through and not re-appear). Instead, I hard coded my boundaries (if character position is where he shouldn't, draw him somewhere else).
For one box hard-code, it takes four if loops. But, it works better than View.WhatDotColor. View.WhatDotColor works with everything else though. This will also solve your issues mentioned above.
If you don't wanna hard-code (especially if there is no gravity), then there isn't any more for me to say here that is helpful.
jinjin




PostPosted: Sun May 18, 2008 7:08 pm   Post subject: Re: More efficient method of whatdotcolor?

Saad @ Sun May 18, 2008 6:42 pm wrote:
Yes there is, what you want to do is use geometrical shapes to represent each object. As a result it becomes simple collision detection between 2 shapes

Collision detection with shapes can be found here

On a another note, Never use whatdotcolor for collision detection. You want both the graphics and the collisions to be independent of each other


Thanks for the tutorial link Saad, I am currently overlooking it and I believe that rectangular collision detection would work best in this case.

isaiahk9 wrote:

If your game involves gravity at all, spare yourself the grief of making boundaries with View.Whatdotcolor. I'm making a fighter game and just maed my boundaries. When gravity is present, View.WhatDotColor won't work for boundaries (character will fall through the boundary and re-appear above it, and eventually just fall through and not re-appear). Instead, I hard coded my boundaries (if character position is where he shouldn't, draw him somewhere else).
For one box hard-code, it takes four if loops. But, it works better than View.WhatDotColor. View.WhatDotColor works with everything else though. This will also solve your issues mentioned above.
If you don't wanna hard-code (especially if there is no gravity), then there isn't any more for me to say here that is helpful.


Thanks isaiahk9, but my game doesn't involve gravity so there is no problems there. I have also already made my boundaries by putting if statements for the walls when the character is walking in the boundary's respective direction (i.e. if *character is walking right* and x < maxx then x := x + 10 end if).
isaiahk9




PostPosted: Sun May 18, 2008 8:01 pm   Post subject: RE:More efficient method of whatdotcolor?

That's what I meant. And how do you have a fighting game without gravity? (not a negative comment)
jinjin




PostPosted: Sun May 18, 2008 8:56 pm   Post subject: Re: More efficient method of whatdotcolor?

isaiahk9 wrote:

That's what I meant. And how do you have a fighting game without gravity? (not a negative comment)


I used increasing and decreasing for loops for the jumps. I know it's probably the most noob way to do jumping but when I looked at Mazer's gravity tutorial, I was completely confused and the ISU is due this Friday so I don't want to tread too far into uncharted territory at this point.
isaiahk9




PostPosted: Mon May 19, 2008 6:18 am   Post subject: RE:More efficient method of whatdotcolor?

Increasing and decreasing for loops are fine. Most people don't include gravity in games till grade 11 or 12.
jinjin




PostPosted: Mon May 19, 2008 3:20 pm   Post subject: Re: More efficient method of whatdotcolor?

Saad @ Sun May 18, 2008 6:42 pm wrote:
Yes there is, what you want to do is use geometrical shapes to represent each object. As a result it becomes simple collision detection between 2 shapes

Collision detection with shapes can be found here

On a another note, Never use whatdotcolor for collision detection. You want both the graphics and the collisions to be independent of each other


Now, when I try doing this, pictures collide at the points at which the boundaries of their pictures are. However, they do not stand exactly like perfect rectangles (i.e. in walking stances one leg is forward but picture boundaries only allow for them to stand like perfectly rectangular totem pole-like figures). Thus, I was forced to adjust x/y values manually and this was quite time consuming. Therefore, I checked back on whatdotcolor simply for testing if it would take less time to do (this is not considering program efficiency as I am right now just trying to complete this game) and whatdotcolor collision detection didn't seem to work for me at all. When I drew grey dots all over one character and red dots over another, collision didn't seem to occur even though, visibly, dots were overlapping. It works fine when I use a Turing-drawn rectangle however. Here is some of the whatdotcolor collision code I used:

Turing:

%% background
 Pic.Draw (scale, 0, 0, picCopy)
%% character 1
Pic.Draw (pic52, x2, y2, picMerge)
%% character 2
Pic.Draw (pic48, x3, y3, picMerge)

drawdot (x2 + 57, y2 + 76, red)
drawdot (x2 + 63, y2 + 76, red)
drawdot (x2 + 59, y2 + 76, red)
drawdot (x2 + 67, y2 + 77, red)
drawdot (x2 + 71, y2 + 78, red)
drawdot (x2 + 75, y2 + 80, red)
drawdot (x2 + 79, y2 + 83, red)
%% etc.. more drawdots for both x2 and drawdots for x3 in grey ... %%

if whatdotcolor (x + 57, y + 76) = grey or
whatdotcolor (x + 63, y + 76) = grey or
whatdotcolor (x + 59, y + 76) = grey or
whatdotcolor (x + 70, y + 78) = grey or
whatdotcolor (x + 71, y + 78) = grey or
%% etc.. more coordinates of checking
then put "COLLISION!"
end if


Note also that the characters are both moving but I am not sure if that makes a difference as the dots are almost exactly in the same place each time.

I later even tried drawing a Turing oval on top of one of the characters and whatdotcolor collision still failed. Any help on this issue is appreciated.
Sponsor
Sponsor
Sponsor
sponsor
r691175002




PostPosted: Mon May 19, 2008 4:28 pm   Post subject: Re: More efficient method of whatdotcolor?

Saad @ Sun May 18, 2008 6:42 pm wrote:
On a another note, Never use whatdotcolor for collision detection. You want both the graphics and the collisions to be independent of each other

Why not? While it is slow there are cases where pixel perfect collision detection is a great bonus, plus generating a geometrical representation of complex shapes puts a lot of work on whoever is providing the art and requires a more complicated engine.
Saad




PostPosted: Mon May 19, 2008 4:47 pm   Post subject: Re: More efficient method of whatdotcolor?

While that is true, for objects with a wide range of colors, the color collision then can become quite a pain. Also, View.WhatDotColor on colors limits Turing to picking from the current color palete (If you didn't add a color then it will be forced to choose from the 8-bit color palette) limiting you to only 256 colors for collision. Another point that I can think of is how do you determine what object it collided with eg. Say I wanted to damage the ship I collided with, I only have the color but what ship?. I think time could be better spent finding ways to represent the object rather then try to find work arounds for these things.
richcash




PostPosted: Mon May 19, 2008 4:54 pm   Post subject: Re: More efficient method of whatdotcolor?

Also, what if you want to extend the game beyond the scope of the screen (there are things colliding elsewhere on the map). You would have to draw everything on your map (not just on-screen objects) and use whatdotcolour. Very inefficient. What if you want to make your game 3d all of a sudden? Whatdotcolour method is null.

Whatdotcolour can only be as accurate as the size of pixels on the screen, but mathematical methods can be perfect. And, most importantly, you can always use math to determine collision between two moving objects, but you can't do that with whatdotcolour. Usually finding the collision in time of two moving objects is an extension of the same methods used to determine the intersection of those same objects while static (for example : circles, convex polygons). Most times when collision detection is used in games, it should be time-based collision, so why not make it perfect?

Edit - But I do see your point, whatdotcolour can be A LOT easier for certain tasks. It is not bad to use it if you are certain of the situation, but it can prevent learning new ways and extending your game.
Insectoid




PostPosted: Mon May 19, 2008 8:30 pm   Post subject: RE:More efficient method of whatdotcolor?

I'm using entirely whatdotcolor for collision in my pacman, but then, the pictures are just 1-2 colors...I do have octagonal collision detection for sprite-on-sprite though
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 12 Posts ]
Jump to:   


Style:  
Search: