[Tutorial] whatdotcolor
Author 
Message 
Cuzty

Posted: Wed May 12, 2004 6:16 pm Post subject: (No subject) 


Ok mister whatdotcolor master guy.. umm i was wondering if you can make the bullet kill the ball that comes down. And i apologize for the crappy code.. i'm not very good at this turing stuff so plz bear with me .
code:  setscreen ("offscreenonly")
var m, x, a, b, ymouse, xmouse, button : int
%The Plane
procedure plane
drawline (xmouse  4, 5, xmouse, 40, 4)
drawline (xmouse  3, 5, xmouse, 40, 4)
drawline (xmouse  2, 5, xmouse, 40, 4)
drawline (xmouse  1, 5, xmouse, 40, 4)
drawline (xmouse, 5, xmouse, 40, 4)
drawline (xmouse + 1, 5, xmouse, 40, 4)
drawline (xmouse + 2, 5, xmouse, 40, 4)
drawline (xmouse + 3, 5, xmouse, 40, 4)
drawline (xmouse + 4, 5, xmouse, 40, 4)
end plane
%The falling ball
process nme
loop
cls
randint (m, 10, maxx  10)
for decreasing i : maxy .. 1 by 7
drawfilloval (m, i, 10, 10, 4)
delay (10)
end for
end loop
end nme
%Your Plane
process you
loop
mousewhere (xmouse, ymouse, button)
cls
plane
View.Update
%The Bullet
if button = 1 then
a := xmouse
b := ymouse
for i : 40 .. 400 by 5
cls
mousewhere (xmouse, ymouse, button)
plane
drawline (a  1, i, a  1, i + 40, 7)
drawline (a, i, a, i + 40, 7)
drawline (a + 1, i, a + 1, i + 40, 7)
View.Update
end for
end if
end loop
end you
fork nme
fork you 
Oh, and if possible.. can you make the ball stop flickering? Thanks so much in advance, sir. 





Sponsor Sponsor



Leny

Posted: Wed Jun 02, 2004 9:17 am Post subject: (No subject) 


Ok so you can do anything with whatdotcolour so help me then how do i do what dot coulr in a circular pattern
i.e. in my curling game i need to do the scoreing at the end by checking which rocks are closer to the center
so if there are two blue rocks closer then the first red rock then the score becomes two blue or one red rock cloest to the center then a blue one closer then the next red one then the score is one red
how would i do that? 





Tony

Posted: Wed Jun 02, 2004 12:06 pm Post subject: (No subject) 


Leny : don't make things complicated and just use Math.Distance() 
Tony's programming blog. DWITE  a programming contest. 




Leny

Posted: Wed Jun 02, 2004 2:35 pm Post subject: (No subject) 


our school computers can't do that i've tried it as well as others and it wont work for anyone including the teach who knows what she's doing 





Tony

Posted: Wed Jun 02, 2004 5:09 pm Post subject: (No subject) 


Leny : Math.Distance is a v4.0.5 feature. If you don't have the latest version of turing installed, you can write this function yourself
code: 
function distance (x1, y1, x2, y2 : int) : real
result sqrt ((x2  x1) ** 2 + (y2  y1) ** 2)
end distance
%example
put distance (0, 0, 3, 4)


Tony's programming blog. DWITE  a programming contest. 




Leny

Posted: Thu Jun 03, 2004 9:14 am Post subject: (No subject) 


so how would i use this math.distance thingger then? is there a tutorial on it?
or maybe a basic program with it to look at 





Tony





Leny

Posted: Thu Jun 03, 2004 5:31 pm Post subject: (No subject) 


thanks man if i have any trouble i'ma ask ya more about it but i should figure it out 





Sponsor Sponsor



theanimator

Posted: Wed Oct 26, 2005 8:11 pm Post subject: (No subject) 


this whatdotcolour makes no sense to me at all. Bare with me i am just a beginner. 





TokenHerbz

Posted: Thu Oct 27, 2005 2:59 am Post subject: (No subject) 


code: 
(x1,xy) <TOP RIGHT OF SQUARE
%%%%%%%
% %
% %
%%%%%%%
(x,y) << BOTTOM LEFT OF SQUARE!
whatdotcolor takes the 2 varibles, say (x,y) and looks on the background
of your program, and sees which colour it is on...

heres an example!
code: 
%%Example.
setscreen("Graphics:max;max,offscreenonly")
var x,y: int
var x1,y1: int
x:= 50
y := 50
x1:= x+50
y1 := y+20
loop
cls
x += 1
x1+= 1
drawfillbox(225,25,175,75,black) %%this is BIG BLACK BOX!
if whatdotcolor(x,y) = 7 then %%IF x,y SEE BLACK!
exit %%LEAVES THE LOOP!
end if
drawbox(x,y,x1,y1,red)
View.Update
delay(20)
end loop
put "Done"

If you run that, you will see it stops only when x,y get hit...
Now if we refer to the top diagram i shows, x1,y1 need to be in play aswell.! this way it will stop at the front.
So we just modify this here...
code: 
if whatdotcolor(x,y) = 7 or %%IF x,y SEE BLACK!
whatdotcolor(x1,y1) = black then %%7 and black are the same thing.
exit %%LEAVES THE LOOP!
end if

run it...
BUT, lets see, change y to this ...
Run that, now you will see that the x1,y1 position is missed, and its not a detection collition at all, so we have to think hard cause programming not easy. For effective collotioning/ useing whatdotcolor, you must cover all angles, i trust you learned a bit??? Well Gl with this! i ll let you try some stuff now
EDIT::
So, we need to be creative (which i am not) and make a simple code what checks all of the obsticle, or at least.. the border of it.
um somthing like??
code: 
%%Example.
setscreen("Graphics:max;max,offscreenonly")
var x,y: int
var x1,y1: int
var endgame: boolean := false
x:= 50
y := 65
x1:= x+50
y1 := y+20
loop
if endgame = true then
exit
end if
cls
x += 1
x1+= 1
drawfillbox(225,25,175,75,black) %%this is BIG BLACK BOX!
for i: x .. x1
for j: y .. y1
if whatdotcolor(i,j) = 7 then %%IF x,y SEE BLACK!
endgame := true %%SETS END GAME!
exit
end if
end for
if endgame = true then
exit
end if
end for
drawbox(x,y,x1,y1,red)
View.Update
delay(20)
end loop
put "Done"

Notice how slow it moves, its not efficiant, cause its checking the INSIDE of the rectangle, when we only need it to check the borders, so ill let you think about it, and work with that... Bye!
EDIT:::
Well again i wish to help you think on how to visualize getting a border..
if we think a 5*5 square..
its,
code: 
x,y: int := 0
drawbox(x,y,x+5,y+5,black)

lets look at the *structure* of this
NOTE::: The 1st numbers are x axis numbers, 2nd are the y axis.
code: 
1,5 2,5 3,5 4,5 5,5
1,4 2,4 3,4 4,4 5,4
1,3 2,3 3,3 4,3 5,3
1,2 2,2 3,2 4,2 5,2
1,1 2,1 3,1 4,1 5,1

So with that there, Try to code a patter which checks essentailly only these numbers.
code: 
1,5 2,5 3,5 4,5 5,5
1,4 5,4
1,3 5,3
1,2 5,2
1,1 2,1 3,1 4,1 5,1

Now, to make it a bit easier for you to get which variables are which..
code: 
x,y+4  x+1,y+4  x+2,y+4  x+3,y+4  x+4,y+4
x,y+3 x+4,y+3
x,y+2 x+4,y+2
x,y+1 x+4,y+1
x,y  x+1,y  x+2,y  x+3,y  x+4,y

Now you wouldn't want to enter in all the possible variables for a big square, so image if you could have a counter??
of course then, you could replayce all the numbers with i(for x axis) and j(for y axis)
The code gets a little complex, and ill post it later if you dont get it
i think i tend to make thinks more complex then they should :S 





BenLi

Posted: Tue May 02, 2006 4:03 pm Post subject: (No subject) 


i have a question, why would you use whatdotcolor for things that can probably be done easier with other methods? its a total waste of time 





md

Posted: Tue May 02, 2006 4:44 pm Post subject: (No subject) 


Because it works for very simple cases and doesn't require consious thought.
Really using math to do collisions is only easy if you know the (admittedly basic) math and are familiar enough with things like records to keep track of everythign easily. 





HellblazerX

Posted: Tue May 02, 2006 4:53 pm Post subject: (No subject) 


Whatdotcolor is not useless. In fact, it's quite useful in collision detection. Normally, you would use coordinates and calculate whether or not one object is within another, but with whatdotcolor, you can easily determine whether or not the objects have collided by checking the colors of a particular point. Also, if you use coordinates, collision detection becomes more and more difficult when more objects are placed on the field, and the objects themselves become more complicated in their shapes. With whatdotcolor, it doesn't get that much more difficult. 





Andy

Posted: Fri May 05, 2006 9:18 pm Post subject: (No subject) 


cornflakes! you're such a blasphemer! how dare you say that about whatdotcolour? haha jk..
my obsession with whatdotcolour has nothing to do with "taking the easy way" but rather thinking abstractly. collision detection whatdotcolor is for noobs... unless you're talking about masking irregular shapes 





BenLi

Posted: Thu May 11, 2006 3:07 pm Post subject: (No subject) 


Though for the example above, it'd be much better to use Math.Distance for the circle 






