dkl
Full Member
 
Posts: 234
|
Post by dkl on Apr 9, 2022 20:40:18 GMT -5
Good Morning/Evening
At present I am working on yet another Word Game! It a mixture of Word Search/Welder and is up and running.
I want to start adding levels. The grid is the same as other grids I have used in Wordle etc), but I want to be able to use different graphics for the letters on each level. I am hoping to have at least 8 levels.
I think the simplest way to do this is keep the letter/bmp names exactly the same and reference a new folder for the relevant level. Meaning all letters are named A.bmp/B.bmp etc. Then use
foldername$ = "L1$" to access letters foldername$ = "L2$" to access letters etc However, I am having trouble trying to access the new folder. At present everything is in the same folder, so I don't even need to use ".\" to direct the programme anywhere. I found that if I say the following.............
Dim Letr$(0,9) p$ = ".\L1\" '<<< add p$ loadbmp "A", "A.bmp" Letr$(0,1) = p$+"A.bmp"':print Letr$(0,1) '<<< add p$+
WindowWidth = 50 WindowHeight = 100 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
bmpbutton #gr.01, Letr$(0,1), [eh], UL, 10, 10 open f$ for Window as #gr wait
This works. However..................
It means I have to change Every reference to Letr$() and add 'p$+'. It also means that ALL references using left$/mid$/etc now have to be changed too. Unfortunately, I didn't anticipate this earlier. It should have been written in at the beginning!
Is there another way around this?
|
|
|
Post by tsh73 on Apr 10, 2022 2:07:04 GMT -5
(try to) do not change your working code. Change only loading code.
How long is to read single set of letters (for one level?) If it is bearable, load new set of letters on a start of new lovel in old data structures (make some visual clue if it takes some seconds - scrollbar, or gradually revealing new background) Probably need to UNLOADBMP first if it is not first level.
|
|
|
Post by Rod on Apr 10, 2022 2:07:49 GMT -5
If the graphics are in different sub directories of the game folder then it’s easy just use “l1\a.bmp” or “l2\a.bmp” if you start a new level you will need to loadbmp all letters. To use the new bmp with a button you will need to use the new path. So a single variable l$ say, specifying the current level “l1” for level one, should be prepended to all button code. Relatively easy to do with find replace in the ide.
|
|
|
Post by Walt Decker on Apr 11, 2022 8:31:50 GMT -5
Before loading bit maps for new level you should remove old bitmaps from memory to prevent potential memory overload.
|
|
dkl
Full Member
 
Posts: 234
|
Post by dkl on Apr 13, 2022 1:12:04 GMT -5
Thank you tsh73, Rod and Walt for your response. I hear what you are all saying but don't seem to be able to put it into practise Rod, I thought that what you have suggested was already being done in the code I posted above?
Here is a slight change
Dim Letr$(0,9) p$ = ".\L1\" '<<<---set directory [reload] loadbmp "A", p$ + "A.bmp" ' <<<-- directory/level prepended to all button code Letr$(0,1) = "A.bmp" ':print Letr$(0,1)
WindowWidth = 150 WindowHeight = 100 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2) button #gr.b, "Next level", [level],UL, 65, 10, 60, 25 '<<<-- added button to test unloadbmp bmpbutton #gr.01, p$ + Letr$(0,1), [eh], UL, 10, 10 ' <<<-- directory/level prepended to all button code open f$ for Window as #gr wait
[level] 'unloadbmp p$ + Letr$(0,1) '<<<-- get error '\.\L1\A.bmp' not found!! p$ = ".\L2\" close #gr goto [reload] I have never succeeded in getting unloadbmp to work on Any occassion I have ever used it. I have always got an error!
The code above works but I have to close the GUI and reopen it, but it only take 2 sec. A new grid of letters has to be opened as well. I did get it going in the full game too. However, I think it's tidier to keep the same graphics for the letters and alter the surrounding area to reflect the new level.
If you are able to tell me what I am doing wrong with UNLOADBMP, I'd really appreciate it.
|
|
|
Post by Rod on Apr 13, 2022 3:31:45 GMT -5
You have a few concepts wrong. First off is that Liberty "names" a bmp and often uses that to manipulate the bmp. So its called "A" no path no .ext
You can address the bmpbutton to change its bmp so no need to close the window.
Dim bmp$(0,9) bmp$(0,1)="A" p$ = ".\L1\" '<<<---set directory 'use literals to loadb bmp loadbmp "A", p$ + "A.bmp" '
WindowWidth = 150 WindowHeight = 100 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2) button #gr.b, "Next level", [level],UL, 65, 10, 60, 25 '<<<-- added button to test unloadbmp bmpbutton #gr.01, p$ + bmp$(0,1)+".bmp", [eh], UL, 10, 10 ' <<<-- directory/level prepended to all button code open f$ for Window as #gr wait
[level] 'use array$ to change bmp if p$ = ".\L2\" then p$=".\L1\"else p$=".\L2\" unloadbmp bmp$(0,1) loadbmp bmp$(0,1), p$ + bmp$(0,1)+".bmp" #gr.01,"bitmap "+bmp$(0,1) wait
|
|
|
Post by tsh73 on Apr 13, 2022 3:35:05 GMT -5
(IMHO)
From the help file:
LOADBMP "name", "filename.bmp" UNLOADBMP "name" "filename.bmp" - filename, could contain path "name" - like a variable name buf for bitmap. There should not be path in "name".
|
|
dkl
Full Member
 
Posts: 234
|
Post by dkl on Apr 13, 2022 5:13:37 GMT -5
Ah....that's a great help now I understand. Thank you. 
|
|
|
Post by Carl Gundel on Apr 13, 2022 7:39:00 GMT -5
(IMHO) From the help file: LOADBMP "name", "filename.bmp" UNLOADBMP "name" "filename.bmp" - filename, could contain path "name" - like a variable name buf for bitmap. There should not be path in "name". In Windows, Mac OS, etc. when you load a bitmap it give you a unique handle which is a number and you assign this to a variable. This numeric handle is managed behind the scenes in Liberty BASIC, and instead you give the bitmap a name in your program so that instead of dealing with numbers you can use a meaningful name, which is easier to deal with, or I think so anyway. 
|
|
|
Post by Walt Decker on Apr 13, 2022 9:02:11 GMT -5
TIP:
Place your load and unload code in callable modules. Example
DIM Lvl$(3, 1)
Lvl$(0, 0) = "BMPA" Lvl$(0, 1) = "A_.BMP) Lvl$(1, 0) = "BMPB" Lvl$(1, 1) = "B_.BMP) Lvl$(2, 0) = "BMPC" Lvl$(2, 1) = "C_.BMP)
Path$ = DefaultDir$ + "\Lvl_1"
FOR I = 0 TO 2 CALL GetBmpFromFile(Lvl$(I, 0), Path$, Lvl$(I, 1) NEXT I
...... DO STUFF
FOR I = 0 TO 2 CALL KillBmp(Lvl$(I, 0)) NEXT I
'-------------------------------------- '--------------------------------------
SUB GetBmpFromFile Tag$, Path$, Fname$ '################################################ 'Tag$, Path$, Fname$ are passed to this module 'by value so concatonating Path$ and Fname$ 'does not change the original Path$ value in the 'calling module '################################################ Path$ = Path$ + Fname$ LOADBMP Tag$, Path$
END SUB
'-------------------------------------- '--------------------------------------
SUB KillBmp Tag$
UNLOADBMP Tag$
END SUB
|
|