Map Explorer - SierraKen - 08-10-2022
Today I wanted to make something I haven't made in awhile, a moving background map while you move your guy around. Except this time I wanted to see if I could do it without an already-made graphic file to use it with. So I figured out how to randomly generate a 3000 x 3000 graphic and save the file as a BMP picture file, which after loading and calculating, it deletes the 30 mb file (or so) that it makes. Feel free to add your own graphics to it. I added a lot of comments in the code. It was Felippe that originally posted how to make something like this probably around a year ago or 2. But I haven't seen much use of it. I used it with my Cave Fighter game awhile back, using the already made picture file. This one shows how to make each game or app have a randomly generated map each time you make it so it's different every time. This map generates random sized houses in different locations and round rocks. That's all I have for it so far so I might create a game with it or something later on. Feel free to do what you wish with it of course. Oh, I also made the guy move his arms and legs as he walks and he walks using the arrow keys. This isn't a game since there's nothing to achieve, but it's an example of how to make this. So when you are done just press Esc or the X.
Also, it would probably be best to put this in its own folder since it generates the explorer-map.bmp file and it automatically deletes it after it's done loading it. I got the BMP saving code from the Wiki pages and I added a couple of modification lines to it to show the timer in the Title Bar on how long it will take to finish loading (calculating) it before you can use it.
Note: I just noticed that it uses around 378 MB of RAM, just so you know.
Enjoy!
(Code deleted: Much better code a few pages from this post, without the extra .bmp file or loading time and much less memory RAM.)
RE: Map Explorer - mdijkens - 08-10-2022
Nice work.
Some remarks:
1.
It's not clear to me why you save to a BPM, then load the BMP and then delete the BMP again?
If you remark SaveImage, _LoadImage and Cls and change map to map2& it's way quicker
2.
Take care to _FreeImage after use (_FreeImage map2& after save)
3.
In your build & save loops use $checking:off|on once it works
RE: Map Explorer - Petr - 08-10-2022
Hi Sierra Ken. I took the liberty of modifying your program so that you don't have to save or delete anything from your hard drive. The reason why the graphics are generated so slowly is the use of the slow PAINT command and also the small step in some loops. Just an information, the same thing as DEL does the KILL command, so you don't need to use SHELL (it's not needed at all in the mentioned modification anyway).
Code: (Select All) 'Scrolling Map Example by SierraKen - August 9, 2022
Cls
Print " Random Large Map Maker"
Print: Print
Print " by SierraKen"
Print: Print
Print "This will create a large explorer-map.bmp file (currently around 30 mb in size)."
Print "After it loads the randomly made map picture, it will delete it off your"
Print "computer. Then you can use the arrow keys to walk around the map."
Print
Print "This is just an example to make something with a moving background."
Print "At first it will show a very large map graphic, just wait until around"
Print "20 seconds when it finishes the loading and calculation."
Print "The countdown timer will be in the topic bar above."
Print
Print "Currently the map only has randomly placed houses, but feel free to add anything"
Print "you wish. I placed notes in the QB64 code."
Print: Print
Input "Press Enter to start."; a$
Cls
Randomize Timer
Type object
x As Single
y As Single
End Type
Const keyUP = 18432
Const keyDOWN = 20480
Const keyLEFT = 19200
Const keyRIGHT = 19712
Const Esc = 27
Dim Shared player As object
Dim Shared camera As object
Dim Shared map As Long
Dim Shared map2 As Long
Dim playerSpeed As Single
Dim housex(30)
Dim housey(30)
Dim rx(250)
Dim ry(250)
start:
_Limit 2000
playerSpeed = 5
'------------------------------------------------------------------------------------------------------------
'Creates large "explorer-map.bmp" file to work off of. It will delete it after it is done loading and calculating.
'The Title Bar will show you how long of time it will take to load and calculate, which is around 20 seconds.
map2& = _NewImage(3000, 3000, 32)
'Screen map2&
_Dest map2&
_Source map2&
'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'Feel free to add any graphics between these 2 lines:
For h = 1 To 30
' _Limit 2000
again:
housex(h) = Rnd * 2500
housey(h) = Rnd * 2500
For check = 0 To h - 1
' _Limit 2000
If housex(check) > housex(h) - 150 And housex(check) < housex(h) + 150 And housey(check) > housey(h) - 225 And housey(check) < housey(h) + 225 Then GoTo again:
Next check
housex2 = (Rnd * 100) + 50
housey2 = (Rnd * 100) + 50
Line (housex(h), housey(h))-(housex(h) + housex2, housey(h) + housey2), _RGB32(255, 255, 255), B
Paint (housex(h) + 5, housey(h) + 5), _RGB32(216, 127, 78), _RGB32(255, 255, 255)
For sz = .25 To (housex2 / 2) Step .1
Circle (housex(h) + (housex2 / 2), housey(h)), sz, _RGB32(255, 255, 255), 2 * _Pi, _Pi, 1
Next sz
tt = 0
Paint (housex(h) + 2, housey(h) - (housey2 / 2) + 2), _RGB32(216, 127, 78), _RGB32(255, 255, 255)
Line (housex(h) + (housex2 / 2) - 10, housey(h) + (housey2 - 20))-(housex(h) + (housex2 / 2) + 10, housey(h) + housey2), _RGB32(255, 255, 255), B
Next h
For r = 1 To 250
' _Limit 2000
again2:
rx(r) = Rnd * 3000
ry(r) = Rnd * 3000
For check = 0 To 30
' _Limit 2000
If housex(check) > rx(r) - 150 And housex(check) < rx(r) + 150 And housey(check) > ry(r) - 225 And housey(check) < ry(r) + 225 Then GoTo again2:
Next check
size = Rnd * 20
Circle (rx(r), ry(r)), size, _RGB32(255, 255, 255)
Next r
Paint (2999, 2999), _RGB32(127, 172, 127), _RGB32(255, 255, 255)
'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'SaveImage map2&, "explorer-map" 'The 20 second wait time is in the modified BMP SaveImage SUB.
'------------------------------------------------------------------------------------------------------------
'map2& = 0
'Cls
_Title "Map Explorer - by SierraKen"
Screen _NewImage(800, 600, 32)
player.x = _Width / 2
player.y = _Height / 2
'map = _LoadImage("explorer-map.bmp", 32)
'_Dest map
'_Dest 0
'_Source 0
'Shell _DontWait _Hide "DEL explorer-map.bmp" 'Deletes big "explorer-map.bmp" file that it creates first, which is around 30 MB.
' KILL statement can do the same as DEL
t = 1
Do
Cls
_PutImage (camera.x, camera.y), map2& 'upgraded
If _KeyDown(keyUP) Then player.y = player.y - playerSpeed: t = t + 1
If _KeyDown(keyDOWN) Then player.y = player.y + playerSpeed: t = t + 1
If _KeyDown(keyLEFT) Then player.x = player.x - playerSpeed: t = t + 1
If _KeyDown(keyRIGHT) Then player.x = player.x + playerSpeed: t = t + 1
If _KeyDown(Esc) Then
Screen 0
_FreeImage map2&
System
End If
If player.x < 0 Then player.x = 0
If player.x > _Width(map) Then player.x = _Width(map)
If player.y < 0 Then player.y = 0
If player.y > _Height(map) Then player.y = _Height(map)
adjustCamera
'Draw Head
For sz = .25 To 10 Step .25
Circle (player.x + camera.x, player.y + camera.y), sz, _RGB32(255, 166, 127)
Next sz
'Draw Smile
Circle (player.x + camera.x, player.y + camera.y + 2), 7, _RGB32(255, 0, 0), _Pi, 2 * _Pi, .5
'Draw Eyes
Circle (player.x + camera.x - 4, player.y + camera.y - 2), 1, _RGB32(0, 0, 255)
Circle (player.x + camera.x + 4, player.y + camera.y - 2), 1, _RGB32(0, 0, 255)
'hat
Line (player.x + camera.x - 10, player.y + camera.y - 10)-(player.x + camera.x + 10, player.y + camera.y - 9), _RGB32(155, 0, 0), BF
Line (player.x + camera.x - 5, player.y + camera.y - 9)-(player.x + camera.x + 5, player.y + camera.y - 15), _RGB32(155, 0, 0), BF
'Body
Line (player.x + camera.x - 10, player.y + camera.y + 10)-(player.x + camera.x + 10, player.y + camera.y + 40), _RGB32(155, 0, 0), BF
If t > 12 Then t = 1
If t > 0 And t < 6 Then
'Left Arm
For wid2 = .1 To 3 Step .1
Line (player.x + camera.x - 10 - wid2, player.y + camera.y + 10)-(player.x + camera.x - 20 - wid2, player.y + camera.y + 30), _RGB32(255, 166, 127)
Next wid2
'Right Arm
For wid1 = .1 To 3 Step .1
Line (player.x + camera.x + 10 + wid1, player.y + camera.y + 10)-(player.x + camera.x + 20 + wid1, player.y + camera.y + 30), _RGB32(255, 166, 127)
Next wid1
'Left leg
For wid2 = .1 To 3 Step .1
Line (player.x + camera.x - 10 + wid2, player.y + camera.y + 40)-(player.x + camera.x - 10 + wid2, player.y + camera.y + 60), _RGB32(255, 166, 127)
Next wid2
'Right leg
For wid1 = .1 To 3 Step .1
Line (player.x + camera.x + 10 - wid1, player.y + camera.y + 40)-(player.x + camera.x + 10 - wid1, player.y + camera.y + 60), _RGB32(255, 166, 127)
Next wid1
End If
If t > 5 And t < 13 Then
'Left Arm
For wid2 = .1 To 3 Step .1
Line (player.x + camera.x - 10 - wid2, player.y + camera.y + 10)-(player.x + camera.x - 30 - wid2, player.y + camera.y + 30), _RGB32(255, 166, 127)
Next wid2
'Right Arm
For wid1 = .1 To 3 Step .1
Line (player.x + camera.x + 10 + wid1, player.y + camera.y + 10)-(player.x + camera.x + 30 + wid1, player.y + camera.y + 30), _RGB32(255, 166, 127)
Next wid1
'Left leg
For wid2 = .1 To 3 Step .1
Line (player.x + camera.x - 10 + wid2, player.y + camera.y + 40)-(player.x + camera.x - 15 + wid2, player.y + camera.y + 60), _RGB32(255, 166, 127)
Next wid2
'Right leg
For wid1 = .1 To 3 Step .1
Line (player.x + camera.x + 10 - wid1, player.y + camera.y + 40)-(player.x + camera.x + 15 - wid1, player.y + camera.y + 60), _RGB32(255, 166, 127)
Next wid1
End If
_Display
_Limit 60
Loop
Sub adjustCamera
If player.x + camera.x > _Width / 2 Or player.x + camera.x < _Width / 2 Then
camera.x = _Width / 2 - player.x
End If
If camera.x > 0 Then camera.x = 0
If camera.x < -(_Width(map2&) - _Width) Then camera.x = -(_Width(map2&) - _Width)
If player.y + camera.y > _Height / 2 Or player.y + camera.y < _Height / 2 Then
camera.y = _Height / 2 - player.y
End If
If camera.y > 0 Then camera.y = 0
If camera.y < -(_Height(map2&) - _Height) Then camera.y = -(_Height(map2&) - _Height)
End Sub
' next is not need
Sub SaveImage (image As Long, filename As String)
bytesperpixel& = _PixelSize(image&)
If bytesperpixel& = 0 Then Print "Text modes unsupported!": End
If bytesperpixel& = 1 Then bpp& = 8 Else bpp& = 24
x& = _Width(image&)
y& = _Height(image&)
b$ = "BM????QB64????" + MKL$(40) + MKL$(x&) + MKL$(y&) + MKI$(1) + MKI$(bpp&) + MKL$(0) + "????" + String$(16, 0) 'partial BMP header info(???? to be filled later)
If bytesperpixel& = 1 Then
For c& = 0 To 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
cv& = _PaletteColor(c&, image&) ' color attribute to read.
b$ = b$ + Chr$(_Blue32(cv&)) + Chr$(_Green32(cv&)) + Chr$(_Red32(cv&)) + Chr$(0) 'spacer byte
Next
End If
Mid$(b$, 11, 4) = MKL$(Len(b$)) ' image pixel data offset(BMP header)
lastsource& = _Source
_Source image&
If ((x& * 3) Mod 4) Then padder$ = String$(4 - ((x& * 3) Mod 4), 0)
timeleft = 3000 'Mod by SierraKen
For py& = y& - 1 To 0 Step -1 ' read JPG image pixel color data
r$ = ""
timeleft = timeleft - 1 'Mod by SierraKen for giant map maker.
timeleft2 = timeleft / 100 'Mod by SierraKen to make an easier countdown in the topic bar.
_Title "Calculating Map Time Left: " + Str$(timeleft2) 'Mod by SierraKen for giant map maker.
For px& = 0 To x& - 1
c& = Point(px&, py&) 'POINT 32 bit values are large LONG values
If bytesperpixel& = 1 Then r$ = r$ + Chr$(c&) Else r$ = r$ + Left$(MKL$(c&), 3)
Next px&
d$ = d$ + r$ + padder$
Next py&
_Source lastsource&
Mid$(b$, 35, 4) = MKL$(Len(d$)) ' image size(BMP header)
b$ = b$ + d$ ' total file data bytes to create file
Mid$(b$, 3, 4) = MKL$(Len(b$)) ' size of data file(BMP header)
If LCase$(Right$(filename$, 4)) <> ".bmp" Then ext$ = ".bmp"
f& = FreeFile
Open filename$ + ext$ For Output As #f&: Close #f& ' erases an existing file
Open filename$ + ext$ For Binary As #f&
Put #f&, , b$
Close #f&
End Sub
RE: Map Explorer - James D Jarvis - 08-10-2022
I have to agree I have no idea why you create and delete the BMP unless you have other plans for the sub that aren't used here in this program.
_freeimage doesn't matter unless you want to free up ram because Map2& will not be called later in the program, as it will be cleaned up when the program ends as it was created in the main module.
RE: Map Explorer - James D Jarvis - 08-10-2022
I like in-program generated graphics.
I fiddled with it for a couple seconds and changed the key handling code in the navigation to only use one call to _keyhit to handle the direction moved instead of 4 calls to _keydown. Not sure if it saves many (if any) cycles but it structures things to make room for collision testing later if you want to add any and it eliminates the need for if then's that don't relate to user input.
Code: (Select All) kd = _KeyHit
Select Case kd
Case keyUP
player.y = player.y - playerSpeed: t = t + 1
If player.y < 0 Then player.y = 0
Case keyDOWN
player.y = player.y + playerSpeed: t = t + 1
If player.y > _Height(map) Then player.y = _Height(map)
Case keyLEFT
player.x = player.x - playerSpeed: t = t + 1
If player.x < 0 Then player.x = 0
Case keyRIGHT
player.x = player.x + playerSpeed: t = t + 1
If player.y > _Height(map) Then player.y = _Height(map)
Case Esc
End
End Select
RE: Map Explorer - SierraKen - 08-10-2022
Petr, yours doesn't work. The guy only moves to the 800 x 600 area and then it stops. Remember, this is a giant 3000 x 3000 map, not a small one. And the map moves while you press the arrow keys. This is why I did make the BMP, because I tried all this already and the only way I could do it is with the BMP image. There still might be a way for someone to make it without the BMP but I have no idea how.
RE: Map Explorer - SierraKen - 08-10-2022
James, I just tried your code. Even though it works a bit differently, I don't like how the man moves a fraction of a distance, then stops, then moves again, when you just press and hold down the arrow key, so I left it how it was.
RE: Map Explorer - SierraKen - 08-10-2022
I was going add the _FREEIMAGE (map2&) command this morning so I just did that. It brings the RAM down to 339 MB or so. Thanks guys for telling me to do that. I also removed some LIMIT 2000's like you said Petr, thanks.
(Code deleted: Much better code a few pages from this post, without the extra .bmp file or loading time and much less memory RAM.)
RE: Map Explorer - Petr - 08-10-2022
This now work correctly. I forgot on rows 140 - 143 replacing map as map2& variables. Also FullScreen to row 111 is added.
Code: (Select All) 'Scrolling Map Example by SierraKen - August 9, 2022
Cls
Print " Random Large Map Maker"
Print: Print
Print " by SierraKen"
Print: Print
Print "This will create a large explorer-map.bmp file (currently around 30 mb in size)."
Print "After it loads the randomly made map picture, it will delete it off your"
Print "computer. Then you can use the arrow keys to walk around the map."
Print
Print "This is just an example to make something with a moving background."
Print "At first it will show a very large map graphic, just wait until around"
Print "20 seconds when it finishes the loading and calculation."
Print "The countdown timer will be in the topic bar above."
Print
Print "Currently the map only has randomly placed houses, but feel free to add anything"
Print "you wish. I placed notes in the QB64 code."
Print: Print
Input "Press Enter to start."; a$
Cls
Randomize Timer
Type object
x As Single
y As Single
End Type
Const keyUP = 18432
Const keyDOWN = 20480
Const keyLEFT = 19200
Const keyRIGHT = 19712
Const Esc = 27
Dim Shared player As object
Dim Shared camera As object
Dim Shared map As Long
Dim Shared map2 As Long
Dim playerSpeed As Single
Dim housex(30)
Dim housey(30)
Dim rx(250)
Dim ry(250)
start:
_Limit 2000
playerSpeed = 5
'------------------------------------------------------------------------------------------------------------
'Creates large "explorer-map.bmp" file to work off of. It will delete it after it is done loading and calculating.
'The Title Bar will show you how long of time it will take to load and calculate, which is around 20 seconds.
map2& = _NewImage(3000, 3000, 32)
'Screen map2&
_Dest map2&
_Source map2&
'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'Feel free to add any graphics between these 2 lines:
For h = 1 To 30
' _Limit 2000
again:
housex(h) = Rnd * 2500
housey(h) = Rnd * 2500
For check = 0 To h - 1
' _Limit 2000
If housex(check) > housex(h) - 150 And housex(check) < housex(h) + 150 And housey(check) > housey(h) - 225 And housey(check) < housey(h) + 225 Then GoTo again:
Next check
housex2 = (Rnd * 100) + 50
housey2 = (Rnd * 100) + 50
Line (housex(h), housey(h))-(housex(h) + housex2, housey(h) + housey2), _RGB32(255, 255, 255), B
Paint (housex(h) + 5, housey(h) + 5), _RGB32(216, 127, 78), _RGB32(255, 255, 255)
For sz = .25 To (housex2 / 2) Step .1
Circle (housex(h) + (housex2 / 2), housey(h)), sz, _RGB32(255, 255, 255), 2 * _Pi, _Pi, 1
Next sz
tt = 0
Paint (housex(h) + 2, housey(h) - (housey2 / 2) + 2), _RGB32(216, 127, 78), _RGB32(255, 255, 255)
Line (housex(h) + (housex2 / 2) - 10, housey(h) + (housey2 - 20))-(housex(h) + (housex2 / 2) + 10, housey(h) + housey2), _RGB32(255, 255, 255), B
Next h
For r = 1 To 250
' _Limit 2000
again2:
rx(r) = Rnd * 3000
ry(r) = Rnd * 3000
For check = 0 To 30
' _Limit 2000
If housex(check) > rx(r) - 150 And housex(check) < rx(r) + 150 And housey(check) > ry(r) - 225 And housey(check) < ry(r) + 225 Then GoTo again2:
Next check
size = Rnd * 20
Circle (rx(r), ry(r)), size, _RGB32(255, 255, 255)
Next r
Paint (2999, 2999), _RGB32(127, 172, 127), _RGB32(255, 255, 255)
'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'SaveImage map2&, "explorer-map" 'The 20 second wait time is in the modified BMP SaveImage SUB.
'------------------------------------------------------------------------------------------------------------
'map2& = 0
'Cls
_Title "Map Explorer - by SierraKen"
Screen _NewImage(800, 600, 32)
_FullScreen 'upgrade
player.x = _Width / 2
player.y = _Height / 2
'map = _LoadImage("explorer-map.bmp", 32)
'_Dest map
'_Dest 0
'_Source 0
'Shell _DontWait _Hide "DEL explorer-map.bmp" 'Deletes big "explorer-map.bmp" file that it creates first, which is around 30 MB.
' KILL statement can do the same as DEL
t = 1
Do
Cls
_PutImage (camera.x, camera.y), map2& 'upgraded
If _KeyDown(keyUP) Then player.y = player.y - playerSpeed: t = t + 1
If _KeyDown(keyDOWN) Then player.y = player.y + playerSpeed: t = t + 1
If _KeyDown(keyLEFT) Then player.x = player.x - playerSpeed: t = t + 1
If _KeyDown(keyRIGHT) Then player.x = player.x + playerSpeed: t = t + 1
If _KeyDown(Esc) Then
Screen 0
_FreeImage map2&
System
End If
'here "map" replaced as "map2&"
If player.x < 0 Then player.x = 0
If player.x > _Width(map2&) Then player.x = _Width(map2&)
If player.y < 0 Then player.y = 0
If player.y > _Height(map2&) Then player.y = _Height(map2&)
adjustCamera
'Draw Head
For sz = .25 To 10 Step .25
Circle (player.x + camera.x, player.y + camera.y), sz, _RGB32(255, 166, 127)
Next sz
'Draw Smile
Circle (player.x + camera.x, player.y + camera.y + 2), 7, _RGB32(255, 0, 0), _Pi, 2 * _Pi, .5
'Draw Eyes
Circle (player.x + camera.x - 4, player.y + camera.y - 2), 1, _RGB32(0, 0, 255)
Circle (player.x + camera.x + 4, player.y + camera.y - 2), 1, _RGB32(0, 0, 255)
'hat
Line (player.x + camera.x - 10, player.y + camera.y - 10)-(player.x + camera.x + 10, player.y + camera.y - 9), _RGB32(155, 0, 0), BF
Line (player.x + camera.x - 5, player.y + camera.y - 9)-(player.x + camera.x + 5, player.y + camera.y - 15), _RGB32(155, 0, 0), BF
'Body
Line (player.x + camera.x - 10, player.y + camera.y + 10)-(player.x + camera.x + 10, player.y + camera.y + 40), _RGB32(155, 0, 0), BF
If t > 12 Then t = 1
If t > 0 And t < 6 Then
'Left Arm
For wid2 = .1 To 3 Step .1
Line (player.x + camera.x - 10 - wid2, player.y + camera.y + 10)-(player.x + camera.x - 20 - wid2, player.y + camera.y + 30), _RGB32(255, 166, 127)
Next wid2
'Right Arm
For wid1 = .1 To 3 Step .1
Line (player.x + camera.x + 10 + wid1, player.y + camera.y + 10)-(player.x + camera.x + 20 + wid1, player.y + camera.y + 30), _RGB32(255, 166, 127)
Next wid1
'Left leg
For wid2 = .1 To 3 Step .1
Line (player.x + camera.x - 10 + wid2, player.y + camera.y + 40)-(player.x + camera.x - 10 + wid2, player.y + camera.y + 60), _RGB32(255, 166, 127)
Next wid2
'Right leg
For wid1 = .1 To 3 Step .1
Line (player.x + camera.x + 10 - wid1, player.y + camera.y + 40)-(player.x + camera.x + 10 - wid1, player.y + camera.y + 60), _RGB32(255, 166, 127)
Next wid1
End If
If t > 5 And t < 13 Then
'Left Arm
For wid2 = .1 To 3 Step .1
Line (player.x + camera.x - 10 - wid2, player.y + camera.y + 10)-(player.x + camera.x - 30 - wid2, player.y + camera.y + 30), _RGB32(255, 166, 127)
Next wid2
'Right Arm
For wid1 = .1 To 3 Step .1
Line (player.x + camera.x + 10 + wid1, player.y + camera.y + 10)-(player.x + camera.x + 30 + wid1, player.y + camera.y + 30), _RGB32(255, 166, 127)
Next wid1
'Left leg
For wid2 = .1 To 3 Step .1
Line (player.x + camera.x - 10 + wid2, player.y + camera.y + 40)-(player.x + camera.x - 15 + wid2, player.y + camera.y + 60), _RGB32(255, 166, 127)
Next wid2
'Right leg
For wid1 = .1 To 3 Step .1
Line (player.x + camera.x + 10 - wid1, player.y + camera.y + 40)-(player.x + camera.x + 15 - wid1, player.y + camera.y + 60), _RGB32(255, 166, 127)
Next wid1
End If
_Display
_Limit 60
Loop
Sub adjustCamera
If player.x + camera.x > _Width / 2 Or player.x + camera.x < _Width / 2 Then
camera.x = _Width / 2 - player.x
End If
If camera.x > 0 Then camera.x = 0
If camera.x < -(_Width(map2&) - _Width) Then camera.x = -(_Width(map2&) - _Width)
If player.y + camera.y > _Height / 2 Or player.y + camera.y < _Height / 2 Then
camera.y = _Height / 2 - player.y
End If
If camera.y > 0 Then camera.y = 0
If camera.y < -(_Height(map2&) - _Height) Then camera.y = -(_Height(map2&) - _Height)
End Sub
RE: Map Explorer - SierraKen - 08-10-2022
Thanks Petr, but I just found out how to do it myself too! I totally forgot that I made something similar a year or 2 ago so I copied that code. I hope it's OK with you that I use my own code this time. It just feels good that I could do it. The map is also now 4000 x 4000 and makes no extra files. Plus the RAM memory is down to 109 mb.
(Code deleted, much better version a few pages from here.)
|