trying to make a maze
Author |
Message |
samthebest_2003
|
Posted: Mon Jan 22, 2007 7:49 pm Post subject: trying to make a maze |
|
|
hi i am a noob at programming but i gotta make this for my final program of the course
but i don't know how to make the ball go back to the start when the ball hits a wall or something
my program so far looks like this:
setscreen ('offscreenonly')
var key:array char of boolean
var x:int:=80
var y:int:=360
drawfillbox (0,maxx,65,0,black)
drawfillbox (100,maxx,300,30,black)
drawfillbox (335,350,380,0,black)
drawfillbox (410,maxx,maxx,30,black)
var font2 := Font.New ("Ariel:9:")
drawfilloval(x,y,10,10,10)
delay(10)
loop
cls
Input.KeyDown(key)
if key (KEY_UP_ARROW) then
y:=y+1
end if
if key (KEY_RIGHT_ARROW)then
x:=x+1
end if
if key (KEY_DOWN_ARROW) then
y:=y-1
end if
if key (KEY_LEFT_ARROW)then
x:=x-1
end if
if key (KEY_DOWN_ARROW)and y=0 then
y:=y+360
end if
if key (KEY_UP_ARROW)and y=390 then
y:=y-1
end if
drawfillbox (0,maxx,65,0,black)
drawfillbox (100,maxx,300,30,black)
drawfillbox (335,350,380,0,black)
drawfillbox (410,maxx,maxx,30,black)
Font.Draw ("End", 615,12,font2,23)
drawfilloval(x,y,10,10,10)
delay (10)
View.Update
end loop
-------------------------------------------------------------------------------------------------------------------------
after this i dont know how to make the ball go back to the start after hitting the left wall
if key (KEY_LEFT_ARROW) and x=75 then
???????? ( wat do i put?) ????????
end if
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Hariss
|
Posted: Tue Jan 23, 2007 12:15 pm Post subject: Re: trying to make a maze |
|
|
ok, i changed some things for you. Firstly your left wall and right wall problem does not exist, because i changed what happens. When the ball touches the wall, it resets in its starting position(just to make it tricky) For the bottom and top, just draw black squares, at the the white spaces and that problem will be taken care of. I also changed your input keydown stuff into hasch and getch, because it is better for the situation you are in, what happens when you reach the end that is completely up to you. Your game is good, try making more levels and increasing the circle's movement speed. You should do well.
Description: |
this is the edited version |
|
Download |
Filename: |
maze.t |
Filesize: |
1.81 KB |
Downloaded: |
160 Time(s) |
|
|
|
|
|
|
MihaiG
|
Posted: Tue Jan 23, 2007 12:44 pm Post subject: Re: trying to make a maze |
|
|
I optimized your maze game by using "Input.KeyDown" instead of using getchar
Quote: var key : array char of boolean
var alive : boolean := true
var horizontal : int := 80
var vertical : int := 360
put "Press any key to play"
put "Do not touch the walls, or you will restart at the beginning!"
Input.Pause
var chars : array char of boolean
setscreen ('offscreenonly')
drawfillbox (0, maxx, 65, 0, black)
drawfillbox (100, maxx, 300, 30, black)
drawfillbox (335, 350, 380, 0, black)
drawfillbox (410, maxx, maxx, 30, black)
loop
cls
drawfilloval (horizontal, vertical, 10, 10, 10)
drawbox (0, 0, maxx, maxy, 7)
drawfillbox (0, maxx, 65, 0, black)
drawfillbox (100, maxx, 300, 30, black)
drawfillbox (335, 350, 380, 0, black)
drawfillbox (410, maxx, maxx, 30, black)
Input.KeyDown (chars)
if chars (KEY_UP_ARROW) then %up arrow
if whatdotcolour (horizontal, vertical + 12) not= black then
vertical += 1
elsif whatdotcolour (horizontal, vertical + 12) = black then
alive := false
end if
elsif chars (KEY_RIGHT_ARROW) then %right arrow
if whatdotcolour (horizontal + 12, vertical) not= black then
horizontal += 1
elsif whatdotcolour (horizontal + 12, vertical) = black then
alive := false
end if
elsif chars (KEY_LEFT_ARROW) then %left arrow
if whatdotcolour (horizontal - 12, vertical) not= black then
horizontal -= 1
elsif whatdotcolour (horizontal - 12, vertical) = black then
alive := false
end if
elsif chars (KEY_DOWN_ARROW) then %down arrow
if whatdotcolour (horizontal, vertical - 12) not= black then
vertical -= 1
elsif whatdotcolour (horizontal, vertical - 12) = black then
alive := false
end if
end if
if alive = false then
horizontal := 80
vertical := 360
alive := true
end if
View.Update
end loop
goes much faster, you can add a delay right before the end loop if if the game runs to fast
Regards,
Mihai
|
|
|
|
|
|
|
|