Author Topic: Circular maze from SierraKen + Bplus ball program = this program.  (Read 1311 times)

0 Members and 1 Guest are viewing this topic.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
Code: QB64: [Select]
  1. 'idea, based on SierraKen's Circle maze and Bplus's upgrade
  2.  
  3. Circles = 13
  4. StepsToCircle = 50
  5.  
  6. TYPE circles
  7.     Exit AS SINGLE '            value in radians
  8.     Radius AS INTEGER
  9.     Kolor AS _UNSIGNED _BYTE
  10.     Wall AS SINGLE
  11.  
  12. DIM C(1 TO Circles) AS circles
  13.  
  14. FOR Fill = 1 TO Circles
  15.     C(Fill).Exit = _PI(2) / 100 * (RND * 100)
  16.     C(Fill).Wall = C(Fill).Exit - _PI(2) / 8 - _PI(2) / 50 * (RND * 50)
  17.     C(Fill).Radius = 30 * Fill
  18.     C(Fill).Kolor = 20 + RND * 75
  19.  
  20. B = Ball
  21. Xb = 400
  22. Yb = 413
  23. memY = 400
  24. Level = 1
  25.  
  26. SCREEN _NEWIMAGE(800, 800, 256)
  27.  
  28.     CLS
  29.     PB Xb, Yb
  30.     FOR D = 1 TO Circles - 1
  31.         radius = C(D).Radius
  32.         Doo = _PI(2) / StepsToCircle
  33.         Doors = _PI(2) / radius * 4
  34.         W = C(D).Wall
  35.  
  36.         RotP = RotP + .005
  37.  
  38.         FOR K = C(D).Exit + Doors TO C(D).Exit + _PI(2) - Doors STEP Doo
  39.             X1 = 400 + COS(K + RotP) * radius
  40.             Y1 = 400 + SIN(K + RotP) * radius
  41.             X2 = 400 + COS(K + Doo + RotP) * radius
  42.             Y2 = 400 + SIN(K + Doo + RotP) * radius
  43.             LINE (X1, Y1)-(X2, Y2), C(D).Kolor
  44.         NEXT K
  45.  
  46.         'calculate door line
  47.         FOR K = 1 TO Circles - 1
  48.             Crad = C(K).Radius
  49.             D30 = (_PI(2) / Crad) * 4
  50.             KX1 = 400 + COS(C(K).Exit + D30 + RotP) * Crad
  51.             KY1 = 400 + SIN(C(K).Exit + D30 + RotP) * Crad
  52.             KX2 = 400 + COS(C(K).Exit - D30 + RotP) * Crad
  53.             KY2 = 400 + SIN(C(K).Exit - D30 + RotP) * Crad
  54.  
  55.             'LINE (KX1, KY1)-(KX2, KY2)
  56.  
  57.             IF KY1 >= Yb AND KY2 >= Yb THEN 'vyrez dveri je pod kulickou
  58.                 IF KX1 < Xb - 6 AND KX2 > Xb - 12 THEN
  59.                     IF K = Level THEN
  60.                         IF Kolide <= 0 THEN
  61.                             FOR AllXs = Xb - 6 TO Xb + 6
  62.                                 Kolide = IL(KX1, KY1, KX2, KY2, AllXs)
  63.                             NEXT
  64.                             IF Kolide THEN memY = Yb
  65.                         END IF
  66.                         OYb = Yb
  67.                     END IF
  68.                 END IF
  69.             END IF
  70.         NEXT K
  71.  
  72.         IF Kolide THEN
  73.             Yb = Yb + .5
  74.         END IF
  75.  
  76.         IF memY THEN
  77.             IF Yb - 400 > C(Level + 1).Radius - 16 THEN Yb = C(Level + 1).Radius + 400 - 16: memY = 0: Level = Level + 1: Kolide = 0
  78.         END IF
  79.         PB Xb, Yb
  80.     NEXT D
  81.     _DISPLAY
  82.     _LIMIT 20
  83.  
  84.     Ball = _NEWIMAGE(24, 24, 256)
  85.     D = _DEST
  86.     _DEST Ball
  87.     CLS , 128
  88.     FOR C = 12 TO 0 STEP -1
  89.         CIRCLE (12, 12), C, 16 + e
  90.         PAINT (12, 12), 16 + e, 16 + e
  91.         e = e + 1
  92.     NEXT
  93.     _DEST D
  94.     _CLEARCOLOR 128, Ball
  95.  
  96. SUB PB (X, Y)
  97.     _PUTIMAGE (X - 12, Y - 12), B
  98.  
  99. FUNCTION IL (Xb, Yb, Xe, Ye, P)
  100.     IF Xb > Xe THEN '
  101.         SWAP Xb, Xe
  102.         SWAP Yb, Ye
  103.     END IF
  104.     IF P >= Xb AND P <= Xe THEN
  105.         IF Xb = Xe THEN IL = -1: EXIT FUNCTION 'error
  106.         IF Yb = Ye THEN
  107.             IL = Yb
  108.         ELSE
  109.             Lenx = Xb - Xe
  110.             LenY = Yb - Ye
  111.             Ratio = LenY / Lenx
  112.             IL = INT(Yb + (P - Xb) * Ratio)
  113.         END IF
  114.     ELSE
  115.  
  116.     END IF
  117.  
  118.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Circular maze from SierraKen + Bplus ball program = this program.
« Reply #1 on: June 15, 2020, 04:15:44 pm »
Oh fun! :)

Offline SierraKen

  • Forum Resident
  • Posts: 1454
Re: Circular maze from SierraKen + Bplus ball program = this program.
« Reply #2 on: June 15, 2020, 04:55:58 pm »
LOL That is so cool! That reminds me of the old arcade game Star Castle where you shoot the turning circle segments, which are barriers around the middle enemy.





Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Circular maze from SierraKen + Bplus ball program = this program.
« Reply #3 on: June 15, 2020, 06:36:16 pm »
We have a squirrel that sounds like that. :-))

Offline SierraKen

  • Forum Resident
  • Posts: 1454
Re: Circular maze from SierraKen + Bplus ball program = this program.
« Reply #4 on: June 15, 2020, 10:11:38 pm »
LOL a squirrel. I was wondering, have any of you experimented with liquid effects on QB64? Besides the water waves and last year's lava lamps, I'm wondering if liquid can be made with particles. Set a particle its own array and use semi-realistic gravity for each one, maybe find a way to keep them clumped together too. I think I'll see what I can figure out.