How do I prevent this code from creating a new line?
Turing: |
var id : int
open : id, "C:/hello.txt", put, mod
put : id, "hi"
close : id
|
If you go inside the file after it's created you can see there's a blank line on line 2. Reason this is an issue is my maze program craps out when I try to parse my mazes I build using the '+' button. You can manually go into the file after you save your maze and remove the last line and save again and it imports fine!
CTRL+f for %%% HERE %%% in the below file to see where I must delete the extra space... (or I must somehow ignore it during creation).
Turing: |
/*********************************************************************
Maze Program - by vahnx
2011 ? vahnx
Completed:
- Import mazes dynamically
- Change maze wall font/color
- Save/load settings
To Do:
- Save highscores for new maps (must delete settings.ini)
- Have AI complete maze to make sure it's possible to
reach the end.
- Race AI?
- Fix extra line appending magically
*********************************************************************/
var debug : boolean := false % Debugging mode
var fontSize : int := 9 % Font size of maze wall
var charFont : int := Font.New ("Sans Serif:" + intstr (fontSize )) % Font of maze wall
var nameFont : int := Font.New ("Sans Serif:14") % Header font
var mazeFont : int := Font.New ("Comic Sans MS:20") % Debug maze font
var tempMazeFont : int := Font.New ("Comic Sans MS:50") % Debug maze temp font
var levelFontSize : int := 20 % Level number font size
var levelFont : int := Font.New ("Sans Serif:" + intstr (levelFontSize )) % Level number font
var fontChrSelFont : int := Font.New ("Comic Sans MS:10") % Maze wall character font select
var debugFont : int := Font.New ("Times New Roman:7") % Debugging font x,y axis
var keyFont : int := Font.New ("Times New Roman:15")
/* Counts the number of mazes */
var dir := Dir.Current % Current directory stored (same dir as this source file)
var fileName : string % Holds each filename in the directory
var stream : int := Dir.Open (dir ) % File stream
var counter : int := 0 % Counts the number of files
var file : flexible array 1 .. 0 of string % Hold each filename
loop % Loop through maze directory
fileName := Dir.Get (stream ) % Obtains filename
exit when fileName = "" % Leaves directory when no more files exist
if length (fileName ) > 4 then % Makes sure you don't compare with files shorter than extension
if Str.Lower (fileName (length (fileName ) - 3 .. length (fileName ))) = ".txt" then % Checks if file ends in .txt
counter + = 1 % Increase number of levels found
new file, counter % Dynamically resizes the array
file (counter ) := fileName % Saves the level name
end if
end if
end loop
Dir.Close (stream ) % Closes stream
/* Load data from all mazes into arrays */
var ch : char := ' ' % Used to scan in characters from text file
var mazeFileID, settingsFileID : int % Files for maze.txt and settings.ini
var row : int := 0 % Default row position
var column : int := 0 % Default column position
var numOfRows, numOfColumns : array 1 .. counter of int % 2D array to store x,y pos of maze
for i : 1 .. counter % Go through each file
open : mazeFileID, file (i ), get % Open current file for counting
loop % Loop through current file
exit when eof (mazeFileID ) % Exit when reaches end of file
get : mazeFileID, ch % Obtain each character
column + = 1 % Increase column count
if ch = '\n' then % Detects CRLF
column := 0 % Reposition column
row + = 1 % Increase row count
end if
end loop
close : mazeFileID % Close file
row + = 1 % Increment row count
numOfRows (i ) := row % Save number of rows in each maze
numOfColumns (i ) := column % Save number of columns in each maze
column := 0 % Reset column counter
row := 0 % Reset row counter
end for
var maze : array 1 .. counter, 1 .. 99, 1 .. 99 of char % 3D array to store each maze square per level, max 99 chars by 99
var mazeX : array 1 .. 99 of int % Save X axis per maze square
var mazeY : array 1 .. 99 of int % Save Y axis per maze square
for i : 1 .. counter % Loop through each maze
for y : 1 .. numOfRows (i ) % Y axis/rows
for x : 1 .. numOfColumns (i ) % X axis/rows
maze (i, x, y ) := ' ' % Empties array
mazeX (x ) := x * fontSize + ((maxx div fontSize - numOfColumns (i )) * 3) + 10 % Increase x axis
mazeY (y ) := maxy - 250 - y * fontSize + (maxy div 4) % Increase y axis
end for
end for
end for
var charX : int := 0 % Keeps track of current chars X
var charY : int := 1 % Keeps track of current chars Y
for i : 1 .. counter % Go through each maze again, multi-dimensional array resizing not possible
open : mazeFileID, file (i ), get % Open current maze for reading
loop % Loop through maze
exit when eof (mazeFileID ) % Exit when reaches end of file
get : mazeFileID, ch % Obtain each character
charX + = 1 % Increase character x position
if ch = '\n' then % If character is CRLF then
charY + = 1 % Increase row count
charX := 0 % Reposition x
else % If no CRLF then
maze (i, charX, charY ) := ch % Store maze character information
end if
end loop
charX := 0 % Reset x
charY := 1 % Reset y
close : mazeFileID % Close current file
end for
var mainWindow := Window.Open ("graphics:800;600;offscreenonly,position:center;middle,nobuttonbar,nocursor, title:Emazizing") % Main window settings
var mouseX, mouseY, button, updown : int % Mouse information
var keys : array char of boolean % Keyboard input
var boxX, boxY : int := 0 % Level box selection area
var boxWidth, boxHeight : int % Size of the box
var mapX, mapY : int := 0 % Map maker grid
var mapSize : int := 10
var col : int % Level font color
var wallCol : int := white % Wall color
var borderCol : int := white % Wall border color
var floorCol : int := black % Floor color
var rCol1, rCol2 : int % Randomize color
var colorBoxSize : int := 30 % Size of color pallet
var colorBoxX := 100 % Color pallet X
var colorBoxY := maxy - 100 % Color pallet Y
var heightY : int % Level selection height
var debugText : string := "" % Debug toggle text
var topText : string := "" % Text at the top of the screen
var topTextX : int := maxx div 2 - 60 % X position of the top text
var highscoreX : int := maxx div 2 - 60 % Highscore X position
var mazeWall : char := chr (35) % Default maze character (#)
var tempMazeWall : char := mazeWall % Temporary char selection
var currentChr : char := mazeWall % Currently selected char
var mazeFloor : char := ' ' % Maze floor character
var borderOn : boolean := false % White borders surround the wall
var firstTime : boolean := true % Used in debug
var hitESC : boolean := false % Needed to avoid ESC overwriting highscore
var changeClick : boolean := false % Wall char selection toggle
var outputID : int % Debug text maze window ID
var wallSelectX : array 1 .. 6 of int := init (37, 86, 86, 690, 690, 86) % Speech bubble with char selection X co-ords
var wallSelectY : array 1 .. 6 of int := init (563, 491, 360, 360, 530, 530) % Speech bubble with char selection Y co-ords
var fontChrSelX : int := wallSelectX (1) % Starting X pos to draw maze wall type
var fontChrSelY : int := wallSelectY (1) % Starting Y pos to draw maze wall type
var startX, endX : int % Starting and ending spots of maze
var startXBool, endXBool : boolean := false % If start and end have been found
var playerX, playerY : int % Used to hold player X/Y co-ords
var playerSteps : int := 3 % Number of steps a player takes
var aiX, aiY : int % Used to hold AI X/Y co-ords
var saveNameCh : char % Input save file name
var saveName : string := "" % File savename
var xyFound, foundBottom : boolean := false % Locate the top left wall of a newly created map
var xStore, yStore : int % Store x/y axis
var farRight, bottom : int := 0 % Find far X and bottom left of new map
var lvlX : int := 0 % Align level numbering properly
var line : string % Line read for file I/O
var timer : int := 0 % Score timer
var back : boolean := false % Needed to go back and not X
var fileArray : flexible array 1 .. 0 of string % Hold each file name
var lineCounter : int := 0 % Count number of rows in settings.ini
var score : array 1 .. counter of int % Store the score for each maze
var scoreCounter : int := 0 % Keep track of score id
for i : 1 .. upper (score ) % Loop through all scores
score (i ) := 0 % Default all scores to 0
end for
var maxMapX : int := 40
var maxMapY : int := 25
var mapXStore : array 1 .. maxMapX of int
var mapYStore : array 1 .. maxMapY of int
var mapClick : array 1 .. maxMapX, 1 .. maxMapY of boolean
mapY := 250
for y : 1 .. maxMapY
for x : 1 .. maxMapX
mapXStore (x ) := mapX
mapYStore (y ) := mapY
mapX + = mapSize
mapClick (x, y ) := false
end for
mapY + = mapSize
mapX := 200
end for
Font.Draw (chr (26), 0, 0, keyFont, black) % Draw initial arrow (facing right)
var rightArrow, leftArrow, upArrow, downArrow : int
rightArrow := Pic.New (0, 0, 10, 10) % Right arrow
downArrow := Pic.Rotate (rightArrow, 270, 5, 5) % Down arrow
leftArrow := Pic.Rotate (rightArrow, 180, 5, 5) % Left arrow
upArrow := Pic.Rotate (rightArrow, 90, 5, 5) % Up arrow
Mouse.ButtonChoose ("multibutton")
var leftClick, middleClick, rightClick : int
% Delete extra width of maze
%%%% SHRINK MAZE SPACE WIDTH BY 1 BLOCK %%%
%%%% THEN END OF LOOP INCREASE AGAIN %%%
%%%% TEMP ARRAY??? %%%
for i : 1 .. counter
for y : 1 .. numOfRows (i )
for x : 1 .. numOfColumns (i )
if maze (i, x, y ) = ' ' then
%maze (i, x+1, y) := mazeWall
end if
end for
end for
end for
function contains (wordCompare : string, lookup : string) : int
var start : int
for i : 1 .. length (wordCompare )
if wordCompare (i .. i + length (lookup ) - 1) = lookup then
result i
else
if i > length (wordCompare ) - length (lookup ) then
result - 1
end if
end if
end for
end contains
if not File.Exists ("settings.ini") then
open : settingsFileID, "settings.ini", put
put : settingsFileID, "char=", mazeWall
put : settingsFileID, "wall=", wallCol
put : settingsFileID, "floor=", floorCol
for i : 1 .. counter
put : settingsFileID, file (i ), "=", 0
end for
close : settingsFileID
else
open : settingsFileID, "settings.ini", get
loop
exit when eof (settingsFileID )
get : settingsFileID, line : *
if length (line ) > 5 then
if line (1 .. 5) = "char=" then
mazeWall := line (6)
end if
end if
if contains (line, "wall=") not= - 1 then
wallCol := strint (line (6 .. length (line )))
end if
if contains (line, "floor=") not= - 1 then
floorCol := strint (line (7 .. length (line )))
end if
if contains (line, ".TXT=") not= - 1 then
scoreCounter := scoreCounter + 1
score (scoreCounter ) := strint (line (contains (line, ".TXT=") + 5 .. length (line )))
end if
end loop
close : settingsFileID
end if
procedure Refresh
Draw.FillBox (0, 0, maxx, maxy, black)
Draw.FillBox (0, maxy - 50, maxx, maxy, blue)
if debug then
Draw.FillBox (10, maxy - 40, 40, maxy - 10, green)
Draw.Box (10, maxy - 40, 40, maxy - 10, brightred)
Font.Draw (mazeWall, 14, maxy - 35, mazeFont, white)
else
Draw.FillBox (10, maxy - 40, 40, maxy - 10, wallCol )
Draw.Box (10, maxy - 40, 40, maxy - 10, white)
end if
Draw.Line (0, 250, maxx, 250, white)
Font.Draw (topText, topTextX, maxy - 32, nameFont, white)
end Refresh
procedure KeyPress
if keys ('a') then
Draw.FillBox (150, 15, 175, 40, yellow)
else
Draw.FillBox (150, 15, 175, 40, white)
end if
if keys ('s') then
Draw.FillBox (180, 15, 205, 40, yellow)
else
Draw.FillBox (180, 15, 205, 40, white)
end if
if keys ('d') then
Draw.FillBox (210, 15, 235, 40, yellow)
else
Draw.FillBox (210, 15, 235, 40, white)
end if
if keys ('w') then
Draw.FillBox (180, 45, 205, 70, yellow)
else
Draw.FillBox (180, 45, 205, 70, white)
end if
Font.Draw ("A", 156, 22, keyFont, black)
Font.Draw ("S", 188, 22, keyFont, black)
Font.Draw ("D", 217, 22, keyFont, black)
Font.Draw ("W", 184, 50, keyFont, black)
if keys (KEY_LEFT_ARROW) then
Draw.FillBox (550, 15, 575, 40, yellow)
else
Draw.FillBox (550, 15, 575, 40, white)
end if
if keys (KEY_DOWN_ARROW) then
Draw.FillBox (580, 15, 605, 40, yellow)
else
Draw.FillBox (580, 15, 605, 40, white)
end if
if keys (KEY_RIGHT_ARROW) then
Draw.FillBox (610, 15, 635, 40, yellow)
else
Draw.FillBox (610, 15, 635, 40, white)
end if
if keys (KEY_UP_ARROW) then
Draw.FillBox (580, 45, 605, 70, yellow)
else
Draw.FillBox (580, 45, 605, 70, white)
end if
Pic.Draw (leftArrow, 556, 22, picMerge)
Pic.Draw (downArrow, 588, 17, picMerge)
Pic.Draw (rightArrow, 617, 22, picMerge)
Pic.Draw (upArrow, 588, 52, picMerge)
end KeyPress
loop
Mouse.Where (mouseX, mouseY, button )
Input.KeyDown (keys )
Refresh
KeyPress
topText := "Select a Level"
topTextX := maxx div 2 - 80
hitESC := false
heightY := 220
boxX := - 50
if wallCol = white then
borderCol := black
else
borderCol := white
end if
for i : 1 .. counter
if boxX > maxx - 100 then
boxX := - 50
heightY - = 50
end if
boxX + = 50
if mouseX >= 20 + boxX and mouseX <= 50 + boxX and mouseY >= heightY - 10 and mouseY <= heightY + 20 then
col := yellow
% DRAW PREVIEW
topText := file (i )
for y : 1 .. numOfRows (i )
for x : 1 .. numOfColumns (i )
if maze (i, x, y ) = ' ' then
Draw.FillBox (x * fontSize + ((maxx div fontSize - numOfColumns (i )) * 3) + 10, maxy - 250 - y * fontSize + (maxy div 4) - 1, x * fontSize +
((maxx div fontSize - numOfColumns (i )) * 3) + 10 + fontSize, maxy - 250 - y * fontSize + (maxy div 4) + fontSize, floorCol )
else
if debug then
Font.Draw (mazeWall, x * fontSize + ((maxx div fontSize - numOfColumns (i )) * 3) + 10, maxy - 250 - y * fontSize + (maxy div 4), charFont, white)
else
Draw.FillBox (x * fontSize + ((maxx div fontSize - numOfColumns (i )) * 3) + 10, maxy - 251 - y * fontSize + (maxy div 4), x * fontSize +
((maxx div fontSize - numOfColumns (i )) * 3) + 10 + fontSize, maxy - 250 - y * fontSize + (maxy div 4) + fontSize, wallCol )
if borderOn then
Draw.Box (x * fontSize + ((maxx div fontSize - numOfColumns (i )) * 3) + 10, maxy - 250 - y * fontSize + (maxy div 4), x * fontSize +
((maxx div fontSize - numOfColumns (i )) * 3) + 10 + fontSize, maxy - 250 - y * fontSize + (maxy div 4) + fontSize, borderCol )
end if
end if
end if
end for
end for
if score (i ) = 0 then
highscoreX := maxx div 2 - 130
Font.Draw ("No highscore for this level yet!", highscoreX, 10, defFontID, white)
else
highscoreX := maxx div 2 - 78
Font.Draw ("Highscore: " + intstr (score (i )) + " points", highscoreX, 10, defFontID, white)
end if
if button = 1 then
% LEVEL SELECTED
if debug then
if not firstTime then
%Window.Close (outputID)
end if
firstTime := false
Mouse.ButtonWait ("up", mouseX, mouseY, button, updown )
outputID := Window.Open ("text,position:" + intstr (maxx * 2 - 30) + "," + intstr (maxy - 300))
open : mazeFileID, file (i ), get
loop
exit when eof (mazeFileID )
get : mazeFileID, ch
put ch ..
charX + = 1
if charX = numOfColumns (i ) then
charX := 1
if charY < numOfRows (i ) then
charY + = 1
end if
end if
end loop
close : mazeFileID
Window.SetActive (mainWindow )
end if
%%%% SHRINK MAZE SPACE WIDTH BY 1 BLOCK %%%
%%%% THEN END OF LOOP INCREASE AGAIN %%%
%%%% TEMP ARRAY??? %%%
for y : 1 .. numOfRows (i )
for x : 1 .. numOfColumns (i )
end for
end for
timer := 0
loop
Draw.FillBox (0, 0, maxx, maxy, black)
Font.Draw ("Press 'ESC' to return", 10, maxy - 20, defFontID, white)
Font.Draw ("Ticker: " + intstr (timer div 10), maxx - 100, maxy - 20, defFontID, white)
Font.Draw ("Highscore " + intstr (score (i )), maxx - 150, maxy - 40, defFontID, white)
KeyPress
for y : 1 .. numOfRows (i )
for x : 1 .. numOfColumns (i )
if maze (i, x, y ) = ' ' then
%put x * fontSize + ((maxx div fontSize - numOfColumns (i)) * 3) + 10
Draw.FillBox (x * fontSize + ((maxx div fontSize - numOfColumns (i )) * 3) + 10, maxy - 250 - y * fontSize + (maxy div 4) - 1, x * fontSize +
((maxx div fontSize - numOfColumns (i )) * 3) + 10 + fontSize, maxy - 250 - y * fontSize + (maxy div 4) + fontSize, floorCol )
if not startXBool then
startXBool := true
startX := x * fontSize + ((maxx div fontSize - numOfColumns (i )) * 3) + fontSize
%Draw.Line (startX, maxy - 250 - y * fontSize + (maxy div 4) + 7, startX + fontSize * 2 - 2, maxy - 250 - y * fontSize + (maxy div 4) + 7, brightgreen)
playerX := startX
playerY := maxy - 250 - y * fontSize + (maxy div 4)
if not debug then
playerX + = 5
end if
%Draw.FillBox (startX, maxy - 250 - y * fontSize + (maxy div 4), startX + fontSize - 4, maxy - 250 - y * fontSize + (maxy div 4) + fontSize - 4, brightblue)
startXBool := true
end if
Font.Draw (mazeFloor, x * fontSize + ((maxx div fontSize - numOfColumns (i )) * 3) + 10, maxy - 250 - y * fontSize + (maxy div 4), defFontID, brightblue)
else
if debug then
Font.Draw (mazeWall, x * fontSize + ((maxx div fontSize - numOfColumns (i )) * 3) + 10, maxy - 250 - y * fontSize + (maxy div 4), defFontID, white)
else
Draw.FillBox (x * fontSize + ((maxx div fontSize - numOfColumns (i )) * 3) + 10, maxy - 250 - y * fontSize + (maxy div 4), x * fontSize +
((maxx div fontSize - numOfColumns (i )) * 3) + 10 + fontSize, maxy - 250 - y * fontSize + (maxy div 4) + fontSize, wallCol )
if borderOn then
Draw.Box (x * fontSize + ((maxx div fontSize - numOfColumns (i )) * 3) + 10, maxy - 250 - y * fontSize + (maxy div 4), x * fontSize +
((maxx div fontSize - numOfColumns (i )) * 3) + 10 + fontSize, maxy - 250 - y * fontSize + (maxy div 4) + fontSize, borderCol )
end if
end if
end if
if y = numOfRows (i ) and maze (i, x, y ) = ' ' then
if not endXBool then
endXBool := true
endX := x * fontSize + ((maxx div fontSize - numOfColumns (i )) * 3) + 10
endXBool := true
end if
end if
end for
end for
Input.KeyDown (keys )
Mouse.Where (mouseX, mouseY, button )
if keys ('w') or keys (KEY_UP_ARROW) /*or (mouseY > playerY and button = 1)*/ then
if debug then
playerY + = fontSize - 3
else
if not whatdotcolor (playerX + 2, playerY + 10) = wallCol or (borderOn and whatdotcolor (playerX + 2, playerY + 10) = white) then
playerY + = fontSize - 3
end if
end if
end if
if keys ('s') or keys (KEY_DOWN_ARROW) /*or (mouseY < playerY and button = 1)*/ then
if debug then
playerY - = fontSize - 3
else
if not whatdotcolor (playerX + 2, playerY - 5) = wallCol or (borderOn and whatdotcolor (playerX + 2, playerY - 5) = white) then
playerY - = fontSize - 3
end if
end if
end if
if keys ('a') or keys (KEY_LEFT_ARROW) /*or (mouseX < playerX and button = 1)*/ then
if debug then
playerX - = fontSize - 3
else
if not whatdotcolor (playerX - 5, playerY + 2) = wallCol or (borderOn and whatdotcolor (playerX - 5, playerY + 2) = white) then
playerX - = fontSize - 3
end if
end if
end if
if keys ('d') or keys (KEY_RIGHT_ARROW) /*or (mouseX > playerX and button = 1)*/ then
if debug then
playerX + = fontSize - 3
else
if not whatdotcolor (playerX + 10, playerY + 2) = wallCol or (borderOn and whatdotcolor (playerX + 10, playerY + 2) = white) then
playerX + = fontSize - 3
end if
end if
end if
if keys (KEY_ESC) then
startXBool := false
endXBool := false
hitESC := true
timer := 0
exit
end if
if playerY > maxy - 105 then
playerY - = fontSize - 3
end if
if playerY < maxy - 105 - numOfRows (i ) * 9 then
startXBool := false
endXBool := false
playerY := 0
playerX := 0
exit
end if
for y : 1 .. numOfRows (i )
for x : 1 .. numOfColumns (i )
%if playerX >
%end if
end for
end for
if debug then
Draw.Line (startX, maxy - 100, startX + 14, maxy - 100, brightgreen)
Draw.Line (endX, maxy - 105 - numOfRows (i ) * 9, endX + 14, maxy - 105 - numOfRows (i ) * 9, brightred)
else
Draw.Line (startX + 2, maxy - 100, startX + 16, maxy - 100, brightgreen)
Draw.Line (endX + 2, maxy - 105 - numOfRows (i ) * 9, endX + 16, maxy - 105 - numOfRows (i ) * 9, brightred)
end if
Draw.FillBox (playerX, playerY, playerX + fontSize - 4, playerY + fontSize - 4, yellow)
Draw.Box (playerX, playerY, playerX + fontSize - 4, playerY + fontSize - 4, black)
View.Update
delay (50)
timer + = 1
end loop
if debug then
Window.Close (outputID )
end if
% SAVE SCORE HERE
if not hitESC then
open : settingsFileID, "settings.ini", put, get, mod
lineCounter := 0
loop
exit when eof (settingsFileID )
get : settingsFileID, line
lineCounter + = 1
new fileArray, lineCounter
fileArray (lineCounter ) := line
if length (line ) > 5 then
for j : 1 .. length (line )
if line (j ) = "." then
if Str.Lower (line (j .. j + 4)) = ".txt=" then
if Str.Lower (line (1 .. j - 1) + ".txt") = Str.Lower (file (i )) then
if contains (line, ".TXT=") not= - 1 then
if timer < score (i ) or score (i ) = 0 then
score (i ) := timer
fileArray (lineCounter ) := line (1 .. length (line ) - length (line (contains (line, ".TXT=") + 5 .. length (line )))) + intstr (score (i ))
end if
end if
exit
end if
end if
end if
end for
end if
end loop
close : settingsFileID
open : settingsFileID, "settings.ini", put
%put : settingsFileID, "char=", mazeWall
%put : settingsFileID, "wall=", wallCol
%put : settingsFileID, "floor=", wallCol
for j : 1 .. upper (fileArray )
put : settingsFileID, fileArray (j )
end for
close : settingsFileID
end if
end if
else
col := white
end if
Draw.FillBox (20 + boxX, heightY - 10, 50 + boxX, heightY + 20, blue)
Draw.Box (20 + boxX, heightY - 10, 50 + boxX, heightY + 20, brightred)
lvlX := 0
if i < 10 then
lvlX - = 6
end if
Font.Draw (intstr (i ), boxX + 20 - lvlX, heightY - 5, levelFont, col )
if i = counter then % Add a + button to add custom map
if boxX > maxx - 100 then
boxX := - 50
heightY - = 50
end if
Draw.FillBox (boxX + 70, heightY - 10, 100 + boxX, heightY + 20, green)
Draw.Box (boxX + 70, heightY - 10, 100 + boxX, heightY + 20, brightblue)
Font.Draw ("+", boxX + 77, heightY - 5, levelFont, brightred)
if mouseX > boxX + 70 and mouseX < 100 + boxX and mouseY > heightY - 10 and mouseY < heightY + 20 then
topText := "Add a new map"
if button = 1 then
loop
Mouse.Where (mouseX, mouseY, button )
Draw.FillBox (0, 0, maxx, maxy, black)
Draw.Box (maxx - 50, maxy - 40, maxx - 80, maxy - 10, white) % Save floppy disk
Font.Draw ("S", maxx - 73, maxy - 35, levelFont, white)
if mouseX > maxx - 80 and mouseX < maxx - 50 and mouseY > maxy - 40 and mouseY < maxy - 10 then
topTextX := 330
topText := "Click to save map"
Font.Draw (topText, topTextX, maxy - 32, nameFont, white)
if button = 1 then
Draw.FillBox (0, maxy, maxx - 100, maxy - 100, black)
topText := "Enter a map name (try to be consistant ie: MAZE8) and hit enter"
topTextX := 150
Font.Draw (topText, topTextX, maxy - 32, nameFont, white)
Input.Flush
delay (250)
for y : 1 .. 25
for x : 1 .. 40
if mapClick (x, y ) then
Draw.FillBox (mapXStore (x ), mapYStore (y ), mapXStore (x ) + mapSize, mapYStore (y ) + mapSize, brightred)
else
Draw.Box (mapXStore (x ), mapYStore (y ), mapXStore (x ) + mapSize, mapYStore (y ) + mapSize, white)
end if
%Font.Draw (intstr (y), mapXStore (x), mapYStore (y), defFontID, white)
end for
end for
View.Update
saveName := ""
loop
saveNameCh := getchar
exit when saveNameCh = '\n'
saveName + = saveNameCh
Font.Draw (saveName, maxx div 2 - 100, maxy - 80, nameFont, white)
View.Update
end loop
% SAVE OUT MAP FILE HERE
new file, upper (file ) + 1
file (upper (file )) := saveName + ".TXT"
for y : 1 .. 25
for x : 1 .. 40
if mapClick (x, y ) then % FOUND BOTTOM OF MAP
foundBottom := true
if foundBottom then
bottom := y
end if
%put "First X: ", x, " Y: ", y, " from bottom left to top right"
for y2 : y .. 25
if not mapClick (x, y2 ) then
%put "2nd X: ", x, " Y: ", y2 - 1, " on the left side"
xStore := x
yStore := y
xyFound := true
% Look for far right
for decreasing x2 : 40 .. 1
if mapClick (x2, y ) then
farRight := x2
%put x2
%quit
exit
end if
end for
end if
end for
exit when xyFound
end if
end for
end for
for decreasing y : yStore .. 1
for x : xStore .. farRight
if mapClick (x, y ) then
%put ' ' ..
else
%put '0' ..
end if
end for
%put "END"
end for
%put yStore
%quit
open : mazeFileID, saveName + ".TXT", put, mod
%put : mazeFileID, yStore
for decreasing y : yStore .. 1
%put : mazeFileID, y, " ", bottom, " " ..
exit when not mapClick (xStore, y )
for x : xStore .. farRight
if mapClick (x, y ) then
put : mazeFileID, '?' ..
else
put : mazeFileID, ' ' ..
end if
end for
put : mazeFileID, ""
end for
close : mazeFileID
%%% HERE %%%
back := true
exit
end if
end if
Draw.Box (maxx - 40, maxy - 40, maxx - 10, maxy - 10, white) % Back button
Font.Draw ("<", maxx - 33, maxy - 35, levelFont, white)
if mouseX > maxx - 40 and mouseX < maxx - 10 and mouseY > maxy - 40 and mouseY < maxy - 10 then
topText := "Click to go back"
Font.Draw (topText, topTextX, maxy - 32, nameFont, white)
if button = 1 then
back := true
exit
end if
end if
leftClick := button mod 10
middleClick := (button - leftClick ) mod 100
rightClick := button - middleClick - leftClick
for y : 1 .. 25
for x : 1 .. 40
%mapX += mapSize
if mapClick (x, y ) then
Draw.FillBox (mapXStore (x ), mapYStore (y ), mapXStore (x ) + mapSize, mapYStore (y ) + mapSize, brightred)
else
Draw.Box (mapXStore (x ), mapYStore (y ), mapXStore (x ) + mapSize, mapYStore (y ) + mapSize, white)
end if
if mouseX > mapXStore (x ) and mouseX < mapXStore (x ) + mapSize and mouseY > mapYStore (y ) and mouseY < mapYStore (y ) + mapSize then
if leftClick = 1 then
mapClick (x, y ) := true
elsif rightClick = 100 then
mapClick (x, y ) := false
end if
%Draw.FillBox (mapXStore (x), mapYStore (y), mapXStore (x) + mapSize, mapYStore (y) + mapSize, red)
end if
end for
%mapY += mapSize
%mapX := 200
end for
%mapY := 200
View.Update
cls
end loop
end if
end if
end if
if mouseX > 10 and mouseX < 40 and mouseY > maxy - 40 and mouseY < maxy - 10 then
if debug then
topText := "Click to change maze wall style"
topTextX := 250
Draw.FillBox (0, 251, maxx, maxy - 100, black)
Draw.FillPolygon (wallSelectX, wallSelectY, 6, white)
if debug then
for pY : 1 .. upper (wallSelectY )
for pX : 1 .. upper (wallSelectY )
%Font.Draw ("(" + intstr (pX) + "," + intstr (pY) + ")", wallSelectX (pX), wallSelectY (pY) + 10, defFontID, brown)
%Font.Draw (intstr (wallSelectX (pX)) + "," + intstr (wallSelectY (pY)), wallSelectX (pX), wallSelectY (pY), debugFont, brightgreen)
end for
end for
end if
Draw.FillBox (0, 0, maxx, 249, black)
Draw.FillBox (maxx div 2 - 50, 80, maxx div 2 + 50, 180, green)
Draw.Box (maxx div 2 - 50, 80, maxx div 2 + 50, 180, brightred)
Font.Draw (tempMazeWall, maxx div 2 - 20, 105, tempMazeFont, white)
for z : 0 .. 255
if z not= 0 and z not= 1 and z not= 9 and z not= 10 and z not= 13
and z not= 28 and z not= 29 and z not= 30 and z not= 31 and z not= 32 and z not= 128
and z not= 129 and z not= 141 and z not= 143 and z not= 144 and z not= 157 and z not= 160 then
Font.Draw (chr (z ), fontChrSelX + 70, fontChrSelY - 65, fontChrSelFont, brightred)
fontChrSelX + = 10
if fontChrSelX > wallSelectX (5) - 90 then
fontChrSelY - = 30
fontChrSelX := wallSelectX (1)
end if
end if
end for
fontChrSelX := wallSelectX (1)
fontChrSelY := wallSelectY (1)
if button = 1 then
Draw.FillBox (50, maxy - 50, maxx - 200, maxy, blue)
delay (100)
if not changeClick then
changeClick := true
end if
topText := "Click a font"
topTextX := 335
Font.Draw (topText, topTextX, maxy - 32, nameFont, white)
%Refresh
loop
Mouse.Where (mouseX, mouseY, button )
exit when (mouseX < 86 or mouseX > 690 or mouseY < 360 or mouseY > 530) and button = 1
Font.Draw ("X:" + intstr (mouseX ) + " Y:" + intstr (mouseY ), 100, 100, defFontID, brightred)
for z : 0 .. 255
if z not= 0 and z not= 1 and z not= 9 and z not= 10 and z not= 13
and z not= 28 and z not= 29 and z not= 30 and z not= 31 and z not= 32 and z not= 128
and z not= 129 and z not= 141 and z not= 143 and z not= 144 and z not= 157 and z not= 160 then
if mouseX >= fontChrSelX + 70 and mouseX <= fontChrSelX + 80
and mouseY >= fontChrSelY - 50 and mouseY <= fontChrSelY - 20 then
tempMazeWall := chr (z )
if button = 1 then
mazeWall := tempMazeWall
changeClick := false
open : settingsFileID, "settings.ini", put
put : settingsFileID, "char=", mazeWall
put : settingsFileID, "wall=", wallCol
put : settingsFileID, "floor=", floorCol
for g : 1 .. upper (score )
put : settingsFileID, file (g ), "=", score (g )
end for
close : settingsFileID
end if
end if
fontChrSelX + = 10
if fontChrSelX > wallSelectX (5) - 90 then
fontChrSelY - = 30
fontChrSelX := wallSelectX (1)
end if
end if
end for
fontChrSelX := wallSelectX (1)
fontChrSelY := wallSelectY (5)
if not changeClick then
exit
end if
Draw.FillBox (0, 0, maxx, 249, black)
Font.Draw ("Preview", maxx div 2 - 50, maxy div 2 - 85, fontChrSelFont, white)
for y : 1 .. 15
for x : 1 .. numOfColumns (i )
if maze (i, x, y ) not= ' ' then
Font.Draw (tempMazeWall, x * fontSize + ((maxx div fontSize - numOfColumns (i )) * 3) + 10, 30 - y * fontSize + (maxy div 4), charFont, white)
end if
end for
end for
View.Update
end loop
end if
else
topText := "Click to change maze wall color"
topTextX := 250
if button = 1 then
Draw.FillBox (100, maxy - 50, maxx - 200, maxy, blue)
delay (100)
if not changeClick then
changeClick := true
end if
topText := "Click a color"
Refresh
Draw.Line (0, 250, maxx, 250, black)
loop
Mouse.Where (mouseX, mouseY, button )
for c : 0 .. 254
colorBoxX + = colorBoxSize
Draw.FillBox (colorBoxX, colorBoxY, colorBoxX + colorBoxSize, colorBoxY + colorBoxSize, c )
Draw.Box (colorBoxX, colorBoxY, colorBoxX + colorBoxSize, colorBoxY + colorBoxSize, white)
if colorBoxX > 600 then
colorBoxY - = colorBoxSize
colorBoxX := 100
end if
end for
colorBoxX := 100
colorBoxY := maxy - 100
Draw.FillBox (55, maxy - 40, 85, maxy - 10, whatdotcolor (mouseX, mouseY ))
Draw.Box (55, maxy - 40, 85, maxy - 10, white)
% DELETES PARTS OF NEXT LINE, 'MAZE.TXT' if color id is 10-99 takes a letter, 100+ takes 2
if button = 1 then
if whatdotcolor (mouseX, mouseY ) not= floorCol then
if mouseX > colorBoxX + colorBoxSize and mouseX < colorBoxX + 540 and mouseY > 80 and mouseY < colorBoxY + colorBoxSize then
wallCol := whatdotcolor (mouseX, mouseY )
open : settingsFileID, "settings.ini", put
put : settingsFileID, "char=", mazeWall
put : settingsFileID, "wall=", wallCol
put : settingsFileID, "floor=", floorCol
for g : 1 .. upper (score )
put : settingsFileID, file (g ), "=", score (g )
end for
close : settingsFileID
exit
else
exit
end if
else
topTextX := 220
topText := "Please make sure floor and wall colors differ"
Draw.FillBox (100, maxy - 50, maxx - 200, maxy, blue)
Font.Draw (topText, topTextX, maxy - 32, nameFont, white)
end if
end if
if not changeClick then
delay (250)
exit
end if
View.Update
end loop
end if
end if
end if
end for
if debugText = "Off" then
Draw.FillBox (maxx - 175, maxy - 35, maxx - 70, maxy - 18, red)
else
Draw.FillBox (maxx - 175, maxy - 35, maxx - 70, maxy - 18, green)
end if
Draw.Box (maxx - 175, maxy - 35, maxx - 70, maxy - 18, white)
if mouseX >= maxx - 175 and mouseX <= maxx - 70 and mouseY >= maxy - 35 and mouseY < maxy - 18 then
topText := "Click to toggle Debug mode on/off"
topTextX := 245
if button = 1 then
if debug = false then
debug := true
else
debug := false
end if
delay (250)
end if
end if
Font.Draw ("Debug is " + debugText, maxx - 170, maxy - 30, defFontID, white)
if not debug then
debugText := "Off"
else
debugText := "On"
end if
Draw.FillBox (maxx - 40, maxy - 35, maxx - 20, maxy - 18, red)
Draw.Box (maxx - 40, maxy - 35, maxx - 20, maxy - 18, white)
Font.Draw ("X", maxx - 34, maxy - 30, defFontID, white)
if mouseX >= maxx - 40 and mouseX <= maxx - 20 and mouseY >= maxy - 35 and mouseY < maxy - 18 then
topText := "Click to exit the game"
topTextX := 280
if back then
button := 0
back := false
delay (250)
end if
if button = 1 then
exit
end if
end if
Draw.FillBox (55, maxy - 10, 85, maxy - 40, floorCol )
Draw.Box (55, maxy - 10, 85, maxy - 40, white)
if mouseX >= 55 and mouseX <= 85 and mouseY >= maxy - 40 and mouseY < maxy - 10 then
topText := "Click to change maze floor tile"
topTextX := 250
if button = 1 then
Draw.FillBox (100, maxy - 50, maxx - 200, maxy, blue)
delay (100)
if not changeClick then
changeClick := true
end if
topText := "Click a color"
Refresh
Draw.Line (0, 250, maxx, 250, black)
loop
Mouse.Where (mouseX, mouseY, button )
for c : 0 .. 254
colorBoxX + = colorBoxSize
Draw.FillBox (colorBoxX, colorBoxY, colorBoxX + colorBoxSize, colorBoxY + colorBoxSize, c )
Draw.Box (colorBoxX, colorBoxY, colorBoxX + colorBoxSize, colorBoxY + colorBoxSize, white)
if colorBoxX > 600 then
colorBoxY - = colorBoxSize
colorBoxX := 100
end if
end for
colorBoxX := 100
colorBoxY := maxy - 100
Draw.FillBox (55, maxy - 40, 85, maxy - 10, whatdotcolor (mouseX, mouseY ))
Draw.Box (55, maxy - 40, 85, maxy - 10, white)
% DELETES PARTS OF NEXT LINE, 'MAZE.TXT' if color id is 10-99 takes a letter, 100+ takes 2
if button = 1 then
if whatdotcolor (mouseX, mouseY ) not= wallCol then
if mouseX > colorBoxX + colorBoxSize and mouseX < colorBoxX + 540 and mouseY > 80 and mouseY < colorBoxY + colorBoxSize then
floorCol := whatdotcolor (mouseX, mouseY )
open : settingsFileID, "settings.ini", put
put : settingsFileID, "char=", mazeWall
put : settingsFileID, "wall=", wallCol
put : settingsFileID, "floor=", floorCol
for g : 1 .. upper (score )
put : settingsFileID, file (g ), "=", score (g )
end for
close : settingsFileID
exit
else
exit
end if
else
topTextX := 220
topText := "Please make sure floor and wall colors differ"
Draw.FillBox (100, maxy - 50, maxx - 200, maxy, blue)
Font.Draw (topText, topTextX, maxy - 32, nameFont, white)
end if
end if
if not changeClick then
exit
end if
View.Update
end loop
end if
end if
if not debug then
Draw.FillBox (100, maxy - 10, 130, maxy - 40, Rand.Int (0, 255))
Draw.Box (100, maxy - 10, 130, maxy - 40, white)
if mouseX >= 100 and mouseX <= 130 and mouseY >= maxy - 40 and mouseY < maxy - 10 then
topText := "Click to randomize color scheme"
topTextX := 230
if button = 1 then
rCol1 := Rand.Int (0, 255)
rCol2 := Rand.Int (0, 255)
if rCol1 = rCol2 then % Makes sure the values cannot be the same
rCol1 := Rand.Int (0, 127)
rCol2 := Rand.Int (128, 255)
end if
floorCol := rCol1
wallCol := rCol2
open : settingsFileID, "settings.ini", put
put : settingsFileID, "char=", mazeWall
put : settingsFileID, "wall=", wallCol
put : settingsFileID, "floor=", floorCol
for g : 1 .. upper (score )
put : settingsFileID, file (g ), "=", score (g )
end for
close : settingsFileID
delay (250)
end if
end if
end if
if not debug then
Draw.Box (145, maxy - 10, 175, maxy - 40, white)
if borderOn then
Draw.Box (150, maxy - 15, 170, maxy - 35, white)
end if
if mouseX >= 145 and mouseX <= 175 and mouseY >= maxy - 40 and mouseY < maxy - 10 then
if not borderOn then
topText := "Click to enable borders"
else
topText := "Click to disable borders"
end if
topTextX := 270
if button = 1 then
if not borderOn then
borderOn := true
else
borderOn := false
end if
delay (250)
end if
end if
end if
View.Update
cls
end loop
Window.Close (mainWindow )
|
Here's a sample maze, just save as MAZE.TXT in the same dir as the program if you wish to run it.
code: |
:--: :--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:
I I I I I
: :--:--: : :--:--:--: : :--: : :--:--: :--:--:--: :
I I I I I I I I I I I
:--:--: : :--:--: : : : : : : : : :--: :--:--:--:
I I I I I I I I I I I I I I
: : : : : :--:--: :--:--: : : : :--: : :--:--: :
I I I I I I I I I I I I I
: :--:--:--:--: : : : : :--: :--: : :--: : :--:--:
I I I I I I I I I I I I
:--:--:--: : :--:--:--: :--: :--: : :--: : : : :--:
I I I I I I I I I I
: : :--:--:--:--:--:--:--:--:--: : :--:--: :--: : : :
I I I I I I I I I I
: :--: : :--:--:--:--:--: : :--:--:--:--:--: : :--: :
I I I I I I I I I
: : :--:--: :--:--:--: : : :--: :--: : : :--:--:--:
I I I I I I I I I I I I I
: :--:--: :--: : : :--:--: : :--: : : : :--: : :
I I I I I I I I I I I
: :--:--:--:--:--: :--:--:--:--: : :--: : :--: :--: :
I I I I I I
:--:--:--:--:--:--:--:--:--:--:--:--: :--:--:--:--:--:--:--:
|
|