Help with a maze program
Author |
Message |
theanimator
|
Posted: Wed Oct 26, 2005 6:16 pm Post subject: 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:
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 ![Smile Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif) |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
MysticVegeta
![](http://www.geocities.com/ohsoinsane/my_avatar.JPG)
|
Posted: Wed Oct 26, 2005 6:32 pm Post subject: (No subject) |
|
|
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! |
|
|
|
|
![](images/spacer.gif) |
theanimator
|
Posted: Wed Oct 26, 2005 8:23 pm Post subject: (No subject) |
|
|
i'm still confused with the whatdotcolor. maybe it needs to be explained a bit more. |
|
|
|
|
![](images/spacer.gif) |
Undr_Xposed
|
Posted: Wed Oct 26, 2005 8:27 pm Post subject: (No subject) |
|
|
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 ![Confused Confused](http://compsci.ca/v3/images/smiles/icon_confused.gif) |
|
|
|
|
![](images/spacer.gif) |
TokenHerbz
![](http://compsci.ca/v3/uploads/user_avatars/717170395558e628d9452b.jpg)
|
Posted: Thu Oct 27, 2005 2:17 am Post subject: (No subject) |
|
|
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..
code: |
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?? |
|
|
|
|
![](images/spacer.gif) |
[Gandalf]
![](http://compsci.ca/v3/uploads/user_avatars/189297994e4c716fec7f1.png)
|
Posted: Thu Oct 27, 2005 2:51 pm Post subject: (No subject) |
|
|
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. |
|
|
|
|
![](images/spacer.gif) |
Albrecd
|
Posted: Tue Nov 08, 2005 2:54 pm Post subject: y += |
|
|
Instead of putting
Quote: if chars (KEY_UP_ARROW) then
y:=y+2
you could put
if chars (KEY_UP_ARROW) then
y+=2 |
|
|
|
|
![](images/spacer.gif) |
iker
![](http://compsci.ca/v3/uploads/user_avatars/6313105374b04e31c7b33a.png)
|
Posted: Tue Nov 08, 2005 5:23 pm Post subject: (No subject) |
|
|
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:
[1]it draws the screen and ball
[2]checks the colors just to the left, right, top and bottom with lx..uy and col1..col4
[3]if a color is other then white to any side of the ball, it moves it one to the other dirrection
code: |
%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
|
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
|
|