Author Topic: Gold Mining Simulation  (Read 3956 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Gold Mining Simulation
« on: January 13, 2020, 12:49:20 am »
Using the circle-fill SUB (finally lol), etc. I was playing around with graphics tonight like I often do and ended up making this Gold Mining Simulation. You watch him make mine shafts and go around and hunt for gold where he hasn't dug before. When he hits a $ it makes a short sound and gets a random amount of money. This is a non-stop game. When just about the whole screen has been mined, he goes to a new screen.  :) You can slow him down and speed him up with the arrow keys and turn the sound off and on with the S key. You also can Pause with the Space Bar. I'm thinking about having him die in cave-ins but so far he doesn't get hurt. Hopefully Pete will like this. :)

Code: QB64: [Select]
  1. 'Gold Mining Simulation"
  2. 'By Ken G."
  3. 'Made on January 12, 2020.
  4. 'I might add more to this later, suggestions welcomes.
  5. 'Freeware
  6. _TITLE "Gold Mining Simulation"
  7. PRINT "                             Gold Mining Simulation"
  8. PRINT "                                   By Ken G."
  9. PRINT "           Keys: Speed Control  = Up and Down Arrow Keys"
  10. PRINT "                 Pause (off/on) = Space Bar"
  11. PRINT "                 Sound (off/on) = S"
  12. PRINT "                 Quit           = Esc"
  13. PRINT "            When the miner hits gold, he receives a random amount of money."
  14. PRINT "            This is a non-stop simulation so press Esc or click X to end."
  15. INPUT "                             Press Enter to start.", bg$
  16.  
  17. lim = 50
  18. start:
  19. t = 0
  20. snd$ = "On"
  21. SCREEN _NEWIMAGE(800, 600, 32)
  22. LINE (0, 0)-(800, 600), _RGB32(128, 128, 6), BF
  23. x = 400: y = 300
  24. c1 = 156: c2 = 156: c3 = 12
  25. COLOR _RGB32(255, 255, 127), _RGB32(128, 128, 6)
  26. FOR gold = 1 TO 100
  27.     gx = INT(RND * 790) + 5
  28.     gy = INT(RND * 590) + 5
  29.     _PRINTSTRING (gx, gy), "$"
  30. NEXT gold
  31.     _LIMIT lim
  32.     again:
  33.     xx = (RND * 10) - 5
  34.     IF xx = 0 THEN xx = .1
  35.     yy = (RND * 10) - 5
  36.     IF yy = 0 THEN yy = .1
  37.     x = x + xx
  38.     y = y + yy
  39.     IF x < 0 THEN x = 800
  40.     IF y < 0 THEN y = 600
  41.     IF x > 800 THEN x = 0
  42.     IF y > 600 THEN y = 0
  43.     IF POINT(x, y) <> _RGB32(128, 128, 6) THEN GOTO again:
  44.     CircleFill x, y, 5, _RGB32(c1, c2, c3)
  45.     a$ = INKEY$
  46.     IF a$ = "S" OR a$ = "s" THEN sd = sd + 1: _DELAY .01
  47.     IF sd = 1 THEN sd2 = 1: snd$ = "Off": _TITLE "Speed: " + lim$ + "    Sound: " + snd$ + "     Money: " + m$
  48.     IF sd = 2 THEN sd2 = 0: sd = 0: snd$ = "On": _TITLE "Speed: " + lim$ + "    Sound: " + snd$ + "     Money: " + m$
  49.     IF a$ = CHR$(0) + CHR$(80) THEN
  50.         lim = lim - 5
  51.         lim$ = STR$(lim)
  52.         _TITLE "Speed: " + lim$ + "    Sound: " + snd$ + "     Money: " + m$
  53.     END IF
  54.     IF lim < 10 THEN lim = 10
  55.     IF a$ = CHR$(0) + CHR$(72) THEN
  56.         lim = lim + 5
  57.         lim$ = STR$(lim)
  58.         _TITLE "Speed: " + lim$ + "    Sound: " + snd$ + "     Money: " + m$
  59.     END IF
  60.     IF lim > 500 THEN lim = 500
  61.     IF a$ = CHR$(27) THEN END
  62.     IF a$ = " " THEN
  63.         pausing:
  64.         a2$ = INKEY$
  65.         IF a2$ = " " THEN GOTO going:
  66.         GOTO pausing:
  67.     END IF
  68.     going:
  69.     t = t + 1
  70.     IF t > 10000 THEN GOTO start:
  71.     FOR ch = -5 TO 5
  72.         IF POINT(x + ch, y + ch) = _RGB32(255, 255, 127) THEN
  73.             LINE (x - 5, y - 5)-(x + 5, y + 5), _RGB32(128, 128, 6), BF
  74.             IF sd2 = 1 THEN GOTO skip:
  75.             SOUND 750, .25
  76.             SOUND 850, .25
  77.             skip:
  78.             RANDOMIZE TIMER
  79.             gd = INT(RND * 1000)
  80.             money = money + gd
  81.             m$ = STR$(money)
  82.             lim$ = STR$(lim)
  83.             _TITLE "Speed: " + lim$ + "    Sound: " + snd$ + "     Money: " + m$
  84.         END IF
  85.     NEXT ch
  86.  
  87. SUB CircleFill (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  88.     ' CX = center x coordinate
  89.     ' CY = center y coordinate
  90.     '  R = radius
  91.     '  C = fill color
  92.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  93.     DIM X AS INTEGER, Y AS INTEGER
  94.     Radius = ABS(R)
  95.     RadiusError = -Radius
  96.     X = Radius
  97.     Y = 0
  98.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  99.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  100.     WHILE X > Y
  101.         RadiusError = RadiusError + Y * 2 + 1
  102.         IF RadiusError >= 0 THEN
  103.             IF X <> Y + 1 THEN
  104.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  105.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  106.             END IF
  107.             X = X - 1
  108.             RadiusError = RadiusError - X * 2
  109.         END IF
  110.         Y = Y + 1
  111.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  112.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  113.     WEND
  114.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Gold Mining Simulation
« Reply #1 on: January 13, 2020, 02:19:57 am »
Ken why not use arrow keys to direct the digger? A few less $ signs and after a timer runs out, switch to new screen money or not. Next thing you know, you could be running away or competing with mutant mole people for $.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Gold Mining Simulation
« Reply #2 on: January 13, 2020, 01:32:08 pm »
LOL that sounds great B+! Make it more like the game Dig Dug. Thanks. I'll look into this. It won't be just like Dig Dug though but a little similar. Not sure if I will have bad guys, we'll see what I come up with.  :)

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Gold Mining Simulation
« Reply #3 on: January 13, 2020, 03:41:19 pm »
Here is what I got so far. If you hit a bomb you explode. You start with 5 players. I changed the $ to yellow bricks. And if the time runs out, the game is over. I also added level numbers. I might add more detail to the screen, it looks VERY Atari 2600-ish. hehe But it's still fun. Use the arrow keys to move and change direction.

Also, I know it changes levels before you get all the bricks. I might change the bricks to their own array, but this is OK for me.

Code: QB64: [Select]
  1. 'Gold Mining Simulation"
  2. 'By Ken G."
  3. 'Made on January 13, 2020.
  4. 'Freeware
  5. _TITLE "Gold Mining Simulation"
  6. PRINT "                             Gold Mining Simulation"
  7. PRINT "                                   By Ken G."
  8. PRINT "           Keys: Move Miner     = Arrow Keys"
  9. PRINT "                 Pause (off/on) = Space Bar"
  10. PRINT "                 Sound (off/on) = S"
  11. PRINT "                 Quit           = Esc"
  12. PRINT "            When the miner hits gold, he receives a random amount of money."
  13. PRINT "            Game is over if the time runs out on that level."
  14. PRINT "            And stay away from the bombs!"
  15. INPUT "                             Press Enter to start.", bg$
  16. begin:
  17. pl = 5
  18. level = 0
  19. start:
  20. level = level + 1
  21. level$ = STR$(level)
  22. gg = 0
  23. d = 0
  24. t = 10000
  25. snd$ = "On"
  26. SCREEN _NEWIMAGE(800, 600, 32)
  27. LINE (0, 0)-(800, 600), _RGB32(128, 128, 6), BF
  28. x = 400: y = 300
  29. FOR gold = 1 TO 25
  30.     gx = INT(RND * 790) + 5
  31.     gy = INT(RND * 590) + 5
  32.     LINE (gx - 5, gy - 5)-(gx + 5, gy + 5), _RGB32(255, 255, 127), BF
  33. NEXT gold
  34. FOR bombs = 1 TO 50
  35.     againbomb:
  36.     bx = INT(RND * 790) + 5
  37.     by = INT(RND * 590) + 5
  38.     IF bx > 350 AND bx < 450 AND by > 250 AND by < 350 THEN GOTO againbomb:
  39.     FOR sz = .25 TO 10 STEP .25
  40.         CIRCLE (bx, by), sz, _RGB32(0, 0, 0)
  41.     NEXT sz
  42. NEXT bombs
  43.  
  44.     _LIMIT 100
  45.     IF x < 0 THEN x = 800
  46.     IF y < 0 THEN y = 600
  47.     IF x > 800 THEN x = 0
  48.     IF y > 600 THEN y = 0
  49.     CircleFill x, y, 5, _RGB32(156, 156, 12)
  50.     a$ = INKEY$
  51.     IF a$ = "S" OR a$ = "s" THEN sd = sd + 1: _DELAY .01
  52.     IF sd = 1 THEN sd2 = 1: snd$ = "Off"
  53.     IF sd = 2 THEN sd2 = 0: sd = 0: snd$ = "On"
  54.     IF a$ = CHR$(0) + CHR$(72) THEN d = 1
  55.     IF a$ = CHR$(0) + CHR$(80) THEN d = 2
  56.     IF a$ = CHR$(0) + CHR$(77) THEN d = 3
  57.     IF a$ = CHR$(0) + CHR$(75) THEN d = 4
  58.     IF d = 1 THEN y = y - 1
  59.     IF d = 2 THEN y = y + 1
  60.     IF d = 3 THEN x = x + 1
  61.     IF d = 4 THEN x = x - 1
  62.     IF a$ = CHR$(27) THEN END
  63.     IF a$ = " " THEN
  64.         pausing:
  65.         a2$ = INKEY$
  66.         IF a2$ = " " THEN GOTO going:
  67.         GOTO pausing:
  68.     END IF
  69.     going:
  70.     t = t - 1
  71.     t$ = STR$(t)
  72.     pl$ = STR$(pl)
  73.     _TITLE "Time: " + t$ + "     Sound: " + snd$ + "    Players: " + pl$ + "    Level: " + level$ + "    Money: " + m$
  74.     IF t < 1 THEN GOTO gameover:
  75.     FOR ch = -7 TO 7
  76.         IF POINT(x + ch, y + ch) = _RGB32(255, 255, 127) THEN
  77.             LINE (x - 15, y - 15)-(x + 15, y + 15), _RGB32(156, 156, 12), BF
  78.             IF sd2 = 1 THEN GOTO skip:
  79.             SOUND 750, .25
  80.             SOUND 850, .25
  81.             skip:
  82.             RANDOMIZE TIMER
  83.             gd = INT(RND * 1000)
  84.             money = money + gd
  85.             m$ = STR$(money)
  86.             gg = gg + 1
  87.             IF gg = 25 THEN GOTO start:
  88.         END IF
  89.         IF POINT(x + ch, y + ch) = _RGB32(0, 0, 0) THEN
  90.             FOR ex = .25 TO 30 STEP .25
  91.                 CIRCLE (x, y), ex, _RGB32(156, 156, 12)
  92.             NEXT ex
  93.             SOUND 150, .5
  94.             pl = pl - 1
  95.             IF pl = 0 THEN GOTO gameover:
  96.         END IF
  97.     NEXT ch
  98. gameover:
  99. _TITLE "Time: " + t$ + "     Sound: " + snd$ + "    Players: " + pl$ + "    Level: " + level$ + "    Money: " + m$
  100. LOCATE 20, 30: PRINT "G A M E   O V E R"
  101. LOCATE 23, 30: INPUT "Again (Y/N):"; ag$
  102. IF LEFT$(ag$, 1) = "y" OR LEFT$(ag$, 1) = "Y" THEN GOTO begin:
  103.  
  104. SUB CircleFill (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  105.     ' CX = center x coordinate
  106.     ' CY = center y coordinate
  107.     '  R = radius
  108.     '  C = fill color
  109.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  110.     DIM X AS INTEGER, Y AS INTEGER
  111.     Radius = ABS(R)
  112.     RadiusError = -Radius
  113.     X = Radius
  114.     Y = 0
  115.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  116.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  117.     WHILE X > Y
  118.         RadiusError = RadiusError + Y * 2 + 1
  119.         IF RadiusError >= 0 THEN
  120.             IF X <> Y + 1 THEN
  121.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  122.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  123.             END IF
  124.             X = X - 1
  125.             RadiusError = RadiusError - X * 2
  126.         END IF
  127.         Y = Y + 1
  128.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  129.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  130.     WEND
  131.  
  132.  
« Last Edit: January 13, 2020, 03:54:53 pm by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Gold Mining Simulation
« Reply #4 on: January 13, 2020, 08:17:46 pm »
Hey not bad :)

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Gold Mining Simulation
« Reply #5 on: January 13, 2020, 10:40:46 pm »
Thanks :)

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Gold Mining Simulation
« Reply #6 on: January 14, 2020, 03:45:09 pm »
This morning I remembered that I forgot to bi-pass the bomb sound when the sound is turned off. So here's the fix:

Code: QB64: [Select]
  1. 'Gold Mining Simulation"
  2. 'By Ken G."
  3. 'Made on January 13, 2020.
  4. 'Freeware
  5. _TITLE "Gold Mining Simulation"
  6. PRINT "                             Gold Mining Simulation"
  7. PRINT "                                   By Ken G."
  8. PRINT "           Keys: Move Miner     = Arrow Keys"
  9. PRINT "                 Pause (off/on) = Space Bar"
  10. PRINT "                 Sound (off/on) = S"
  11. PRINT "                 Quit           = Esc"
  12. PRINT "            When the miner hits gold, he receives a random amount of money."
  13. PRINT "            Game is over if the time runs out on that level."
  14. PRINT "            And stay away from the bombs!"
  15. INPUT "                             Press Enter to start.", bg$
  16. begin:
  17. pl = 5
  18. level = 0
  19. start:
  20. level = level + 1
  21. level$ = STR$(level)
  22. gg = 0
  23. d = 0
  24. t = 10000
  25. snd$ = "On"
  26. SCREEN _NEWIMAGE(800, 600, 32)
  27. LINE (0, 0)-(800, 600), _RGB32(128, 128, 6), BF
  28. x = 400: y = 300
  29. FOR gold = 1 TO 25
  30.     gx = INT(RND * 790) + 5
  31.     gy = INT(RND * 590) + 5
  32.     LINE (gx - 5, gy - 5)-(gx + 5, gy + 5), _RGB32(255, 255, 127), BF
  33. NEXT gold
  34. FOR bombs = 1 TO 50
  35.     againbomb:
  36.     bx = INT(RND * 790) + 5
  37.     by = INT(RND * 590) + 5
  38.     IF bx > 350 AND bx < 450 AND by > 250 AND by < 350 THEN GOTO againbomb:
  39.     FOR sz = .25 TO 10 STEP .25
  40.         CIRCLE (bx, by), sz, _RGB32(0, 0, 0)
  41.     NEXT sz
  42. NEXT bombs
  43.  
  44.     _LIMIT 100
  45.     IF x < 0 THEN x = 800
  46.     IF y < 0 THEN y = 600
  47.     IF x > 800 THEN x = 0
  48.     IF y > 600 THEN y = 0
  49.     CircleFill x, y, 5, _RGB32(156, 156, 12)
  50.     a$ = INKEY$
  51.     IF a$ = "S" OR a$ = "s" THEN sd = sd + 1: _DELAY .01
  52.     IF sd = 1 THEN sd2 = 1: snd$ = "Off"
  53.     IF sd = 2 THEN sd2 = 0: sd = 0: snd$ = "On"
  54.     IF a$ = CHR$(0) + CHR$(72) THEN d = 1
  55.     IF a$ = CHR$(0) + CHR$(80) THEN d = 2
  56.     IF a$ = CHR$(0) + CHR$(77) THEN d = 3
  57.     IF a$ = CHR$(0) + CHR$(75) THEN d = 4
  58.     IF d = 1 THEN y = y - 1
  59.     IF d = 2 THEN y = y + 1
  60.     IF d = 3 THEN x = x + 1
  61.     IF d = 4 THEN x = x - 1
  62.     IF a$ = CHR$(27) THEN END
  63.     IF a$ = " " THEN
  64.         pausing:
  65.         a2$ = INKEY$
  66.         IF a2$ = " " THEN GOTO going:
  67.         GOTO pausing:
  68.     END IF
  69.     going:
  70.     t = t - 1
  71.     t$ = STR$(t)
  72.     pl$ = STR$(pl)
  73.     _TITLE "Time: " + t$ + "     Sound: " + snd$ + "    Players: " + pl$ + "    Level: " + level$ + "    Money: " + m$
  74.     IF t < 1 THEN GOTO gameover:
  75.     FOR ch = -7 TO 7
  76.         IF POINT(x + ch, y + ch) = _RGB32(255, 255, 127) THEN
  77.             LINE (x - 15, y - 15)-(x + 15, y + 15), _RGB32(156, 156, 12), BF
  78.             IF sd2 = 1 THEN GOTO skip:
  79.             SOUND 750, .25
  80.             SOUND 850, .25
  81.             skip:
  82.             RANDOMIZE TIMER
  83.             gd = INT(RND * 1000)
  84.             money = money + gd
  85.             m$ = STR$(money)
  86.             gg = gg + 1
  87.             IF gg = 25 THEN GOTO start:
  88.         END IF
  89.         IF POINT(x + ch, y + ch) = _RGB32(0, 0, 0) THEN
  90.             FOR ex = .25 TO 30 STEP .25
  91.                 CIRCLE (x, y), ex, _RGB32(156, 156, 12)
  92.             NEXT ex
  93.             IF sd2 = 1 THEN GOTO skip2:
  94.             SOUND 150, .5
  95.             skip2:
  96.             pl = pl - 1
  97.             IF pl = 0 THEN GOTO gameover:
  98.         END IF
  99.     NEXT ch
  100. gameover:
  101. _TITLE "Time: " + t$ + "     Sound: " + snd$ + "    Players: " + pl$ + "    Level: " + level$ + "    Money: " + m$
  102. LOCATE 20, 30: PRINT "G A M E   O V E R"
  103. LOCATE 23, 30: INPUT "Again (Y/N):"; ag$
  104. IF LEFT$(ag$, 1) = "y" OR LEFT$(ag$, 1) = "Y" THEN GOTO begin:
  105.  
  106. SUB CircleFill (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  107.     ' CX = center x coordinate
  108.     ' CY = center y coordinate
  109.     '  R = radius
  110.     '  C = fill color
  111.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  112.     DIM X AS INTEGER, Y AS INTEGER
  113.     Radius = ABS(R)
  114.     RadiusError = -Radius
  115.     X = Radius
  116.     Y = 0
  117.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  118.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  119.     WHILE X > Y
  120.         RadiusError = RadiusError + Y * 2 + 1
  121.         IF RadiusError >= 0 THEN
  122.             IF X <> Y + 1 THEN
  123.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  124.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  125.             END IF
  126.             X = X - 1
  127.             RadiusError = RadiusError - X * 2
  128.         END IF
  129.         Y = Y + 1
  130.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  131.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  132.     WEND
  133.