Author Topic: Basic map problem  (Read 2594 times)

0 Members and 1 Guest are viewing this topic.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Basic map problem
« on: April 09, 2021, 08:39:26 pm »
The program below is a simple tile map. Please excuse the crudity as it is just a concept.

I would appreciate some clarity. The program does not work as it should. I have run this example on both RCBasic and SDLBasic and it ran just fine.
I thought I would try to convert a tile map game to QB64 and went with this concept first.

Code: QB64: [Select]
  1. Screen _NewImage(640, 480, 32)
  2.  
  3. Dim map(20, 15)
  4.  
  5. Data 11111111111111111111
  6. Data 10000000000000000001
  7. Data 10000000000000000001
  8. Data 10000000000000000001
  9. Data 10000000000000000001
  10. Data 10000000000000000001
  11. Data 10000000000000000001
  12. Data 10000000000000000001
  13. Data 10000000000000000001
  14. Data 10000000000000000001
  15. Data 10000000000000000001
  16. Data 10000000000000000001
  17. Data 10022222222222222001
  18. Data 10222222222222222201
  19. Data 11111111111111111111
  20.  
  21.  
  22. For y = 0 To 14
  23.     Read z$
  24.     For x = 0 To 19
  25.         map(x, y) = Val(Mid$(z$, x, 1))
  26.         If map(x, y) = 1 Then
  27.             ink = _RGB32(255, 128, 0)
  28.         ElseIf map(x, y) = 2 Then
  29.             ink = _RGB32(255, 255, 0)
  30.         Else
  31.             ink = 0
  32.         End If
  33.         Line (x * 32, y * 32)-Step(32, 32), ink, BF
  34.     Next x
  35.  

As you can see, the first "block" of the x and y coords should start a 0,0 but somehow it doesn't.

Can someone run this in Windows? I'm hoping that it's not another "Linux thing"...

I am running on Linux Mint 20 using QB64 1.5 stable from git 3043116

Thank you

J

  [ You are not allowed to view this attachment ]  
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Basic map problem
« Reply #1 on: April 09, 2021, 08:49:01 pm »
Missed by 1, MID$ assumes a base 1 string not 0
Code: QB64: [Select]
  1. Screen _NewImage(640, 480, 32)
  2.  
  3. Dim map(20, 15) As Long
  4.  
  5. Data 11111111111111111111
  6. Data 10000000000000000001
  7. Data 10000000000000000001
  8. Data 10000000000000000001
  9. Data 10000000000000000001
  10. Data 10000000000000000001
  11. Data 10000000000000000001
  12. Data 10000000000000000001
  13. Data 10000000000000000001
  14. Data 10000000000000000001
  15. Data 10000000000000000001
  16. Data 10000000000000000001
  17. Data 10022222222222222001
  18. Data 10222222222222222201
  19. Data 11111111111111111111
  20.  
  21.  
  22. For y = 0 To 14
  23.     Read z$
  24.     For x = 0 To 19
  25.         map(x, y) = Val(Mid$(z$, x + 1, 1)) ' <  x+ 1
  26.         If map(x, y) = 1 Then
  27.             ink = _RGB32(255, 128, 0)
  28.         ElseIf map(x, y) = 2 Then
  29.             ink = _RGB32(255, 255, 0)
  30.         Else
  31.             ink = 0
  32.         End If
  33.         Line (x * 32, y * 32)-Step(32, 32), ink, BF
  34.     Next x
  35.  
  36.  
  37.  

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Basic map problem
« Reply #2 on: April 09, 2021, 10:06:26 pm »
I have no idea how I could have missed that one... There are none as blind as those that choose not to see....  Many thanks...

J
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Basic map problem
« Reply #3 on: April 10, 2021, 12:58:49 pm »
Well at least no loud slap heard around the world ;-))