When I make an executable file of this program and run the executable, the background and text flash in a most annoying way. Anyone have any idea what the problem might be? The program runs fine when executed directly from DB.
I revised the code, taking everything out of the main game loop that might cause it to flash but that didn't help. I am running DB on a PC with an XP professional OS and not having a problem with any other programs. Below is the current code.
Jim
`CREDITS: http://www.atnasonline.com (minesweeper tutorial but with sprites and such instead of text)
`By J.W. Nov. 2005
`--------------------------------------------------------------------------------------- S E T U P
sync on
set display mode 640, 480, 16
REM Minesin different place each time game is played
Randomize timer()
REM load bitmap for sprites
Load Bitmap "sprite_sheet.bmp",1
REM Select bitmap
set current bitmap 1
REM Make images for sprites
for x = 1 to 16
get image x,(x-1)*25,0,x*25,25,1
next x
`Remove bitmap from memory
delete bitmap 1
`Initialize variables
`Height and width of board, number of mines - Is adjustable but if too big will go off screen -10,24,30 default
MFHeight = 10 : MFWidth = 24 : MFMines = 30
Done = 0 : Square = 0 : Score = 0
`Setup text defaults
set text font "Times New Roman" : set text size 14 : set text opaque
ink rgb(0,100,255), rgb(180,180,180)
`Dimension arrays
AllArrays:
dim MineField(MFWidth,MFHeight)
dim ScoreTrack(Score)
`Setup and draw the minefield
gosub MField
`--------------------------------------------------------------------------------------- M A I N G A M E L O O P
do
sync
`Variables to center grid
startX = (640 / 2) - ((MFwidth * 25)/2)
startY = (480 / 2) - ((MFheight * 25)/2)
`Mouse
`Setup grid to detect mouse location relative to sprites
`flags and question marks
for y = 1 to MFHeight
for x = 1 to MFWidth
if mouseclick() = 1
Mouse1( x, y, MFWidth, MFHeight, MFMines, startX, startY, Score)
DisplayScore(Score, MFWidth, MFHeight, MFMines)
endif
if mouseclick() = 2
Mouse2( x, y, MFWidth, MFHeight, MFMines, startX, startY)
endif
if mouseclick() = 3
Mouse3( x, y, MFWidth, MFHeight, MFMines, startX, startY)
endif
next x
next y
loop
end
`-------------------------------------------------------------------------------------- G O S U B S
`Setup and draw a minefield with 'buried' mines
MField:
`Add a few mines in a randomly random fashion
for Mines = 1 to MFMines
AddMines:
x = rnd(MFWidth-1)+1
y = rnd(MFHeight-1)+1
If MineField(x,y)=99 then goto AddMines
If MineField(x,y)<>99 then MineField(x,y) = 99
next Mines
`Add numbers next to mines indicating number of mines adjacent to the numbered square
for x = 1 to MFWidth
for y = 1 to MFHeight
`If there is a mine, check the adjacent squares and add 1 to the array value for that square
`Check to left, to right, above, below, left and above, etc.
if MineField(x,y) = 99
if x > 1 and MineField((x-1),y) <> 99 then MineField((x-1),y) = MineField((x-1),y) + 1
if x+1 <= MFWidth
if MineField(x+1,y) <> 99
MineField(x+1,y) = MineField(x+1,y) + 1
endif
endif
if y > 1 and MineField(x,(y-1)) <> 99 then MineField(x,(y-1)) = MineField(x,(y-1)) + 1
if x+1 <= MFWidth and y > 1 and MineField((x+1),(y-1)) <> 99 then MineField((x+1),(y-1)) = MineField((x+1),(y-1)) + 1
if x > 1 and y > 1 and MineField((x-1),(y-1)) <> 99 then MineField((x-1),(y-1)) = MineField((x-1),(y-1)) + 1
if y+1 <= MFHeight
if MineField(x,(y+1)) <> 99
MineField(x,(y+1)) = MineField(x,(y+1)) + 1
endif
endif
if x > 1 and y+1 <= MFHeight
if MineField((x-1),(y+1)) <> 99
MineField((x-1),(y+1)) = MineField((x-1),(y+1)) + 1
endif
endif
if x+1 <= MFWidth and y+1 <= MFHeight
if MineField((x+1),(y+1)) <> 99
MineField((x+1),(y+1)) = MineField((x+1),(y+1)) + 1
endif
endif
endif
next y
next x
`Display 'ground' over mines
for y = 1 to MFHeight
for x = 1 to MFWidth
`Variables used to center the play area
startX = (640 / 2) - ((MFwidth * 25)/2)
startY = (480 / 2) - ((MFheight * 25)/2)
`Covers the board with the purple graphic that is removed by clicking on it
sprite ((y - 1) * MFwidth + x) + 500, (x * 25) + startX - 25, (y * 25) + startY - 25, 16
next x
next y
`Create background and display initial starting score
ink rgb(180,180,180), rgb(0,0,0)
box 1,1,639,479
ink rgb(0,100,255), rgb(180,180,180)
DisplayScore(Score, MFWidth, MFHeight, MFMines)
return : `End of MField gosub (draw and setup minefield)
end
`-------------------------------------------------------------------------------------- F U N C T I O N S
`mouse button 1
function Mouse1( x, y, MFWidth, MFHeight, MFMines, startX, startY, Score)
if mousex() > ((x-1)*25)+startX and mousex() < (x*25)+startX and mousey() > ((y-1)*25)+startY and mousey() < (y*25)+startY
`If not a mine then do this stuff
`display x,y locations on screen
`text 90, 60, "X = " + str$(x) + " "
`text 150,60, "Y =" + str$(y) + " "
`To Do: Auto display all open squares in field if open square selected by player is part of field
` Display other numbered squares directly adjacent to that '0' field
` Add to score for all squares displayed.
`Picks a loser
if MineField(x,y) = 99
DisplayArray(x, y, MFWidth, MFHeight)
Die()
endif
if MineField(x,y) <> 99
`Score handling
if MineField(x,y) <> -1
ScoreTrack(Score) = ScoreTrack(Score) + 1
DisplayArray(x, y, MFWidth, MFHeight)
endif
`Value used later to prevent adding to score more than once for clicking on an exposed tile
MineField(x,y) = -1
`Picks a winner
if ScoreTrack(Score) >0 and ScoreTrack(Score) = (MFWidth * MFHeight) - MFMines
AWinner()
endif
endif
endif
if mousex() > (380) and mousex() < (640) and mousey() > (0) and mousey() < (40)
HelpScreen()
endif
endfunction Score
`mouse button 2
function Mouse2( x, y, MFWidth, MFHeight, MFMines, startX, startY)
`To Do: Make this flagging function so you can't flag or ? a square already exposed
`Flag - Right click
if mousex() > ((x-1)*25)+startX and mousex() < (x*25)+startX and mousey() > ((y-1)*25)+startY and mousey() < (y*25)+startY
sprite (y - 1) * MFwidth + x, (x * 25) + startX - 25, (y * 25)+ startY - 25, 12
endif
endfunction
`mouse button 3
function Mouse3( x, y, MFWidth, MFHeight, MFMines, startX, startY)
`? - left & right button pressed
if mousex() > ((x-1)*25)+startX and mousex() < (x*25)+startX and mousey() > ((y-1)*25)+startY and mousey() < (y*25)+startY
sprite (y - 1) * MFwidth + x, (x * 25) + startX - 25, (y * 25)+ startY - 25, 14
endif
endfunction
`Display minefield under purple squares
function DisplayArray(x, y, MFWidth, MFHeight)
`Variables used to center display
startX = (640 / 2) - ((MFwidth * 25)/2)
startY = (480 / 2) - ((MFheight * 25)/2)
`Place mine graphics on screen
If MineField(x,y) = 99 then sprite (y - 1) * MFwidth + x, (x * 25) + startX - 25, (y * 25)+ startY - 25, 9
`Place blank square graphics on board
If MineField(x,y) = 0 then sprite (y - 1) * MFwidth + x, (x*25) + startX - 25, (y * 25) + startY - 25, 10
`Place square graphics with numbers on board
For t = 1 to 8
If MineField(x,y) = t then sprite (y - 1) * MFwidth + x, (x*25) + startX- 25,(y*25) + startY - 25, t
next t
endfunction
`Display the Score
function DisplayScore(Score, MFWidth, MFHeight, MFMines)
set text size 20
text 90, 20, "Score: " + str$(ScoreTrack(Score))
text 90, 40, "Left to clear: " + str$(((MFWidth * MFHeight) - MFMines) - ScoreTrack(Score)) + " "
text 400, 20, "Click for instructions"
set text size 14
endfunction Score
`Help Text - Click to view
function HelpScreen()
set text size 16
center text 320, 380, "To Play: Click on any square to start. If you are very unlucky and click on a mine the first time, you die."
center text 320, 400, "Hopefully you don't. Each square you expose will either be blank or have a number on it. A blank square means"
center text 320, 420, "no mines are adjacent to it. A numbered square indicates the number of adjacent mines. If you 'clear' the board"
center text 320, 440, "without clicking on a mine, you win. You can right click a square to flag what you know is a mine or click"
center text 320, 460, "both buttons together to flag with a question mark."
set text size 14
endfunction
`Declare a Winner
function AWinner()
ink rgb(0,255,0), rgb(255,255,225)
set text size 22
center text 320, 80, "Congrats-You Win!"
end
endfunction
`Declare a Loser after Done = 1 and ends the repeat loop
function Die()
ink rgb(255,0,0), rgb(255,255,255)
set text size 22
center text 320, 80, "BOOM-You Die!"
end
endfunction