Computer Science Canada S.O.S I need help |
Author: | Derpmemes [ Sat Jun 02, 2012 12:42 pm ] |
Post subject: | S.O.S I need help |
So... at school I was told to create a Maze in Turing. I got the moving part and the whole maze down (ex. maze walls). I am trying hard to make a collision system whenever my character touches the wall, but I don't know how??? This is the code I have var chars : array char of boolean var x, y := 5 var x2, y2 := 20 var box1_x1, box1_y1, box1_x2, box1_y2 : int var box2_x1, box2_y1, box2_x2, box2_y2 : int var box3_x1, box3_y1, box3_x2, box3_y2 : int var box4_x1, box4_y1, box4_x2, box4_y2 : int var box5_x1, box5_y1, box5_x2, box5_y2 : int var box6_x1, box6_y1, box6_x2, box6_y2 : int var box7_x1, box7_y1, box7_x2, box7_y2 : int var box8_x1, box8_y1, box8_x2, box8_y2 : int var box9_x1, box9_y1, box9_x2, box9_y2 : int var box10_x1, box10_y1, box10_x2, box10_y2 : int var box11_x1, box11_y1, box11_x2, box11_y2 : int var box12_x1, box12_y1, box12_x2, box12_y2 : int var box13_x1, box13_y1, box13_x2, box13_y2 : int var box14_x1, box14_y1, box14_x2, box14_y2 : int %The background of the maze drawfillbox (0, 0, maxx, maxy, black) %Box 1 box1_x1 := 0 box1_y1 := 50 box1_x2 := 300 box1_y2 := 60 drawfillbox (box1_x1, box1_y1, box1_x2, box1_y2, yellow) %Box 2 box2_x1 := 350 box2_y1 := 0 box2_x2 := 360 box2_y2 := 145 drawfillbox (box2_x1, box2_y1, box2_x2, box2_y2, yellow) %Box 3 box3_x1 := 105 box3_y1 := 145 box3_x2 := 450 box3_y2 := 155 drawfillbox (box3_x1, box3_y1, box3_x2, box3_y2, yellow) %Box 4 box4_x1 := 105 box4_y1 := 145 box4_x2 := 115 box4_y2 := 310 drawfillbox (box4_x1, box4_y1, box4_x2, box4_y2, yellow) %Box 5 box5_x1 := 440 box5_y1 := 145 box5_x2 := 450 box5_y2 := 215 drawfillbox (box5_x1, box5_y1, box5_x2, box5_y2, yellow) %Box 6 box6_x1 := 200 box6_y1 := 215 box6_x2 := 360 box6_y2 := 225 drawfillbox (box6_x1, box6_y1, box6_x2, box6_y2, yellow) %Box 7 box7_x1 := 200 box7_y1 := 215 box7_x2 := 210 box7_y2 := 310 drawfillbox (box7_x1, box7_y1, box7_x2, box7_y2, yellow) %Box 8 box8_x1 := 350 box8_y1 := 215 box8_x2 := 360 box8_y2 := 310 drawfillbox (box8_x1, box8_y1, box8_x2, box8_y2, yellow) %Box 9 box9_x1 := 270 box9_y1 := 275 box9_x2 := 280 box9_y2 := maxy drawfillbox (box9_x1, box9_y1, box9_x2, box9_y2, yellow) %Box 10 box10_x1 := 350 box10_y1 := 300 box10_x2 := maxx box10_y2 := 310 drawfillbox (box10_x1, box10_y1, box10_x2, box10_y2, yellow) %Box 11 box11_x1 := 550 box11_y1 := 195 box11_x2 := 560 box11_y2 := 310 drawfillbox (box11_x1, box11_y1, box11_x2, box11_y2, yellow) %Box 12 box12_x1 := 440 box12_y1 := 50 box12_x2 := maxx box12_y2 := 60 drawfillbox (box12_x1, box12_y1, box12_x2, box12_y2, yellow) %Box 13 box13_x1 := 495 box13_y1 := 50 box13_x2 := 505 box13_y2 := 200 drawfillbox (box13_x1, box13_y1, box13_x2, box13_y2, yellow) %The finish box box14_x1 := 585 box14_y1 := 0 box14_x2 := maxx box14_y2 := 50 drawfillbox (box14_x1, box14_y1, box14_x2, box14_y2, brightgreen) %The box that moves in the maze drawfillbox (x, y, x2, y2, brightred) loop Input.KeyDown (chars) if chars (KEY_UP_ARROW) then drawfillbox (x, y, x2, y2, brightred) delay (5) View.Update drawfillbox (x, y, x2, y2, black) % If it wasn't for this the box will View.Update % seem to grow instead of moving y := y + 1 y2 := y2 + 1 drawfillbox (x, y, x2, y2, brightred) end if if chars (KEY_RIGHT_ARROW) then drawfillbox (x, y, x2, y2, brightred) delay (5) View.Update drawfillbox (x, y, x2, y2, black) x := x + 1 x2 := x2 + 1 drawfillbox (x, y, x2, y2, brightred) end if if chars (KEY_DOWN_ARROW) and y = 1 then y := y + 0 y2 := y2 + 0 elsif chars (KEY_DOWN_ARROW) then drawfillbox (x, y, x2, y2, brightred) delay (5) View.Update drawfillbox (x, y, x2, y2, black) y := y - 1 y2 := y2 - 1 drawfillbox (x, y, x2, y2, brightred) end if if chars (KEY_LEFT_ARROW) and x = 1 then x := x + 0 x2 := x2 + 0 elsif chars (KEY_LEFT_ARROW) then drawfillbox (x, y, x2, y2, brightred) delay (5) View.Update drawfillbox (x, y, x2, y2, black) x := x - 1 x2 := x2 - 1 drawfillbox (x, y, x2, y2, brightred) end if end loop Please help ! I admire your work and I trust you. ![]() |
Author: | Aange10 [ Sat Jun 02, 2012 1:04 pm ] | ||
Post subject: | RE:S.O.S I need help | ||
Given the fact that your program is black other than the walls (yellow) and the finish line (green), I suppose you could just use whatdotcolor.
Although learning about arrays would make your code so much cleaner and easier to manage. Not to mention if you decided to use more colors, you could do collision a more mathmatical way. Also, wrap your code in [ syntax="turing" ] and [ /syntax ] (without spaces in it) so that we can read your code easier. |