Author Topic: Practicing Coding Game  (Read 4555 times)

0 Members and 1 Guest are viewing this topic.

Offline eddy498

  • Newbie
  • Posts: 25
    • View Profile
Re: Practicing Coding Game
« Reply #15 on: March 21, 2019, 05:34:48 pm »
thanks lol. if i want to be able to do my own games i want to be able to do them from scratch not just getting pictures and working with them. ill dissect this code for a bit if i come up with any questions ill post it up again :)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Practicing Coding Game
« Reply #16 on: March 21, 2019, 08:41:59 pm »
A simpler tree:
Code: QB64: [Select]
  1. _TITLE "Basic Tree from branch"
  2. SCREEN _NEWIMAGE(800, 600, 32)
  3. _SCREENMOVE 300, 20
  4. COLOR _RGB32(0, 255, 0)
  5.  
  6. 'just test call to sub
  7. '       x,   y,  270, .2*height, 1  start a tree with 270 degrees to point up, and about 1/5 the height you want to grow the tree
  8. branch 400, 500, 270, 100, 1
  9. PRINT "press any to see the forest..."
  10.  
  11. horizon = .35 * _HEIGHT
  12. FOR i = 0 TO horizon
  13.     LINE (0, i)-(_WIDTH, i), _RGB(0, 0, .25 * i + 100)
  14. FOR i = horizon TO _HEIGHT
  15.     LINE (0, i)-(_WIDTH, i), _RGB(0, 255 - .25 * i - 50, 0)
  16. FOR i = 1 TO 250
  17.     y = randWeight(horizon, _HEIGHT, 3)
  18.     branch _WIDTH * RND, y, 270, .04 * y, 1
  19.  
  20. SUB branch (x, y, angD, lngth, lev)
  21.     x2 = x + COS(_D2R(angD)) * lngth
  22.     y2 = y + SIN(_D2R(angD)) * lngth
  23.     LINE (x, y)-(x2, y2), _RGB32(RND * 100, RND * 170 + 80, RND * 50)
  24.     IF lev > 6 OR lngth < 2 THEN EXIT SUB
  25.     l = lev + 1
  26.     branch x2, y2, angD + 10 + 30 * RND, .7 * lngth + .2 * RND * lngth, l
  27.     branch x2, y2, angD - 10 - 30 * RND, .7 * lngth + .2 * RND * lngth, l
  28.     IF RND < .65 THEN branch x2, y2, angD + 20 * RND - 10, .7 * lngth + .2 * RND * lngth, l
  29.  
  30. FUNCTION randWeight (manyValue, fewValue, power)
  31.     randWeight = manyValue + RND ^ power * (fewValue - manyValue)
  32.