Author Topic: Find The Gold!  (Read 6573 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Find The Gold!
« on: October 23, 2020, 09:12:51 pm »
This is my first game made using Felippe's moving map camera code. Use your arrow keys to move your cowboy around the different land areas, trees, and lakes, to find the gold bars. If you find 20 of them you advance to the next level. Level 1 starts out with 300 seconds to finish and every level it decreases by 5 seconds. After level 20 you win the game. Instructions are in the Title bar and the game is paused when it loads and starts when you press any key and your cowboy appears on screen. You lose if your time runs out and you still have gold bars left to find on that level.
The maps on each level are randomly generated.

*NOTE: Don't use the code below, it has one error I accidentally made where you can't go past level 1 LOL. Scroll down to get the fixed code. Sorry about that!

Code: QB64: [Select]
  1. 'Find the Gold! by SierraKen
  2. 'October 23, 2020
  3. 'Thanks for the great mapping code by FellipeHeitor and help from B+!
  4. 'Additions: Body, Arms, and Legs. Levels and 20 gold per level. Larger land area sizes. Lakes and Trees. 20 Level limit.
  5.  
  6. SCREEN _NEWIMAGE(1000, 800, 32)
  7.  
  8. TYPE object
  9.     x AS SINGLE
  10.     y AS SINGLE
  11.  
  12. DIM SHARED player AS object
  13. DIM SHARED camera AS object
  14. DIM playerSpeed AS SINGLE
  15.  
  16. _TITLE "Find The Gold! Use the arrow keys to find 20 gold bars per level. Every level will have a shorter time. After Level 20 you win the game."
  17.  
  18. start:
  19. score = 0
  20. level = 1
  21. player.x = _WIDTH / 2
  22. player.y = _HEIGHT / 2
  23.  
  24. map = _NEWIMAGE(_WIDTH * 7, _HEIGHT * 7, 32)
  25.  
  26. _DEST map
  27. PAINT (2, 2), _RGB32(0, 200, 0)
  28.  
  29. 'Land Areas
  30. FOR blocks = 1 TO 400
  31.     blocks:
  32.     xx = (RND * _WIDTH)
  33.     yy = (RND * _HEIGHT)
  34.     sz = INT(RND * 300) + 50
  35.     blockcolors:
  36.     c1 = INT(RND * 155) + 100
  37.     c2 = INT(RND * 155) + 100
  38.     c3 = INT(RND * 155) + 100
  39.     IF c1 = 255 AND c2 = 255 AND c3 = 128 THEN GOTO blockcolors:
  40.     LINE (xx, yy)-(xx + sz, yy + sz), _RGB32(c1, c2, c3), BF
  41.     IF POINT(_WIDTH / 2, _HEIGHT / 2) = _RGB32(c1, c2, c3) THEN GOTO blocks:
  42.  
  43. 'Lakes
  44. FOR lakes = 1 TO 10
  45.     w = RND
  46.     h = RND
  47.     sze = (RND * 150) + 50
  48.     FOR sz = .25 TO sze STEP .25
  49.         CIRCLE (w * _WIDTH, h * _HEIGHT), sz, _RGB32(0, 0, 255)
  50.     NEXT sz
  51. NEXT lakes
  52.  
  53. 'Trees
  54. FOR trees = 1 TO 400
  55.     tx = RND
  56.     tx = tx * _WIDTH
  57.     ty = RND
  58.     ty = ty * _HEIGHT
  59.     tsz = (RND * 40) + 10
  60.     LINE (tx, ty)-(tx, ty + tsz + 5), _RGB32(188, 127, 127)
  61.     FOR branches = ty TO ty + tsz STEP 3
  62.         LINE (tx, branches)-(tx - 10, branches + 5), _RGB32(127, 255, 127)
  63.         LINE (tx, branches)-(tx + 10, branches + 5), _RGB32(127, 255, 127)
  64.     NEXT branches
  65. NEXT trees
  66.  
  67.  
  68. 'Place Gold
  69. FOR gold = 1 TO 20
  70.     w2 = INT(RND * _WIDTH) - 15
  71.     h2 = INT(RND * _HEIGHT) - 10
  72.     IF w2 < 15 THEN w2 = 15
  73.     IF h2 < 10 THEN h2 = 10
  74.  
  75.     'Gold
  76.     COLOR _RGB32(0, 0, 0), _RGB32(255, 255, 128)
  77.     _PRINTSTRING (w2, h2), "GOLD"
  78. NEXT gold
  79.  
  80.  
  81.  
  82. playerSpeed = 10
  83.  
  84. CONST keyUP = 18432
  85. CONST keyDOWN = 20480
  86. CONST keyLEFT = 19200
  87. CONST keyRIGHT = 19712
  88. CONST keyESC = 27
  89. _PUTIMAGE (camera.x, camera.y), map
  90.  
  91. LOCATE 10, 55: PRINT "Press Any Key To Begin."
  92.  
  93. pause:
  94. a$ = INKEY$
  95. IF a$ <> "" THEN GOTO begin:
  96. GOTO pause:
  97.  
  98. begin:
  99.  
  100. seconds = INT(TIMER)
  101.     CLS
  102.     leveltime = level * 5
  103.     gametime = (305 - leveltime) - (INT(TIMER) - seconds)
  104.     _PUTIMAGE (camera.x, camera.y), map
  105.     LOCATE 1, 1: PRINT "Time Left: "; gametime
  106.     IF gametime < 1 THEN GOTO done:
  107.     IF _KEYDOWN(keyUP) THEN
  108.         player.y = player.y - playerSpeed
  109.         t = t + 1
  110.     END IF
  111.     IF _KEYDOWN(keyDOWN) THEN
  112.         player.y = player.y + playerSpeed
  113.         t = t + 1
  114.     END IF
  115.     IF _KEYDOWN(keyLEFT) THEN
  116.         player.x = player.x - playerSpeed
  117.         t = t + 1
  118.     END IF
  119.     IF _KEYDOWN(keyRIGHT) THEN
  120.         player.x = player.x + playerSpeed
  121.         t = t + 1
  122.     END IF
  123.     IF _KEYDOWN(keyESC) THEN END
  124.     IF player.x < 0 THEN player.x = 0
  125.     IF player.x > _WIDTH(map) THEN player.x = _WIDTH(map)
  126.     IF player.y < 0 THEN player.y = 0
  127.     IF player.y > _HEIGHT(map) THEN player.y = _HEIGHT(map)
  128.  
  129.     adjustCamera
  130.  
  131.     'Draw Head
  132.     FOR sz = .25 TO 10 STEP .25
  133.         CIRCLE (player.x + camera.x, player.y + camera.y), sz, _RGB32(255, 166, 127)
  134.     NEXT sz
  135.     'Draw Smile
  136.     CIRCLE (player.x + camera.x, player.y + camera.y + 2), 7, _RGB32(255, 0, 0), _PI, 2 * _PI, .5
  137.     'Draw Eyes
  138.     CIRCLE (player.x + camera.x - 4, player.y + camera.y - 2), 1, _RGB32(0, 0, 255)
  139.     CIRCLE (player.x + camera.x + 4, player.y + camera.y - 2), 1, _RGB32(0, 0, 255)
  140.     'hat
  141.     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
  142.     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
  143.     'body
  144.     LINE (player.x + camera.x, player.y + camera.y + 10)-(player.x + camera.x, player.y + camera.y + 20), _RGB32(155, 0, 0)
  145.  
  146.     IF t > 7 THEN t = 0
  147.  
  148.     'rest of body
  149.     IF t = 0 THEN
  150.         'left arm
  151.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x - 15, player.y + camera.y + 25), _RGB32(155, 0, 0)
  152.         'right arm
  153.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x + 15, player.y + camera.y + 25), _RGB32(155, 0, 0)
  154.         'left leg
  155.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x - 15, player.y + camera.y + 35), _RGB32(155, 0, 0)
  156.         'right leg
  157.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x + 15, player.y + camera.y + 35), _RGB32(155, 0, 0)
  158.     END IF
  159.  
  160.     IF t = 1 OR t = 7 THEN
  161.         'left arm
  162.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x - 11, player.y + camera.y + 25), _RGB32(155, 0, 0)
  163.         'right arm
  164.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x + 11, player.y + camera.y + 25), _RGB32(155, 0, 0)
  165.         'left leg
  166.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x - 11, player.y + camera.y + 35), _RGB32(155, 0, 0)
  167.         'right leg
  168.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x + 11, player.y + camera.y + 35), _RGB32(155, 0, 0)
  169.     END IF
  170.  
  171.     IF t = 2 OR t = 6 THEN
  172.         'left arm
  173.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x - 9, player.y + camera.y + 24), _RGB32(155, 0, 0)
  174.         'right arm
  175.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x + 9, player.y + camera.y + 24), _RGB32(155, 0, 0)
  176.         'left leg
  177.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x - 9, player.y + camera.y + 35), _RGB32(155, 0, 0)
  178.         'right leg
  179.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x + 9, player.y + camera.y + 35), _RGB32(155, 0, 0)
  180.     END IF
  181.  
  182.     IF t = 3 OR t = 5 THEN
  183.         'left arm
  184.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x - 7, player.y + camera.y + 24), _RGB32(155, 0, 0)
  185.         'right arm
  186.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x + 7, player.y + camera.y + 24), _RGB32(155, 0, 0)
  187.         'left leg
  188.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x - 7, player.y + camera.y + 35), _RGB32(155, 0, 0)
  189.         'right leg
  190.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x + 7, player.y + camera.y + 35), _RGB32(155, 0, 0)
  191.     END IF
  192.  
  193.     IF t = 4 THEN
  194.         'left arm
  195.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x - 5, player.y + camera.y + 23), _RGB32(155, 0, 0)
  196.         'right arm
  197.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x + 5, player.y + camera.y + 23), _RGB32(155, 0, 0)
  198.         'left leg
  199.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x - 5, player.y + camera.y + 35), _RGB32(155, 0, 0)
  200.         'right leg
  201.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x + 5, player.y + camera.y + 35), _RGB32(155, 0, 0)
  202.     END IF
  203.  
  204.  
  205.     FOR check = -15 TO 15
  206.         IF POINT(player.x + check, player.y + check) = _RGB32(255, 255, 128) THEN
  207.             _DEST map
  208.             FOR sz = .2 TO 35 STEP .2
  209.                 CIRCLE (player.x + check, player.y + check), sz, _RGB32(127, 127, 127)
  210.             NEXT sz
  211.             GOSUB findgold:
  212.         END IF
  213.         IF POINT(player.x + check, player.y - check) = _RGB32(255, 255, 128) THEN
  214.             _DEST map
  215.             FOR sz = .2 TO 35 STEP .2
  216.                 CIRCLE (player.x + check, player.y - check), sz, _RGB32(127, 127, 127)
  217.             NEXT sz
  218.             GOSUB findgold:
  219.         END IF
  220.         IF POINT(player.x - check, player.y + check) = _RGB32(255, 255, 128) THEN
  221.             _DEST map
  222.             FOR sz = .2 TO 35 STEP .2
  223.                 CIRCLE (player.x - check, player.y + check), sz, _RGB32(127, 127, 127)
  224.             NEXT sz
  225.             GOSUB findgold:
  226.         END IF
  227.     NEXT check
  228.     _DISPLAY
  229.     _LIMIT 60
  230.  
  231. findgold:
  232. FOR snd = 800 TO 400 STEP -100
  233.     SOUND snd, .5
  234. NEXT snd
  235. score = score + 100
  236. score$ = STR$(score)
  237. level$ = STR$(level)
  238. _TITLE "Level: " + level$ + "   Score: " + score$
  239. IF score / 2000 = INT(score / 2000) THEN
  240.     level = level + 1
  241.     level$ = STR$(level)
  242.     _TITLE "Level: " + level$ + "   Score: " + score$
  243.     IF level = 21 THEN GOTO win:
  244.     GOTO start:
  245.  
  246. done:
  247. LOCATE 10, 55: PRINT "G A M E     O V E R"
  248. FOR snd = 450 TO 150 STEP -25
  249.     SOUND snd, .5
  250. NEXT snd
  251. LOCATE 13, 55: PRINT "Again (Y/N)?"
  252. ag:
  253. ag$ = INKEY$
  254. IF ag$ = "y" OR ag$ = "Y" THEN GOTO start:
  255. IF ag$ = "n" OR ag$ = "N" THEN END
  256. GOTO ag:
  257.  
  258. win:
  259. LOCATE 10, 55: PRINT "G A M E     W O N ! ! ! ! ! ! !"
  260. FOR snd = 450 TO 150 STEP -25
  261.     SOUND snd, .5
  262. NEXT snd
  263. LOCATE 13, 55: PRINT "Again (Y/N)?"
  264. ag2:
  265. ag$ = INKEY$
  266. IF ag$ = "y" OR ag$ = "Y" THEN GOTO start:
  267. IF ag$ = "n" OR ag$ = "N" THEN END
  268. GOTO ag2:
  269.  
  270. 'Thanks to FelippeHeitor for this Sub and the camera code above.
  271. SUB adjustCamera
  272.     IF player.x + camera.x > _WIDTH / 2 OR player.x + camera.x < _WIDTH / 2 THEN
  273.         camera.x = _WIDTH / 2 - player.x
  274.     END IF
  275.     IF camera.x > 0 THEN camera.x = 0
  276.     IF camera.x < -(_WIDTH(map) - _WIDTH) THEN camera.x = -(_WIDTH(map) - _WIDTH)
  277.  
  278.     IF player.y + camera.y > _HEIGHT / 2 OR player.y + camera.y < _HEIGHT / 2 THEN
  279.         camera.y = _HEIGHT / 2 - player.y
  280.     END IF
  281.     IF camera.y > 0 THEN camera.y = 0
  282.     IF camera.y < -(_HEIGHT(map) - _HEIGHT) THEN camera.y = -(_HEIGHT(map) - _HEIGHT)
  283.  


 
« Last Edit: October 23, 2020, 10:42:45 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Find The Gold!
« Reply #1 on: October 23, 2020, 09:17:21 pm »
If you want to learn more about the map and camera movement as well as another example Felippe did using online players with it,
go here: https://www.qb64.org/forum/index.php?topic=3139.0

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Find The Gold!
« Reply #2 on: October 23, 2020, 10:43:40 pm »
Here is the fixed code that lets you go past level 1. This is what happens when a couple weeks of not programming does, it gets me rusty. :) Sorry about that guys.

Code: QB64: [Select]
  1. 'Find the Gold! by SierraKen
  2. 'October 23, 2020
  3. 'Thanks for the great mapping code by FellipeHeitor and help from B+!
  4. 'Additions: Body, Arms, and Legs. Levels and 20 gold per level. Larger land area sizes. Lakes and Trees. 20 Level limit.
  5.  
  6.  
  7. SCREEN _NEWIMAGE(1000, 800, 32)
  8.  
  9. TYPE object
  10.     x AS SINGLE
  11.     y AS SINGLE
  12.  
  13. DIM SHARED player AS object
  14. DIM SHARED camera AS object
  15. DIM playerSpeed AS SINGLE
  16.  
  17. _TITLE "Find The Gold! Use the arrow keys to find 20 gold bars per level. Every level will have a shorter time. After Level 20 you win the game."
  18.  
  19. start:
  20. score = 0
  21. level = 1
  22.  
  23. start2:
  24. player.x = _WIDTH / 2
  25. player.y = _HEIGHT / 2
  26.  
  27. map = _NEWIMAGE(_WIDTH * 7, _HEIGHT * 7, 32)
  28.  
  29. _DEST map
  30. PAINT (2, 2), _RGB32(0, 200, 0)
  31.  
  32. 'Land Areas
  33. FOR blocks = 1 TO 400
  34.     blocks:
  35.     xx = (RND * _WIDTH)
  36.     yy = (RND * _HEIGHT)
  37.     sz = INT(RND * 300) + 50
  38.     blockcolors:
  39.     c1 = INT(RND * 155) + 100
  40.     c2 = INT(RND * 155) + 100
  41.     c3 = INT(RND * 155) + 100
  42.     IF c1 = 255 AND c2 = 255 AND c3 = 128 THEN GOTO blockcolors:
  43.     LINE (xx, yy)-(xx + sz, yy + sz), _RGB32(c1, c2, c3), BF
  44.     IF POINT(_WIDTH / 2, _HEIGHT / 2) = _RGB32(c1, c2, c3) THEN GOTO blocks:
  45.  
  46. 'Lakes
  47. FOR lakes = 1 TO 10
  48.     w = RND
  49.     h = RND
  50.     sze = (RND * 150) + 50
  51.     FOR sz = .25 TO sze STEP .25
  52.         CIRCLE (w * _WIDTH, h * _HEIGHT), sz, _RGB32(0, 0, 255)
  53.     NEXT sz
  54. NEXT lakes
  55.  
  56. 'Trees
  57. FOR trees = 1 TO 400
  58.     tx = RND
  59.     tx = tx * _WIDTH
  60.     ty = RND
  61.     ty = ty * _HEIGHT
  62.     tsz = (RND * 40) + 10
  63.     LINE (tx, ty)-(tx, ty + tsz + 5), _RGB32(188, 127, 127)
  64.     FOR branches = ty TO ty + tsz STEP 3
  65.         LINE (tx, branches)-(tx - 10, branches + 5), _RGB32(127, 255, 127)
  66.         LINE (tx, branches)-(tx + 10, branches + 5), _RGB32(127, 255, 127)
  67.     NEXT branches
  68. NEXT trees
  69.  
  70.  
  71. 'Place Gold
  72. FOR gold = 1 TO 20
  73.     w2 = INT(RND * _WIDTH) - 15
  74.     h2 = INT(RND * _HEIGHT) - 10
  75.     IF w2 < 15 THEN w2 = 15
  76.     IF h2 < 10 THEN h2 = 10
  77.  
  78.     'Gold
  79.     COLOR _RGB32(0, 0, 0), _RGB32(255, 255, 128)
  80.     _PRINTSTRING (w2, h2), "GOLD"
  81. NEXT gold
  82.  
  83.  
  84.  
  85. playerSpeed = 10
  86.  
  87. CONST keyUP = 18432
  88. CONST keyDOWN = 20480
  89. CONST keyLEFT = 19200
  90. CONST keyRIGHT = 19712
  91. CONST keyESC = 27
  92. _PUTIMAGE (camera.x, camera.y), map
  93.  
  94. LOCATE 10, 55: PRINT "Press Any Key To Begin."
  95.  
  96. pause:
  97. a$ = INKEY$
  98. IF a$ <> "" THEN GOTO begin:
  99. GOTO pause:
  100.  
  101. begin:
  102.  
  103. seconds = INT(TIMER)
  104.     CLS
  105.     leveltime = level * 5
  106.     gametime = (305 - leveltime) - (INT(TIMER) - seconds)
  107.     _PUTIMAGE (camera.x, camera.y), map
  108.     LOCATE 1, 1: PRINT "Time Left: "; gametime
  109.     IF gametime < 1 THEN GOTO done:
  110.     IF _KEYDOWN(keyUP) THEN
  111.         player.y = player.y - playerSpeed
  112.         t = t + 1
  113.     END IF
  114.     IF _KEYDOWN(keyDOWN) THEN
  115.         player.y = player.y + playerSpeed
  116.         t = t + 1
  117.     END IF
  118.     IF _KEYDOWN(keyLEFT) THEN
  119.         player.x = player.x - playerSpeed
  120.         t = t + 1
  121.     END IF
  122.     IF _KEYDOWN(keyRIGHT) THEN
  123.         player.x = player.x + playerSpeed
  124.         t = t + 1
  125.     END IF
  126.     IF _KEYDOWN(keyESC) THEN END
  127.     IF player.x < 0 THEN player.x = 0
  128.     IF player.x > _WIDTH(map) THEN player.x = _WIDTH(map)
  129.     IF player.y < 0 THEN player.y = 0
  130.     IF player.y > _HEIGHT(map) THEN player.y = _HEIGHT(map)
  131.  
  132.     adjustCamera
  133.  
  134.     'Draw Head
  135.     FOR sz = .25 TO 10 STEP .25
  136.         CIRCLE (player.x + camera.x, player.y + camera.y), sz, _RGB32(255, 166, 127)
  137.     NEXT sz
  138.     'Draw Smile
  139.     CIRCLE (player.x + camera.x, player.y + camera.y + 2), 7, _RGB32(255, 0, 0), _PI, 2 * _PI, .5
  140.     'Draw Eyes
  141.     CIRCLE (player.x + camera.x - 4, player.y + camera.y - 2), 1, _RGB32(0, 0, 255)
  142.     CIRCLE (player.x + camera.x + 4, player.y + camera.y - 2), 1, _RGB32(0, 0, 255)
  143.     'hat
  144.     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
  145.     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
  146.     'body
  147.     LINE (player.x + camera.x, player.y + camera.y + 10)-(player.x + camera.x, player.y + camera.y + 20), _RGB32(155, 0, 0)
  148.  
  149.     IF t > 7 THEN t = 0
  150.  
  151.     'rest of body
  152.     IF t = 0 THEN
  153.         'left arm
  154.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x - 15, player.y + camera.y + 25), _RGB32(155, 0, 0)
  155.         'right arm
  156.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x + 15, player.y + camera.y + 25), _RGB32(155, 0, 0)
  157.         'left leg
  158.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x - 15, player.y + camera.y + 35), _RGB32(155, 0, 0)
  159.         'right leg
  160.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x + 15, player.y + camera.y + 35), _RGB32(155, 0, 0)
  161.     END IF
  162.  
  163.     IF t = 1 OR t = 7 THEN
  164.         'left arm
  165.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x - 11, player.y + camera.y + 25), _RGB32(155, 0, 0)
  166.         'right arm
  167.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x + 11, player.y + camera.y + 25), _RGB32(155, 0, 0)
  168.         'left leg
  169.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x - 11, player.y + camera.y + 35), _RGB32(155, 0, 0)
  170.         'right leg
  171.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x + 11, player.y + camera.y + 35), _RGB32(155, 0, 0)
  172.     END IF
  173.  
  174.     IF t = 2 OR t = 6 THEN
  175.         'left arm
  176.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x - 9, player.y + camera.y + 24), _RGB32(155, 0, 0)
  177.         'right arm
  178.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x + 9, player.y + camera.y + 24), _RGB32(155, 0, 0)
  179.         'left leg
  180.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x - 9, player.y + camera.y + 35), _RGB32(155, 0, 0)
  181.         'right leg
  182.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x + 9, player.y + camera.y + 35), _RGB32(155, 0, 0)
  183.     END IF
  184.  
  185.     IF t = 3 OR t = 5 THEN
  186.         'left arm
  187.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x - 7, player.y + camera.y + 24), _RGB32(155, 0, 0)
  188.         'right arm
  189.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x + 7, player.y + camera.y + 24), _RGB32(155, 0, 0)
  190.         'left leg
  191.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x - 7, player.y + camera.y + 35), _RGB32(155, 0, 0)
  192.         'right leg
  193.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x + 7, player.y + camera.y + 35), _RGB32(155, 0, 0)
  194.     END IF
  195.  
  196.     IF t = 4 THEN
  197.         'left arm
  198.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x - 5, player.y + camera.y + 23), _RGB32(155, 0, 0)
  199.         'right arm
  200.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x + 5, player.y + camera.y + 23), _RGB32(155, 0, 0)
  201.         'left leg
  202.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x - 5, player.y + camera.y + 35), _RGB32(155, 0, 0)
  203.         'right leg
  204.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x + 5, player.y + camera.y + 35), _RGB32(155, 0, 0)
  205.     END IF
  206.  
  207.  
  208.     FOR check = -15 TO 15
  209.         IF POINT(player.x + check, player.y + check) = _RGB32(255, 255, 128) THEN
  210.             _DEST map
  211.             FOR sz = .2 TO 35 STEP .2
  212.                 CIRCLE (player.x + check, player.y + check), sz, _RGB32(127, 127, 127)
  213.             NEXT sz
  214.             GOSUB findgold:
  215.         END IF
  216.         IF POINT(player.x + check, player.y - check) = _RGB32(255, 255, 128) THEN
  217.             _DEST map
  218.             FOR sz = .2 TO 35 STEP .2
  219.                 CIRCLE (player.x + check, player.y - check), sz, _RGB32(127, 127, 127)
  220.             NEXT sz
  221.             GOSUB findgold:
  222.         END IF
  223.         IF POINT(player.x - check, player.y + check) = _RGB32(255, 255, 128) THEN
  224.             _DEST map
  225.             FOR sz = .2 TO 35 STEP .2
  226.                 CIRCLE (player.x - check, player.y + check), sz, _RGB32(127, 127, 127)
  227.             NEXT sz
  228.             GOSUB findgold:
  229.         END IF
  230.     NEXT check
  231.     _DISPLAY
  232.     _LIMIT 60
  233.  
  234. findgold:
  235. FOR snd = 800 TO 400 STEP -100
  236.     SOUND snd, .5
  237. NEXT snd
  238. score = score + 100
  239. score$ = STR$(score)
  240. level$ = STR$(level)
  241. _TITLE "Level: " + level$ + "   Score: " + score$
  242. IF score / 2000 = INT(score / 2000) THEN
  243.     level = level + 1
  244.     level$ = STR$(level)
  245.     _TITLE "Level: " + level$ + "   Score: " + score$
  246.     IF level = 21 THEN GOTO win:
  247.     GOTO start2:
  248.  
  249. done:
  250. LOCATE 10, 55: PRINT "G A M E     O V E R"
  251. FOR snd = 450 TO 150 STEP -25
  252.     SOUND snd, .5
  253. NEXT snd
  254. LOCATE 13, 55: PRINT "Again (Y/N)?"
  255. ag:
  256. ag$ = INKEY$
  257. IF ag$ = "y" OR ag$ = "Y" THEN GOTO start:
  258. IF ag$ = "n" OR ag$ = "N" THEN END
  259. GOTO ag:
  260.  
  261. win:
  262. LOCATE 10, 55: PRINT "G A M E     W O N ! ! ! ! ! ! !"
  263. FOR snd = 450 TO 150 STEP -25
  264.     SOUND snd, .5
  265. NEXT snd
  266. LOCATE 13, 55: PRINT "Again (Y/N)?"
  267. ag2:
  268. ag$ = INKEY$
  269. IF ag$ = "y" OR ag$ = "Y" THEN GOTO start:
  270. IF ag$ = "n" OR ag$ = "N" THEN END
  271. GOTO ag2:
  272.  
  273. 'Thanks to FelippeHeitor for this Sub and the camera code above.
  274. SUB adjustCamera
  275.     IF player.x + camera.x > _WIDTH / 2 OR player.x + camera.x < _WIDTH / 2 THEN
  276.         camera.x = _WIDTH / 2 - player.x
  277.     END IF
  278.     IF camera.x > 0 THEN camera.x = 0
  279.     IF camera.x < -(_WIDTH(map) - _WIDTH) THEN camera.x = -(_WIDTH(map) - _WIDTH)
  280.  
  281.     IF player.y + camera.y > _HEIGHT / 2 OR player.y + camera.y < _HEIGHT / 2 THEN
  282.         camera.y = _HEIGHT / 2 - player.y
  283.     END IF
  284.     IF camera.y > 0 THEN camera.y = 0
  285.     IF camera.y < -(_HEIGHT(map) - _HEIGHT) THEN camera.y = -(_HEIGHT(map) - _HEIGHT)
  286.  

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Find The Gold!
« Reply #3 on: October 24, 2020, 04:16:37 am »
I could be wrong....

Replacing line #33 with 'LINE (0, 0)-STEP(_WIDTH * 7, _HEIGHT * 7), _RGB32(0, 200, 0), BF' maybe a longer command but I think it maybe a quicker method of "filling" the screen and perhaps a little more efficient on memory...

Just a thought...

J
Logic is the beginning of wisdom.

Offline qbkiller101

  • Newbie
  • Posts: 73
    • View Profile
Re: Find The Gold!
« Reply #4 on: October 24, 2020, 05:24:54 am »
@SierraKen now I have to change my code too :c
anyways, here's the code I made before this post was made:
Code: QB64: [Select]
  1. 'Find the Gold! by SierraKen
  2. 'October 21, 2020
  3. 'Thanks for the great mapping code by FellipeHeitor and help from B+!
  4. 'This is mostly an example game, I hope to expand on it sometime soon.
  5. 'October 22, 2020
  6. 'Edits by Omer H., or qbkiller101 in the forums
  7. 'Added wasd support, fast and normal mode (see 113), and choosing
  8. 'dimensions for people with small screens (like me)
  9.  
  10.  
  11. SCREEN _NEWIMAGE(500, 400, 256)
  12. LINE (125, 100)-(375, 175), 15, BF
  13. LINE (125, 225)-(375, 300), 15, BF
  14. _PRINTSTRING (150, 0), "Choose the dimensions:"
  15. _PRINTSTRING (210, 125), "800 x 600"
  16. _PRINTSTRING (175, 250), "Default (1000 x 800)"
  17. dimx% = 800
  18. dimy% = 600
  19. ischosen = false
  20. WHILE ischosen = false
  21.         IF _MOUSEX > 125 AND _MOUSEX < 375 THEN
  22.             IF _MOUSEY > 100 AND _MOUSEY < 175 THEN
  23.                 IF _MOUSEBUTTON(1) = -1 THEN
  24.                     dimx% = 800
  25.                     dimy% = 600
  26.                     ischosen = true
  27.                     EXIT WHILE
  28.                 END IF
  29.             END IF
  30.         END IF
  31.         IF _MOUSEX > 125 AND _MOUSEX < 375 THEN
  32.             IF _MOUSEY > 225 AND _MOUSEY < 300 THEN
  33.                 IF _MOUSEBUTTON(1) = -1 THEN
  34.                     dimx% = 1000
  35.                     dimy% = 800
  36.                     ischosen = true
  37.                     EXIT WHILE
  38.                 END IF
  39.             END IF
  40.         END IF
  41.  
  42.     LOOP
  43. SCREEN _NEWIMAGE(dimx%, dimy%, 32)
  44. TYPE object
  45.     x AS SINGLE
  46.     y AS SINGLE
  47.  
  48. DIM SHARED player AS object
  49. DIM SHARED camera AS object
  50. DIM playerSpeed AS SINGLE
  51. DIM score AS INTEGER
  52. CONST height800 = 4200
  53. CONST width800 = 5600
  54. CONST height1000 = 5600
  55. CONST width1000 = 7000
  56.  
  57. _TITLE "Find The Gold! One gold bar per map. Use your arrow and wasd keys."
  58.  
  59. start:
  60. player.x = _WIDTH / 2
  61. player.y = _HEIGHT / 2
  62.  
  63. map = _NEWIMAGE(_WIDTH * 7, _HEIGHT * 7, 32)
  64.  
  65. _DEST map
  66. PAINT (2, 2), _RGB32(0, 200, 0)
  67.  
  68. IF _WIDTH = width800 AND _HEIGHT = height800 THEN
  69.  
  70.  
  71. w2 = INT(RND * _WIDTH) - 15
  72. h2 = INT(RND * _HEIGHT) - 10
  73. IF w2 < 15 THEN w2 = 15
  74. IF h2 < 10 THEN h2 = 10
  75.  
  76. 'Gold
  77. COLOR _RGB32(0, 0, 0), _RGB32(255, 255, 128)
  78. _PRINTSTRING (w2, h2), "GOLD"
  79.  
  80.  
  81.  
  82. playerSpeed = 10
  83.  
  84. CONST keyUP = 18432
  85. CONST keyDOWN = 20480
  86. CONST keyLEFT = 19200
  87. CONST keyRIGHT = 19712
  88.  
  89.     CLS
  90.  
  91.     _PUTIMAGE (camera.x, camera.y), map
  92.  
  93.     IF _KEYDOWN(keyUP) THEN player.y = player.y - playerSpeed
  94.     IF _KEYDOWN(keyDOWN) THEN player.y = player.y + playerSpeed
  95.     IF _KEYDOWN(keyLEFT) THEN player.x = player.x - playerSpeed
  96.     IF _KEYDOWN(keyRIGHT) THEN player.x = player.x + playerSpeed
  97.     IF _KEYDOWN(119) THEN player.y = player.y - playerSpeed 'Omer Hijazi
  98.     IF _KEYDOWN(115) THEN player.y = player.y + playerSpeed 'Omer Hijazi
  99.     IF _KEYDOWN(97) THEN player.x = player.x - playerSpeed 'Omer Hijazi
  100.     IF _KEYDOWN(100) THEN player.x = player.x + playerSpeed 'Omer Hijazi
  101.  
  102.  
  103.     IF player.x < 0 THEN player.x = 0
  104.     IF player.x > _WIDTH(map) THEN player.x = _WIDTH(map)
  105.     IF player.y < 0 THEN player.y = 0
  106.     IF player.y > _HEIGHT(map) THEN player.y = _HEIGHT(map)
  107.  
  108.     adjustCamera
  109.  
  110.     'Draw Head
  111.     FOR sz = .25 TO 10 STEP .25
  112.         CIRCLE (player.x + camera.x, player.y + camera.y), sz, _RGB32(255, 166, 127)
  113.     NEXT sz
  114.     'Draw Smile
  115.     CIRCLE (player.x + camera.x, player.y + camera.y + 2), 7, _RGB32(255, 0, 0), _PI, 2 * _PI, .5
  116.     'Draw Eyes
  117.     CIRCLE (player.x + camera.x - 4, player.y + camera.y - 2), 1, _RGB32(0, 0, 255)
  118.     CIRCLE (player.x + camera.x + 4, player.y + camera.y - 2), 1, _RGB32(0, 0, 255)
  119.     'hat
  120.     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
  121.     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
  122.     FOR check = -15 TO 15
  123.         IF POINT(player.x + check, player.y + check) = _RGB32(255, 255, 128) THEN SOUND 500, .5: score = score + 100: score$ = STR$(score): _TITLE "Score: " + score$: GOTO start:
  124.         IF POINT(player.x + check, player.y - check) = _RGB32(255, 255, 128) THEN SOUND 500, .5: score = score + 100: score$ = STR$(score): _TITLE "Score: " + score$: GOTO start:
  125.         IF POINT(player.x - check, player.y + check) = _RGB32(255, 255, 128) THEN SOUND 500, .5: score = score + 100: score$ = STR$(score): _TITLE "Score: " + score$: GOTO start:
  126.     NEXT check
  127.  
  128.     _DISPLAY
  129.     _LIMIT 60
  130.  
  131. SUB adjustCamera
  132.     IF player.x + camera.x > _WIDTH / 2 OR player.x + camera.x < _WIDTH / 2 THEN
  133.         camera.x = _WIDTH / 2 - player.x
  134.     END IF
  135.     IF camera.x > 0 THEN camera.x = 0
  136.     IF camera.x < -(_WIDTH(map) - _WIDTH) THEN camera.x = -(_WIDTH(map) - _WIDTH)
  137.  
  138.     IF player.y + camera.y > _HEIGHT / 2 OR player.y + camera.y < _HEIGHT / 2 THEN
  139.         camera.y = _HEIGHT / 2 - player.y
  140.     END IF
  141.     IF camera.y > 0 THEN camera.y = 0
  142.     IF camera.y < -(_HEIGHT(map) - _HEIGHT) THEN camera.y = -(_HEIGHT(map) - _HEIGHT)
and also, you should make a git repo for collaboration
« Last Edit: October 24, 2020, 05:30:55 am by qbkiller101 »

FellippeHeitor

  • Guest
Re: Find The Gold!
« Reply #5 on: October 24, 2020, 09:19:29 am »
I could be wrong....

Replacing line #33 with 'LINE (0, 0)-STEP(_WIDTH * 7, _HEIGHT * 7), _RGB32(0, 200, 0), BF' maybe a longer command but I think it maybe a quicker method of "filling" the screen and perhaps a little more efficient on memory...

Just a thought...

J

Might wanna try this too:

Code: QB64: [Select]
  1. CLS ,  _RGB32(0, 200, 0)

Offline Aurel

  • Forum Regular
  • Posts: 167
    • View Profile
Re: Find The Gold!
« Reply #6 on: October 24, 2020, 09:30:46 am »
very good, maybe better will be with more natural objects but then will be lot more larger ?
all in all ..nice ;
//////////////////////////////////////////////////////////////////
https://aurelsoft.ucoz.com
https://www.facebook.com/groups/470369984111370
//////////////////////////////////////////////////////////////////

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Find The Gold!
« Reply #7 on: October 24, 2020, 02:44:32 pm »
Thanks everyone! Using the CLS , _RGB32(0,200,0) makes a huge improvement on loading time! Thanks to all of you for the suggestions.

On this version I have made many improvements, here's the list:

Changed PAINT to CLS , _RGB32(0,200,0) which greatly improves the loading speed.
Added 4 times the amount of trees and made 3 levels of mountains.
Added random creeks. Added twice the lakes with random shapes.
Changed screen size to 800 x 600 to be compatible with all players.
Added 100 seconds to level time, to 400 for level 1.
Slowed player speed from 10 to 8.
Changed color after you get the gold from brown to green.
Changed to a happier sound when getting gold.

Code: QB64: [Select]
  1. 'Find the Gold! by SierraKen
  2. 'October 24, 2020
  3. 'Thanks for the great mapping code by FellipeHeitor and help from B+!
  4. 'Additions:
  5. 'Body, Arms, and Legs. Levels and 20 gold per level. Larger land area sizes. Lakes and Trees. 20 Level limit.
  6. 'Changed PAINT to CLS , _RGB32(0,200,0) which greatly improves the loading speed.
  7. 'Added 4 times the amount of trees and made 3 levels of mountains.
  8. 'Added random creeks. Added twice the lakes with random shapes.
  9. 'Changed screen size to 800 x 600 to be compatible with all players.
  10. 'Added 100 seconds to level time, to 400 for level 1.
  11. 'Slowed player speed from 10 to 8.
  12. 'Changed color after you get the gold from brown to green.
  13. 'Changed to a happier sound when getting gold.
  14.  
  15. SCREEN _NEWIMAGE(800, 600, 32)
  16.  
  17. TYPE object
  18.     x AS SINGLE
  19.     y AS SINGLE
  20.  
  21. DIM SHARED player AS object
  22. DIM SHARED camera AS object
  23. DIM playerSpeed AS SINGLE
  24.  
  25. _TITLE "Find The Gold!"
  26.  
  27. start:
  28. score = 0
  29. level = 1
  30.  
  31. start2:
  32. player.x = _WIDTH / 2
  33. player.y = _HEIGHT / 2
  34.  
  35. map = _NEWIMAGE(_WIDTH * 7, _HEIGHT * 7, 32)
  36.  
  37. _DEST map
  38. CLS , _RGB32(0, 200, 0)
  39.  
  40. 'Land Areas
  41. FOR blocks = 1 TO 400
  42.     blocks:
  43.     xx = (RND * _WIDTH)
  44.     yy = (RND * _HEIGHT)
  45.     sz = INT(RND * 300) + 50
  46.     blockcolors:
  47.     c1 = INT(RND * 155) + 100
  48.     c2 = INT(RND * 155) + 100
  49.     c3 = INT(RND * 155) + 100
  50.     IF c1 = 255 AND c2 = 255 AND c3 = 128 THEN GOTO blockcolors:
  51.     c4 = INT(RND * 155) + 100
  52.     c5 = INT(RND * 155) + 100
  53.     c6 = INT(RND * 155) + 100
  54.     blockcolors2:
  55.     IF c4 = 255 AND c5 = 255 AND c6 = 128 THEN GOTO blockcolors2:
  56.     c7 = INT(RND * 155) + 100
  57.     c8 = INT(RND * 155) + 100
  58.     c9 = INT(RND * 155) + 100
  59.     blockcolors3:
  60.     IF c7 = 255 AND c8 = 255 AND c9 = 128 THEN GOTO blockcolors3:
  61.  
  62.     LINE (xx, yy)-(xx + sz, yy + sz), _RGB32(c1, c2, c3), BF
  63.     LINE (xx + (sz * .25), yy + (sz * .25))-(xx + (sz * .75), yy + (sz * .75)), _RGB32(c4, c5, c6), BF
  64.     LINE (xx + (sz * .40), yy + (sz * .40))-(xx + (sz * .60), yy + (sz * .60)), _RGB32(c7, c8, c9), BF
  65.  
  66.  
  67. 'Lakes
  68. FOR lakes = 1 TO 20
  69.     w = RND
  70.     h = RND
  71.     sze = (RND * 200) + 50
  72.     shape = RND
  73.     FOR sz = .25 TO sze STEP .25
  74.         CIRCLE (w * _WIDTH, h * _HEIGHT), sz, _RGB32(0, 128, 255), , , shape
  75.     NEXT sz
  76. NEXT lakes
  77.  
  78. 'Creeks
  79. FOR creeks = 1 TO 100
  80.     cw1 = RND * _WIDTH
  81.     ch1 = RND * _HEIGHT
  82.     cw2 = (RND * 50) + cw1
  83.     ch2 = (RND * 50) + ch1
  84.     cw3 = (RND * 50) + cw2
  85.     ch3 = (RND * 50) + ch2
  86.     cw4 = (RND * 50) + cw3
  87.     ch4 = (RND * 50) + ch3
  88.     cw5 = (RND * 50) + cw4
  89.     ch5 = (RND * 50) + ch4
  90.     cw6 = (RND * 50) + cw5
  91.     ch6 = (RND * 50) + ch5
  92.     cw7 = (RND * 50) + cw6
  93.     ch7 = (RND * 50) + ch6
  94.     cw8 = (RND * 50) + cw7
  95.     ch8 = (RND * 50) + ch7
  96.     cw9 = (RND * 50) + cw8
  97.     ch9 = (RND * 50) + ch8
  98.     cw10 = (RND * 50) + cw9
  99.     ch10 = (RND * 50) + ch9
  100.  
  101.     LINE (cw1, ch1)-(cw2, ch2), _RGB32(0, 128, 255)
  102.     LINE (cw2, ch2)-(cw3, ch3), _RGB32(0, 128, 255)
  103.     LINE (cw3, ch3)-(cw4, ch4), _RGB32(0, 128, 255)
  104.     LINE (cw4, ch4)-(cw5, ch5), _RGB32(0, 128, 255)
  105.     LINE (cw5, ch5)-(cw6, ch6), _RGB32(0, 128, 255)
  106.     LINE (cw6, ch6)-(cw7, ch7), _RGB32(0, 128, 255)
  107.     LINE (cw7, ch7)-(cw8, ch8), _RGB32(0, 128, 255)
  108.     LINE (cw8, ch8)-(cw9, ch9), _RGB32(0, 128, 255)
  109.     LINE (cw9, ch9)-(cw10, ch10), _RGB32(0, 128, 255)
  110.  
  111. NEXT creeks
  112.  
  113. 'Trees
  114. FOR trees = 1 TO 1600
  115.     tx = RND
  116.     tx = tx * _WIDTH
  117.     ty = RND
  118.     ty = ty * _HEIGHT
  119.     tsz = (RND * 40) + 10
  120.     LINE (tx, ty)-(tx, ty + tsz + 5), _RGB32(188, 127, 127)
  121.     FOR branches = ty TO ty + tsz STEP 3
  122.         LINE (tx, branches)-(tx - 10, branches + 5), _RGB32(127, 255, 127)
  123.         LINE (tx, branches)-(tx + 10, branches + 5), _RGB32(127, 255, 127)
  124.     NEXT branches
  125. NEXT trees
  126.  
  127. 'Place Gold
  128. FOR gold = 1 TO 20
  129.     gold:
  130.     w2 = INT(RND * _WIDTH) - 40
  131.     h2 = INT(RND * _HEIGHT) - 40
  132.     IF w2 < 40 THEN w2 = 40
  133.     IF h2 < 40 THEN h2 = 40
  134.     IF POINT(w2, h2) = _RGB32(255, 255, 128) THEN GOTO gold:
  135.     IF POINT(w2, h2) = _RGB32(0, 0, 0) THEN GOTO gold:
  136.     'Gold
  137.     COLOR _RGB32(0, 0, 0), _RGB32(255, 255, 128)
  138.     _PRINTSTRING (w2, h2), "GOLD"
  139. NEXT gold
  140.  
  141.  
  142.  
  143. playerSpeed = 8
  144.  
  145. CONST keyUP = 18432
  146. CONST keyDOWN = 20480
  147. CONST keyLEFT = 19200
  148. CONST keyRIGHT = 19712
  149. CONST keyESC = 27
  150. _PUTIMAGE (camera.x, camera.y), map
  151.  
  152. LOCATE 3, 30: PRINT "Use the arrow keys to find 20 gold bars per level."
  153. LOCATE 4, 30: PRINT "Every level will have a shorter time."
  154. LOCATE 5, 30: PRINT "After Level 20 you win the game."
  155. LOCATE 10, 40: PRINT "Press Any Key To Begin."
  156.  
  157. pause:
  158. a$ = INKEY$
  159. IF a$ <> "" THEN GOTO begin:
  160. GOTO pause:
  161.  
  162. begin:
  163.  
  164. seconds = INT(TIMER)
  165.     CLS
  166.     leveltime = level * 5
  167.     gametime = (405 - leveltime) - (INT(TIMER) - seconds)
  168.     _PUTIMAGE (camera.x, camera.y), map
  169.     LOCATE 1, 1: PRINT "Time Left: "; gametime
  170.     IF gametime < 1 THEN GOTO done:
  171.     IF _KEYDOWN(keyUP) THEN
  172.         player.y = player.y - playerSpeed
  173.         t = t + 1
  174.     END IF
  175.     IF _KEYDOWN(keyDOWN) THEN
  176.         player.y = player.y + playerSpeed
  177.         t = t + 1
  178.     END IF
  179.     IF _KEYDOWN(keyLEFT) THEN
  180.         player.x = player.x - playerSpeed
  181.         t = t + 1
  182.     END IF
  183.     IF _KEYDOWN(keyRIGHT) THEN
  184.         player.x = player.x + playerSpeed
  185.         t = t + 1
  186.     END IF
  187.     IF _KEYDOWN(keyESC) THEN END
  188.     IF player.x < 0 THEN player.x = 0
  189.     IF player.x > _WIDTH(map) THEN player.x = _WIDTH(map)
  190.     IF player.y < 0 THEN player.y = 0
  191.     IF player.y > _HEIGHT(map) THEN player.y = _HEIGHT(map)
  192.  
  193.     adjustCamera
  194.  
  195.     'Draw Head
  196.     FOR sz = .25 TO 10 STEP .25
  197.         CIRCLE (player.x + camera.x, player.y + camera.y), sz, _RGB32(255, 166, 127)
  198.     NEXT sz
  199.     'Draw Smile
  200.     CIRCLE (player.x + camera.x, player.y + camera.y + 2), 7, _RGB32(255, 0, 0), _PI, 2 * _PI, .5
  201.     'Draw Eyes
  202.     CIRCLE (player.x + camera.x - 4, player.y + camera.y - 2), 1, _RGB32(0, 0, 255)
  203.     CIRCLE (player.x + camera.x + 4, player.y + camera.y - 2), 1, _RGB32(0, 0, 255)
  204.     'hat
  205.     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
  206.     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
  207.     'body
  208.     LINE (player.x + camera.x, player.y + camera.y + 10)-(player.x + camera.x, player.y + camera.y + 20), _RGB32(155, 0, 0)
  209.  
  210.     IF t > 7 THEN t = 0
  211.  
  212.     'rest of body
  213.     IF t = 0 THEN
  214.         'left arm
  215.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x - 15, player.y + camera.y + 25), _RGB32(155, 0, 0)
  216.         'right arm
  217.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x + 15, player.y + camera.y + 25), _RGB32(155, 0, 0)
  218.         'left leg
  219.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x - 15, player.y + camera.y + 35), _RGB32(155, 0, 0)
  220.         'right leg
  221.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x + 15, player.y + camera.y + 35), _RGB32(155, 0, 0)
  222.     END IF
  223.  
  224.     IF t = 1 OR t = 7 THEN
  225.         'left arm
  226.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x - 11, player.y + camera.y + 25), _RGB32(155, 0, 0)
  227.         'right arm
  228.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x + 11, player.y + camera.y + 25), _RGB32(155, 0, 0)
  229.         'left leg
  230.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x - 11, player.y + camera.y + 35), _RGB32(155, 0, 0)
  231.         'right leg
  232.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x + 11, player.y + camera.y + 35), _RGB32(155, 0, 0)
  233.     END IF
  234.  
  235.     IF t = 2 OR t = 6 THEN
  236.         'left arm
  237.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x - 9, player.y + camera.y + 24), _RGB32(155, 0, 0)
  238.         'right arm
  239.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x + 9, player.y + camera.y + 24), _RGB32(155, 0, 0)
  240.         'left leg
  241.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x - 9, player.y + camera.y + 35), _RGB32(155, 0, 0)
  242.         'right leg
  243.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x + 9, player.y + camera.y + 35), _RGB32(155, 0, 0)
  244.     END IF
  245.  
  246.     IF t = 3 OR t = 5 THEN
  247.         'left arm
  248.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x - 7, player.y + camera.y + 24), _RGB32(155, 0, 0)
  249.         'right arm
  250.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x + 7, player.y + camera.y + 24), _RGB32(155, 0, 0)
  251.         'left leg
  252.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x - 7, player.y + camera.y + 35), _RGB32(155, 0, 0)
  253.         'right leg
  254.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x + 7, player.y + camera.y + 35), _RGB32(155, 0, 0)
  255.     END IF
  256.  
  257.     IF t = 4 THEN
  258.         'left arm
  259.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x - 5, player.y + camera.y + 23), _RGB32(155, 0, 0)
  260.         'right arm
  261.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x + 5, player.y + camera.y + 23), _RGB32(155, 0, 0)
  262.         'left leg
  263.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x - 5, player.y + camera.y + 35), _RGB32(155, 0, 0)
  264.         'right leg
  265.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x + 5, player.y + camera.y + 35), _RGB32(155, 0, 0)
  266.     END IF
  267.  
  268.     FOR check = -15 TO 15
  269.         IF POINT(player.x + check, player.y + check) = _RGB32(255, 255, 128) THEN
  270.             _DEST map
  271.             FOR sz = .2 TO 35 STEP .2
  272.                 CIRCLE (player.x + check, player.y + check), sz, _RGB32(127, 255, 127)
  273.             NEXT sz
  274.             GOSUB findgold:
  275.         END IF
  276.         IF POINT(player.x + check, player.y - check) = _RGB32(255, 255, 128) THEN
  277.             _DEST map
  278.             FOR sz = .2 TO 35 STEP .2
  279.                 CIRCLE (player.x + check, player.y - check), sz, _RGB32(127, 255, 127)
  280.             NEXT sz
  281.             GOSUB findgold:
  282.         END IF
  283.         IF POINT(player.x - check, player.y + check) = _RGB32(255, 255, 128) THEN
  284.             _DEST map
  285.             FOR sz = .2 TO 35 STEP .2
  286.                 CIRCLE (player.x - check, player.y + check), sz, _RGB32(127, 255, 127)
  287.             NEXT sz
  288.             GOSUB findgold:
  289.         END IF
  290.     NEXT check
  291.     _DISPLAY
  292.     _LIMIT 60
  293.  
  294. findgold:
  295. FOR snd = 400 TO 800 STEP 100
  296.     SOUND snd, .5
  297. NEXT snd
  298. score = score + 100
  299. score$ = STR$(score)
  300. level$ = STR$(level)
  301. _TITLE "Level: " + level$ + "   Score: " + score$
  302. IF score / 2000 = INT(score / 2000) THEN
  303.     level = level + 1
  304.     level$ = STR$(level)
  305.     _TITLE "Level: " + level$ + "   Score: " + score$
  306.     IF level = 21 THEN GOTO win:
  307.     GOTO start2:
  308.  
  309. done:
  310. LOCATE 10, 55: PRINT "G A M E     O V E R"
  311. FOR snd = 450 TO 150 STEP -25
  312.     SOUND snd, .5
  313. NEXT snd
  314. LOCATE 13, 55: PRINT "Again (Y/N)?"
  315. ag:
  316. ag$ = INKEY$
  317. IF ag$ = "y" OR ag$ = "Y" THEN GOTO start:
  318. IF ag$ = "n" OR ag$ = "N" THEN END
  319. GOTO ag:
  320.  
  321. win:
  322. LOCATE 10, 55: PRINT "G A M E     W O N ! ! ! ! ! ! !"
  323. FOR snd = 450 TO 150 STEP -25
  324.     SOUND snd, .5
  325. NEXT snd
  326. LOCATE 13, 55: PRINT "Again (Y/N)?"
  327. ag2:
  328. ag$ = INKEY$
  329. IF ag$ = "y" OR ag$ = "Y" THEN GOTO start:
  330. IF ag$ = "n" OR ag$ = "N" THEN END
  331. GOTO ag2:
  332.  
  333. 'Thanks to FelippeHeitor for this Sub and the camera code above.
  334. SUB adjustCamera
  335.     IF player.x + camera.x > _WIDTH / 2 OR player.x + camera.x < _WIDTH / 2 THEN
  336.         camera.x = _WIDTH / 2 - player.x
  337.     END IF
  338.     IF camera.x > 0 THEN camera.x = 0
  339.     IF camera.x < -(_WIDTH(map) - _WIDTH) THEN camera.x = -(_WIDTH(map) - _WIDTH)
  340.     IF player.y + camera.y > _HEIGHT / 2 OR player.y + camera.y < _HEIGHT / 2 THEN
  341.         camera.y = _HEIGHT / 2 - player.y
  342.     END IF
  343.     IF camera.y > 0 THEN camera.y = 0
  344.     IF camera.y < -(_HEIGHT(map) - _HEIGHT) THEN camera.y = -(_HEIGHT(map) - _HEIGHT)
  345.  
« Last Edit: October 24, 2020, 02:59:49 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Find The Gold!
« Reply #8 on: October 24, 2020, 02:56:40 pm »
Here is another quick update for WASD player movement support (along with arrow keys). I remember B+ didn't like the arrow keys and I see QBKiller needs this as well. Thanks QBKiller for the keydown numbers. :) I also included a picture of the game below.

Code: QB64: [Select]
  1. 'Find the Gold! by SierraKen
  2. 'October 24, 2020
  3. 'Thanks for the great mapping code by FellipeHeitor and help from B+!
  4. 'Additions:
  5. 'Body, Arms, and Legs. Levels and 20 gold per level. Larger land area sizes. Lakes and Trees. 20 Level limit.
  6. 'Changed PAINT to CLS , _RGB32(0,200,0) which greatly improves the loading speed.
  7. 'Added 4 times the amount of trees and made 3 levels of mountains.
  8. 'Added random creeks. Added twice the lakes with random shapes.
  9. 'Changed screen size to 800 x 600 to be compatible with all players.
  10. 'Added 100 seconds to level time, to 400 for level 1.
  11. 'Slowed player speed from 10 to 8.
  12. 'Changed to a happier sound when getting gold.
  13. 'Changed color after you get the gold from brown to green.
  14. 'Added WASD keys to move player along with arrow keys.
  15.  
  16. SCREEN _NEWIMAGE(800, 600, 32)
  17.  
  18. TYPE object
  19.     x AS SINGLE
  20.     y AS SINGLE
  21.  
  22. DIM SHARED player AS object
  23. DIM SHARED camera AS object
  24. DIM playerSpeed AS SINGLE
  25.  
  26. _TITLE "Find The Gold!"
  27.  
  28. start:
  29. score = 0
  30. level = 1
  31.  
  32. start2:
  33. player.x = _WIDTH / 2
  34. player.y = _HEIGHT / 2
  35.  
  36. map = _NEWIMAGE(_WIDTH * 7, _HEIGHT * 7, 32)
  37.  
  38. _DEST map
  39. CLS , _RGB32(0, 200, 0)
  40.  
  41. 'Land Areas
  42. FOR blocks = 1 TO 400
  43.     blocks:
  44.     xx = (RND * _WIDTH)
  45.     yy = (RND * _HEIGHT)
  46.     sz = INT(RND * 300) + 50
  47.     blockcolors:
  48.     c1 = INT(RND * 155) + 100
  49.     c2 = INT(RND * 155) + 100
  50.     c3 = INT(RND * 155) + 100
  51.     IF c1 = 255 AND c2 = 255 AND c3 = 128 THEN GOTO blockcolors:
  52.     c4 = INT(RND * 155) + 100
  53.     c5 = INT(RND * 155) + 100
  54.     c6 = INT(RND * 155) + 100
  55.     blockcolors2:
  56.     IF c4 = 255 AND c5 = 255 AND c6 = 128 THEN GOTO blockcolors2:
  57.     c7 = INT(RND * 155) + 100
  58.     c8 = INT(RND * 155) + 100
  59.     c9 = INT(RND * 155) + 100
  60.     blockcolors3:
  61.     IF c7 = 255 AND c8 = 255 AND c9 = 128 THEN GOTO blockcolors3:
  62.  
  63.     LINE (xx, yy)-(xx + sz, yy + sz), _RGB32(c1, c2, c3), BF
  64.     LINE (xx + (sz * .25), yy + (sz * .25))-(xx + (sz * .75), yy + (sz * .75)), _RGB32(c4, c5, c6), BF
  65.     LINE (xx + (sz * .40), yy + (sz * .40))-(xx + (sz * .60), yy + (sz * .60)), _RGB32(c7, c8, c9), BF
  66.  
  67.  
  68. 'Lakes
  69. FOR lakes = 1 TO 20
  70.     w = RND
  71.     h = RND
  72.     sze = (RND * 200) + 50
  73.     shape = RND
  74.     FOR sz = .25 TO sze STEP .25
  75.         CIRCLE (w * _WIDTH, h * _HEIGHT), sz, _RGB32(0, 128, 255), , , shape
  76.     NEXT sz
  77. NEXT lakes
  78.  
  79. 'Creeks
  80. FOR creeks = 1 TO 100
  81.     cw1 = RND * _WIDTH
  82.     ch1 = RND * _HEIGHT
  83.     cw2 = (RND * 50) + cw1
  84.     ch2 = (RND * 50) + ch1
  85.     cw3 = (RND * 50) + cw2
  86.     ch3 = (RND * 50) + ch2
  87.     cw4 = (RND * 50) + cw3
  88.     ch4 = (RND * 50) + ch3
  89.     cw5 = (RND * 50) + cw4
  90.     ch5 = (RND * 50) + ch4
  91.     cw6 = (RND * 50) + cw5
  92.     ch6 = (RND * 50) + ch5
  93.     cw7 = (RND * 50) + cw6
  94.     ch7 = (RND * 50) + ch6
  95.     cw8 = (RND * 50) + cw7
  96.     ch8 = (RND * 50) + ch7
  97.     cw9 = (RND * 50) + cw8
  98.     ch9 = (RND * 50) + ch8
  99.     cw10 = (RND * 50) + cw9
  100.     ch10 = (RND * 50) + ch9
  101.  
  102.     LINE (cw1, ch1)-(cw2, ch2), _RGB32(0, 128, 255)
  103.     LINE (cw2, ch2)-(cw3, ch3), _RGB32(0, 128, 255)
  104.     LINE (cw3, ch3)-(cw4, ch4), _RGB32(0, 128, 255)
  105.     LINE (cw4, ch4)-(cw5, ch5), _RGB32(0, 128, 255)
  106.     LINE (cw5, ch5)-(cw6, ch6), _RGB32(0, 128, 255)
  107.     LINE (cw6, ch6)-(cw7, ch7), _RGB32(0, 128, 255)
  108.     LINE (cw7, ch7)-(cw8, ch8), _RGB32(0, 128, 255)
  109.     LINE (cw8, ch8)-(cw9, ch9), _RGB32(0, 128, 255)
  110.     LINE (cw9, ch9)-(cw10, ch10), _RGB32(0, 128, 255)
  111.  
  112. NEXT creeks
  113.  
  114. 'Trees
  115. FOR trees = 1 TO 1600
  116.     tx = RND
  117.     tx = tx * _WIDTH
  118.     ty = RND
  119.     ty = ty * _HEIGHT
  120.     tsz = (RND * 40) + 10
  121.     LINE (tx, ty)-(tx, ty + tsz + 5), _RGB32(188, 127, 127)
  122.     FOR branches = ty TO ty + tsz STEP 3
  123.         LINE (tx, branches)-(tx - 10, branches + 5), _RGB32(127, 255, 127)
  124.         LINE (tx, branches)-(tx + 10, branches + 5), _RGB32(127, 255, 127)
  125.     NEXT branches
  126. NEXT trees
  127.  
  128. 'Place Gold
  129. FOR gold = 1 TO 20
  130.     gold:
  131.     w2 = INT(RND * _WIDTH) - 40
  132.     h2 = INT(RND * _HEIGHT) - 40
  133.     IF w2 < 40 THEN w2 = 40
  134.     IF h2 < 40 THEN h2 = 40
  135.     IF POINT(w2, h2) = _RGB32(255, 255, 128) THEN GOTO gold:
  136.     IF POINT(w2, h2) = _RGB32(0, 0, 0) THEN GOTO gold:
  137.     'Gold
  138.     COLOR _RGB32(0, 0, 0), _RGB32(255, 255, 128)
  139.     _PRINTSTRING (w2, h2), "GOLD"
  140. NEXT gold
  141.  
  142.  
  143.  
  144. playerSpeed = 8
  145.  
  146. CONST keyUP = 18432
  147. CONST keyDOWN = 20480
  148. CONST keyLEFT = 19200
  149. CONST keyRIGHT = 19712
  150. CONST keyESC = 27
  151. _PUTIMAGE (camera.x, camera.y), map
  152.  
  153. LOCATE 3, 30: PRINT "Use the arrow keys (or WASD keys) to find 20 gold bars per level."
  154. LOCATE 4, 30: PRINT "Every level will have a shorter time."
  155. LOCATE 5, 30: PRINT "After Level 20 you win the game."
  156. LOCATE 10, 40: PRINT "Press Any Key To Begin."
  157.  
  158. pause:
  159. a$ = INKEY$
  160. IF a$ <> "" THEN GOTO begin:
  161. GOTO pause:
  162.  
  163. begin:
  164.  
  165. seconds = INT(TIMER)
  166.     CLS
  167.     leveltime = level * 5
  168.     gametime = (405 - leveltime) - (INT(TIMER) - seconds)
  169.     _PUTIMAGE (camera.x, camera.y), map
  170.     LOCATE 1, 1: PRINT "Time Left: "; gametime
  171.     IF gametime < 1 THEN GOTO done:
  172.     IF _KEYDOWN(keyUP) OR _KEYDOWN(119) THEN
  173.         player.y = player.y - playerSpeed
  174.         t = t + 1
  175.     END IF
  176.     IF _KEYDOWN(keyDOWN) OR _KEYDOWN(115) THEN
  177.         player.y = player.y + playerSpeed
  178.         t = t + 1
  179.     END IF
  180.     IF _KEYDOWN(keyLEFT) OR _KEYDOWN(97) THEN
  181.         player.x = player.x - playerSpeed
  182.         t = t + 1
  183.     END IF
  184.     IF _KEYDOWN(keyRIGHT) OR _KEYDOWN(100) THEN
  185.         player.x = player.x + playerSpeed
  186.         t = t + 1
  187.     END IF
  188.     IF _KEYDOWN(keyESC) THEN END
  189.     IF player.x < 0 THEN player.x = 0
  190.     IF player.x > _WIDTH(map) THEN player.x = _WIDTH(map)
  191.     IF player.y < 0 THEN player.y = 0
  192.     IF player.y > _HEIGHT(map) THEN player.y = _HEIGHT(map)
  193.  
  194.     adjustCamera
  195.  
  196.     'Draw Head
  197.     FOR sz = .25 TO 10 STEP .25
  198.         CIRCLE (player.x + camera.x, player.y + camera.y), sz, _RGB32(255, 166, 127)
  199.     NEXT sz
  200.     'Draw Smile
  201.     CIRCLE (player.x + camera.x, player.y + camera.y + 2), 7, _RGB32(255, 0, 0), _PI, 2 * _PI, .5
  202.     'Draw Eyes
  203.     CIRCLE (player.x + camera.x - 4, player.y + camera.y - 2), 1, _RGB32(0, 0, 255)
  204.     CIRCLE (player.x + camera.x + 4, player.y + camera.y - 2), 1, _RGB32(0, 0, 255)
  205.     'hat
  206.     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
  207.     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
  208.     'body
  209.     LINE (player.x + camera.x, player.y + camera.y + 10)-(player.x + camera.x, player.y + camera.y + 20), _RGB32(155, 0, 0)
  210.  
  211.     IF t > 7 THEN t = 0
  212.  
  213.     'rest of body
  214.     IF t = 0 THEN
  215.         'left arm
  216.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x - 15, player.y + camera.y + 25), _RGB32(155, 0, 0)
  217.         'right arm
  218.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x + 15, player.y + camera.y + 25), _RGB32(155, 0, 0)
  219.         'left leg
  220.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x - 15, player.y + camera.y + 35), _RGB32(155, 0, 0)
  221.         'right leg
  222.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x + 15, player.y + camera.y + 35), _RGB32(155, 0, 0)
  223.     END IF
  224.  
  225.     IF t = 1 OR t = 7 THEN
  226.         'left arm
  227.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x - 11, player.y + camera.y + 25), _RGB32(155, 0, 0)
  228.         'right arm
  229.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x + 11, player.y + camera.y + 25), _RGB32(155, 0, 0)
  230.         'left leg
  231.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x - 11, player.y + camera.y + 35), _RGB32(155, 0, 0)
  232.         'right leg
  233.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x + 11, player.y + camera.y + 35), _RGB32(155, 0, 0)
  234.     END IF
  235.  
  236.     IF t = 2 OR t = 6 THEN
  237.         'left arm
  238.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x - 9, player.y + camera.y + 24), _RGB32(155, 0, 0)
  239.         'right arm
  240.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x + 9, player.y + camera.y + 24), _RGB32(155, 0, 0)
  241.         'left leg
  242.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x - 9, player.y + camera.y + 35), _RGB32(155, 0, 0)
  243.         'right leg
  244.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x + 9, player.y + camera.y + 35), _RGB32(155, 0, 0)
  245.     END IF
  246.  
  247.     IF t = 3 OR t = 5 THEN
  248.         'left arm
  249.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x - 7, player.y + camera.y + 24), _RGB32(155, 0, 0)
  250.         'right arm
  251.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x + 7, player.y + camera.y + 24), _RGB32(155, 0, 0)
  252.         'left leg
  253.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x - 7, player.y + camera.y + 35), _RGB32(155, 0, 0)
  254.         'right leg
  255.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x + 7, player.y + camera.y + 35), _RGB32(155, 0, 0)
  256.     END IF
  257.  
  258.     IF t = 4 THEN
  259.         'left arm
  260.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x - 5, player.y + camera.y + 23), _RGB32(155, 0, 0)
  261.         'right arm
  262.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x + 5, player.y + camera.y + 23), _RGB32(155, 0, 0)
  263.         'left leg
  264.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x - 5, player.y + camera.y + 35), _RGB32(155, 0, 0)
  265.         'right leg
  266.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x + 5, player.y + camera.y + 35), _RGB32(155, 0, 0)
  267.     END IF
  268.  
  269.  
  270.     FOR check = -15 TO 15
  271.         IF POINT(player.x + check, player.y + check) = _RGB32(255, 255, 128) THEN
  272.             _DEST map
  273.             FOR sz = .2 TO 35 STEP .2
  274.                 CIRCLE (player.x + check, player.y + check), sz, _RGB32(127, 255, 127)
  275.             NEXT sz
  276.             GOSUB findgold:
  277.         END IF
  278.         IF POINT(player.x + check, player.y - check) = _RGB32(255, 255, 128) THEN
  279.             _DEST map
  280.             FOR sz = .2 TO 35 STEP .2
  281.                 CIRCLE (player.x + check, player.y - check), sz, _RGB32(127, 255, 127)
  282.             NEXT sz
  283.             GOSUB findgold:
  284.         END IF
  285.         IF POINT(player.x - check, player.y + check) = _RGB32(255, 255, 128) THEN
  286.             _DEST map
  287.             FOR sz = .2 TO 35 STEP .2
  288.                 CIRCLE (player.x - check, player.y + check), sz, _RGB32(127, 255, 127)
  289.             NEXT sz
  290.             GOSUB findgold:
  291.         END IF
  292.     NEXT check
  293.     _DISPLAY
  294.     _LIMIT 60
  295.  
  296. findgold:
  297. FOR snd = 400 TO 800 STEP 100
  298.     SOUND snd, .5
  299. NEXT snd
  300. score = score + 100
  301. score$ = STR$(score)
  302. level$ = STR$(level)
  303. _TITLE "Level: " + level$ + "   Score: " + score$
  304. IF score / 2000 = INT(score / 2000) THEN
  305.     level = level + 1
  306.     level$ = STR$(level)
  307.     _TITLE "Level: " + level$ + "   Score: " + score$
  308.     IF level = 21 THEN GOTO win:
  309.     GOTO start2:
  310.  
  311. done:
  312. LOCATE 10, 55: PRINT "G A M E     O V E R"
  313. FOR snd = 450 TO 150 STEP -25
  314.     SOUND snd, .5
  315. NEXT snd
  316. LOCATE 13, 55: PRINT "Again (Y/N)?"
  317. ag:
  318. ag$ = INKEY$
  319. IF ag$ = "y" OR ag$ = "Y" THEN GOTO start:
  320. IF ag$ = "n" OR ag$ = "N" THEN END
  321. GOTO ag:
  322.  
  323. win:
  324. LOCATE 10, 55: PRINT "G A M E     W O N ! ! ! ! ! ! !"
  325. FOR snd = 450 TO 150 STEP -25
  326.     SOUND snd, .5
  327. NEXT snd
  328. LOCATE 13, 55: PRINT "Again (Y/N)?"
  329. ag2:
  330. ag$ = INKEY$
  331. IF ag$ = "y" OR ag$ = "Y" THEN GOTO start:
  332. IF ag$ = "n" OR ag$ = "N" THEN END
  333. GOTO ag2:
  334.  
  335. 'Thanks to FelippeHeitor for this Sub and the camera code above.
  336. SUB adjustCamera
  337.     IF player.x + camera.x > _WIDTH / 2 OR player.x + camera.x < _WIDTH / 2 THEN
  338.         camera.x = _WIDTH / 2 - player.x
  339.     END IF
  340.     IF camera.x > 0 THEN camera.x = 0
  341.     IF camera.x < -(_WIDTH(map) - _WIDTH) THEN camera.x = -(_WIDTH(map) - _WIDTH)
  342.  
  343.     IF player.y + camera.y > _HEIGHT / 2 OR player.y + camera.y < _HEIGHT / 2 THEN
  344.         camera.y = _HEIGHT / 2 - player.y
  345.     END IF
  346.     IF camera.y > 0 THEN camera.y = 0
  347.     IF camera.y < -(_HEIGHT(map) - _HEIGHT) THEN camera.y = -(_HEIGHT(map) - _HEIGHT)
  348.  
Find The Gold - game by SierraKen.jpg
* Find The Gold - game by SierraKen.jpg (Filesize: 87.32 KB, Dimensions: 800x625, Views: 110)
« Last Edit: October 24, 2020, 03:02:54 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Find The Gold!
« Reply #9 on: October 24, 2020, 06:29:34 pm »
I just removed the Atari looking square mountains and put more realistic looking hills in its place. I also put the lakes on the ground (before everything else is placed). It took me awhile to figure out how to overlap the hills correctly. So instead of a random vertical coordinate for them, I just use yy=yy+4 and made the horizontal value random. Check out the picture below. :) I'm super happy about this. Oh also, since it still takes a couple seconds to load with all of the hill graphics, I added a "Loading...." in the Topic bar so people know to wait.
Also, just so you all know, I will be gone from Sunday afternoon to Wednesday because my power company is shutting off 1000's of people's power in Northern California for their Public Safety Power Shut-Offs they do when dry winds come. I'll be back later this week. But please check out this version. I really think I'm getting better at my games thanks to all of you!
On a side note: This game does get a bit boring if you keep playing it. I suggest playing it for a couple of levels and that's about it. I'll probably add bad guys or something to make more action and harder to play. But the main reason I like it is because it gets you thinking about running around in the mountains. :)

Code: QB64: [Select]
  1. 'Find the Gold! by SierraKen
  2. 'October 24, 2020
  3. 'Thanks for the great mapping code by FellipeHeitor and help from B+!
  4. 'Additions:
  5. 'Body, Arms, and Legs. Levels and 20 gold per level. Larger land area sizes. Lakes and Trees. 20 Level limit.
  6. 'Changed PAINT to CLS , _RGB32(0,200,0) which greatly improves the loading speed.
  7. 'Added 4 times the amount of trees and made 3 levels of mountains.
  8. 'Added random creeks. Added twice the lakes with random shapes.
  9. 'Changed screen size to 800 x 600 to be compatible with all players.
  10. 'Added 100 seconds to level time, to 400 for level 1.
  11. 'Slowed player speed from 10 to 8.
  12. 'Changed to a happier sound when getting gold.
  13. 'Changed color after you get the gold from brown to green.
  14. 'Added WASD keys to move player along with arrow keys.
  15. 'Removed the square mountains and made more realistic hills.
  16. 'Put the lakes on the ground, before everything else.
  17. 'Added Loading.... in the topic bar.
  18.  
  19. SCREEN _NEWIMAGE(800, 600, 32)
  20.  
  21. TYPE object
  22.     x AS SINGLE
  23.     y AS SINGLE
  24.  
  25. DIM SHARED player AS object
  26. DIM SHARED camera AS object
  27. DIM playerSpeed AS SINGLE
  28.  
  29. _TITLE "Loading....."
  30.  
  31. start:
  32. score = 0
  33. level = 1
  34.  
  35. start2:
  36. player.x = _WIDTH / 2
  37. player.y = _HEIGHT / 2
  38.  
  39. map = _NEWIMAGE(_WIDTH * 7, _HEIGHT * 7, 32)
  40.  
  41. _DEST map
  42.  
  43. CLS , _RGB32(0, 200, 0)
  44.  
  45. 'Lakes
  46. FOR lakes = 1 TO 100
  47.     w = RND
  48.     h = RND
  49.     sze = (RND * 250) + 100
  50.     shape = RND
  51.     FOR sz = .25 TO sze STEP .25
  52.         CIRCLE (w * _WIDTH, h * _HEIGHT), sz, _RGB32(0, 128, 255), , , shape
  53.     NEXT sz
  54. NEXT lakes
  55.  
  56.  
  57. 'Hills
  58. FOR hills = 1 TO 1200
  59.     _LIMIT 2000
  60.     xx = (RND * _WIDTH)
  61.     sz = INT(RND * 100) + 200
  62.     shape = RND
  63.     hillcolors:
  64.     c1 = INT(RND * 100) + 55
  65.     c2 = INT(RND * 100) + 55
  66.     c3 = INT(RND * 100) + 55
  67.     IF c1 = 255 AND c2 = 255 AND c3 = 128 THEN GOTO hillcolors:
  68.     yy = yy + 4
  69.     FOR hill = 1 TO sz STEP .25
  70.         hh = hh + .025
  71.         IF hh > 100 THEN hh = 100
  72.         cc1 = c1 + hh
  73.         cc2 = c2 + hh
  74.         cc3 = c3 + hh
  75.         CIRCLE (xx, yy), hill, _RGB32(cc1, cc2, cc3), 2 * _PI, _PI, shape
  76.     NEXT hill
  77.     hh = 0
  78. NEXT hills
  79. yy = 0
  80.  
  81. 'Creeks
  82. FOR creeks = 1 TO 100
  83.     cw1 = RND * _WIDTH
  84.     ch1 = RND * _HEIGHT
  85.     cw2 = (RND * 50) + cw1
  86.     ch2 = (RND * 50) + ch1
  87.     cw3 = (RND * 50) + cw2
  88.     ch3 = (RND * 50) + ch2
  89.     cw4 = (RND * 50) + cw3
  90.     ch4 = (RND * 50) + ch3
  91.     cw5 = (RND * 50) + cw4
  92.     ch5 = (RND * 50) + ch4
  93.     cw6 = (RND * 50) + cw5
  94.     ch6 = (RND * 50) + ch5
  95.     cw7 = (RND * 50) + cw6
  96.     ch7 = (RND * 50) + ch6
  97.     cw8 = (RND * 50) + cw7
  98.     ch8 = (RND * 50) + ch7
  99.     cw9 = (RND * 50) + cw8
  100.     ch9 = (RND * 50) + ch8
  101.     cw10 = (RND * 50) + cw9
  102.     ch10 = (RND * 50) + ch9
  103.  
  104.     LINE (cw1, ch1)-(cw2, ch2), _RGB32(0, 128, 255)
  105.     LINE (cw2, ch2)-(cw3, ch3), _RGB32(0, 128, 255)
  106.     LINE (cw3, ch3)-(cw4, ch4), _RGB32(0, 128, 255)
  107.     LINE (cw4, ch4)-(cw5, ch5), _RGB32(0, 128, 255)
  108.     LINE (cw5, ch5)-(cw6, ch6), _RGB32(0, 128, 255)
  109.     LINE (cw6, ch6)-(cw7, ch7), _RGB32(0, 128, 255)
  110.     LINE (cw7, ch7)-(cw8, ch8), _RGB32(0, 128, 255)
  111.     LINE (cw8, ch8)-(cw9, ch9), _RGB32(0, 128, 255)
  112.     LINE (cw9, ch9)-(cw10, ch10), _RGB32(0, 128, 255)
  113.  
  114. NEXT creeks
  115.  
  116. 'Trees
  117. FOR trees = 1 TO 1600
  118.     tx = RND
  119.     tx = tx * _WIDTH
  120.     ty = RND
  121.     ty = ty * _HEIGHT
  122.     tsz = (RND * 40) + 10
  123.     LINE (tx, ty)-(tx, ty + tsz + 5), _RGB32(188, 127, 127)
  124.     FOR branches = ty TO ty + tsz STEP 3
  125.         LINE (tx, branches)-(tx - 10, branches + 5), _RGB32(127, 255, 127)
  126.         LINE (tx, branches)-(tx + 10, branches + 5), _RGB32(127, 255, 127)
  127.     NEXT branches
  128. NEXT trees
  129.  
  130. 'Place Gold
  131. FOR gold = 1 TO 20
  132.     gold:
  133.     w2 = INT(RND * _WIDTH) - 40
  134.     h2 = INT(RND * _HEIGHT) - 40
  135.     IF w2 < 40 THEN w2 = 40
  136.     IF h2 < 40 THEN h2 = 40
  137.     IF POINT(w2, h2) = _RGB32(255, 255, 128) THEN GOTO gold:
  138.     IF POINT(w2, h2) = _RGB32(0, 0, 0) THEN GOTO gold:
  139.     'Gold
  140.     COLOR _RGB32(0, 0, 0), _RGB32(255, 255, 128)
  141.     _PRINTSTRING (w2, h2), "GOLD"
  142. NEXT gold
  143.  
  144.  
  145. _TITLE "Find The Gold!"
  146. playerSpeed = 8
  147.  
  148. CONST keyUP = 18432
  149. CONST keyDOWN = 20480
  150. CONST keyLEFT = 19200
  151. CONST keyRIGHT = 19712
  152. CONST keyESC = 27
  153. _PUTIMAGE (camera.x, camera.y), map
  154.  
  155. LOCATE 3, 30: PRINT "Use the arrow keys (or WASD keys) to find 20 gold bars per level."
  156. LOCATE 4, 30: PRINT "Every level will have a shorter time."
  157. LOCATE 5, 30: PRINT "After Level 20 you win the game."
  158. LOCATE 10, 40: PRINT "Press Any Key To Begin."
  159.  
  160. pause:
  161. a$ = INKEY$
  162. IF a$ <> "" THEN GOTO begin:
  163. GOTO pause:
  164.  
  165. begin:
  166.  
  167. seconds = INT(TIMER)
  168.     CLS
  169.     leveltime = level * 5
  170.     gametime = (405 - leveltime) - (INT(TIMER) - seconds)
  171.     _PUTIMAGE (camera.x, camera.y), map
  172.     LOCATE 1, 1: PRINT "Time Left: "; gametime
  173.     IF gametime < 1 THEN GOTO done:
  174.     IF _KEYDOWN(keyUP) OR _KEYDOWN(119) THEN
  175.         player.y = player.y - playerSpeed
  176.         t = t + 1
  177.     END IF
  178.     IF _KEYDOWN(keyDOWN) OR _KEYDOWN(115) THEN
  179.         player.y = player.y + playerSpeed
  180.         t = t + 1
  181.     END IF
  182.     IF _KEYDOWN(keyLEFT) OR _KEYDOWN(97) THEN
  183.         player.x = player.x - playerSpeed
  184.         t = t + 1
  185.     END IF
  186.     IF _KEYDOWN(keyRIGHT) OR _KEYDOWN(100) THEN
  187.         player.x = player.x + playerSpeed
  188.         t = t + 1
  189.     END IF
  190.     IF _KEYDOWN(keyESC) THEN END
  191.     IF player.x < 0 THEN player.x = 0
  192.     IF player.x > _WIDTH(map) THEN player.x = _WIDTH(map)
  193.     IF player.y < 0 THEN player.y = 0
  194.     IF player.y > _HEIGHT(map) THEN player.y = _HEIGHT(map)
  195.  
  196.     adjustCamera
  197.  
  198.     'Draw Head
  199.     FOR sz = .25 TO 10 STEP .25
  200.         CIRCLE (player.x + camera.x, player.y + camera.y), sz, _RGB32(255, 166, 127)
  201.     NEXT sz
  202.     'Draw Smile
  203.     CIRCLE (player.x + camera.x, player.y + camera.y + 2), 7, _RGB32(255, 0, 0), _PI, 2 * _PI, .5
  204.     'Draw Eyes
  205.     CIRCLE (player.x + camera.x - 4, player.y + camera.y - 2), 1, _RGB32(0, 0, 255)
  206.     CIRCLE (player.x + camera.x + 4, player.y + camera.y - 2), 1, _RGB32(0, 0, 255)
  207.     'hat
  208.     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
  209.     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
  210.     'body
  211.     LINE (player.x + camera.x, player.y + camera.y + 10)-(player.x + camera.x, player.y + camera.y + 20), _RGB32(155, 0, 0)
  212.  
  213.     IF t > 7 THEN t = 0
  214.  
  215.     'rest of body
  216.     IF t = 0 THEN
  217.         'left arm
  218.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x - 15, player.y + camera.y + 25), _RGB32(155, 0, 0)
  219.         'right arm
  220.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x + 15, player.y + camera.y + 25), _RGB32(155, 0, 0)
  221.         'left leg
  222.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x - 15, player.y + camera.y + 35), _RGB32(155, 0, 0)
  223.         'right leg
  224.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x + 15, player.y + camera.y + 35), _RGB32(155, 0, 0)
  225.     END IF
  226.  
  227.     IF t = 1 OR t = 7 THEN
  228.         'left arm
  229.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x - 11, player.y + camera.y + 25), _RGB32(155, 0, 0)
  230.         'right arm
  231.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x + 11, player.y + camera.y + 25), _RGB32(155, 0, 0)
  232.         'left leg
  233.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x - 11, player.y + camera.y + 35), _RGB32(155, 0, 0)
  234.         'right leg
  235.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x + 11, player.y + camera.y + 35), _RGB32(155, 0, 0)
  236.     END IF
  237.  
  238.     IF t = 2 OR t = 6 THEN
  239.         'left arm
  240.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x - 9, player.y + camera.y + 24), _RGB32(155, 0, 0)
  241.         'right arm
  242.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x + 9, player.y + camera.y + 24), _RGB32(155, 0, 0)
  243.         'left leg
  244.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x - 9, player.y + camera.y + 35), _RGB32(155, 0, 0)
  245.         'right leg
  246.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x + 9, player.y + camera.y + 35), _RGB32(155, 0, 0)
  247.     END IF
  248.  
  249.     IF t = 3 OR t = 5 THEN
  250.         'left arm
  251.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x - 7, player.y + camera.y + 24), _RGB32(155, 0, 0)
  252.         'right arm
  253.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x + 7, player.y + camera.y + 24), _RGB32(155, 0, 0)
  254.         'left leg
  255.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x - 7, player.y + camera.y + 35), _RGB32(155, 0, 0)
  256.         'right leg
  257.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x + 7, player.y + camera.y + 35), _RGB32(155, 0, 0)
  258.     END IF
  259.  
  260.     IF t = 4 THEN
  261.         'left arm
  262.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x - 5, player.y + camera.y + 23), _RGB32(155, 0, 0)
  263.         'right arm
  264.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x + 5, player.y + camera.y + 23), _RGB32(155, 0, 0)
  265.         'left leg
  266.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x - 5, player.y + camera.y + 35), _RGB32(155, 0, 0)
  267.         'right leg
  268.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x + 5, player.y + camera.y + 35), _RGB32(155, 0, 0)
  269.     END IF
  270.  
  271.  
  272.     FOR check = -15 TO 15
  273.         IF POINT(player.x + check, player.y + check) = _RGB32(255, 255, 128) THEN
  274.             _DEST map
  275.             FOR sz = .2 TO 35 STEP .2
  276.                 CIRCLE (player.x + check, player.y + check), sz, _RGB32(127, 255, 127)
  277.             NEXT sz
  278.             GOSUB findgold:
  279.         END IF
  280.         IF POINT(player.x + check, player.y - check) = _RGB32(255, 255, 128) THEN
  281.             _DEST map
  282.             FOR sz = .2 TO 35 STEP .2
  283.                 CIRCLE (player.x + check, player.y - check), sz, _RGB32(127, 255, 127)
  284.             NEXT sz
  285.             GOSUB findgold:
  286.         END IF
  287.         IF POINT(player.x - check, player.y + check) = _RGB32(255, 255, 128) THEN
  288.             _DEST map
  289.             FOR sz = .2 TO 35 STEP .2
  290.                 CIRCLE (player.x - check, player.y + check), sz, _RGB32(127, 255, 127)
  291.             NEXT sz
  292.             GOSUB findgold:
  293.         END IF
  294.     NEXT check
  295.     _DISPLAY
  296.     _LIMIT 60
  297.  
  298. findgold:
  299. FOR snd = 400 TO 800 STEP 100
  300.     SOUND snd, .5
  301. NEXT snd
  302. score = score + 100
  303. score$ = STR$(score)
  304. level$ = STR$(level)
  305. _TITLE "Level: " + level$ + "   Score: " + score$
  306. IF score / 2000 = INT(score / 2000) THEN
  307.     level = level + 1
  308.     level$ = STR$(level)
  309.     _TITLE "Level: " + level$ + "   Score: " + score$
  310.     IF level = 21 THEN GOTO win:
  311.     GOTO start2:
  312.  
  313. done:
  314. LOCATE 10, 55: PRINT "G A M E     O V E R"
  315. FOR snd = 450 TO 150 STEP -25
  316.     SOUND snd, .5
  317. NEXT snd
  318. LOCATE 13, 55: PRINT "Again (Y/N)?"
  319. ag:
  320. ag$ = INKEY$
  321. IF ag$ = "y" OR ag$ = "Y" THEN GOTO start:
  322. IF ag$ = "n" OR ag$ = "N" THEN END
  323. GOTO ag:
  324.  
  325. win:
  326. LOCATE 10, 55: PRINT "G A M E     W O N ! ! ! ! ! ! !"
  327. FOR snd = 450 TO 150 STEP -25
  328.     SOUND snd, .5
  329. NEXT snd
  330. LOCATE 13, 55: PRINT "Again (Y/N)?"
  331. ag2:
  332. ag$ = INKEY$
  333. IF ag$ = "y" OR ag$ = "Y" THEN GOTO start:
  334. IF ag$ = "n" OR ag$ = "N" THEN END
  335. GOTO ag2:
  336.  
  337. 'Thanks to FelippeHeitor for this Sub and the camera code above.
  338. SUB adjustCamera
  339.     IF player.x + camera.x > _WIDTH / 2 OR player.x + camera.x < _WIDTH / 2 THEN
  340.         camera.x = _WIDTH / 2 - player.x
  341.     END IF
  342.     IF camera.x > 0 THEN camera.x = 0
  343.     IF camera.x < -(_WIDTH(map) - _WIDTH) THEN camera.x = -(_WIDTH(map) - _WIDTH)
  344.  
  345.     IF player.y + camera.y > _HEIGHT / 2 OR player.y + camera.y < _HEIGHT / 2 THEN
  346.         camera.y = _HEIGHT / 2 - player.y
  347.     END IF
  348.     IF camera.y > 0 THEN camera.y = 0
  349.     IF camera.y < -(_HEIGHT(map) - _HEIGHT) THEN camera.y = -(_HEIGHT(map) - _HEIGHT)
  350.  
Find The Gold - game by SierraKen 2.jpg
* Find The Gold - game by SierraKen 2.jpg (Filesize: 115.82 KB, Dimensions: 801x623, Views: 79)
« Last Edit: October 24, 2020, 06:49:17 pm by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Find The Gold!
« Reply #10 on: October 25, 2020, 11:26:21 am »
Well I definitely like your 2nd version of mountains and lake! Now if we can get the trees dark green to brown and wider at base than top... ;-))

Is it cherry picked or have you managed not to get trees in the lake? ;)
Ohp! no there's a tree in the lake, oh well ;-))

Oh and should lose the rivers coming down from sky!
« Last Edit: October 25, 2020, 11:30:27 am by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Find The Gold!
« Reply #11 on: October 25, 2020, 11:44:00 am »
Thanks B+! Well the rivers aren't actually in the sky, they are 2 different rivers on different hills. Because there is no sky in my game but I understand what you mean. Just pretend they are 2 different rivers. :) Good idea on the trees, I'll see what I can do. I don't have much time today so if I don't post anything, I'll try to post when my power comes back on around Wed. from the Public Safety Power Shut-Off.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Find The Gold!
« Reply #12 on: October 25, 2020, 12:03:03 pm »
Man that sucks about the power! Don't need another Colorado and California has enough fires already.

The overhead view of map is probably better for game just saying landscape looked better.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Find The Gold!
« Reply #13 on: October 25, 2020, 12:14:57 pm »
This might be a little off topic but does anyone have code for drawing isobars around say 3 or 4 hill or mountain peaks?

That would look good for overhead map and gold would be found around streams from mountains.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Find The Gold!
« Reply #14 on: October 25, 2020, 12:29:40 pm »
I got the trees really good now. :) I also decided to remove the creeks because after a few attempts, I couldn't figure out how to keep a creek on its own hill. It looks much cleaner without the creeks anyway. I also made a little less trees to ease up on memory.

Note: Don't use this one, the title bar is messed up. The fix is on the next forum page.

Code: QB64: [Select]
  1. 'Find the Gold! by SierraKen
  2. 'October 24, 2020
  3. 'Thanks for the great mapping code by FellipeHeitor and help from B+!
  4. 'Additions:
  5. 'Body, Arms, and Legs. Levels and 20 gold per level. Larger land area sizes. Lakes and Trees. 20 Level limit.
  6. 'Changed PAINT to CLS , _RGB32(0,200,0) which greatly improves the loading speed.
  7. 'Added 4 times the amount of trees and made 3 levels of mountains.
  8. 'Added random creeks. Added twice the lakes with random shapes.
  9. 'Changed screen size to 800 x 600 to be compatible with all players.
  10. 'Added 100 seconds to level time, to 400 for level 1.
  11. 'Slowed player speed from 10 to 8.
  12. 'Changed to a happier sound when getting gold.
  13. 'Changed color after you get the gold from brown to green.
  14. 'Added WASD keys to move player along with arrow keys.
  15. 'Removed the square mountains and made more realistic hills.
  16. 'Put the lakes on the ground, before everything else.
  17. 'Made trees look better.
  18. 'Removed creeks.
  19.  
  20. SCREEN _NEWIMAGE(800, 600, 32)
  21.  
  22. TYPE object
  23.     x AS SINGLE
  24.     y AS SINGLE
  25.  
  26. DIM SHARED player AS object
  27. DIM SHARED camera AS object
  28. DIM playerSpeed AS SINGLE
  29.  
  30. _TITLE "Loading....."
  31.  
  32. start:
  33. score = 0
  34. level = 1
  35.  
  36. start2:
  37. player.x = _WIDTH / 2
  38. player.y = _HEIGHT / 2
  39.  
  40. map = _NEWIMAGE(_WIDTH * 7, _HEIGHT * 7, 32)
  41.  
  42. _DEST map
  43.  
  44. CLS , _RGB32(0, 200, 0)
  45. _LIMIT 2000
  46.  
  47. 'Lakes
  48. FOR lakes = 1 TO 100
  49.     w = RND
  50.     h = RND
  51.     sze = (RND * 250) + 100
  52.     shape = RND
  53.     FOR sz = .25 TO sze STEP .25
  54.         CIRCLE (w * _WIDTH, h * _HEIGHT), sz, _RGB32(0, 128, 255), , , shape
  55.     NEXT sz
  56. NEXT lakes
  57.  
  58.  
  59. 'Hills
  60. FOR hills = 1 TO 1200
  61.     xx = (RND * _WIDTH)
  62.     sz = INT(RND * 100) + 200
  63.     shape = RND
  64.     hillcolors:
  65.     c1 = INT(RND * 100) + 55
  66.     c2 = INT(RND * 100) + 55
  67.     c3 = INT(RND * 100) + 55
  68.     IF c1 = 255 AND c2 = 255 AND c3 = 128 THEN GOTO hillcolors:
  69.     yy = yy + 4
  70.     FOR hill = 1 TO sz STEP .25
  71.         hh = hh + .025
  72.         IF hh > 100 THEN hh = 100
  73.         cc1 = c1 + hh
  74.         cc2 = c2 + hh
  75.         cc3 = c3 + hh
  76.         CIRCLE (xx, yy), hill, _RGB32(cc1, cc2, cc3), 2 * _PI, _PI, shape
  77.     NEXT hill
  78.     hh = 0
  79. NEXT hills
  80. yy = 0
  81.  
  82.  
  83. 'Trees
  84. FOR trees = 1 TO 1000
  85.     tx = RND
  86.     tx = tx * _WIDTH
  87.     ty = RND
  88.     ty = ty * _HEIGHT
  89.     tsz = (RND * 40) + 10
  90.     LINE (tx, ty)-(tx, ty + tsz + 5), _RGB32(188, 127, 127)
  91.     FOR branches = ty TO ty + tsz STEP 3
  92.         trim = trim + 2
  93.         LINE (tx, branches)-(tx - trim, branches + 5), _RGB32(0, 183, 127)
  94.         LINE (tx, branches)-(tx + trim, branches + 5), _RGB32(0, 183, 127)
  95.     NEXT branches
  96.     trim = 0
  97. NEXT trees
  98.  
  99. 'Place Gold
  100. FOR gold = 1 TO 20
  101.     gold:
  102.     w2 = INT(RND * _WIDTH) - 40
  103.     h2 = INT(RND * _HEIGHT) - 40
  104.     IF w2 < 40 THEN w2 = 40
  105.     IF h2 < 40 THEN h2 = 40
  106.     IF POINT(w2, h2) = _RGB32(255, 255, 128) THEN GOTO gold:
  107.     IF POINT(w2, h2) = _RGB32(0, 0, 0) THEN GOTO gold:
  108.     'Gold
  109.     COLOR _RGB32(0, 0, 0), _RGB32(255, 255, 128)
  110.     _PRINTSTRING (w2, h2), "GOLD"
  111. NEXT gold
  112.  
  113.  
  114.  
  115. playerSpeed = 8
  116.  
  117. CONST keyUP = 18432
  118. CONST keyDOWN = 20480
  119. CONST keyLEFT = 19200
  120. CONST keyRIGHT = 19712
  121. CONST keyESC = 27
  122. _PUTIMAGE (camera.x, camera.y), map
  123.  
  124. LOCATE 3, 30: PRINT "Use the arrow keys (or WASD keys) to find 20 gold bars per level."
  125. LOCATE 4, 30: PRINT "Every level will have a shorter time."
  126. LOCATE 5, 30: PRINT "After Level 20 you win the game."
  127. LOCATE 10, 40: PRINT "Press Any Key To Begin."
  128.  
  129. pause:
  130. a$ = INKEY$
  131. IF a$ <> "" THEN GOTO begin:
  132. GOTO pause:
  133.  
  134. begin:
  135.  
  136. seconds = INT(TIMER)
  137.     CLS
  138.     leveltime = level * 5
  139.     gametime = (405 - leveltime) - (INT(TIMER) - seconds)
  140.     _PUTIMAGE (camera.x, camera.y), map
  141.     LOCATE 1, 1: PRINT "Time Left: "; gametime
  142.     IF gametime < 1 THEN GOTO done:
  143.     IF _KEYDOWN(keyUP) OR _KEYDOWN(119) THEN
  144.         player.y = player.y - playerSpeed
  145.         t = t + 1
  146.     END IF
  147.     IF _KEYDOWN(keyDOWN) OR _KEYDOWN(115) THEN
  148.         player.y = player.y + playerSpeed
  149.         t = t + 1
  150.     END IF
  151.     IF _KEYDOWN(keyLEFT) OR _KEYDOWN(97) THEN
  152.         player.x = player.x - playerSpeed
  153.         t = t + 1
  154.     END IF
  155.     IF _KEYDOWN(keyRIGHT) OR _KEYDOWN(100) THEN
  156.         player.x = player.x + playerSpeed
  157.         t = t + 1
  158.     END IF
  159.     IF _KEYDOWN(keyESC) THEN END
  160.     IF player.x < 0 THEN player.x = 0
  161.     IF player.x > _WIDTH(map) THEN player.x = _WIDTH(map)
  162.     IF player.y < 0 THEN player.y = 0
  163.     IF player.y > _HEIGHT(map) THEN player.y = _HEIGHT(map)
  164.  
  165.     adjustCamera
  166.  
  167.     'Draw Head
  168.     FOR sz = .25 TO 10 STEP .25
  169.         CIRCLE (player.x + camera.x, player.y + camera.y), sz, _RGB32(255, 166, 127)
  170.     NEXT sz
  171.     'Draw Smile
  172.     CIRCLE (player.x + camera.x, player.y + camera.y + 2), 7, _RGB32(255, 0, 0), _PI, 2 * _PI, .5
  173.     'Draw Eyes
  174.     CIRCLE (player.x + camera.x - 4, player.y + camera.y - 2), 1, _RGB32(0, 0, 255)
  175.     CIRCLE (player.x + camera.x + 4, player.y + camera.y - 2), 1, _RGB32(0, 0, 255)
  176.     'hat
  177.     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
  178.     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
  179.     'body
  180.     LINE (player.x + camera.x, player.y + camera.y + 10)-(player.x + camera.x, player.y + camera.y + 20), _RGB32(155, 0, 0)
  181.  
  182.     IF t > 7 THEN t = 0
  183.  
  184.     'rest of body
  185.     IF t = 0 THEN
  186.         'left arm
  187.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x - 15, player.y + camera.y + 25), _RGB32(155, 0, 0)
  188.         'right arm
  189.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x + 15, player.y + camera.y + 25), _RGB32(155, 0, 0)
  190.         'left leg
  191.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x - 15, player.y + camera.y + 35), _RGB32(155, 0, 0)
  192.         'right leg
  193.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x + 15, player.y + camera.y + 35), _RGB32(155, 0, 0)
  194.     END IF
  195.  
  196.     IF t = 1 OR t = 7 THEN
  197.         'left arm
  198.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x - 11, player.y + camera.y + 25), _RGB32(155, 0, 0)
  199.         'right arm
  200.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x + 11, player.y + camera.y + 25), _RGB32(155, 0, 0)
  201.         'left leg
  202.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x - 11, player.y + camera.y + 35), _RGB32(155, 0, 0)
  203.         'right leg
  204.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x + 11, player.y + camera.y + 35), _RGB32(155, 0, 0)
  205.     END IF
  206.  
  207.     IF t = 2 OR t = 6 THEN
  208.         'left arm
  209.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x - 9, player.y + camera.y + 24), _RGB32(155, 0, 0)
  210.         'right arm
  211.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x + 9, player.y + camera.y + 24), _RGB32(155, 0, 0)
  212.         'left leg
  213.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x - 9, player.y + camera.y + 35), _RGB32(155, 0, 0)
  214.         'right leg
  215.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x + 9, player.y + camera.y + 35), _RGB32(155, 0, 0)
  216.     END IF
  217.  
  218.     IF t = 3 OR t = 5 THEN
  219.         'left arm
  220.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x - 7, player.y + camera.y + 24), _RGB32(155, 0, 0)
  221.         'right arm
  222.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x + 7, player.y + camera.y + 24), _RGB32(155, 0, 0)
  223.         'left leg
  224.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x - 7, player.y + camera.y + 35), _RGB32(155, 0, 0)
  225.         'right leg
  226.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x + 7, player.y + camera.y + 35), _RGB32(155, 0, 0)
  227.     END IF
  228.  
  229.     IF t = 4 THEN
  230.         'left arm
  231.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x - 5, player.y + camera.y + 23), _RGB32(155, 0, 0)
  232.         'right arm
  233.         LINE (player.x + camera.x, player.y + camera.y + 13)-(player.x + camera.x + 5, player.y + camera.y + 23), _RGB32(155, 0, 0)
  234.         'left leg
  235.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x - 5, player.y + camera.y + 35), _RGB32(155, 0, 0)
  236.         'right leg
  237.         LINE (player.x + camera.x, player.y + camera.y + 20)-(player.x + camera.x + 5, player.y + camera.y + 35), _RGB32(155, 0, 0)
  238.     END IF
  239.  
  240.  
  241.     FOR check = -15 TO 15
  242.         IF POINT(player.x + check, player.y + check) = _RGB32(255, 255, 128) THEN
  243.             _DEST map
  244.             FOR sz = .2 TO 35 STEP .2
  245.                 CIRCLE (player.x + check, player.y + check), sz, _RGB32(127, 255, 127)
  246.             NEXT sz
  247.             GOSUB findgold:
  248.         END IF
  249.         IF POINT(player.x + check, player.y - check) = _RGB32(255, 255, 128) THEN
  250.             _DEST map
  251.             FOR sz = .2 TO 35 STEP .2
  252.                 CIRCLE (player.x + check, player.y - check), sz, _RGB32(127, 255, 127)
  253.             NEXT sz
  254.             GOSUB findgold:
  255.         END IF
  256.         IF POINT(player.x - check, player.y + check) = _RGB32(255, 255, 128) THEN
  257.             _DEST map
  258.             FOR sz = .2 TO 35 STEP .2
  259.                 CIRCLE (player.x - check, player.y + check), sz, _RGB32(127, 255, 127)
  260.             NEXT sz
  261.             GOSUB findgold:
  262.         END IF
  263.     NEXT check
  264.     _DISPLAY
  265.     _LIMIT 60
  266.  
  267. findgold:
  268. FOR snd = 400 TO 800 STEP 100
  269.     SOUND snd, .5
  270. NEXT snd
  271. score = score + 100
  272. score$ = STR$(score)
  273. level$ = STR$(level)
  274. _TITLE "Level: " + level$ + "   Score: " + score$
  275. IF score / 2000 = INT(score / 2000) THEN
  276.     level = level + 1
  277.     level$ = STR$(level)
  278.     _TITLE "Level: " + level$ + "   Score: " + score$
  279.     IF level = 21 THEN GOTO win:
  280.     GOTO start2:
  281.  
  282. done:
  283. LOCATE 10, 45: PRINT "G A M E     O V E R"
  284. FOR snd = 450 TO 150 STEP -25
  285.     SOUND snd, .5
  286. NEXT snd
  287. LOCATE 13, 45: PRINT "Again (Y/N)?"
  288. ag:
  289. ag$ = INKEY$
  290. IF ag$ = "y" OR ag$ = "Y" THEN GOTO start:
  291. IF ag$ = "n" OR ag$ = "N" THEN END
  292. GOTO ag:
  293.  
  294. win:
  295. LOCATE 10, 45: PRINT "G A M E     W O N ! ! ! ! ! ! !"
  296. FOR snd = 450 TO 150 STEP -25
  297.     SOUND snd, .5
  298. NEXT snd
  299. LOCATE 13, 45: PRINT "Again (Y/N)?"
  300. ag2:
  301. ag$ = INKEY$
  302. IF ag$ = "y" OR ag$ = "Y" THEN GOTO start:
  303. IF ag$ = "n" OR ag$ = "N" THEN END
  304. GOTO ag2:
  305.  
  306. 'Thanks to FelippeHeitor for this Sub and the camera code above.
  307. SUB adjustCamera
  308.     IF player.x + camera.x > _WIDTH / 2 OR player.x + camera.x < _WIDTH / 2 THEN
  309.         camera.x = _WIDTH / 2 - player.x
  310.     END IF
  311.     IF camera.x > 0 THEN camera.x = 0
  312.     IF camera.x < -(_WIDTH(map) - _WIDTH) THEN camera.x = -(_WIDTH(map) - _WIDTH)
  313.  
  314.     IF player.y + camera.y > _HEIGHT / 2 OR player.y + camera.y < _HEIGHT / 2 THEN
  315.         camera.y = _HEIGHT / 2 - player.y
  316.     END IF
  317.     IF camera.y > 0 THEN camera.y = 0
  318.     IF camera.y < -(_HEIGHT(map) - _HEIGHT) THEN camera.y = -(_HEIGHT(map) - _HEIGHT)
  319.  
« Last Edit: October 25, 2020, 12:40:29 pm by SierraKen »