
-----------------------------------
theanimator
Wed Oct 26, 2005 6:16 pm

Help with a maze program
-----------------------------------
i am trying to make a maze and i am able to make the collision for the first line but then i can't get around a turn. I am just a beginner so bare with me here. Here is my code:

%maze program
var x,y,x1,y1,a,b : int
x:=17
y:=10
x1:=5
y1:=0
a:=30
b:=0
procedure Bumping
if x < 30 then
        x := 29
    end if
    if x > 18 then
        x := 17
    end if
    if y < 5 then
        y := 4
    end if
    if y > 187 then
        y := 186
    end if
    end Bumping
var chars : array char of boolean
            loop
            Bumping
            Input.KeyDown (chars)
           
            if chars (KEY_UP_ARROW) then
                y:=y+2
            end if
            if chars (KEY_RIGHT_ARROW) then
                x:=x+2
            end if
            if chars (KEY_LEFT_ARROW) then
                x:=x-2
            end if
            if chars (KEY_DOWN_ARROW) then
                y:=y-2
            end if

            drawfilloval(x,y,10,10,red)
            drawline(x1,y1,5,200,black)
            drawline(5,200,300,200,black)
            drawline(a,b,30,165,black)
            delay(10)
cls
           
        end loop

if anyone could help me out on this turn that would be great :)

-----------------------------------
MysticVegeta
Wed Oct 26, 2005 6:32 pm


-----------------------------------
you are doing the turning thing wrong, your bumping procedure retricts on your turning possibilites. What you need to do is instead of doing that kind of collision, check on whatdotcolor collision, in the turing tutorials, because then your ball can stay inside your circles, and can turn!

-----------------------------------
theanimator
Wed Oct 26, 2005 8:23 pm


-----------------------------------
i'm still confused with the whatdotcolor. maybe it needs to be explained a bit more.

-----------------------------------
Undr_Xposed
Wed Oct 26, 2005 8:27 pm


-----------------------------------
yes ill agree with theanimator i kno im a n00b and cant really understand a lot of wat were talking about but its really confusing to me as well :?

-----------------------------------
TokenHerbz
Thu Oct 27, 2005 2:17 am


-----------------------------------
whatdotcolor works by taking a x and y chordnant and checking its background color...

Effectivly if you are using a snake game, with say BLACK walls you can check collition like so..


if whatdotcolor(ballx,bally) = black then
   %%now this means, if your balls X/Y chords are on black pixle
end if


Its complicated if you have odd colours in paint, but its very usfull..



Edit:::

Also you should use more effective variables...  better names, etc:

also your varaibles "a,b,x1,y1" dosn't seem you need, as there just premanent lines??

-----------------------------------
[Gandalf]
Thu Oct 27, 2005 2:51 pm


-----------------------------------
Better variable names are always good, but x1, x2, y1, y2, etc reflect what you mean in this case.  No, the use of variables isn't really bad there since it makes the code more readable, and easier to modify when you are looking back on it after a while.  The problem with them is, that in this case they should be constants.

-----------------------------------
Albrecd
Tue Nov 08, 2005 2:54 pm

y +=
-----------------------------------
Instead of putting

if chars (KEY_UP_ARROW) then 
                y:=y+2 

you could put

if chars (KEY_UP_ARROW) then
                y+=2

-----------------------------------
iker
Tue Nov 08, 2005 5:23 pm


-----------------------------------
try out this code, it has your problems fixed

I changed some variables, such as for the lines, I used a..d, and the move to +=1 or -=1 so that you don't skip any lines, but lowered the delay time so you will see no difference

heres how it works:

%maze program
setscreen ("offscreenonly")
var x, y, a, b, c, d, col1, col2, col3, col4,lx, rx, dy, uy : int
x := 17
y := 10
c := 5
d := 0
a := 30
b := 0
procedure Bumping
    lx := x - 11
    rx := x + 11
    uy := y + 11
    dy := y - 11
    col1 := View.WhatDotColor (lx, y)
    col2 := View.WhatDotColor (rx, y)
    col3 := View.WhatDotColor (x, dy)
    col4 := View.WhatDotColor (x, uy)
    if col1 = black then
        x += 1
    end if
    if col2 = black then
        x -= 1
    end if
    if col3 = black then
        y += 1
    end if
    if col4 = black then
        y -= 1
    end if
end Bumping
var chars : array char of boolean
loop
    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) then
        y += 1
    end if
    if chars (KEY_RIGHT_ARROW) then
        x += 1
    end if
    if chars (KEY_LEFT_ARROW) then
        x -= 1
    end if
    if chars (KEY_DOWN_ARROW) then
        y -= 1
    end if
    drawfilloval (x, y, 10, 10, red)
    drawline (c, d, 5, 200, black)
    drawline (5, 200, 300, 200, black)
    drawline (a, b, 30, 165, black)
    View.Update
    Bumping
    delay (5)
    cls
end loop

