Whatdotcolour problem, too many colours?
Author |
Message |
jmarsiglio
|
Posted: Tue May 25, 2010 8:58 pm Post subject: Whatdotcolour problem, too many colours? |
|
|
What is it you are trying to achieve?
I'm trying to recognize the crosshairs colliding with the targets
What is the problem you are having?
I believe the whatdotcolour function does not recognize the colour of the target.
Describe what you have tried to solve this problem
Placing collision method in different places
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing: |
setscreen ("graphics:800;600,offscreenonly,nobuttonbar,position:center;center, title:Josh's game")
Text.ColourBack (black)
cls
var mx, my, mb, clr, posx, posy, random : int := 0
var colr : array 1 .. 3 of int := init (49, 36, 34)
var target : boolean := false
clr := white
proc Check_Collision
for i : 1 .. 3
if whatdotcolour (mx, my ) = colr (i ) then
cls
View.Update
delay (10000)
end if
end for
end Check_Collision
proc Draw_Cross (mx, my : int)
Draw.Oval (mx, my, 80, 80, clr )
Draw.Oval (mx, my, 40, 40, clr )
Draw.Line (mx - 90, my, mx + 90, my, clr )
Draw.Line (mx, my - 90, mx, my + 90, clr )
Draw.FillOval (mx, my, 5, 5, red)
end Draw_Cross
proc Draw_Target (posx, posy, colr : int)
case (colr ) of
label 49 :
Draw.FillOval (posx, posy, 25, 25, colr )
target := true
label 36 :
Draw.FillOval (posx, posy, 15, 15, colr )
target := true
label 34 :
Draw.FillOval (posx, posy, 10, 10, colr )
target := true
end case
end Draw_Target
posx := Rand.Int (25, maxx - 25)
posy := Rand.Int (25, maxy - 25)
random := Rand.Int (1, 3)
loop
mousewhere (mx, my, mb )
if target = false then
random := Rand.Int (1, 3)
posx := Rand.Int (25, maxx - 25)
posy := Rand.Int (25, maxy - 25)
end if
Draw_Target (posx, posy, colr (random ))
Check_Collision
Draw_Cross (mx, my )
View.Update
Time.DelaySinceLast (1)
cls
end loop
|
Please specify what version of Turing you are using
4.11
#EDIT: I got it to work using Math.Distance, but I still would like to know how i do this with whatdotcolour! Thanks |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Wed May 26, 2010 11:16 am Post subject: RE:Whatdotcolour problem, too many colours? |
|
|
What does your program do during this line?
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
jmarsiglio
|
Posted: Wed May 26, 2010 2:51 pm Post subject: Re: Whatdotcolour problem, too many colours? |
|
|
For testing purposes! I just wanted to make sure that it recognizes the collision, so it pauses the whole game, i assume!
... but it doesn't so something is flawed, any ideas?
I probably should have commented my program but I guess if someone could tell me this general question: How do i use whatdotcolour on a dot with multiple colours on it? Because in this case I don't think it detects any colour in my colr array! |
|
|
|
|
|
chrisbrown
|
Posted: Wed May 26, 2010 3:12 pm Post subject: Re: Whatdotcolour problem, too many colours? |
|
|
jmarsiglio @ Wed May 26, 2010 2:51 pm wrote: How do i use whatdotcolour on a dot with multiple colours on it? Because in this case I don't think it detects any colour in my colr array!
The problem is in the order that things occur. Because you are using offscreenonly, you are drawing to the buffer instead of directly to the screen, so this is what is happening:
1) Get mouse position
2) Draw a target to the buffer
3) Check the screen colour (not the buffer colour) at the mouse position
4) Draw the crosshairs to the buffer
5) Draw the buffer to the screen
6) Clear the screen
As far as your program is concerned, the colour at the mouse position is always going to be the default background colour. To prove it to yourself, remove the "offscreenonly" as a test (expect flickering). After that, you can figure out how to restructure the flow of the program to account for this. Logically though, you were on track.
Added: This is an example of why colour-based collision detection is a bad idea. The display should be nothing more than a representation of the program's internal state at some point; the program should never rely on the display to determine behaviour, because it is clearly not guarenteed to be a current representation. |
|
|
|
|
|
jmarsiglio
|
Posted: Wed May 26, 2010 5:07 pm Post subject: Re: Whatdotcolour problem, too many colours? |
|
|
Ahhh thanks that explains a lot! So to fix this, could I simply Update the screen after I draw the target, then check collision before I draw the Crosshair? I can only think of doing this. Again, I got my program to work using circle collision detection but I like being able to use a variety of things available in a language. I might even use this program as my final project ( so far I got score, timer and a basic game where you hit the targets as fast as you can and win/gain points according to time and/or size of target ). Any suggestions to improve my game? I am definitely going to add music, and I will post the "Beta" on this thread, if I'm allowed? Thanks and appreciate your feedback |
|
|
|
|
|
chrisbrown
|
Posted: Wed May 26, 2010 5:43 pm Post subject: RE:Whatdotcolour problem, too many colours? |
|
|
Forgive me, I don't have time to look at the details right now, but I just wanted to point out that I'm not sure whether "cls" clears the screen or the buffer. I'll look into it and the rest later.
But by all means, post your progress if you continue. |
|
|
|
|
|
Insectoid
|
Posted: Wed May 26, 2010 9:37 pm Post subject: RE:Whatdotcolour problem, too many colours? |
|
|
Clears the buffer. Gotta View.Update after CLSing. |
|
|
|
|
|
jmarsiglio
|
Posted: Thu May 27, 2010 9:34 am Post subject: Re: Whatdotcolour problem, too many colours? |
|
|
I updated after i cleared the screen, and only a black screen is shown.
Anyways, the first *final copy is here : http://www.mediafire.com/?tzrlmy5wzkm
Contains the file with source + pics + music.
1 question, when I create a stand-alone program, it doesn't create it with my pictures and music added, how do I add these files to the executable so it runs correctly? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
chrisbrown
|
Posted: Thu May 27, 2010 9:58 am Post subject: RE:Whatdotcolour problem, too many colours? |
|
|
It's not as easy as adding an update or rearranging the order. However, since you're using the better distance approach, there's no point trying to perfect a flawed method. Just be aware of and avoid it.
Now, "how do I add these files to the executable so it runs correctly?"
Everything including the .exe should be in one parent folder, and your file paths should be relative to that parent. You should not have any occurrences of C:\... or some other drive letter.
If you mean how do you create a stand-alone .exe without having to include all the pics and music, it cant't be done without some seriously dirty stuff, and it's definitely not worth the time. Just include them alongside it. |
|
|
|
|
|
jmarsiglio
|
Posted: Thu May 27, 2010 10:48 am Post subject: Re: Whatdotcolour problem, too many colours? |
|
|
but *how would I do it with whatdotcolour? And anyone feel free to post feedback on my program if you feel like even downloading it And btw, anyone have any good compression software, because winrar compressed only makes it about 10% smaller. Add: Actually more like 4%... Edit: I checked out that all compression software can't compress mp3 more than 1%, so I deleted one of the music files. Now it should only be 4.1MB. |
|
|
|
|
|
|
|