Author Topic: Mystical rooms, collect the diamonds!  (Read 4897 times)

0 Members and 1 Guest are viewing this topic.

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Mystical rooms, collect the diamonds!
« on: March 06, 2022, 02:11:14 pm »
I made a game.
There are rooms. The rooms have doors. There is only 1 door in 1 room, which takes you to the next room! Find the right way! Get to the last room and collect all the diamonds!
The engine of the game is from Mover Bricks. The challenge here was how I connected the doors. There is only one way up.
The number of rooms and doors can be set at the beginning of the source code. It is very chaotic to raise these values, but whoever has a good memory and a good location recognizer can easily find the right doors!

No file accessories.

 
ss.jpg


Code: QB64: [Select]
  1. monx = 800: DIM SHARED rm(9, 1): DIM SHARED p(3, 2): RANDOMIZE TIMER
  2.  
  3. '---------------------- settings -----------------------------------
  4.  
  5.  
  6. room_c = 4 'how many rooms should be in the game?
  7. diamant_c = 10 'average number of diamonds / room
  8. room_doormin = 2 'there must be at least as many doors in a room
  9. room_doormax = 3 'there should be a maximum of this number of doors in a room
  10. me_speed = .15 'my speed
  11. mouse_sens = .5
  12.  
  13.  
  14.  
  15.  
  16.  
  17. '-----ADVANCED SETTINGS ----------------------------------------------------------------------------------------------------------------
  18. diamant_speed_min = .05 'diamant speed 1. room
  19. diamant_speed_max = .15 'diamant speed last room
  20. room_buffsize = 100
  21. room_relsize = 20
  22. room_boxmin_c = 4
  23. room_boxmax_c = 6
  24. shdw_c = 40
  25.  
  26. CONST pip180 = 3.141592 / 180
  27. cheat_active = 0
  28.  
  29. 'make colors
  30. DIM SHARED b_colors(room_c - 1) AS _INTEGER64: FOR t = 0 TO room_c - 1: b_colors(t) = _RGB32(30 + 180 * RND(1), 30 + 180 * RND(1), 30 + 180 * RND(1)): NEXT t
  31. DIM temp_color(9) AS _INTEGER64
  32. DIM SHARED crash_active
  33.  
  34. 'shadows
  35. DIM SHARED shdw(16383) AS _BYTE: FOR t = 0 TO 16383: ashdw = INT((shdw_c - 1) * 0.0006 * t): IF ashdw > shdw_c - 1 THEN ashdw = shdw_c - 1
  36. shdw(t) = ashdw: NEXT t
  37.  
  38. 'make textures
  39. dia_text_c = 20: DIM dia_text(dia_text_c - 1, shdw_c - 1)
  40. dt_c = 10
  41. marg = .12: DIM SHARED text_tile(room_c - 1, shdw_c - 1) AS _INTEGER64: DIM door_text(dt_c - 1, shdw_c - 1)
  42. FOR t = 0 TO shdw_c - 1: tmax = 40: tmin = 40: size = INT(tmax - (tmax - tmin) / (shdw_c - 1) * t): dark = 1 - 1 / (shdw_c - 1) * t
  43.     stand_temp = _NEWIMAGE(size, size, 32): _DEST stand_temp: CLS , _RGB32(50, 50, 50) 'frame color
  44.     LINE (size * marg, size * marg)-(size - size * marg, size - size * marg), _RGB32(180, 180, 180), BF: _SOURCE stand_temp
  45.     noise = 5 + 5 * (1 / (shdw_c - 1) * t) ^ 1.2: FOR tx = 0 TO size - 1: FOR ty = 0 TO size - 1: temp_color(0) = POINT(tx, ty)
  46.             PSET (tx, ty), _RGB32(_RED32(temp_color(0)) - noise / 2 + RND(1) * noise, _GREEN32(temp_color(0)) - noise / 2 * RND(1) * noise, _BLUE32(temp_color(0)) - noise / 2 + RND(1) * noise)
  47.     NEXT ty, tx
  48.  
  49.     'make wall
  50.     FOR t2 = 0 TO room_c - 1: temp = _COPYIMAGE(stand_temp, 32): _DEST temp
  51.         trans = _NEWIMAGE(5, 5, 32): _DEST trans: CLS , _RGBA32(_RED32(b_colors(t2)) * dark, _GREEN32(b_colors(t2)) * dark, _BLUE32(b_colors(t2)) * dark, 150)
  52.         _SOURCE trans: _DEST temp: _BLEND temp: _PUTIMAGE: _FREEIMAGE trans: 'tile coloring
  53.         trans = _NEWIMAGE(5, 5, 32): _DEST trans: CLS , _RGBA32(0, 0, 0, (1 - dark) * 255)
  54.         _SOURCE trans: _DEST temp: _PUTIMAGE: _FREEIMAGE trans 'tile darking
  55.     text_tile(t2, t) = _COPYIMAGE(temp, 33): _FREEIMAGE temp: NEXT t2: _FREEIMAGE stand_temp
  56.  
  57.     'make door-flash
  58.     temp_color(0) = _RGB32(255, 100, 100): temp_color(1) = _RGB32(100, 100, 255) 'door 2 colors
  59.     FOR t2 = 0 TO dt_c - 1: a = 1 / (dt_c - 1) * t2: temp = _NEWIMAGE(3, 3, 32): _DEST temp: m = .5 * dark
  60.         cr = (_RED32(temp_color(0)) * a + _RED32(temp_color(1)) * (1 - a)) * m: cg = (_GREEN32(temp_color(0)) * a + _GREEN32(temp_color(1)) * (1 - a)) * m
  61.         cb = (_BLUE32(temp_color(0)) * a + _BLUE32(temp_color(1)) * (1 - a)) * m: CLS , _RGB32(cr, cg, cb)
  62.     door_text(t2, t) = _COPYIMAGE(temp, 33): _FREEIMAGE temp: NEXT t2
  63.  
  64.     'make diamants
  65.     tmax = 100: tmin = 40: size = INT(tmax - (tmax - tmin) / (shdw_c - 1) * t)
  66.     FOR t2 = 0 TO dia_text_c - 1: temp = _NEWIMAGE(size, size, 32): _DEST temp: _SOURCE temp
  67.         temp_color(0) = _RGB32(2 + dark * 186 * RND(1), 2 + dark * 186 * RND(1), 2 + dark * 186 * RND(1))
  68.         COLOR temp_color(0): CIRCLE (size / 2, size / 2), size / 2 * .95: PAINT (size / 2, size / 2), temp_color(0), temp_color(0)
  69.     _CLEARCOLOR POINT(0, 0): dia_text(t2, t) = _COPYIMAGE(temp, 33): _FREEIMAGE temp: NEXT t2
  70.  
  71. 'white flash
  72. wf_c = 20: DIM wf_text(wf_c - 1): sizex = INT(monx * .3): sizey = INT(mony * .3)
  73. FOR t = 0 TO wf_c - 1: temp = _NEWIMAGE(sizex, sizey, 32): _DEST temp: FOR tx = 0 TO sizex - 1: FOR ty = 0 TO sizey - 1
  74.             PSET (tx, ty), _RGBA32(255, 255, 255, ((255 / (sizex / 2) * SQR((sizex / 2 - tx) ^ 2 + (sizey / 2 - ty) ^ 2) + 200) * (1 / (wf_c - 1) * t)) * .6)
  75. NEXT ty, tx: wf_text(t) = _COPYIMAGE(temp, 33): _FREEIMAGE temp: NEXT t
  76.  
  77.  
  78. DIM d(7, 1) AS _BYTE 'directions array
  79. d(0, 1) = -1: d(1, 0) = 1: d(1, 1) = -1: d(2, 0) = 1: d(3, 0) = 1: d(3, 1) = 1
  80. d(4, 1) = 1: d(5, 0) = -1: d(5, 1) = 1: d(6, 0) = -1: d(7, 0) = -1: d(7, 1) = -1
  81.  
  82. 'ROOM array
  83. '0,1,2,3 x1,y1,x2,y2 position in room_map array
  84. '4 number of doors
  85. '20+ ,21+  door coordinates (step5)
  86. '22+ door exit direction
  87.  
  88. 'ROOM_MAP array  (room,x,y)
  89. 'nothing
  90. 'bit 0-walking area
  91. 'bit 1,2,3,4-wall
  92. 'bit 5 door
  93. DIM SHARED me(9), cam(9) '0,1,2 XYZ 3,4 angAB , 5 room
  94.  
  95. 'make rooms
  96. DIM SHARED room(room_c - 1, 99), room_map(room_c - 1, room_buffsize - 1, room_buffsize - 1) AS _UNSIGNED _BYTE
  97.  
  98. mapsize0 = 20: room(0, 1) = mapsize0: room(0, 3) = mapsize0: FOR tx = 0 TO mapsize0 - 1: FOR ty = 0 TO mapsize0 - 1
  99. room_map(0, tx, ty) = 1 + ABS(tx = 0 OR tx = mapsize0 - 1 OR ty = 0 OR ty = mapsize0 - 1) * 3: NEXT ty, tx
  100.  
  101. FOR ar = 0 TO room_c - 1
  102.     IF ar THEN
  103.         room_map(ar, INT(room_buffsize / 2), INT(room_buffsize / 2)) = 1: reg_minmax_reset 0: reg_minmax_reset 1
  104.         FOR t = 0 TO INT(randscale(room_boxmin_c, room_boxmax_c)) - 1
  105.             FOR t2 = 0 TO 1: box(t2) = INT(randscale(INT(room_relsize * (.4 + .2 * t2)), INT(room_relsize * (.5 + .2 * t2)))): NEXT t2
  106.             IF INT(2 * RND(1)) THEN SWAP box(0), box(1)
  107.             DO: px = INT(room_buffsize * RND(1)): py = INT(room_buffsize * RND(1)): LOOP UNTIL room_map(ar, px, py)
  108.             px2 = INT(box(0) * RND(1) / 2): py2 = INT(box(1) * RND(1) / 2): FOR tx = 0 TO box(0) - 1: FOR ty = 0 TO box(1) - 1
  109.         wx = tx + px - px2: wy = ty + py - py2: room_map(ar, wx, wy) = 1: reg_minmax 0, wx: reg_minmax 1, wy: NEXT ty, tx, t
  110.         room(ar, 0) = rm(0, 0) - 2: room(ar, 1) = rm(0, 1) + 2: room(ar, 2) = rm(1, 0) - 2: room(ar, 3) = rm(1, 1) + 2
  111.         'make doors
  112.         room(ar, 4) = INT(randscale(room_doormin, room_doormax)): FOR ad = 0 TO room(ar, 4) - 1: agent = 0
  113.             DO: px = INT((room_buffsize - 2) * RND(1)) + 1: py = INT((room_buffsize - 2) * RND(1)) + 1: REDIM cnt(1, 1): dis_nook = 0
  114.                 FOR t2 = 0 TO 1: FOR t = 0 TO 7 STEP 2 - t2: c = room_map(ar, px + d(t, 0), py + d(t, 1)): cnt(t2, c) = cnt(t2, c) + 1: NEXT t, t2
  115.                 FOR ad2 = 0 TO ad: dis_nook = dis_nook OR (SQR((room(ar, 20 + ad2 * 5) - px) ^ 2 + (room(ar, 21 + ad2 * 5) - py) ^ 2) < 5 AND (ad2 <> ad))
  116.                     agent = agent + 1: IF agent > 100000 THEN room(ar, 4) = ad + 0: agent2 = 1: GOTO exitroom
  117.             NEXT ad2: LOOP UNTIL cnt(0, 0) = 3 AND cnt(0, 1) = 1 AND cnt(1, 0) = 5 AND cnt(1, 1) = 3 AND dis_nook = 0
  118.             room(ar, 20 + ad * 5) = px: room(ar, 21 + ad * 5) = py
  119.         FOR t = 0 TO 7 STEP 2: room(ar, 22 + ad * 5) = room(ar, 22 + ad * 5) OR room_map(ar, px + d(t, 0), py + d(t, 1)) * t: NEXT t, ad 'door exit dir
  120.         exitroom:
  121.         'make wall type
  122.         FOR tx = room(ar, 0) TO room(ar, 1): FOR ty = room(ar, 2) TO room(ar, 3): IF room_map(ar, tx, ty) = 1 THEN _CONTINUE
  123.                 FOR t = 0 TO 7 STEP 2: room_map(ar, tx, ty) = room_map(ar, tx, ty) OR (2 ^ (t / 2) * 2) * ABS(room_map(ar, tx + d(t, 0), ty + d(t, 1)) = 1)
  124.         NEXT t, ty, tx
  125.     END IF
  126.  
  127.     'add door to the room interior
  128.     IF ar THEN add_room_c = INT(3 * RND(1)): ELSE add_room_c = 1
  129.     IF add_room_c THEN
  130.         FOR t = 0 TO add_room_c - 1: agent = 0
  131.             DO: FOR t2 = 0 TO 1: box(t2) = randscale(room(ar, t2 * 2), room(ar, 1 + t2 * 2) - 1): NEXT t2: room_ok = 1
  132.                 FOR tx = 0 TO 4: FOR ty = 0 TO 4: IF room_map(ar, tx + box(0), ty + box(1)) <> 1 THEN room_ok = 0
  133.                 NEXT ty, tx: agent = agent + 1: IF agent > 500000 THEN GOTO exitroom2
  134.             LOOP UNTIL room_ok: FOR tx = 1 TO 3: FOR ty = 1 TO 3: room_map(ar, tx + box(0), ty + box(1)) = 2: NEXT ty, tx
  135.             FOR t2 = 0 TO 1: room(ar, 20 + room(ar, 4) * 5 + t2) = box(t2) + 2: NEXT t2: room(ar, 22 + room(ar, 4) * 5) = INT(4 * RND(1)) * 2
  136.             room_map(ar, box(0) + 2 + d(room(ar, 22 + room(ar, 4) * 5), 0), box(1) + 2 + d(room(ar, 22 + room(ar, 4) * 5), 1)) = 1
  137.         room(ar, 4) = room(ar, 4) + 1: NEXT t
  138.     END IF
  139.     exitroom2:
  140.  
  141.     'doors to map
  142.     FOR ad = 0 TO room(ar, 4) - 1: room_map(ar, room(ar, 20 + ad * 5), room(ar, 21 + ad * 5)) = 2 ^ 5: NEXT ad
  143. NEXT ar
  144.  
  145.  
  146. 'diamants location
  147. dia_c = diamant_c * (room_c - 1): DIM dia(dia_c - 1, 9): FOR ad = 0 TO dia_c - 1: dia(ad, 3) = INT((room_c - 1) * RND(1)) + 1
  148.     DO: FOR t = 0 TO 1: dia(ad, t) = randscale(room(dia(ad, 3), t * 2), room(dia(ad, 3), 1 + t * 2)): NEXT t
  149.     LOOP UNTIL room_map(dia(ad, 3), dia(ad, 0), dia(ad, 1)) = 1: dia(ad, 2) = .5
  150.     dv = (1 + RND(1)) * (diamant_speed_min + (diamant_speed_max - diamant_speed_min) / (room_c - 1) * dia(ad, 3))
  151.     dega = 360 * RND(1) * pip180: degb = 360 * RND(1) * pip180: dia(ad, 8) = 1
  152. dia(ad, 4) = SIN(degb) * COS(dega) * dv: dia(ad, 5) = SIN(degb) * SIN(dega) * dv: dia(ad, 6) = COS(degb) * dv / 2: NEXT ad
  153.  
  154.  
  155. 'my start position
  156. DO: FOR t = 0 TO 1: me(t) = randscale(room(me(5), t * 2), room(me(5), 1 + t * 2)): NEXT t: LOOP UNTIL room_map(me(5), me(0), me(1)) = 1
  157.  
  158. 'allocation of doors
  159. DIM adoor(room_c - 1, room_doormax + 10, 9) '9-present 0-trans to room 1-trans to door,8 -the only route
  160. FOR ar = 0 TO room_c - 2 'create only route
  161.     DO: door1 = INT(room(ar, 4) * RND(1)): LOOP WHILE adoor(ar, door1, 9)
  162.     DO: door2 = INT(room(ar + 1, 4) * RND(1)): LOOP WHILE adoor(ar + 1, door2, 9)
  163.     adoor(ar, door1, 0) = ar + 1: adoor(ar, door1, 1) = door2: adoor(ar, door1, 8) = 1: adoor(ar, door1, 9) = 1
  164. adoor(ar + 1, door2, 0) = ar: adoor(ar + 1, door2, 1) = door1: adoor(ar + 1, door2, 9) = 1: NEXT ar
  165.  
  166. FOR ar = 1 TO room_c - 1: FOR ad = 0 TO room(ar, 4) - 1: IF adoor(ar, ad, 9) THEN _CONTINUE
  167. adoor(ar, ad, 0) = INT(ar * RND(1)): adoor(ar, ad, 1) = INT(room(adoor(ar, ad, 0), 4) * RND(1)): adoor(ar, ad, 9) = 1: NEXT ad, ar
  168.  
  169. mon2 = _NEWIMAGE(800, 800, 32): SCREEN mon2: PRINT "DOORS ALLOCATION ": FOR ar = 0 TO room_c - 1: FOR ad = 0 TO room(ar, 4) - 1
  170.         IF adoor(ar, ad, 8) THEN COLOR _RGB32(255, 255, 255) ELSE COLOR _RGB32(100, 100, 100)
  171. PRINT ar; ".room,"; ad; ".door   TRANS TO  room:"; adoor(ar, ad, 0); ",door:"; adoor(ar, ad, 1): NEXT ad: PRINT: NEXT ar
  172. COLOR _RGB32(50, 50, 50): PRINT "Press any key !": DO: _LIMIT 30: LOOP WHILE INKEY$ = ""
  173.  
  174.  
  175.  
  176.  
  177. door_clip_d = 1: crash_active = 1: me(2) = .2 'my height in the game 0-1
  178. '----------------------------------------- BOSS CYCLE -------------------------------------------------------------------------
  179. DO: IF boss_limit = 0 THEN _LIMIT 50
  180.     inkey2$ = INKEY$
  181.     'cheat keys
  182.     boss_limit = boss_limit XOR ABS(cheat_active AND inkey2$ = "l"): crash_active = crash_active XOR ABS(cheat_active AND inkey2$ = "c")
  183.     me(2) = me(2) + (_KEYDOWN(ASC("+")) - _KEYDOWN(ASC("-"))) * .05 * cheat_active
  184.  
  185.     'control me
  186.     mousex = 0: mousey = 0: mw = 0: WHILE _MOUSEINPUT: mousex = mousex + _MOUSEMOVEMENTX: mousey = mousey + _MOUSEMOVEMENTY: mw = mw + _MOUSEWHEEL: WEND
  187.     k_left = _KEYDOWN(19200) OR _KEYDOWN(ASC("a")): k_right = _KEYDOWN(19712) OR _KEYDOWN(ASC("d"))
  188.     k_up = _KEYDOWN(18432) OR _KEYDOWN(ASC("w")) OR _MOUSEBUTTON(1): k_down = _KEYDOWN(20480) OR _KEYDOWN(ASC("s")) OR _MOUSEBUTTON(2)
  189.     me(3) = me(3) + mousex * mouse_sens: me(4) = me(4) + mousey * mouse_sens: IF ABS(me(4)) > 80 THEN me(4) = 80 * SGN(me(4))
  190.  
  191.     try_ang_sc = 85: FOR try_ang = 0 TO try_ang_sc STEP 6: FOR try_ang_dir = 0 TO 1
  192.             go = me_speed * ABS((k_left + k_right + k_up + k_down) = -1) * (1 / try_ang_sc * (try_ang_sc - try_ang))
  193.             go_ang = k_down * 180 + 90 * (k_left - k_right) + (me(3) + (try_ang_dir * 2 - 1) * try_ang): kit = .2
  194.             go_xa = SIN(go_ang * pip180) * kit + me(0): go_ya = -COS(go_ang * pip180) * kit + me(1): go_xg = SIN(go_ang * pip180) * go + me(0)
  195.             go_yg = -COS(go_ang * pip180) * go + me(1): IF crash(go_xa, go_ya) = 0 THEN me(0) = go_xg: me(1) = go_yg: GOTO ok
  196.     NEXT try_ang_dir, try_ang
  197.     ok:
  198.  
  199.     FOR t = 0 TO 9: cam(t) = me(t): NEXT t: door_clip = door_clip + door_clip_d: IF INT(door_clip) < 1 OR INT(door_clip) > dt_c - 2 THEN door_clip_d = -door_clip_d
  200.  
  201.     'draw objects
  202.     FOR tx = 0 TO room(me(5), 1) - room(me(5), 0): FOR ty = 0 TO room(me(5), 3) - room(me(5), 2)
  203.             l = room_map(me(5), room(me(5), 0) + tx, room(me(5), 2) + ty)
  204.             IF l = 1 OR l = 32 THEN 'TILE
  205.                 roof = (1 - ABS(me(5) = 0))
  206.                 FOR t2 = 0 TO roof: FOR t = 0 TO 3: p(t, 0) = tx + (SGN(t AND 1) * 2 - 1) * .5: p(t, 2) = ty + (SGN(t AND 2) * 2 - 1) * .5: p(t, 1) = t2
  207.                     point_3d p(t, 0), p(t, 1), p(t, 2): NEXT t: draw_square p(), text_tile(me(5), shdw(ABS(INT((p(0, 2) + p(1, 2) + p(2, 2) + p(3, 2)) / 4))))
  208.                 NEXT t2
  209.             END IF
  210.             IF l / 2 AND 15 THEN draw_brick_3d tx, ty 'WALL
  211.             IF l AND 32 THEN 'GATE
  212.                 dt = 0: FOR t2 = 0 TO 7 STEP 2: dt = dt OR (t2 * ABS(room_map(me(5), room(me(5), 0) + tx + d(t2, 0), room(me(5), 2) + ty + d(t2, 1)) = 1))
  213.                     NEXT t2: FOR t = 0 TO 3: p(t, 0) = (SGN(t AND 1) * 2 - 1) * .5: p(t, 2) = 0: p(t, 1) = (SGN(t AND 2) * 2 - 1) * .5 + .5
  214.                     rotate_2d p(t, 0), p(t, 2), 90 * pip180 * SGN(dt AND 2)
  215.                     p(t, 0) = p(t, 0) + tx: p(t, 2) = p(t, 2) + ty: point_3d p(t, 0), p(t, 1), p(t, 2)
  216.                 NEXT t: draw_square p(), door_text(INT(door_clip), shdw(ABS(INT((p(0, 2) + p(1, 2) + p(2, 2) + p(3, 2)) / 4))))
  217.             END IF
  218.     NEXT ty, tx
  219.  
  220.     'white flash
  221.     w_dis = .7: mindis = 999999: FOR ad = 0 TO room(me(5), 4) - 1
  222.         dis = SQR((me(0) - room(me(5), 20 + 5 * ad)) ^ 2 + (me(1) - room(me(5), 21 + 5 * ad)) ^ 2): IF dis < mindis THEN mindis = dis: trans_door = ad
  223.     NEXT ad: IF mindis > w_dis THEN awf_add = -.5
  224.     awf = awf + awf_add: IF INT(awf) < 0 THEN awf = 0 ELSE IF INT(awf) > wf_c - 1 THEN awf = wf_c - 1
  225.     _PUTIMAGE , wf_text(INT(awf))
  226.  
  227.  
  228.     'near door / trans to another room
  229.     IF mindis < .5 AND adoor(me(5), trans_door, 9) THEN
  230.         ndoor = adoor(me(5), trans_door, 1): me(5) = adoor(me(5), trans_door, 0)
  231.         FOR t = 0 TO 1: q(t) = d(room(me(5), 22 + ndoor * 5), t): me(t) = room(me(5), 20 + t + ndoor * 5) + q(t): NEXT t
  232.         me(3) = -degree(q(0), q(1)) + 180: awf = wf_c - 1
  233.     END IF
  234.  
  235.     'draw diamants
  236.     'DIAMANT array
  237.     '0,1,2 XYZ-location
  238.     '3,room-location
  239.     '4,5,6 XYZ vector
  240.     '8 active status 1-active
  241.  
  242.     diar = 10
  243.     FOR ad = 0 TO dia_c - 1: IF dia(ad, 3) <> me(5) OR dia(ad, 8) = 0 THEN _CONTINUE
  244.         'catch
  245.         catch = ABS((k_left + k_right + k_up + k_down) = -1) AND SQR((dia(ad, 0) - me(0)) ^ 2 + (dia(ad, 1) - me(1)) ^ 2) < .5
  246.         IF catch THEN dia(ad, 8) = 0: awf = (wf_c - 1) * .6: _CONTINUE
  247.  
  248.         'diamants move
  249.         newpos = dia(ad, 2) + dia(ad, 6): IF newpos < 0 OR newpos > 1 THEN dia(ad, 6) = -dia(ad, 6)
  250.         newpos = dia(ad, 0) + dia(ad, 4): IF room_map(me(5), newpos, dia(ad, 1)) <> 1 THEN dia(ad, 4) = -dia(ad, 4)
  251.         newpos = dia(ad, 1) + dia(ad, 5): IF room_map(me(5), dia(ad, 0), newpos) <> 1 THEN dia(ad, 5) = -dia(ad, 5)
  252.         FOR t = 0 TO 2: dia(ad, t) = dia(ad, t) + dia(ad, 4 + t): NEXT t
  253.  
  254.         'diamants draw
  255.         x = dia(ad, 0) - room(me(5), 0): z = dia(ad, 1) - room(me(5), 2): y = dia(ad, 2): point_3d x, y, z
  256.         FOR t = 0 TO 3: p(t, 0) = (SGN(t AND 1) * 2 - 1) * diar + x: p(t, 2) = z: p(t, 1) = (SGN(t AND 2) * 2 - 1) * diar + y: NEXT t
  257.         draw_square p(), dia_text(INT(dia_text_c * RND(1)), shdw(ABS(INT((p(0, 2) + p(1, 2) + p(2, 2) + p(3, 2)) / 4))))
  258.     NEXT ad
  259.  
  260.  
  261.     'stroryline
  262.     REDIM sum(room_c - 1): my_dia = 0: FOR ad = 0 TO dia_c - 1: my_dia = my_dia + dia(ad, 8): sum(dia(ad, 3)) = sum(dia(ad, 3)) + dia(ad, 8): NEXT ad
  263.  
  264.     FOR ar = 0 TO room_c - 1: COLOR _RGB32(255, 255, 255), b_colors(ar): LOCATE 2 + ar, 2
  265.         IF ar = 0 THEN PRINT "START ROOM"; ELSE IF sum(ar) THEN PRINT ar; ".room :"; sum(ar); " diamant"; ELSE PRINT ar; ".room is OK !";
  266.         IF ar = me(5) THEN COLOR _RGB32(255, 255, 255), 0: PRINT "    <-- YOU ARE HERE"
  267.     NEXT ar
  268.  
  269.     IF my_dia THEN
  270.         mess$ = "Get all diamant !"
  271.     ELSE
  272.         IF me(5) = 0 THEN mess$ = "CONGRATULATION !" ELSE mess$ = "Go back to the START-ROOM !"
  273.     END IF
  274.     LOCATE mony / 16 - 2, 2: COLOR _RGB32(255, 255, 255), 0: PRINT mess$
  275.  
  276.     _DISPLAY: CLS , 0
  277.  
  278.  
  279. FUNCTION crash (x, y): f = room_map(me(5), INT(x + .5), INT(y + .5)): crash = (f = 0 OR (f / 2 AND 15)) * crash_active: END FUNCTION
  280. FUNCTION randscale (a, b): randscale = a + (b - a) * RND(1): END FUNCTION
  281. SUB reg_minmax_reset (n): rm(n, 0) = 9999999: rm(n, 1) = -rm(n, 0): END SUB
  282. SUB reg_minmax (n, a): IF a < rm(n, 0) THEN rm(n, 0) = a ELSE IF a > rm(n, 1) THEN rm(n, 1) = a
  283. FUNCTION degree (a, b): degreex = ATN(a / (b + .00001)) / pip180: degreex = degreex - 180 * ABS(0 > b): degreex = degreex - 360 * (degreex < 0): degree = degreex: END FUNCTION
  284. SUB rotate_2d (x, y, ang): x1 = -(x * COS(ang) - y * SIN(ang)): y1 = -(x * SIN(ang) + y * COS(ang)): x = x1: y = y1: END SUB
  285.  
  286. SUB point_3d (x, y, z): x = (x - cam(0) + room(cam(5), 0)) * 100: y = (y - cam(2)) * 100: z = (z - cam(1) + room(cam(5), 2)) * 100
  287. rotate_2d x, z, -(cam(3) + 180) * pip180: rotate_2d y, z, (cam(4) + 180) * pip180: END SUB
  288.  
  289. SUB draw_square (p(), text)
  290.     wtext = _WIDTH(text) - 1: htext = _HEIGHT(text) - 1
  291.     _MAPTRIANGLE (0, 0)-(wtext, 0)-(0, htext), text TO(p(0, 0), p(0, 1), p(0, 2))-(p(1, 0), p(1, 1), p(1, 2))-(p(2, 0), p(2, 1), p(2, 2)), , _SMOOTH
  292.     _MAPTRIANGLE (wtext, htext)-(wtext, 0)-(0, htext), text TO(p(3, 0), p(3, 1), p(3, 2))-(p(1, 0), p(1, 1), p(1, 2))-(p(2, 0), p(2, 1), p(2, 2)), , _SMOOTH
  293.  
  294. SUB draw_brick_3d (x, y)
  295.     REDIM pc(7, 2): FOR t = 0 TO 7: pc(t, 0) = .5 * (SGN(t AND 1) * 2 - 1) + x: pc(t, 2) = .5 * (SGN(t AND 2) * 2 - 1) + y: pc(t, 1) = .5 * SGN(t AND 4) * 2
  296.         point_3d pc(t, 0), pc(t, 1), pc(t, 2): NEXT t: FOR t = 0 TO 4: FOR t2 = 0 TO 3: side = VAL(MID$("-0246-2367-3175-1054-4567", 2 + t * 5 + t2, 1))
  297.         FOR t3 = 0 TO 2: p(t2, t3) = pc(side, t3): NEXT t3, t2: draw_square p(), text_tile(me(5), shdw(ABS(INT((p(0, 2) + p(1, 2) + p(2, 2) + p(3, 2)) / 4))))
  298.     NEXT t
  299.  
  300.  
  301.  

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Mystical rooms, collect the diamonds!
« Reply #1 on: March 07, 2022, 02:36:19 am »
Cool game! Took a little while to get the hang of navigating with the mouse. Really fast when turning... Added to the difficulty...  Really impressed. No loading of sprites... and everything done in about 300 lines of code. Very nicely done!
Logic is the beginning of wisdom.

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: Mystical rooms, collect the diamonds!
« Reply #2 on: March 07, 2022, 04:46:42 am »
thanks ! You can adjust the sensitivity of the mouse at the beginning of the program. "mouse_sens". For example, type 0.2 instead of 0.5.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Mystical rooms, collect the diamonds!
« Reply #3 on: March 07, 2022, 05:41:26 am »
... and remove the challenge? lol
Logic is the beginning of wisdom.

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: Mystical rooms, collect the diamonds!
« Reply #4 on: March 07, 2022, 05:54:54 am »
if you want a challenge (which is still achievable), rewrite the beginning like this :)


room_c = 5 'how many rooms should be in the game?
diamant_c = 15 'average number of diamonds / room
room_doormin = 3 'there must be at least as many doors in a room
room_doormax = 4 'there should be a maximum of this number of doors in a room
me_speed = .15 'my speed
mouse_sens = .2

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Mystical rooms, collect the diamonds!
« Reply #5 on: March 07, 2022, 05:37:21 pm »
I did find a door, but couldn't get to it. Oh well, I never play games, so that didn't surprise me. Not being above to use the esc key to end did surprise me, so I had to do an ALT+Tab and "x" click to end it.

Pretty amazing to see how a map engine works. Lots of math instead of lots of code.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Mystical rooms, collect the diamonds!
« Reply #6 on: March 07, 2022, 06:23:25 pm »
You are not allowed to leave!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Mystical rooms, collect the diamonds!
« Reply #7 on: March 07, 2022, 10:45:11 pm »
... but you can check out anytime you like.

 - Hotel California
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/