Code: Select all
'' Microbot by Neil
Screenres 544,556,32
setmouse 0,0,0
Type Coord
x As Ushort
y as Ushort
End Type
Dim C(16) As Coord
Dim As Long fps
Dim As UShort m,z
Dim As Byte d,u,v,speed
Function Regulate(Byval MyFps As Long,Byref fps As Long) As Long
Static As Double timervalue,_lastsleeptime,t3,frames
frames+=1
If (Timer-t3)>=1 Then t3=Timer:fps=frames:frames=0
Var sleeptime=_lastsleeptime+((1/myfps)-Timer+timervalue)*1000
If sleeptime<1 Then sleeptime=1
_lastsleeptime=sleeptime
timervalue=Timer
Return sleeptime
End Function
sub microbot(x as ushort,y as ulong,c as ulong)
line(x,y)-(x+31,y+31),c,bf
end sub
Do
Cls
'' Simple Maze
line(16 ,0)-(542,16),rgb(225,0,0),bf
line(16 ,540)-(542,556),rgb(225,0,0),bf
line(0 ,556)-(16,0),rgb(225,0,0),bf
line(100 ,124)-(316,140),rgb(225,0,0),bf
line(100 ,16)-(116,124),rgb(225,0,0),bf
line(16 ,224)-(116,240),rgb(225,0,0),bf
line(100 ,330)-(116,556),rgb(225,0,0),bf
line(200 ,224)-(216,344),rgb(225,0,0),bf
line(116 ,330)-(200,344),rgb(225,0,0),bf
line(216 ,224)-(316,240),rgb(225,0,0),bf
line(116 ,434)-(324,450),rgb(225,0,0),bf
line(310 ,224)-(326,340),rgb(225,0,0),bf
line(424 ,434)-(524,450),rgb(225,0,0),bf
line(424 ,124)-(440,434),rgb(225,0,0),bf
line(526 ,540)-(542,0),rgb(225,0,0),bf
m = 0:z = 1:d = 0: v = 0:u = 0
speed = 8
c(0).y = 31
c(0).x = 2
Locate 67,5:print "START"
Locate 32,31:PRINT "FINISH"
restore goal
Do
Screenlock
microbot C(M).X * 16, C(M).Y * 16,rgb(0,0,0) ''erase microbot
m = 1 '' fixes bug erasing upper left corner
c(z) = c(z - 1)
microbot c(z).x * 16, c(z).y * 16,rgb(0,225,0) '' microbot color
c(0).x = c(0).x + U
c(0).y = c(0).y + V
read d
if d = 5 Then u = 0:v = -1 '' up
if d = 4 Then u = 1:v = 0 '' right
if d = 3 Then u = 0:v = 1 '' down
if d = 2 Then u = -1:v = 0 '' left
microbot C(0).X * 16, C(0).Y * 16,rgb(0,225,0) ''microbot color
Screenunlock
if d = 0 Then exit do
Sleep regulate(speed,fps),1
Loop until inkey = chr(27)
Locate 10,28:Print "FINISHED MAZE"
sleep
Loop until inkey = chr(27)
'' steers microbot to goal
goal:
Data 5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,4,4,4,4,4,4,5,5,5,5,5,5,5
Data 4,4,4,4,4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,3,3,3
Data 2,2,2,2,2,2,2,5,5,5,5,5,5,5,0