Computer Science Canada Turing - Blocking my dot using if whatdotcolor URGENT |
Author: | TuringMaster87 [ Sat Jan 19, 2013 11:12 am ] | ||
Post subject: | Turing - Blocking my dot using if whatdotcolor URGENT | ||
What is it you are trying to achieve? <Replace all the <> with your answers/code and remove the <>> Hey guys i have an assignment due sunday night, and i need to block off my dot from going over the boundries. So i have 2 dots one blue and green. And i did if whatdotcolor to each of them with no luck. The boundries work for some sides but not all. What is the problem you are having? <Answer Here> Cannot block off the boundries Describe what you have tried to solve this problem <Answer Here> I tried looking at other posts but got no help. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) <Answer Here> var input : string (1) var x : int := 180 var y : int := 180 var x1:int :=190 var y1: int :=190 var xx, yy : int := 0 var xx1,yy1 :int := 0 var LOSE : int := 0 var chars : array char of boolean %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% drawfillbox (0,0,640,400,black) drawbox (1,1,636,389,54) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% loop %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Input.KeyDown (chars) if chars ('w') then yy := 3 xx := 0 elsif chars ('a') then yy := 0 xx := -3 elsif chars ('s') then yy := -3 xx := 0 elsif chars ('d') then yy := 0 xx := 3 end if x := x + xx y := y + yy drawfilloval (x, y, 5, 5, 54) delay (10) drawfilloval (x,y, 5, 5, 54) if xx= -3 and whatdotcolor (x-6,y)= 54 or whatdotcolor (x-6,y) = 10 %Left Direction then cls exit elsif yy= +3 and whatdotcolor (x,y+6) =54 or whatdotcolor (x,y+6)= 10%Up direction then cls exit elsif xx= +3 and whatdotcolor (x+6,y) =54 or whatdotcolor (x+6,y) = 10%Right Direction then cls exit elsif yy= -3 and whatdotcolor (x,y-6)=54 or whatdotcolor (x,y-6)= 10%Down Direction then cls exit end if %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if chars (KEY_UP_ARROW) then yy1 := 3 xx1 := 0 elsif chars (KEY_LEFT_ARROW)then yy1 := 0 xx1 := -3 elsif chars (KEY_DOWN_ARROW) then yy1 := -3 xx1 := 0 elsif chars (KEY_RIGHT_ARROW) then yy1 := 0 xx1 := 3 end if x1 := x1 + xx1 y1 := y1 + yy1 drawfilloval (x1, y1, 5, 5, 10) delay (5) drawfilloval (x1,y1, 5, 5, 10) if xx1= -3 and whatdotcolor (x1-6,y1)= 10 or whatdotcolor (x1-6,y1)= 54 %Left Direction then cls exit elsif yy1= +3 and whatdotcolor (x1,y1+6) =10 or whatdotcolor (x1,y1+6) = 54 %Up direction then cls exit elsif xx1= +3 and whatdotcolor (x1+6,y1) =10 or whatdotcolor (x1+6,y1) = 54 %Right Direction then cls exit elsif yy1= -3 and whatdotcolor (x1,y1-6)=10 or whatdotcolor (x1,y1-6) = 54 %Down Direction then cls exit end if end loop %%%%%%%%%%%%%%%%%%%%%%%%% x,y,xx,yy = Blue x1,y1,xx1,yy1 = Green
Please specify what version of Turing you are using <Answer Here> I am using latest version |
Author: | evildaddy911 [ Sat Jan 19, 2013 11:35 am ] |
Post subject: | RE:Turing - Blocking my dot using if whatdotcolor URGENT |
You need to put the boundary detection where you update the x/y coordinates. First, you need to check if the dot is moving left. Then you check if it is within the left boundary. if both are true, you then update the x coordinate. If either are false, check if moving right and dot is within the right boundary. If those are true, update the x coord. Repeat for the y coordinates. If you have to use whatdotcolor (i wouldn't reccommend it), then to check the left boundary for example, you need a for loop (for y: lowerBound .. upperBound) and check whatdotcolor (leftBound, y) if you get a hit, exit the loop. if you make it to the end of the loop, then you know the boundary is clear. |