Author Topic: Practicing Coding Game  (Read 4556 times)

0 Members and 1 Guest are viewing this topic.

Offline eddy498

  • Newbie
  • Posts: 25
    • View Profile
Practicing Coding Game
« on: March 20, 2019, 07:56:08 pm »
Im trying to write a code for a quick small cave adventure game.
Right now all i have is this

Code: QB64: [Select]
  1. _TITLE "Little Cave"
  2. DIM SHARED scrn&, left&, right&, forward&, back&
  3. DIM SHARED black&, white&, green&, gold&
  4. DIM SHARED gold, counter
  5. scrn& = _NEWIMAGE(800, 600, 32)
  6.  
  7. SCREEN scrn&
  8. CALL MakeColors
  9. CALL MakeCaveEntrance
  10. CALL MakeCaveRoom
  11. CALL MakeSlime
  12. CALL MakeTreasure
  13.  
  14. 'make a timer
  15. ON TIMER(t, 1) Countup
  16. sec = 0
  17.  
  18. _DEST display&
  19. gameover$ = "false"
  20.     CLS
  21.     _PUTIMAGE (0, 0), cave&
  22.     _PRINTSTRING (375, 10), "Time: " + STR$(hrs) + ":" + STR$(mins) + STR$(sec)
  23.     _DISPLAY
  24.  
  25.  
  26.  
  27.  
  28.  
  29. LOOP UNTIL gameover$ = "true"
  30.     _DISPLAY
  31.  
  32. SUB Countup
  33.     mins = 0
  34.     hrs = 0
  35.     sec = sec + 1
  36.     IF sec >= 60 THEN
  37.         min = FIX(counter / 60)
  38.         sec = sec - (60 * mins)
  39.     END IF
  40.     IF mins >= 60 THEN
  41.         hrs = FIX(min / 60)
  42.         mins = mins - (60 * hrs)
  43.     END IF
  44.  
  45.  
  46. SUB MakeColors
  47.     white& = _RGB(225, 225, 225)
  48.     black& = _RGB(0, 0, 0)
  49.     green& = _RGB(0, 255, 0)
  50.     gold& = _RGB(255, 215, 0)
  51.     grey& = _RGB(125, 125, 125)
  52.  
  53. SUB MakeSlime
  54.     slime& = _NEWIMAGE(60, 60)
  55.     _DEST slime&
  56.     'draw the slime
  57.     CIRCLE (50, 50), black&
  58.     CIRCLE (48, 48), green&
  59.  
  60. SUB MakeTreasure
  61.     treasure& = _NEWIMAGE(60, 60)
  62.     _DEST treasure&
  63.     CIRCLE (20, 20), 20, black&
  64.     PAINT (20, 10), black&
  65.     CIRCLE (20, 20), 17, gold&
  66.     PAINT (20, 20), gold&
  67.     LINE (0, 20)-(40, 49), black&, BF
  68.     LINE (2, 22)-(38, 45), gold, BF
  69.     LINE (17, 17)-(23, 25), black&, BF
  70.  
  71. SUB MakeCaveEntrance
  72.     cave& = _NEWIMAGE(800, 600)
  73.     _DEST cave&
  74.     LINE (0, 0)-(800, 600), black&, BF
  75.     CIRCLE (400, 300), 100, grey&
  76.     PAINT (400, 300), grey&
  77.  
  78. SUB MakeCaveRoom
  79.     room& = _NEWIMAGE(800, 600)
  80.     _DEST room&
  81.     LINE (0, 0)-(800, 600), black&, BF
  82.     LINE (0, 0)-(160, 120), grey&
  83.     LINE (0, 600)-(160, 480), grey&
  84.     LINE (640, 120)-(800, 0), grey&
  85.     LINE (640, 480)-(800, 600), grey&
  86.     LINE (160, 120)-(640, 480), white&, BF
]

When i try to run this as is, just to check if it will put the image cave& on screen. i get an error on line 24 = (_PUTIMAGE (0, 0), cave&)
i have no idea why or what is wrong with the code. i would like to be able to test the images that appear as i go through the coding so if you understand what is wrong with it please let me know thanks:)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Practicing Coding Game
« Reply #1 on: March 20, 2019, 08:42:30 pm »
If you add cave& to the list of DIM SHARED variables, your error there will go away. Of course do same with other images created in SUBs. The error goes away but no image is drawn.

I have been told colors for graphics screen are best assigned with _RGB32() and best DIM  SHARED AS _UNSIGNED LONG

eg
DIM SHARED white AS _UNSIGNED LONG
white = _RGB32(255, 255, 255)

or quicker

CONST white = &HFFFFFFFF   '&H is hexadecimal first 2 F's are transparency, next two are Red, next 2 are Green Level, Last 2 are Blue level


Code: QB64: [Select]
  1. _TITLE "Little Cave"
  2. CONST white = &HFFFFFFFF
  3. CONST black = &HFF000000
  4. CONST green = &HFF00FF00
  5. CONST gold = &HFFFFC700
  6. CONST grey = &HFF7C7C7C
  7.  
  8. DIM SHARED scrn&, left&, right&, forward&, back&, cave&
  9.  
  10. DIM SHARED counter
  11. scrn& = _NEWIMAGE(800, 600, 32)
  12.  
  13. SCREEN scrn&
  14. 'CALL MakeColors
  15.  
  16. 'SUB MakeColors
  17. '    white& = _RGB(225, 225, 225)
  18. '    black& = _RGB(0, 0, 0)
  19. '    green& = _RGB(0, 255, 0)
  20. '    gold& = _RGB(255, 215, 0)
  21. '    grey& = _RGB(125, 125, 125)
  22. 'END SUB
  23.  
  24. CALL MakeCaveEntrance
  25. CALL MakeCaveRoom
  26. CALL MakeSlime
  27. CALL MakeTreasure
  28.  
  29. _DEST display& '<<<<<<<<<<<<< there is no display& assigned so same as 0 which is main screen
  30.  
  31. 'make a timer
  32. ON TIMER(t, 1) Countup
  33. sec = 0
  34. gameover$ = "false"
  35.     CLS
  36.  
  37.     _PUTIMAGE (0, 0), cave&
  38.     _PRINTSTRING (375, 10), "Time: " + STR$(hrs) + ":" + STR$(mins) + STR$(sec)
  39.     _DISPLAY
  40.  
  41.  
  42.  
  43.  
  44.  
  45. LOOP UNTIL gameover$ = "true"
  46.     _DISPLAY
  47.  
  48. SUB Countup
  49.     mins = 0
  50.     hrs = 0
  51.     sec = sec + 1
  52.     IF sec >= 60 THEN
  53.         min = FIX(counter / 60)
  54.         sec = sec - (60 * mins)
  55.     END IF
  56.     IF mins >= 60 THEN
  57.         hrs = FIX(min / 60)
  58.         mins = mins - (60 * hrs)
  59.     END IF
  60.  
  61.  
  62. 'SUB MakeColors
  63. '    white& = _RGB(225, 225, 225)
  64. '    black& = _RGB(0, 0, 0)
  65. '    green& = _RGB(0, 255, 0)
  66. '    gold& = _RGB(255, 215, 0)
  67. '    grey& = _RGB(125, 125, 125)
  68. 'END SUB
  69.  
  70. SUB MakeSlime
  71.     slime& = _NEWIMAGE(60, 60)
  72.     _DEST slime&
  73.     'draw the slime
  74.     CIRCLE (50, 50), black
  75.     CIRCLE (48, 48), green
  76.  
  77. SUB MakeTreasure
  78.     treasure& = _NEWIMAGE(60, 60)
  79.     _DEST treasure&
  80.     CIRCLE (20, 20), 20, black
  81.     PAINT (20, 10), black
  82.     CIRCLE (20, 20), 17, gold
  83.     PAINT (20, 20), gold
  84.     LINE (0, 20)-(40, 49), black, BF
  85.     LINE (2, 22)-(38, 45), gold, BF
  86.     LINE (17, 17)-(23, 25), black, BF
  87.  
  88. SUB MakeCaveEntrance
  89.     cave& = _NEWIMAGE(800, 600)
  90.     _DEST cave&
  91.     LINE (0, 0)-(800, 600), black, BF
  92.     CIRCLE (400, 300), 100, grey
  93.     PAINT (400, 300), grey
  94.  
  95. SUB MakeCaveRoom
  96.     room& = _NEWIMAGE(800, 600)
  97.     _DEST room&
  98.     LINE (0, 0)-(800, 600), black, BF
  99.     LINE (0, 0)-(160, 120), grey
  100.     LINE (0, 600)-(160, 480), grey
  101.     LINE (640, 120)-(800, 0), grey
  102.     LINE (640, 480)-(800, 600), grey
  103.     LINE (160, 120)-(640, 480), white, BF
  104.  
  105.  

« Last Edit: March 20, 2019, 09:18:38 pm by bplus »

Offline eddy498

  • Newbie
  • Posts: 25
    • View Profile
Re: Practicing Coding Game
« Reply #2 on: March 20, 2019, 10:09:51 pm »
Code: QB64: [Select]
  1. _TITLE "Pirate Treasure"
  2. DIM SHARED scrn&, island&, cloud&, pirate&, treasure&
  3. DIM SHARED white&, black&, green&, gold&, brown&, sky&, darksand&, sand&
  4. DIM SHARED ocean&, counter
  5. scrn& = _NEWIMAGE(800, 600, 32)
  6.  
  7. SCREEN scrn&
  8. CALL MakeColors
  9. CALL MakeIsland
  10. CALL MakeCloud
  11.  
  12. CALL MakePirate
  13. pirate_x = 10 + RND * 700
  14. pirate_y = 280 + RND * 200
  15.  
  16. CALL MakeTreasure
  17. treasure_x = 10 + RND * 700
  18. treasure_y = 280 + RND * 220
  19.  
  20. 'start a stopwatch timer
  21. ON TIMER(t, 1) CountDown
  22. counter = 31
  23.  
  24. _DEST display&
  25. gameover$ = "false"
  26.     CLS
  27.     _PUTIMAGE (0, 0), island&, scrn&
  28.     _PUTIMAGE (100, 40), cloud&, scrn&
  29.     _PUTIMAGE (600, 70), cloud&, scrn&
  30.     _PUTIMAGE (treasure_x, treasure_y), treasure&, scrn&
  31.     _PUTIMAGE (pirate_x, pirate_y), pirate&, scrn&
  32.     _PRINTSTRING (350, 10), "Time: " + STR$(counter)
  33.  
  34.     k$ = INKEY$
  35.     IF k$ <> "" THEN
  36.         code = ASC(k$)
  37.         IF code = 0 THEN
  38.             code = ASC(k$, 2)
  39.             IF code = 72 THEN 'move up
  40.                 pirate_y = pirate_y - 5
  41.             ELSEIF code = 80 THEN 'move down
  42.                 pirate_y = pirate_y + 5
  43.             ELSEIF code = 75 THEN 'move left
  44.                 pirate_x = pirate_x - 5
  45.             ELSEIF code = 77 THEN 'move right
  46.                 pirate_x = pirate_x + 5
  47.             END IF
  48.         ELSE
  49.             IF k$ = CHR$(27) THEN gameover$ = "true"
  50.         END IF
  51.     END IF
  52.  
  53.     'see if you got the treasure
  54.     px = pirate_x + 30
  55.     py = pirate_y + 30
  56.     IF px > treasure_x AND py > treasure_y THEN
  57.         IF px < treasure_x + 60 AND py < treasure_y + 60 THEN
  58.             _PRINTSTRING (350, 50), "You got the treasure!"
  59.             gold = INT((30 = counter) * 100 + RND * 100)
  60.             _PRINTSTRING (350, 70), "You found" + STR$(gold) + " gold!"
  61.             _PRINTSTRING (350, 120), "Press ESC to quit."
  62.             gameover$ = "true"
  63.         END IF
  64.     END IF
  65.     IF py < 270 THEN
  66.         _PRINTSTRING (350, 50), "You drowned in the ocean!"
  67.         gameover$ = "true"
  68.     ELSEIF counter <= 0 THEN
  69.         _PRINTSTRING (350, 50), "You ran out of time!"
  70.         gameover$ = "true"
  71.     END IF
  72.     _DISPLAY
  73.  
  74. LOOP UNTIL gameover$ = "true"
  75.     _DISPLAY
  76.  
  77. SUB CountDown ()
  78.     counter = counter - 1
  79.  
  80. SUB MakeColors ()
  81.     white& = _RGB(255, 255, 255)
  82.     black& = _RGB(0, 0, 0)
  83.     green& = _RGB(0, 255, 0)
  84.     gold& = _RGB(255, 215, 0)
  85.     brown& = _RGB(100, 100, 40)
  86.     sky& = _RGB(110, 110, 240)
  87.     darksand& = _RGB(214, 165, 116)
  88.     sand& = _RGB(234, 185, 136)
  89.     ocean& = _RGB(60, 60, 240)
  90.  
  91. SUB MakePirate ()
  92.     pirate& = _NEWIMAGE(60, 60)
  93.     _DEST pirate&
  94.     'make the pirate's shadow
  95.     LINE (7, 11)-(19, 0), black&
  96.     LINE (19, 1)-(31, 11), black&
  97.     LINE (7, 11)-(31, 11), black&
  98.     PAINT (19, 9), black&
  99.     CIRCLE (19, 16), 6, black&
  100.     LINE (19, 23)-(19, 37), black&
  101.     LINE (19, 27)-(12, 31), black&
  102.     LINE (19, 27)-(26, 31), black&
  103.     LINE (19, 37)-(14, 49), black&
  104.     LINE (19, 37)-(24, 49), black&
  105.     'draw the pirate
  106.     LINE (8, 12)-(20, 1), green&
  107.     LINE (20, 1)-(32, 12), green&
  108.     LINE (8, 12)-(32, 12), green&
  109.     PAINT (20, 10), green&
  110.     CIRCLE (20, 17), 6, green&
  111.     LINE (20, 24)-(20, 38), green&
  112.     LINE (20, 28)-(13, 32), green&
  113.     LINE (20, 28)-(27, 32), green&
  114.     LINE (20, 38)-(15, 50), green&
  115.     LINE (20, 38)-(25, 50), green&
  116.  
  117. SUB MakeTreasure ()
  118.     treasure& = _NEWIMAGE(60, 60)
  119.     _DEST treasure&
  120.     CIRCLE (20, 20), 20, brown&
  121.     PAINT (20, 10), brown&
  122.     CIRCLE (20, 20), 17, gold&
  123.     PAINT (20, 20), gold&
  124.     LINE (0, 20)-(40, 49), brown&, BF
  125.     LINE (2, 22)-(38, 45), gold&, BF
  126.     LINE (17, 17)-(23, 25), black&, BF
  127.  
  128. SUB MakeIsland ()
  129.     island& = _NEWIMAGE(800, 600)
  130.     _DEST island&
  131.     LINE (0, 0)-(799, 200), sky&, BF
  132.     LINE (0, 200)-(799, 270), ocean&, BF
  133.     LINE (0, 270)-(799, 350), sand&, BF
  134.     LINE (0, 350)-(799, 599), darksand&, BF
  135.  
  136. SUB MakeCloud ()
  137.     cloud& = _NEWIMAGE(100, 100)
  138.     _DEST cloud&
  139.     CIRCLE (20, 20), 20, white&
  140.     PAINT (20, 20), white&
  141.     CIRCLE (45, 25), 25, white&
  142.     PAINT (45, 30), white&
  143.     CIRCLE (70, 45), 28, white&
  144.     PAINT (70, 45), white&
  145.     CIRCLE (35, 45), 30, white&
  146.     PAINT (35, 60), white&
  147.  

But this one works as it is using that RBG. so what is difference between this one and the one im working on right now. I dont know why its calling out the colors like it should.

another problem is my timer in the other codes. i tryied to make is so that it starts counting up and when it reaches a certain thing adds to minutes and such but its not working.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Practicing Coding Game
« Reply #3 on: March 20, 2019, 10:39:35 pm »
:) I remember that Pirate Game!

For timer how about something like this?
Code: QB64: [Select]
  1. start = TIMER
  2. WHILE _KEYDOWN(27) = 0
  3.     CLS
  4.     PRINT "  Time:"; INT(TIMER - start)
  5.     _LIMIT 60
  6. PRINT "Time:"; INT(TIMER - start)
  7.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Practicing Coding Game
« Reply #4 on: March 20, 2019, 10:49:46 pm »
Oh ha! you forgot to DIM SHARE Grey&

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Practicing Coding Game
« Reply #5 on: March 20, 2019, 10:58:20 pm »
Here is minutes and seconds:
Code: QB64: [Select]
  1. start = TIMER
  2. WHILE _KEYDOWN(27) = 0
  3.     CLS
  4.     timeElapsed = INT(TIMER - start)
  5.     mins = INT(timeElapsed / 60)
  6.     secs = timeElapsed - mins * 60
  7.     PRINT "  Mins:"; mins; " Secs:"; secs
  8.  
  9.  
  10.     _LIMIT 30
  11.  
  12.  
  13.  

Offline eddy498

  • Newbie
  • Posts: 25
    • View Profile
Re: Practicing Coding Game
« Reply #6 on: March 20, 2019, 10:58:30 pm »
I redid and dim shared grey still screen comes out black.
decided to take timer off since for my small game a timer like that wont really be needed so ill switch it around to a countdown making you have to compete before a certain amount of time passes.

something like
Code: QB64: [Select]
  1. ON TIMER(t, 1) CountDown
  2. counter = 30
  3.  
  4. SUB CountDown ()
  5.     counter = counter - 1
  6.  
  7.  
That creates a counter and works well but ill have to test how to get a minute and second timer together. want it to be like 5:00 minutes start and count down 4:59. ext.

Have to find how to make it collect gold for the game was thinking somewhere around the line of
gold = 0
While _KEYDOWN(27) = 0
    CLS
    PRINT "GOLD: "; gold
WEND

Then whenever a chest opens or money gets collected just do a
gold = gold + (gold collected)

as a forced change in whichever if statement or loop i put the gold grab into.

Any idea on how to make that easier or is what i thought about good?

Back to the whole grey&
my colors still havnt shown up and idk how to make the colors show up for it like how the pirate game made the bacground and island pop up just fine.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Practicing Coding Game
« Reply #7 on: March 20, 2019, 11:03:30 pm »
As I said, you had to DIM SHARE grey& AND cave&

Code: QB64: [Select]
  1.  
  2. _TITLE "Little Cave"
  3. DIM SHARED scrn&, left&, right&, forward&, back&, cave& '<<<
  4. DIM SHARED black&, white&, green&, gold&, grey& '<<<
  5. DIM SHARED gold, counter
  6. scrn& = _NEWIMAGE(800, 600, 32)
  7.  
  8. SCREEN scrn&
  9. CALL MakeColors
  10. CALL MakeCaveEntrance
  11. CALL MakeCaveRoom
  12. CALL MakeSlime
  13. CALL MakeTreasure
  14.  
  15. 'make a timer
  16. 't = _FREETIMER
  17. 'ON TIMER(t, 1) Countup
  18. 'TIMER(t) ON
  19. 'sec = 0
  20.  
  21. _DEST display&
  22. gameover$ = "false"
  23. start = TIMER
  24.     CLS
  25.  
  26.     _PUTIMAGE (0, 0), cave&
  27.     timeElapsed = INT(TIMER - start)
  28.     mins = INT(timeElapsed / 60)
  29.     secs = timeElapsed - mins * 60
  30.     PRINT "  Mins:"; mins; " Secs:"; secs
  31.  
  32.     '_PRINTSTRING (375, 10), "Time: " + STR$(hrs) + ":" + STR$(mins) + STR$(sec)
  33.     _DISPLAY
  34.  
  35.  
  36.  
  37.  
  38.  
  39. LOOP UNTIL gameover$ = "true"
  40.     _DISPLAY
  41.  
  42. SUB Countup
  43.     mins = 0
  44.     hrs = 0
  45.     sec = sec + 1
  46.     IF sec >= 60 THEN
  47.         min = FIX(counter / 60)
  48.         sec = sec - (60 * mins)
  49.     END IF
  50.     IF mins >= 60 THEN
  51.         hrs = FIX(min / 60)
  52.         mins = mins - (60 * hrs)
  53.     END IF
  54.  
  55.  
  56. SUB MakeColors
  57.     white& = _RGB(225, 225, 225)
  58.     black& = _RGB(0, 0, 0)
  59.     green& = _RGB(0, 255, 0)
  60.     gold& = _RGB(255, 215, 0)
  61.     grey& = _RGB(125, 125, 125)
  62.  
  63. SUB MakeSlime
  64.     slime& = _NEWIMAGE(60, 60)
  65.     _DEST slime&
  66.     'draw the slime
  67.     CIRCLE (50, 50), black&
  68.     CIRCLE (48, 48), green&
  69.  
  70. SUB MakeTreasure
  71.     treasure& = _NEWIMAGE(60, 60)
  72.     _DEST treasure&
  73.     CIRCLE (20, 20), 20, black&
  74.     PAINT (20, 10), black&
  75.     CIRCLE (20, 20), 17, gold&
  76.     PAINT (20, 20), gold&
  77.     LINE (0, 20)-(40, 49), black&, BF
  78.     LINE (2, 22)-(38, 45), gold, BF
  79.     LINE (17, 17)-(23, 25), black&, BF
  80.  
  81. SUB MakeCaveEntrance
  82.     cave& = _NEWIMAGE(800, 600)
  83.     _DEST cave&
  84.     LINE (0, 0)-(800, 600), black&, BF
  85.     CIRCLE (400, 300), 100, grey&
  86.     PAINT (400, 300), grey&
  87.  
  88. SUB MakeCaveRoom
  89.     room& = _NEWIMAGE(800, 600)
  90.     _DEST room&
  91.     LINE (0, 0)-(800, 600), black&, BF
  92.     LINE (0, 0)-(160, 120), grey&
  93.     LINE (0, 600)-(160, 480), grey&
  94.     LINE (640, 120)-(800, 0), grey&
  95.     LINE (640, 480)-(800, 600), grey&
  96.     LINE (160, 120)-(640, 480), white&, BF
  97.  
« Last Edit: March 20, 2019, 11:10:18 pm by bplus »

Offline eddy498

  • Newbie
  • Posts: 25
    • View Profile
Re: Practicing Coding Game
« Reply #8 on: March 20, 2019, 11:09:07 pm »
okay retried and it worked. ill continue working on that later.
btw on that timer you did its great and im saving it for later.
tried to add the hrs doing same thing and it got screwed up xD

Code: QB64: [Select]
  1. start = TIMER
  2. WHILE _KEYDOWN(27) = 0
  3.     CLS
  4.     timeElapsed = INT(TIMER - start)
  5.     hrs = INT(timeElapsed / 3600)
  6.     mins = INT(timeElapsed / 60)
  7.     secs = timeElapsed - mins * 60
  8.     mins = timeElapsed - hrs * 3600
  9.     PRINT " Hrs:"; hrs; " Mins:"; mins; " Secs:"; secs
  10.  
  11.  
  12.     _LIMIT 30
  13.  
where did i go wrong?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Practicing Coding Game
« Reply #9 on: March 20, 2019, 11:18:57 pm »
Subtract Hours * 3600 off TimeEllapsed before calculate minutes as we subtracted minutes off before finding secs remaining.
Code: QB64: [Select]
  1. timeElapsed = INT(TIMER - start)
  2. hrs = INT(timeElapsed / 3600)
  3. te = timeElapsed - hrs * 3600
  4. mins = INT(te / 60)
  5. secs = te - mins * 60
  6. PRINT " Hrs:"; hrs; " Mins:"; mins; " Secs:"; secs
« Last Edit: March 20, 2019, 11:23:26 pm by bplus »

Offline eddy498

  • Newbie
  • Posts: 25
    • View Profile
Re: Practicing Coding Game
« Reply #10 on: March 20, 2019, 11:24:07 pm »
Subtract Hours * 3600 off TimeEllapsed before calculate minutes as we subtracted minutes off before finding secs remaining.

I dont get what you mean. i already for the mins and subtracted the hrs * 3600 from it. when i run the script it counts up the minutes at the same time as the seconds.

edit// nvm

i moved the mins elapes time above the mins count time and now its counting right. gonna leave it on for a bit to see if the counting goes well thanks. then gonna try to reverse it to make a countdown using this method :)

gotta try to get a bit more into the art so my backgrounds dont look so bland in the game. any ideas where i can find some references for objects such as rocks, trees, ext?
« Last Edit: March 20, 2019, 11:27:16 pm by eddy498 »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Practicing Coding Game
« Reply #11 on: March 20, 2019, 11:49:10 pm »
My code works
  [ You are not allowed to view this attachment ]  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Practicing Coding Game
« Reply #12 on: March 20, 2019, 11:57:22 pm »
Here are some trees
Code: QB64: [Select]
  1. _TITLE "Fall Foliage 2017-10-21 by bplus"
  2. 'fall foliage.bas SmallBASIC 0.12.9 (B+=MGA) 2017-10-21
  3. 'test landscape and portrait views for Android
  4. 'xmx = min(xmax, 400) : ymx = min(700, ymax) 'portrait
  5. 'OK it's just plain better in landscape view
  6.  
  7. 'now for full viewing enjoyment
  8. 'xmx = xmax : ymx = ymax
  9.  
  10. CONST xmx = 1200
  11. CONST ymx = 700
  12. DEFSNG A-Z
  13.  
  14. rad = _PI(1 / 180)
  15. SCREEN _NEWIMAGE(xmx, ymx, 32)
  16. _SCREENMOVE 100, 20 'adjust as needed _MIDDLE needs a delay .5 or more for me
  17.  
  18.  
  19. n = 3
  20.     IF n < 15 THEN n = n + 3
  21.     horizon = rand%(.8 * ymx, .9 * ymx)
  22.     FOR i = 0 TO horizon
  23.         midInk 0, 0, 128, 10, 120, 128, i / horizon
  24.         lien 0, i, xmx, i
  25.     NEXT
  26.     FOR i = horizon TO ymx
  27.         midInk 70, 108, 30, 60, 10, 5, (i - horizon) / (ymx - horizon)
  28.         lien 0, i, xmx, i
  29.     NEXT
  30.     FOR i = 1 TO xmx * ymx * .00018
  31.         leaf rand%(0, xmx), rand%(horizon * 1.002, ymx)
  32.     NEXT
  33.     IF n < .01 * xmx THEN trees = n ELSE trees = rand%(.002 * xmx, .03 * xmx)
  34.     FOR i = 1 TO trees
  35.         y = horizon + .04 * ymx + i / trees * (ymx - horizon - .1 * ymx)
  36.         r = .01 * y: h = rand%(y * .15, y * .18)
  37.         branch rand%(10, xmx - 10), y, r, 90, h, 0
  38.     NEXT
  39.     fRect xmx, 0, xmax, ymax, 0
  40.     fRect 0, ymx, xmx, ymax, 0
  41.     _DISPLAY
  42.     SLEEP 2
  43.  
  44. SUB branch (xx, yy, startrr, angDD, lengthh, levv)
  45.     x = xx: y = yy
  46.     lev = levv
  47.     length = lengthh
  48.     angD = angDD
  49.     startr = startrr
  50.     x2 = x + COS(rad * (angD)) * length
  51.     y2 = y - SIN(rad * (angD)) * length
  52.     dx = (x2 - x) / length
  53.     dy = (y2 - y) / length
  54.     bc& = _RGB(30 + 6 * lev, 15 + 3 * lev, 5 + 2 * lev)
  55.     FOR i = 0 TO length
  56.         COLOR bc&
  57.         fCirc x + dx * i, y + dy * i, startr
  58.     NEXT
  59.     IF lev > 1 THEN leaf x2, y2
  60.     IF .8 * startr < .1 OR lev > 7 OR length < 3 THEN EXIT SUB
  61.     lev = lev + 1
  62.     branch x2, y2, .8 * startr, angD + 22 + rand%(-10, 19), rand%(.75 * length, .9 * length), lev
  63.     branch x2, y2, .8 * startr, angD - 22 - rand%(-10, 19), rand%(.75 * length, .9 * length), lev
  64.  
  65. 'Steve McNeil's  copied from his forum   note: Radius is too common a name
  66. SUB fCirc (CX AS LONG, CY AS LONG, R AS LONG)
  67.     DIM subRadius AS LONG, RadiusError AS LONG
  68.     DIM X AS LONG, Y AS LONG
  69.  
  70.     subRadius = ABS(R)
  71.     RadiusError = -subRadius
  72.     X = subRadius
  73.     Y = 0
  74.  
  75.     IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB
  76.  
  77.     ' Draw the middle span here so we don't draw it twice in the main loop,
  78.     ' which would be a problem with blending turned on.
  79.     LINE (CX - X, CY)-(CX + X, CY), , BF
  80.  
  81.     WHILE X > Y
  82.         RadiusError = RadiusError + Y * 2 + 1
  83.         IF RadiusError >= 0 THEN
  84.             IF X <> Y + 1 THEN
  85.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF
  86.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF
  87.             END IF
  88.             X = X - 1
  89.             RadiusError = RadiusError - X * 2
  90.         END IF
  91.         Y = Y + 1
  92.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF
  93.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF
  94.     WEND
  95.  
  96. SUB fRect (x1, y1, x2, y2, c&)
  97.     LINE (x1, y1)-(x2, y2), c&, BF
  98.  
  99. SUB fRectStep (x1, y1, x2, y2)
  100.     LINE (x1, y1)-STEP(x2, y2), , BF
  101.  
  102. SUB lien (x1, y1, x2, y2)
  103.     LINE (x1, y1)-(x2, y2)
  104.  
  105. SUB leaf (x, y)
  106.     sp = 15: leafs = rand%(xmx * ymx * .00001, xmx * ymx * .00002)
  107.     FOR n = 1 TO leafs
  108.         COLOR _RGB(rand%(50, 250), rand%(25, 255), rand%(0, 40))
  109.         xoff = x + RND * sp - RND * sp
  110.         yoff = y + RND * sp - RND * sp
  111.         woff = 3 + RND * 3
  112.         hoff = 3 + RND * 3
  113.         fRectStep xoff, yoff, woff, hoff
  114.     NEXT
  115.  
  116. SUB midInk (r1%, g1%, b1%, r2%, g2%, b2%, fr##)
  117.     COLOR _RGB(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##)
  118.  
  119. FUNCTION rand% (lo%, hi%)
  120.     rand% = INT(RND * (hi% - lo% + 1)) + lo%
  121.  
  122.  

Offline eddy498

  • Newbie
  • Posts: 25
    • View Profile
Re: Practicing Coding Game
« Reply #13 on: March 21, 2019, 12:18:00 pm »
Hmm that code confuses me. I'm still not at that level.
Want something more along the lines of
SUB makerocks
And the do a bunch of lines to make an outline of a rock. But my problem is how do I go about making angles and the faces different colors. For example u know how rocks have shades on different sides. And they are different shapes. I know about line BF which will fill the box in but how do I go about making a parrellelogram where the box is at an angle and it's filled with a different shade??
This is what has me confused since I don't want to just use boxes as rocks.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Practicing Coding Game
« Reply #14 on: March 21, 2019, 04:05:59 pm »
I must say, most people would grab images and manipulate them. But I admire the brave soul who chooses to draw by code! :)

Here is quad drawing tools. Basically you need a triangle fill routine and then draw 2 triangles that share an edge.

I constructed rectangles, random quad and rhombus from central point. I am afraid the level for that is a little high too.
Fortunately you don't need allot of math to get 4 points for the quad but you do have to watch that the shared edge is line x2, y2 to x4, y4 for quad sub.

Code: QB64: [Select]
  1. _TITLE "A draw quad tool, white = rectangle, red = random quad, blue = rhombus" 'B+ started 2019-03-21
  2.  
  3. CONST white = &HFFFFFFFF
  4. CONST red = &HFFFF0000
  5. CONST blue = &HFF0000FF
  6.  
  7. 'a quad is 4 points about a center, squares, rectangles, rhombus, parallelogram, trapizoids are special cases
  8. SCREEN _NEWIMAGE(800, 600, 32)
  9. _SCREENMOVE 300, 40
  10.  
  11. WHILE _KEYDOWN(27) = 0
  12.     CLS
  13.     'try rectangle  white
  14.     'pick a random point not too close to edge of screen (50 away) to be center of rect
  15.     x0 = (_WIDTH - 100) * RND + 50: y0 = (_HEIGHT - 100) * RND + 50
  16.     'pick a random radius from center, all are equal for rect
  17.     r = RND * 40 + 10
  18.     'pick an angle between 0 and 180 degrees =_PI radians
  19.     a = RND * _PI
  20.     'a par o gram has 2 angles that sum to 180 = _PI
  21.     p1 = RND * PI(11 / 6) + _PI(1 / 6): p2 = _PI - p1
  22.     a1 = a + p1
  23.     a2 = a1 + p2
  24.     a3 = a2 + p1
  25.     x1 = x0 + r * COS(a): y1 = y0 + r * SIN(a)
  26.     x2 = x0 + r * COS(a1): y2 = y0 + r * SIN(a1)
  27.     x3 = x0 + r * COS(a2): y3 = y0 + r * SIN(a2)
  28.     x4 = x0 + r * COS(a3): y4 = y0 + r * SIN(a3)
  29.     fquad x1, y1, x2, y2, x3, y3, x4, y4, white
  30.  
  31.     'random quad
  32.     ' or lets say all the angles are 90 more than last but use random radius from center point
  33.     x0 = (_WIDTH - 100) * RND + 50: y0 = (_HEIGHT - 100) * RND + 50
  34.     a = _PI(.25) * RND 'start point angle from center
  35.     r = 10 + 40 * RND
  36.     x1 = x0 + r * COS(a): y1 = y0 + r * SIN(a)
  37.     r = 10 + 40 * RND
  38.     x2 = x0 + r * COS(a + _PI(.5)): y2 = y0 + r * SIN(a + _PI(.5)) 'plus 90 degree = pi/2 = .5*pi
  39.     r = 10 + 40 * RND
  40.     x3 = x0 + r * COS(a + _PI): y3 = y0 + r * SIN(a + _PI) 'plus 180 degrees = pi
  41.     r = 10 + 40 * RND
  42.     x4 = x0 + r * COS(a + _PI(1.5)): y4 = y0 + r * SIN(a + _PI(1.5)) 'plus 270 degrees = 3/2*pi
  43.     fquad x1, y1, x2, y2, x3, y3, x4, y4, red
  44.     'PSET (x0, y0), white
  45.     'LINE (x0, y0)-(x1, y1), white
  46.     'LINE (x0, y0)-(x2, y2), blue
  47.     'LINE (x0, y0)-(x3, y3), white
  48.     'LINE (x0, y0)-(x4, y4), blue
  49.  
  50.     'rhombus like ellipse 2 radii
  51.     r1 = RND * 35 + 15: r2 = RND * 35 + 15
  52.     x0 = (_WIDTH - 100) * RND + 50: y0 = (_HEIGHT - 100) * RND + 50
  53.     a = _PI(.25) * RND 'start point angle from center
  54.     x1 = x0 + r1 * COS(a): y1 = y0 + r1 * SIN(a)
  55.     x2 = x0 + r2 * COS(a + _PI(.5)): y2 = y0 + r2 * SIN(a + _PI(.5)) 'plus 90 degree = pi/2 = .5*pi
  56.     x3 = x0 + r1 * COS(a + _PI): y3 = y0 + r1 * SIN(a + _PI) 'plus 180 degrees = pi
  57.     x4 = x0 + r2 * COS(a + _PI(1.5)): y4 = y0 + r2 * SIN(a + _PI(1.5)) 'plus 270 degrees = 3/2*pi
  58.     fquad x1, y1, x2, y2, x3, y3, x4, y4, blue
  59.     _DISPLAY
  60.     _LIMIT 1
  61. ' if you connect 2 points that are not adjacent but opposite each other you divide a quad to 2 triangle
  62. ' So if we have code to draw a filled triangle we have to just draw 2 filled triangles.
  63.  
  64. 'need 4 non linear points (not all on 1 line) list them clockwise so x2, y2 is opposite of x4, y4
  65. SUB fquad (x1, y1, x2, y2, x3, y3, x4, y4, K AS _UNSIGNED LONG)
  66.     ftri x1, y1, x2, y2, x4, y4, K
  67.     ftri x3, y3, x2, y2, x4, y4, K
  68.  
  69. 'Very Handy code to draw a filled triangle
  70. SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  71.     a& = _NEWIMAGE(1, 1, 32)
  72.     _DEST a&
  73.     PSET (0, 0), K
  74.     _DEST 0
  75.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  76.     _FREEIMAGE a& '<<< this is important!
  77.  
  78.  


EDIT: I meant rectangles not parallelograms.
« Last Edit: March 21, 2019, 05:16:37 pm by bplus »