Author Topic: Pointer For NASA World Map  (Read 3878 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Pointer For NASA World Map
« on: October 30, 2020, 02:28:03 am »
I figured out how to use the background scrolling method on a picture and it works really good! I added mouse support and WASD keys as well as the arrow keys. Included is a NASA world topography map that I found on a NASA website tonight. I shrunk the map down a bit so it wouldn't be too large. Notice there's a white dot pointer as well as the mouse pointer. I almost deleted the white dot but I thought why not, it just adds another pointer and using the keyboard keys the map moves slower and more precise than the mouse. I had to keep the mouse at a fast speed so people won't keep having to take the mouse off the screen and start on the other side of the screen to keep scrolling it. In most situations you can keep the mouse on the screen the entire time this way. Tell me what you think, thanks. But imagine now the games and programs we can make with background pictures made using a graphics program or even a camera. :)
The zip file is attached below.


* World Map by SierraKen and NASA.zip (Filesize: 4.39 MB, Downloads: 220)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Pointer For NASA World Map
« Reply #1 on: October 31, 2020, 12:32:50 pm »
Never ceases to amaze me how far North Europe is in comparison to US!

Yeah, I get dizzy moving map with mouse and glad you left the arrow keys in but even they need some fine tuning so you can pin point a  spot.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Pointer For NASA World Map
« Reply #2 on: October 31, 2020, 01:35:28 pm »
Thanks B+. I just fine-tuned it a little better. The mouse doesn't move as fast I believe and the arrow keys and WASD keys move more specifically. Here is just the code below. The map is in the .zip file above.

Code: QB64: [Select]
  1. s& = _NEWIMAGE(800, 600, 32)
  2. SCREEN _NEWIMAGE(800, 600, 32)
  3. TYPE object
  4.     x AS SINGLE
  5.     y AS SINGLE
  6.  
  7. DIM SHARED player AS object
  8. DIM SHARED camera AS object
  9. DIM playerSpeed AS SINGLE
  10.  
  11. map = _LOADIMAGE("worldtopoNASA6000x3000.jpg", 32)
  12.  
  13. xx = _WIDTH(map)
  14. yy = _HEIGHT(map)
  15.  
  16. player.x = _WIDTH / 2
  17. player.y = _HEIGHT / 2
  18.  
  19. playerSpeed = 1
  20.  
  21. CONST keyUP = 18432
  22. CONST keyDOWN = 20480
  23. CONST keyLEFT = 19200
  24. CONST keyRIGHT = 19712
  25. CONST KeyUp2 = 119
  26. CONST KeyDown2 = 115
  27. CONST KeyLeft2 = 97
  28. CONST KeyRight2 = 100
  29. CONST KeyEsc = 27
  30.  
  31. _TITLE "The World - Using NASA Topography Map - Use Mouse, Arrow Keys or WASD Keys."
  32.     mouseWheel = 0
  33.         mouseX = _MOUSEX
  34.         mouseY = _MOUSEY
  35.         mouseLeftButton = _MOUSEBUTTON(1)
  36.         mouseRightButton = _MOUSEBUTTON(2)
  37.         mouseMiddleButton = _MOUSEBUTTON(3)
  38.         mouseWheel = mouseWheel + _MOUSEWHEEL
  39.     LOOP
  40.     IF mouseX > oldmousex THEN player.x = player.x + (playerSpeed * 8)
  41.     IF mouseX < oldmousex THEN player.x = player.x - (playerSpeed * 8)
  42.     IF mouseY > oldmousey THEN player.y = player.y + (playerSpeed * 5)
  43.     IF mouseY < oldmousey THEN player.y = player.y - (playerSpeed * 5)
  44.  
  45.     oldmousex = mouseX
  46.     oldmousey = mouseY
  47.  
  48.     IF _KEYDOWN(keyUP) OR _KEYDOWN(KeyUp2) THEN player.y = player.y - playerSpeed
  49.     IF _KEYDOWN(keyDOWN) OR _KEYDOWN(KeyDown2) THEN player.y = player.y + playerSpeed
  50.     IF _KEYDOWN(keyLEFT) OR _KEYDOWN(KeyLeft2) THEN player.x = player.x - playerSpeed
  51.     IF _KEYDOWN(keyRIGHT) OR _KEYDOWN(KeyRight2) THEN player.x = player.x + playerSpeed
  52.  
  53.  
  54.     IF player.x < 0 THEN player.x = 0
  55.     IF player.x > _WIDTH(map) THEN player.x = _WIDTH(map)
  56.     IF player.y < 0 THEN player.y = 0
  57.     IF player.y > _HEIGHT(map) THEN player.y = _HEIGHT(map)
  58.  
  59.     adjustCamera
  60.     CLS
  61.     _PUTIMAGE (camera.x, camera.y), map
  62.  
  63.     FOR sz = .25 TO 5 STEP .25
  64.         CIRCLE (player.x + camera.x, player.y + camera.y), sz, _RGB32(255)
  65.     NEXT sz
  66.  
  67.     _DISPLAY
  68.     _LIMIT 500
  69.  
  70.  
  71. SUB adjustCamera
  72.     IF player.x + camera.x > _WIDTH / 2 OR player.x + camera.x < _WIDTH / 2 THEN
  73.         camera.x = _WIDTH / 2 - player.x
  74.     END IF
  75.     IF camera.x > 0 THEN camera.x = 0
  76.     IF camera.x < -(_WIDTH(map) - _WIDTH) THEN camera.x = -(_WIDTH(map) - _WIDTH)
  77.  
  78.     IF player.y + camera.y > _HEIGHT / 2 OR player.y + camera.y < _HEIGHT / 2 THEN
  79.         camera.y = _HEIGHT / 2 - player.y
  80.     END IF
  81.     IF camera.y > 0 THEN camera.y = 0
  82.     IF camera.y < -(_HEIGHT(map) - _HEIGHT) THEN camera.y = -(_HEIGHT(map) - _HEIGHT)
  83.  

Offline mynameispaul

  • Newbie
  • Posts: 49
    • View Profile
Re: Pointer For NASA World Map
« Reply #3 on: October 31, 2020, 02:04:04 pm »
that's pretty cool.
i like that.
opens up programming possibilities.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Pointer For NASA World Map
« Reply #4 on: October 31, 2020, 08:43:00 pm »
that's pretty cool.
i like that.
opens up programming possibilities.

Yes did you see Fellippe's from which this was taken? He did a video demo on set up.
https://www.qb64.org/forum/index.php?topic=3139.msg124093#msg124093
Ken's Gold game inspired by that too!

A zoom in and zoom out with mouse wheel would be most excellent here.
« Last Edit: October 31, 2020, 08:54:23 pm by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Pointer For NASA World Map
« Reply #5 on: October 31, 2020, 09:09:43 pm »
I tried to do zoom but it would only work with what is on the screen, not the part that's not on the screen. I was probably doing something wrong. But my efforts on that have been erased. Anyone is free to mess around with this code too.