Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #lang "qb"
- '$DYNAMIC
- defint A-Z
- declare function checkbounds% ()
- declare sub makedungeon (IsFirstMaze%)
- declare sub fixwalls ()
- declare sub fixmaze ()
- declare sub randomizemonsters ()
- declare sub waiter (Amount#)
- declare sub square (X%, Y%, Col%)
- declare sub drawmaze ()
- declare sub findpath (M%, StartX%, StartY%, TargX%, TargY%)
- common shared MazeLength, MazeHeight, TotalMonsters, TotalRooms
- const true = -1, OpenL = 1, CloseL = -1, null = 0
- const GryHi = 15, BluHi = 1, RedHi = 4, GrnHi = 2
- screen 12
- width 80, 60
- randomize timer
- MazeLength = 50
- MazeHeight = 50
- TotalMonsters = 16
- TotalRooms = 16
- type MonsterStuff
- X as integer
- Y as integer
- Hp as integer
- TargX as integer
- TargY as integer
- TempX as integer
- TempY as integer
- WalkCnt as integer
- AMoves as integer
- HitTarg as integer
- end type
- type MazeStuff
- AssY as integer
- Exposed as integer
- InRad as integer
- Col as integer
- Typ as integer
- end type
- type RoomStuff
- X as integer
- Y as integer
- Sx as integer
- Sy as integer
- Lit as integer
- end type
- type PathStuff
- Cs as integer
- Px as integer
- Py as integer
- F as integer
- G as integer
- H as single
- P as integer
- end type
- type WalkStuff
- X as integer
- Y as integer
- end type
- dim shared Rm(TotalRooms) as RoomStuff, Sort(1 to MazeLength, 1 to MazeHeight) as integer
- dim shared Maz(1 to MazeLength, 1 to MazeHeight) as MazeStuff, Mark(1 to MazeLength, 1 to MazeHeight) as integer
- dim shared Mnstr(1 to TotalMonsters) as MonsterStuff
- dim shared Path(1 to MazeLength, 1 to MazeHeight) as PathStuff
- dim shared Walk(1 to ((MazeLength * MazeHeight) \ 2)) as WalkStuff, TPath(1 to TotalMonsters, 1 to TotalMonsters) as WalkStuff
- do
- color (15)
- locate 58, 1
- print "Building maze, Please Wait.."
- makedungeon 1
- locate 58, 1
- print string$(28, 32)
- randomizemonsters
- for M = 1 to TotalMonsters
- Fx = Mnstr(M).X
- Fy = Mnstr(M).Y
- Tx = Mnstr(M).TargX
- Ty = Mnstr(M).TargY
- findpath M, Tx, Ty, Fx, Fy
- next
- drawmaze
- do
- In$ = inkey$
- GoodCnt = 0
- GotPath = false
- StartAt = StartAt + 1
- if StartAt > TotalMonsters then StartAt = 1
- Fx = Mnstr(StartAt).X
- Fy = Mnstr(StartAt).Y
- Tx = Mnstr(StartAt).TargX
- Ty = Mnstr(StartAt).TargY
- findpath StartAt, Tx, Ty, Fx, Fy
- for M = 1 to TotalMonsters
- Mnstr(M).HitTarg = false
- Ox = Mnstr(M).X
- Oy = Mnstr(M).Y
- OWalkCnt = Mnstr(M).WalkCnt
- Mnstr(M).WalkCnt = Mnstr(M).WalkCnt + 1
- if Mnstr(M).WalkCnt > Mnstr(M).AMoves then
- Mnstr(M).WalkCnt = Mnstr(M).AMoves
- end if
- Mnstr(M).TempX = TPath(M, Mnstr(M).WalkCnt).X
- Mnstr(M).TempY = TPath(M, Mnstr(M).WalkCnt).Y
- if Mnstr(M).X < Mnstr(M).TempX then Mnstr(M).X = Mnstr(M).X + 1
- if Mnstr(M).X > Mnstr(M).TempX then Mnstr(M).X = Mnstr(M).X - 1
- if Mnstr(M).Y < Mnstr(M).TempY then Mnstr(M).Y = Mnstr(M).Y + 1
- if Mnstr(M).Y > Mnstr(M).TempY then Mnstr(M).Y = Mnstr(M).Y - 1
- select case Maz(Mnstr(M).X, Mnstr(M).Y).AssY
- case 24, 25, 176, 234
- 'These are walkable tiles...
- case else
- 'These are walls...
- Mnstr(M).X = Ox
- Mnstr(M).Y = Oy
- Mnstr(M).WalkCnt = OWalkCnt
- end select
- if Mnstr(M).X = Mnstr(M).TargX and Mnstr(M).Y = Mnstr(M).TargY then
- Mnstr(M).X = Ox
- Mnstr(M).Y = Oy
- Mnstr(M).HitTarg = true
- end if
- for C = 1 to TotalMonsters
- if C <> M then
- if Mnstr(C).Hp > 0 then
- if Mnstr(M).X = Mnstr(C).X and Mnstr(M).Y = Mnstr(C).Y then
- Mnstr(M).X = Ox
- Mnstr(M).Y = Oy
- Mnstr(M).WalkCnt = OWalkCnt
- if Mnstr(C).HitTarg then Mnstr(M).HitTarg = true
- end if
- end if
- end if
- next
- color (Maz(Ox, Oy).Col)
- locate Oy, Ox
- print chr$(Maz(Ox, Oy).AssY)
- MonCol = M - 1
- if MonCol = 0 then MonCol = 15
- color (MonCol)
- locate Mnstr(M).Y, Mnstr(M).X
- print chr$(2)
- square Mnstr(M).TargX, Mnstr(M).TargY, 7
- if Mnstr(M).X = Ox and Mnstr(M).Y = Oy then
- if Mnstr(M).HitTarg then
- GoodCnt = GoodCnt + 1
- end if
- end if
- next
- 'waiter .075
- sleep 100,1
- if In$ = chr$(27) then goto Ender
- Loops = Loops + 1
- if Loops >= 250 then exit do
- loop until GoodCnt >= TotalMonsters
- Loops = 0
- loop
- Ender:
- system
- rem $static
- function checkbounds%
- 'This function scans the entire level and returns true if it's good...
- TotalDots = 0
- for Y = 1 to MazeHeight
- for X = 1 to MazeLength
- Sort(X, Y) = true
- Mark(X, Y) = true
- next
- next
- for Y = 2 to MazeHeight - 1
- for X = 2 to MazeLength - 1
- if Maz(X, Y).AssY = 0 then
- TotalDots = TotalDots + 1
- Sort(X, Y) = 1
- Mark(X, Y) = 0
- end if
- next
- next
- Tys = MazeHeight - 1
- Txs = MazeLength - 1
- for Y = 2 to Tys
- for X = 2 to Txs
- if Sort(X, Y) <> true and not GotTheMark then
- GotTheMark = true
- Mark(X, Y) = true
- end if
- next
- next
- for Y1 = 2 to Tys
- for X1 = 2 to Txs
- YBegin = Y1 - (Tys - (Tys - Y1))
- YFinal = Y1 + (Tys - Y1)
- XBegin = X1 - (Txs - (Txs - X1))
- XFinal = X1 + (Txs - X1)
- Cnt1 = 0: Cnt2 = 0
- FakeDots = FakeDots + 1
- for Y2 = YBegin to YFinal
- for X2 = XBegin to XFinal
- if X2 >= 2 and X2 <= Txs and Y2 >= 2 and Y2 <= Tys then
- Ok1 = Sort(X2 - 1, Y2) <> true and Mark(X2 - 1, Y2)
- Ok2 = Sort(X2 + 1, Y2) <> true and Mark(X2 + 1, Y2)
- Ok3 = Sort(X2, Y2 - 1) <> true and Mark(X2, Y2 - 1)
- Ok4 = Sort(X2, Y2 + 1) <> true and Mark(X2, Y2 + 1)
- Ok = Ok1 or Ok2 or Ok3 or Ok4
- if Ok and Sort(X2, Y2) <> true then
- Mark(X2, Y2) = true
- Cnt1 = Cnt1 + 1
- if Sort(X2, Y2) = 1 then
- Cnt2 = Cnt2 + 1
- CountDots = CountDots + 1
- Sort(X2, Y2) = 0
- if CountDots = TotalDots then goto Finale
- end if
- end if
- end if
- next
- next
- if Cnt1 = OCnt1 and Cnt2 = OCnt2 then goto Finale
- OCnt1 = Cnt1
- OCnt2 = Cnt2
- next
- next
- Finale:
- if TotalDots = CountDots then checkbounds% = true
- end function
- sub drawmaze
- for Y = 1 to MazeHeight
- for X = 1 to MazeLength
- color (Maz(X, Y).Col)
- locate Y, X
- print chr$(Maz(X, Y).AssY)
- next
- next
- end sub
- sub findpath (M%, StartX%, StartY%, TargX%, TargY%)
- if StartX = TargX and StartY = TargY then
- AlreadyThere = true
- goto Finalize
- end if
- redim Path(1 to MazeLength, 1 to MazeHeight) as PathStuff
- Path(StartX, StartY).Cs = OpenL
- for C = 1 to TotalMonsters
- if C <> M then
- if Mnstr(C).Hp > 0 then
- 'This gives a penalty to the nodes that are taken by the other monsters.
- 'It encourages the algo to find another path.
- Path(Mnstr(C).X, Mnstr(C).Y).P = 1000
- end if
- end if
- next
- OnOpenList = 1
- Walk(1).X = StartX
- Walk(1).Y = StartY
- do
- OCurX = CurX
- OCurY = CurY
- CurScore = 10000
- for C = 1 to OnOpenList
- if Walk(C).X > 0 and Walk(C).Y > 0 then
- if Path(Walk(C).X, Walk(C).Y).Cs = OpenL then
- if Path(Walk(C).X, Walk(C).Y).F <= CurScore then
- CurX = Walk(C).X
- CurY = Walk(C).Y
- CurScore = Path(Walk(C).X, Walk(C).Y).F
- TempC = C
- end if
- end if
- end if
- next
- Path(CurX, CurY).Cs = CloseL
- Walk(TempC).X = 0
- Walk(TempC).Y = 0
- if CurX = TargX and CurY = TargY then exit do
- if CurX = OCurX and CurY = OCurY then exit do
- OldHole = false
- for Y = -1 to 1
- for X = -1 to 1
- Tx = X + CurX
- Ty = Y + CurY
- if X = 0 or Y = 0 then MoveCost = 10 else MoveCost = 14
- if Tx = CurX and Ty = CurY then goto SkipNode
- select case Maz(Tx, Ty).AssY
- case 24, 25, 176, 234
- case else
- goto SkipNode
- end select
- if Path(Tx, Ty).Cs = null then
- Path(Tx, Ty).Cs = OpenL
- Path(Tx, Ty).Px = CurX
- Path(Tx, Ty).Py = CurY
- Path(Tx, Ty).G = Path(CurX, CurY).G + MoveCost
- Path(Tx, Ty).H = sqr( (Tx - TargX)^2+(Ty - TargY)^2)*10' (abs(Tx - TargX) + abs(Ty - TargY)) * 10
- Path(Tx, Ty).F = Path(Tx, Ty).G + Path(Tx, Ty).H + Path(Tx, Ty).P
- if OldHole then
- OnOpenList = OnOpenList + 1
- Walk(OnOpenList).X = Tx
- Walk(OnOpenList).Y = Ty
- else
- OldHole = true
- Walk(TempC).X = Tx
- Walk(TempC).Y = Ty
- end if
- end if
- SkipNode:
- next
- next
- loop
- Finalize:
- Mnstr(M).WalkCnt = 0
- Mnstr(M).AMoves = 1
- if AlreadyThere then
- TPath(M, 1).X = StartX
- TPath(M, 1).Y = StartY
- exit sub
- end if
- Tx = Mnstr(M).X
- Ty = Mnstr(M).Y
- for C = 1 to TotalMonsters
- TPath(M, C).X = Path(Tx, Ty).Px
- TPath(M, C).Y = Path(Tx, Ty).Py
- Tx2 = Path(Tx, Ty).Px
- Ty2 = Path(Tx, Ty).Py
- Tx = Tx2
- Ty = Ty2
- if C > 1 then
- Mnstr(M).AMoves = C - 1
- end if
- if Tx = 0 or Ty = 0 then
- exit for
- end if
- next
- end sub
- sub fixmaze
- for Y = 1 to MazeHeight
- for X = 1 to MazeLength
- Sort(X, Y) = 0
- Maz(X, Y).Typ = 0
- if Maz(X, Y).AssY = true then
- Sort(X, Y) = true
- end if
- next
- next
- for Y = 1 to MazeHeight
- for X = 1 to MazeLength
- Nw = 0
- Nr = 0
- Ne = 0
- ws = 0
- ES = 0
- Sw = 0
- St = 0
- Se = 0
- if X > 1 and Y > 1 then
- Nw = Sort(X - 1, Y - 1) = true
- end if
- if Y > 1 then
- Nr = Sort(X, Y - 1) = true
- end if
- if Y > 1 and X < MazeLength then
- Ne = Sort(X + 1, Y - 1) = true
- end if
- if X > 1 then
- ws = Sort(X - 1, Y) = true
- end if
- Md = Sort(X, Y) = true
- if X < MazeLength then
- ES = Sort(X + 1, Y) = true
- end if
- if X > 1 and Y < MazeHeight then
- Sw = Sort(X - 1, Y + 1) = true
- end if
- if Y < MazeHeight then
- St = Sort(X, Y + 1) = true
- end if
- if X < MazeLength and Y < MazeHeight then
- Se = Sort(X + 1, Y + 1) = true
- end if
- TLcn = not Nr and not ws and St and ES and Md
- BLcn = not St and not ws and Nr and ES and Md
- TRcn = not Nr and not ES and St and ws and Md
- BRcn = not St and not ES and Nr and ws and Md
- Hori = not Nr and not St and ws and ES and Md
- Vert = not ws and not ES and Nr and St and Md
- TopT = not Nr and St and ws and ES and Md
- BotT = not St and Nr and ws and ES and Md
- LevT = not ws and ES and Nr and St and Md
- RigT = not ES and ws and Nr and St and Md
- Tend = not ES and not ws and not Nr and St and Md
- Bend = not ES and not ws and not St and Nr and Md
- Lend = not Nr and not St and not ws and ES and Md
- Rend = not Nr and not St and not ES and ws and Md
- Cros = Nr and St and ES and ws and Md
- Midl = Md and not Nr and not St and not ES and not ws
- if TLcn then Maz(X, Y).AssY = 201: Maz(X, Y).Col = BluHi: Maz(X, Y).Typ = true
- if BLcn then Maz(X, Y).AssY = 200: Maz(X, Y).Col = BluHi: Maz(X, Y).Typ = true
- if TRcn then Maz(X, Y).AssY = 187: Maz(X, Y).Col = BluHi: Maz(X, Y).Typ = true
- if BRcn then Maz(X, Y).AssY = 188: Maz(X, Y).Col = BluHi: Maz(X, Y).Typ = true
- if Hori then Maz(X, Y).AssY = 205: Maz(X, Y).Col = BluHi: Maz(X, Y).Typ = true
- if Vert then Maz(X, Y).AssY = 186: Maz(X, Y).Col = BluHi: Maz(X, Y).Typ = true
- if TopT then Maz(X, Y).AssY = 203: Maz(X, Y).Col = BluHi: Maz(X, Y).Typ = true
- if BotT then Maz(X, Y).AssY = 202: Maz(X, Y).Col = BluHi: Maz(X, Y).Typ = true
- if LevT then Maz(X, Y).AssY = 204: Maz(X, Y).Col = BluHi: Maz(X, Y).Typ = true
- if RigT then Maz(X, Y).AssY = 185: Maz(X, Y).Col = BluHi: Maz(X, Y).Typ = true
- if Tend then Maz(X, Y).AssY = 186: Maz(X, Y).Col = BluHi: Maz(X, Y).Typ = true
- if Bend then Maz(X, Y).AssY = 186: Maz(X, Y).Col = BluHi: Maz(X, Y).Typ = true
- if Lend then Maz(X, Y).AssY = 205: Maz(X, Y).Col = BluHi: Maz(X, Y).Typ = true
- if Rend then Maz(X, Y).AssY = 205: Maz(X, Y).Col = BluHi: Maz(X, Y).Typ = true
- if Cros then Maz(X, Y).AssY = 206: Maz(X, Y).Col = BluHi: Maz(X, Y).Typ = true
- if Midl then Maz(X, Y).AssY = 254: Maz(X, Y).Col = BluHi: Maz(X, Y).Typ = true
- if Maz(X, Y).AssY = 0 then Maz(X, Y).AssY = 176: Maz(X, Y).Col = 8: Maz(X, Y).Typ = 0
- next
- next
- for Y1 = 1 to MazeHeight
- for X1 = 1 to MazeLength
- if Maz(X1, Y1).AssY < 0 then
- Maz(X1, Y1).AssY = 177 + int(rnd * 2)
- Maz(X1, Y1).Typ = true
- Maz(X1, Y1).Col = 8
- end if
- next
- next
- for R = 1 to TotalRooms
- for Y = Rm(R).Y - 1 to Rm(R).Y + Rm(R).Sy + 1
- for X = Rm(R).X - 1 to Rm(R).X + Rm(R).Sx + 1
- InXBox = X >= Rm(R).X and X <= Rm(R).X + Rm(R).Sx
- InYBox = Y >= Rm(R).Y and Y <= Rm(R).Y + Rm(R).Sy
- Corner1 = X = Rm(R).X - 1 and Y = Rm(R).Y - 1
- Corner2 = X = Rm(R).X + Rm(R).Sx + 1 and Y = Rm(R).Y - 1
- Corner3 = X = Rm(R).X - 1 and Y = Rm(R).Y + Rm(R).Sy + 1
- Corner4 = X = Rm(R).X + Rm(R).Sx + 1 and Y = Rm(R).Y + Rm(R).Sy + 1
- OnCorner = Corner1 or Corner2 or Corner3 or Corner4
- if not InXBox or not InYBox then
- if Maz(X, Y).AssY = 176 and not OnCorner then
- Maz(X, Y).AssY = 234
- Maz(X, Y).Col = 9
- Maz(X, Y).Typ = true
- end if
- end if
- next
- next
- next
- end sub
- sub fixwalls
- for Y = 1 to MazeHeight
- for X = 1 to MazeLength
- if Maz(X, Y).AssY <> 0 then
- Maz(X, Y).AssY = -3
- end if
- next
- next
- for Y = 1 to MazeHeight
- for X = 1 to MazeLength
- for Y2 = Y - 1 to Y + 1
- for X2 = X - 1 to X + 1
- if X2 >= 1 and Y2 >= 1 and X2 <= MazeLength and Y2 <= MazeHeight then
- if Maz(X, Y).AssY = 0 then
- if Maz(X2, Y2).AssY <> 0 then
- Maz(X2, Y2).AssY = -1
- end if
- end if
- end if
- next
- next
- next
- next
- end sub
- sub makedungeon (IsFirstMaze%)
- StartAgain:
- for Y = 1 to MazeHeight
- for X = 1 to MazeLength
- Maz(X, Y).AssY = true
- Maz(X, Y).Exposed = false
- next
- next
- if IsFirstMaze% = 1 then
- StartRooms = 1
- else
- StartRooms = 2
- if not StartAgainFlag then
- Rm(1).X = Rm(TotalRooms).X
- Rm(1).Y = Rm(TotalRooms).Y
- Rm(1).Sx = Rm(TotalRooms).Sx
- Rm(1).Sy = Rm(TotalRooms).Sy
- end if
- for Ry = Rm(1).Y to Rm(1).Y + Rm(1).Sy
- for Rx = Rm(1).X to Rm(1).X + Rm(1).Sx
- Maz(Rx, Ry).AssY = 0
- next
- next
- end if
- StartAgainFlag = true
- for Rooms = StartRooms to TotalRooms
- Rm(Rooms).X = -1000
- Rm(Rooms).Y = -1000
- Rm(Rooms).Sx = 1
- Rm(Rooms).Sy = 1
- Rm(Rooms).Lit = false
- if int(rnd * 100) >= 75 then Rm(Rooms).Lit = true
- next
- Rooms = StartRooms
- RandomRooms:
- do
- randomize timer
- Rm(Rooms).X = 2 + int(rnd * (MazeLength - 2))
- Rm(Rooms).Y = 2 + int(rnd * (MazeHeight - 2))
- Rm(Rooms).Sx = 3 + int(rnd * 5)
- Rm(Rooms).Sy = 3 + int(rnd * 5)
- if Rm(Rooms).X + Rm(Rooms).Sx > MazeLength - 1 then goto RandomRooms
- if Rm(Rooms).Y + Rm(Rooms).Sy > MazeHeight - 1 then goto RandomRooms
- for R2 = 1 to TotalRooms
- if R2 <> Rooms then
- InX = Rm(R2).X + (Rm(R2).Sx + 3) >= Rm(Rooms).X and Rm(R2).X <= Rm(Rooms).X + (Rm(Rooms).Sx + 3)
- InY = Rm(R2).Y + (Rm(R2).Sy + 3) >= Rm(Rooms).Y and Rm(R2).Y <= Rm(Rooms).Y + (Rm(Rooms).Sy + 3)
- InBox = InX and InY
- if InBox then goto RandomRooms
- end if
- next
- for Ey = Rm(Rooms).Y to Rm(Rooms).Y + Rm(Rooms).Sy
- for Ex = Rm(Rooms).X to Rm(Rooms).X + Rm(Rooms).Sx
- if Ex >= 2 and Ex <= MazeLength - 1 and Ey >= 2 and Ey <= MazeHeight - 1 then
- Maz(Ex, Ey).AssY = 0
- end if
- next
- next
- Rooms = Rooms + 1
- loop until Rooms >= TotalRooms + 1
- AtX = Rm(1).X + (Rm(1).Sx \ 2)
- AtY = Rm(1).Y + (Rm(1).Sy \ 2)
- for Rooms = 1 to TotalRooms
- TryRoomsAgain:
- for Fy = 1 to MazeHeight
- for Fx = 1 to MazeLength
- Sort(Fx, Fy) = Maz(Fx, Fy).AssY
- next
- next
- AtX = Rm(Rooms).X + int(rnd * ((Rm(Rooms).Sx)))
- AtY = Rm(Rooms).Y + int(rnd * ((Rm(Rooms).Sy)))
- if Rooms < TotalRooms then
- TargX = Rm(Rooms + 1).X + int(rnd * (Rm(Rooms + 1).Sx))
- TargY = Rm(Rooms + 1).Y + int(rnd * (Rm(Rooms + 1).Sy))
- else
- TargX = Rm(1).X + int(rnd * (Rm(1).Sx))
- TargY = Rm(1).Y + int(rnd * (Rm(1).Sy))
- end if
- HitTarget = 0
- do
- AddX = 0
- AddY = 0
- if AtX < TargX then AddX = 1
- if AtX > TargX then AddX = -1
- if AtY < TargY then AddY = 1
- if AtY > TargY then AddY = -1
- for R = 1 to TotalRooms
- InX = AtX >= Rm(R).X - 1 and AtX <= Rm(R).X + Rm(R).Sx + 1
- InY = AtY >= Rm(R).Y - 1 and AtY <= Rm(R).Y + Rm(R).Sy + 1
- OnXBorder = AtX = Rm(R).X - 1 or AtX = Rm(R).X + Rm(R).Sx + 1
- OnYBorder = AtY = Rm(R).Y - 1 or AtY = Rm(R).Y + Rm(R).Sy + 1
- OnBorder = InX and InY
- if OnBorder then exit for
- next
- if OnBorder then
- if OnXBorder and not OnYBorder then AddY = 0
- if OnYBorder and not OnXBorder then AddX = 0
- end if
- if AddX <> 0 and AddY <> 0 then
- RandGo = int(rnd * 2)
- if RandGo = 0 then AddX = 0
- if RandGo = 1 then AddY = 0
- end if
- if AddX = 0 and AddY = 0 then goto TryRoomsAgain
- AtX = AtX + AddX
- AtY = AtY + AddY
- for AtY2 = AtY - 1 to AtY + 1
- for AtX2 = AtX - 1 to AtX + 1
- if AtX2 >= 2 and AtX2 <= MazeLength - 1 and AtY2 >= 2 and AtY2 <= MazeHeight - 1 then
- InX = AtX2 >= Rm(Rooms).X and AtX2 <= Rm(Rooms).X + Rm(Rooms).Sx
- InY = AtY2 >= Rm(Rooms).Y and AtY2 <= Rm(Rooms).Y + Rm(Rooms).Sy
- InStartBox = InX and InY
- if Sort(AtX2, AtY2) = 0 then
- if not InStartBox then
- if AtX2 = AtX or AtY2 = AtY then
- HitTarget = true
- end if
- end if
- end if
- end if
- next
- next
- Sort(AtX, AtY) = 3
- if AtX = TargX and AtY = TargY then HitTarget = true
- if not HitTarget then
- for R = 1 to TotalRooms
- Corner1 = AtX = Rm(R).X - 1 and AtY = Rm(R).Y - 1
- Corner2 = AtX = Rm(R).X + Rm(R).Sx + 1 and AtY = Rm(R).Y - 1
- Corner3 = AtX = Rm(R).X - 1 and AtY = Rm(R).Y + Rm(R).Sy + 1
- Corner4 = AtX = Rm(R).X + Rm(R).Sx + 1 and AtY = Rm(R).Y + Rm(R).Sy + 1
- OnCorner5 = Corner1 or Corner2 or Corner3 or Corner4
- OnCorner = OnCorner5 and Rooms <> R
- if OnCorner then
- goto TryRoomsAgain
- end if
- next
- end if
- loop until HitTarget
- for FixY = 1 to MazeHeight
- for FixX = 1 to MazeLength
- if Sort(FixX, FixY) = 3 then
- Maz(FixX, FixY).AssY = 3
- Sort(FixX, FixY) = 0
- end if
- next
- next
- next
- for FixY = 1 to MazeHeight
- for FixX = 1 to MazeLength
- if Maz(FixX, FixY).AssY = 3 then
- Maz(FixX, FixY).AssY = 0
- end if
- next
- next
- if not checkbounds% then goto StartAgain
- for Y = 1 to MazeHeight
- for X = 1 to MazeLength
- if Y = 1 or Y = MazeHeight or X = 1 or X = MazeLength then
- Maz(X, Y).AssY = true
- end if
- next
- next
- fixwalls
- fixmaze
- X1 = Rm(1).X + (Rm(1).Sx \ 2)
- Y1 = Rm(1).Y + (Rm(1).Sy \ 2)
- X2 = Rm(TotalRooms).X + (Rm(TotalRooms).Sx \ 2)
- Y2 = Rm(TotalRooms).Y + (Rm(TotalRooms).Sy \ 2)
- Maz(X1, Y1).AssY = 24
- Maz(X1, Y1).Col = RedHi
- Maz(X2, Y2).AssY = 25
- Maz(X2, Y2).Col = BluHi
- end sub
- sub randomizemonsters
- RandomTarg:
- TargX = 1 + int(rnd * MazeLength)
- TargY = 1 + int(rnd * MazeHeight)
- select case Maz(TargX, TargY).AssY
- case 24, 25, 176, 234
- case else
- goto RandomTarg
- end select
- for M = 1 to TotalMonsters
- RandomPos:
- Mnstr(M).X = 1 + int(rnd * MazeLength)
- Mnstr(M).Y = 1 + int(rnd * MazeHeight)
- Mnstr(M).TargX = TargX
- Mnstr(M).TargY = TargY
- Mnstr(M).Hp = 100
- Mnstr(M).HitTarg = false
- select case Maz(Mnstr(M).X, Mnstr(M).Y).AssY
- case 24, 25, 176, 234
- case else
- goto RandomPos
- end select
- if Mnstr(M).X = TargX and Mnstr(M).Y = TargY then goto RandomPos
- for M2 = 1 to TotalMonsters
- if M2 <> M then
- if Mnstr(M).X = Mnstr(M2).X and Mnstr(M).Y = Mnstr(M2).X then goto RandomPos
- end if
- next
- next
- end sub
- sub square (X%, Y%, Col%)
- color (15)
- locate Y, X
- print "X"
- end sub
- sub waiter (Amount#)
- TTime# = timer + Amount#
- do: loop until timer > TTime#
- end sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement