Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - MasterGy

Pages: [1] 2 3 4
1
Programs / Garland of pearls
« on: March 21, 2022, 08:12:03 pm »
in principle, if I create a cobweb of points and connections, it will be a real cobweb in 3d that takes over all the vibrations of the spider


Code: QB64: [Select]
  1.  
  2. CONST pip180 = 3.141592 / 180
  3. monx = 800: mony = 800: mon = _NEWIMAGE(monx, mony, 32): SCREEN mon
  4.  
  5. gravity = 1
  6. obj_c = 15 'number objects
  7. DIM obj(obj_c - 1, 9) '0,1 posX,Y 3fix/mover
  8.  
  9.  
  10.  
  11. cent_x = monx / 2: cent_y = 20: zoom = 2
  12.  
  13. 'install "garland of pearls"
  14.  
  15.  
  16. 'garland
  17. min_weight = 6
  18. FOR a = 0 TO obj_c - 1
  19.     obj(a, 0) = (RND(1) - .5) * 100
  20.     obj(a, 1) = (RND(1) - .5) * 100
  21.     obj(a, 2) = min_weight + min_weight / 2 * RND(1)
  22.     obj(a, 3) = 1 '<---- 0 if fix, 1 if fly
  23.  
  24. obj(0, 0) = -64.5: obj(0, 1) = 5: obj(0, 3) = 0
  25. obj(obj_c - 1, 0) = 183.5: obj(obj_c - 1, 1) = -.5: obj(obj_c - 1, 3) = 0
  26.  
  27. 'connections
  28. conn_c = 100: DIM conn(conn_c - 1, 4)
  29. FOR a = 0 TO obj_c - 2
  30.     conn(a, 0) = a
  31.     conn(a, 1) = a + 1
  32.     conn(a, 2) = 20 'rope width
  33.     conn(a, 3) = 1
  34.  
  35.  
  36.  
  37.  
  38.  
  39. DO: _LIMIT 100
  40.  
  41.     'show info
  42.     wch = -1: FOR a = 0 TO obj_c - 1
  43.         IF _MOUSEX < 200 AND INT(_MOUSEY / 16) = a THEN wch = a: COLOR _RGB32(255, 255, 255) ELSE COLOR _RGB32(100, 100, 100)
  44.         LOCATE a + 1, 1: PRINT a; "# weight:"; INT(obj(a, 2) * 10) / 10;: IF obj(a, 3) = 0 THEN PRINT "FIX";
  45.         IF wch = a THEN PRINT "<--- using mousewheel !"
  46.         IF wch <> -1 THEN obj(wch, 2) = obj(wch, 2) + mw / 10: IF obj(wch, 2) < min_weight THEN obj(wch, 2) = min_weight
  47.     NEXT a
  48.     LOCATE mony / 16 - 1, 1: IF moving THEN PRINT "press SPACE to FIX/FLY"; ELSE PRINT "grab the ball with the mouse and move it!";
  49.  
  50.     'draw objects
  51.     FOR a = 0 TO obj_c - 1
  52.         x = cent_x + obj(a, 0) * zoom
  53.         y = cent_y + obj(a, 1) * zoom
  54.         IF mouse_near = a THEN COLOR _RGB32(255, 0, 0) ELSE COLOR _RGB32(200, 200, 200)
  55.         CIRCLE (x, y), obj(a, 2) * zoom
  56.         _PRINTSTRING (x, y), LTRIM$(STR$(a))
  57.     NEXT a
  58.  
  59.     'draw connections
  60.  
  61.     COLOR _RGB32(150, 150, 150)
  62.     FOR a = 0 TO conn_c - 1: IF conn(a, 3) = 0 THEN _CONTINUE
  63.         x1 = obj(conn(a, 0), 0) * zoom + cent_x
  64.         y1 = obj(conn(a, 0), 1) * zoom + cent_y
  65.         x2 = obj(conn(a, 1), 0) * zoom + cent_x
  66.         y2 = obj(conn(a, 1), 1) * zoom + cent_y
  67.     LINE (x1, y1)-(x2, y2): NEXT a
  68.  
  69.     'calculate moving
  70.  
  71.  
  72.     FOR a = 0 TO obj_c - 1: IF obj(a, 3) = 0 OR (mouse_near = a AND _MOUSEBUTTON(1)) THEN _CONTINUE
  73.  
  74.         'connections vector
  75.         vec_x = 0: vec_y = 0: vec_c = 0
  76.         FOR t = 0 TO conn_c - 1: IF conn(t, 3) = 0 THEN _CONTINUE
  77.             x = -1: FOR t2 = 0 TO 1: IF conn(t, t2) = a THEN x = conn(t, t2 XOR 1)
  78.             NEXT t2
  79.             IF x <> -1 THEN
  80.                 disx = obj(a, 0) - obj(x, 0)
  81.                 disy = obj(a, 1) - obj(x, 1)
  82.                 ang = (-degree(disx, disy) + 0) * pip180
  83.                 dis = SQR(disx * disx + disy * disy)
  84.                 power = dis / obj(a, 2) / 5
  85.                 '  IF dis < (obj(a, 2) + obj(x, 2)) THEN power = -power / 10000
  86.                 vec_x = vec_x + SIN(ang) * power
  87.                 vec_y = vec_y - COS(ang) * power
  88.                 vec_c = vec_c + 1
  89.             END IF
  90.         NEXT t
  91.  
  92.         gravity = .1
  93.         lass = .98
  94.  
  95.         obj(a, 4) = (obj(a, 4) + vec_x / vec_c) * lass
  96.         obj(a, 5) = (obj(a, 5) + vec_y / vec_c) * lass + gravity
  97.  
  98.         lx = obj(a, 0) + obj(a, 4)
  99.         ly = obj(a, 1) + obj(a, 5)
  100.  
  101.         obj(a, 0) = obj(a, 0) + obj(a, 4)
  102.         obj(a, 1) = obj(a, 1) + obj(a, 5)
  103.  
  104.  
  105.  
  106.     NEXT a
  107.  
  108.     mw = 0: WHILE _MOUSEINPUT: mw = mw + _MOUSEWHEEL: WEND
  109.  
  110.     'mouse moving activing
  111.     IF moving = 0 THEN
  112.         mouse_near = -1
  113.         FOR a = 0 TO obj_c - 1
  114.             disx = (cent_x + obj(a, 0) * zoom) - _MOUSEX
  115.             disy = (cent_y + obj(a, 1) * zoom) - _MOUSEY
  116.             dis = SQR(disx * disx + disy * disy)
  117.             IF dis < 10 THEN mouse_near = a
  118.         NEXT a
  119.     END IF
  120.  
  121.     IF (_MOUSEBUTTON(1) AND mouse_near <> -1) OR moving THEN
  122.         moving = 1
  123.         obj(mouse_near, 0) = (_MOUSEX - cent_x) / zoom
  124.         obj(mouse_near, 1) = (_MOUSEY - cent_y) / zoom
  125.     END IF
  126.  
  127.     moving = moving AND _MOUSEBUTTON(1)
  128.  
  129.  
  130.     'change weights with mousewheel
  131.  
  132.  
  133.  
  134.     _DISPLAY: CLS
  135.  
  136.     'commands
  137.     inkey2$ = INKEY$: IF inkey2$ = CHR$(27) THEN END
  138.     IF inkey2$ = " " AND _MOUSEBUTTON(1) AND moving THEN obj(mouse_near, 3) = obj(mouse_near, 3) XOR 1
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145. 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
  146.  

2
Programs / EVIL SPIDERS <--- only for the nervous system!
« on: March 11, 2022, 02:33:40 pm »
It's done!
I opened a new post because the game is ready from now on.
I intentionally didn’t put out either a video or a picture because I’m curious about the first reactions.
I didn't write the "strong" nervous system one out of a joke. Anyone unfamiliar with games like this can be scary at first.
The mood of the game is depressing, dark, depressing, and EVIL! :)

Thanks to Johnno56, the forum member for the newsprint idea !!!

3
Programs / Spider animation
« on: March 07, 2022, 10:04:17 am »
i want spiders in the game but not 2d gifs but i want my legs to move in 3d. I searched the internet and found good animations to move my legs.

https://in.pinterest.com/joysonvaz/animated-spider/

I downloaded the images and determined the position of the joints with an image editing program and built them into a system. Of course, the values went through a lot of transformations before I could store them in fairly well-compressed ASCII. Some samples, combined with linear interpolation, return very meticulous motion.

Code: QB64: [Select]
  1. DIM SHARED spani$
  2. spani$ = "LNKOJKGJDKMNMNQLROSQNNOOPKSMSPPNPNUMWOYRLNKOJKGKDMMNMONJNNNPNNOOOKPMPPPNQNTKXNZPLNKOJLHNFQMNMOLKKNLPNNOOOKNONQPNQOSLXMZPLNKOILGOGRMNMNLJILIO"
  3. spani$ = spani$ + "NNOOOLPOPRPNQNQKUNUQLNKOJKHOIRMNMNMKJMHPNNOORKUNURPNPOQKTNSQLNKOILHOIRMNMOLKKOJQNNPORLUOVRPNQOQKRNRRLNLOJMIOKRMNMOLKLOMRNNNOLMKPMRPNQORLRORR"
  4. spani$ = spani$ + "LNLOLKHMHOMNMNOJPNOQNNNONLJMJPPNPNSLUOTRLNLOKLGKFNMNMNPKQNQRNNPOQKTMTPPNPNTLWNXQ"
  5.  
  6.  
  7.  
  8. monx = 800: mony = 800: mon = _NEWIMAGE(monx, mony, 32): SCREEN mon
  9.  
  10. DIM xy(1)
  11. zoom = 12
  12.     FOR leg = 0 TO 3
  13.         FOR bre = 0 TO 3
  14.             sl_read xy(), ani, leg, bre
  15.             x1 = xy(0) * zoom + monx / 2
  16.             y1 = xy(1) * zoom + mony / 2
  17.             sl_read xy(), ani, leg, bre + 1
  18.             x2 = xy(0) * zoom + monx / 2
  19.             y2 = xy(1) * zoom + mony / 2
  20.             LINE (x1, y1)-(x2, y2)
  21.         NEXT bre
  22.     NEXT leg
  23.  
  24.     _DISPLAY: CLS
  25.     ani = ani + .1
  26.  
  27. SUB sl_read (xy(), ani, leg, bre): n1 = INT(ani) MOD 9: n2 = (n1 + 1) MOD 9: n3 = ani - INT(ani): pre = 1 + bre * 2 + leg * 10
  28. FOR t = 0 TO 1: a = ASC(MID$(spani$, t + pre + n1 * 40, 1)) - 78: b = ASC(MID$(spani$, t + pre + n2 * 40, 1)) - 78: xy(t) = a + (b - a) * n3: NEXT t: END SUB
  29.  
  30.  

4
Programs / 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.  

5
Programs / Mover Bricks 2D and 3D
« on: February 21, 2022, 03:46:47 pm »
Hello !

The game is complete, it does not use external files. At start-up, the difficulty level can be adjusted (1-5).
I could still increase the design, but it wasn’t my goal with all this to make a design game, so I won’t deal with it anymore.
I was wondering how many of you make games. You make very good 2D games. I especially like walking games.A small change can be made from these games into a 3D game.

The program would ultimately be a demonstration. At the end of the source code, those few lines perform the 3D calculations.
You need a 3D coordinate system, you need to include many points (many points form textures), and you need a point in this space who is an "observer." This is the most important ! The observer! Who looks at the other points. The observer has 5 data. X, Y, Z coordinates and direction to look. This is the angle of 2 planes perpendicular to each other. So X, Y, Z, ALPHA, BETA Knowing this, you can calculate the projected position of all the points on the screen, and _maptriangle can come.
I was thinking of a 3d engine that anyone could easily try based on their own ideas, but since the whole thing would be about 5 lines, I figured out instead that I would try to describe it as simply as possible to make it understandable.
A short, perfectly understandable writing about this. Put 2d theory and 3D projection on one level! It's a lot simpler than it looks.
Next time, I’ll check to see if a lot of people get to deal with it.



Code: QB64: [Select]
  1. DIM SHARED size_block, size_wall, me(9), cam(9), monx, mony, mb_c, map_x, map_y, crash_test_disable, shdw_c, speed_min, speed_max, draw_2d_map, zoom_3d
  2. '----------------- settings ---------------------------------------------------------------------------------------------
  3.  
  4.  
  5. PRINT "MOVER BRICK game  (MasterGy 2022)"
  6. PRINT "Choise level !  Press key 1,2,3,4,5"
  7. PRINT "(1-no move bricks 2-easy 3-medium 4-high 5-extreme)"
  8. DO: _LIMIT 10: x = ASC(RIGHT$(" " + INKEY$, 1)): IF x = 27 THEN SYSTEM
  9. LEVEL = x - 49: LOOP WHILE LEVEL < 0 OR LEVEL > 4
  10. 'LEVEL = 3
  11.  
  12. map_x = 30 'size map X
  13. map_y = 30 'size map Y
  14. money_c = 10 'money number what you find
  15. mb_c = 90 'maximum mover bricks in the map
  16. me_speed = .12 'my speed
  17. mouse_sens = 1
  18.  
  19.  
  20.  
  21. '------------------------------------------------------ advanced settings -------------------------------------------------------------
  22. add_wall_c = 4 'cross road-walls inside map
  23. walk_limit = 8 'walk limit outside map
  24. tile_marg = 5 'tiles outside near wall
  25. me(5) = .5 'the size of my extent relative to a brick (1=standard size)
  26. cheat_keys = 0 'enable cheat keys
  27. monx = 800: mony = INT(monx / _DESKTOPWIDTH * _DESKTOPHEIGHT)
  28. size_wall = .9 'size percent size_block (1=standard)
  29. b_colors = 12 'brick colors
  30. shdw_c = 50 'mipmap
  31. speed_max = .11 * LEVEL / 4 'bricks maximum speed
  32. speed_min = speed_max * .7 'bricks minimum speed
  33. zoom_2d = .8
  34. '----------------------------------------------------------------------------------------
  35.  
  36. 'ARRAYS
  37. 'MB array 0-ena/disa 1,2-XYlocation 3-direction 4-stopcounter 5-colorindex 6-relativespeed 7-levelratiospeed
  38. 'MAP array 0-empty 1-wall 2-wall-crossroad 3-money
  39. 'ME/CAM array  '0,1,2-X,Y,Z   3=angXY 4=angXZ    5'XY dimension
  40.  
  41. DIM SHARED temp_color(9) AS _INTEGER64
  42. CONST pip180 = 3.141592 / 180
  43.  
  44. 'ME install
  45. me(0) = -1: me(1) = -1 'my start locate
  46. size = 100: temp = _NEWIMAGE(size, size, 32): _DEST temp: CLS 0, _RGB32(10, 10, 10): CIRCLE (size / 2, size / 2), size / 2 * size_wall, _RGB32(200, 200, 200)
  47. PAINT (size / 2, size / 2), _RGB32(200, 200, 200): _CLEARCOLOR _RGB32(10, 10, 10): me_text = _COPYIMAGE(temp, 33): _FREEIMAGE temp
  48.  
  49. 'shadows
  50. DIM SHARED shdw(16383) AS _BYTE: FOR t = 0 TO 16383
  51.     ashdw = INT((shdw_c - 1) * 0.0006 * t): IF ashdw > shdw_c - 1 THEN ashdw = shdw_c - 1
  52.     shdw(t) = ashdw
  53.  
  54.  
  55. 'directions
  56. DIM d(3, 1) AS _BYTE: d(3, 1) = -1: d(0, 0) = 1: d(1, 1) = 1: d(2, 0) = -1: d(3, 1) = -1
  57.  
  58. DIM SHARED map(map_x - 1, map_y - 1) AS _UNSIGNED _BYTE, mb(mb_c - 1, 9)
  59.  
  60. 'make colors
  61. DIM SHARED b_colors(b_colors - 1) AS _INTEGER64: FOR t = 1 TO b_colors - 1: b_colors(t) = _RGB32(30 + 180 * RND(1), 30 + 180 * RND(1), 30 + 180 * RND(1)): NEXT t
  62. b_colors(0) = _RGB32(150, 20, 20) 'wall color
  63.  
  64. 'make textures
  65. marg = .12: tmax = 40: tmin = 40
  66. DIM SHARED text_mb(mb_c - 1, shdw_c - 1), text_wall(shdw_c - 1)
  67. FOR t = 0 TO shdw_c - 1: size = INT(tmax - (tmax - tmin) / (shdw_c - 1) * t): dark = 1 - 1 / (shdw_c - 1) * t
  68.     stand_temp = _NEWIMAGE(size, size, 32): _DEST stand_temp: CLS , _RGB32(50, 50, 50) 'frame color
  69.     LINE (size * marg, size * marg)-(size - size * marg, size - size * marg), _RGB32(180, 180, 180), BF: _SOURCE stand_temp
  70.     noise = 5 + 5 * (1 / (shdw_c - 1) * t) ^ 1.2 'add noise far tiles
  71.     FOR tx = 0 TO size - 1: FOR ty = 0 TO size - 1: temp_color(0) = POINT(tx, ty)
  72.             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)
  73.     NEXT ty, tx
  74.  
  75.     'make wall
  76.     FOR t2 = 0 TO b_colors - 1: temp = _COPYIMAGE(stand_temp, 32): _DEST temp
  77.         IF t2 = 0 THEN LINE (0, 0)-(size, size), _RGB32(50, 50, 50): LINE (size, 0)-(0, size), _RGB32(50, 50, 50) 'no mover wall
  78.         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)
  79.         _SOURCE trans: _DEST temp: _BLEND temp: _PUTIMAGE: _FREEIMAGE trans 'tile coloring
  80.         trans = _NEWIMAGE(5, 5, 32): _DEST trans: CLS , _RGBA32(0, 0, 0, (1 - dark) * 255)
  81.         _SOURCE trans: _DEST temp: _PUTIMAGE: _FREEIMAGE trans 'tile darking
  82.     text_mb(t2, t) = _COPYIMAGE(temp, 33): _FREEIMAGE temp: NEXT t2: _FREEIMAGE stand_temp
  83.  
  84.  
  85. 'skys_color
  86. DIM text_sky(999)
  87. FOR t = 0 TO 499
  88.     temp = _NEWIMAGE(3, 3, 32): _DEST temp: CLS , _RGB32(20, 20, 255 / 499 * t): text_sky(t) = _COPYIMAGE(temp, 33): _FREEIMAGE temp
  89.  
  90.  
  91. 'make walls
  92. FOR tx = 0 TO map_x - 1: FOR ty = 0 TO map_y - 1: map(tx, ty) = ABS(tx = 0 OR ty = 0 OR tx = map_x - 1 OR ty = map_y - 1): NEXT ty, tx
  93.  
  94. 'add walls within the framework
  95. add_wall_p(0) = .8: add_wall_p(1) = .8: FOR t = 1 TO add_wall_c
  96.     DO: FOR t2 = 0 TO 3: p(t2) = map_x * add_wall_p(t2 MOD 2) * RND(1) + map_x * (1 - add_wall_p(t2 MOD 2)) / 2: NEXT t2
  97.     dis = SQR((p(0) - p(2)) ^ 2 + (p(1) - p(3)) ^ 2): LOOP WHILE dis < 5: dis = dis * .7
  98. FOR t2 = 0 TO dis: map(INT(p(0) + (p(2) - p(0)) / dis * t2), INT(p(1) + (p(3) - p(1)) / dis * t2)) = 2: NEXT t2, t
  99.  
  100. 'money install
  101. DIM SHARED text_money(9)
  102. FOR t = 0 TO 9: temp = _NEWIMAGE(8, 16, 32): _DEST temp: COLOR _RGB32(256 * RND(1), 256 * RND(1), 256 * RND(1)): PRINT "$";
  103. _CLEARCOLOR _RGB32(0, 0, 0): text_money(t) = _COPYIMAGE(temp, 33): _FREEIMAGE temp: NEXT t
  104. DIM money(money_c - 1, 9)
  105. FOR t = 0 TO money_c - 1: DO: money(t, 0) = INT(1 + (map_x - 2) * RND(1)): money(t, 1) = INT(1 + (map_y - 2) * RND(1))
  106. LOOP WHILE map(money(t, 0), money(t, 1)): map(money(t, 0), money(t, 1)) = 3: NEXT t
  107.  
  108. 'make mover bricks
  109. FOR t = 0 TO mb_c - 1: agent_timer = TIMER
  110.     DO: mb(t, 1) = INT(1 + (map_x - 2) * RND(1)): mb(t, 2) = INT(1 + (map_y - 2) * RND(1)): mb(t, 3) = INT(4 * RND(1)): busy = 0
  111.         FOR tx = -1 TO 1: FOR ty = -1 TO 1: what = map(tx + mb(t, 1), ty + mb(t, 2)): busy = busy OR ABS(what = 2 OR what = 3): NEXT ty, tx
  112.         FOR t2 = 0 TO mb_c - 1: IF mb(t2, 0) = 0 OR busy THEN _CONTINUE
  113.         busy = busy OR (SQR((mb(t2, 1) - mb(t, 1)) ^ 2 + (mb(t2, 2) - mb(t, 2)) ^ 2) < 2): NEXT t2: IF ABS(agent_timer - TIMER) > 2 THEN EXIT FOR
  114.     LOOP WHILE busy: mb(t, 0) = 1: mb(t, 5) = 1 + INT((b_colors - 1) * RND(1))
  115.     mb(t, 7) = RND(1)
  116.  
  117. 'entri brick to the area
  118. DO: t = INT(2 * RND(1)): posx = INT((1 + (map_x - 2) * RND(1)) * t) + INT(2 * RND(1)) * (map_x - 1) * ABS(t = 0)
  119.     posy = INT((1 + (map_y - 2) * RND(1)) * (t XOR 1)) + INT(2 * RND(1)) * (map_x - 1) * ABS((t XOR 1) = 0)
  120.     busy = 0: FOR t = 0 TO mb_c - 1: busy = busy OR SQR((posx - mb(t, 1)) ^ 2 + (posy - mb(t, 2)) ^ 2) < 1.5: NEXT t
  121. LOOP WHILE busy: map(posx, posy) = 0
  122.  
  123.  
  124.  
  125. COLOR , _RGBA32(0, 0, 0, 0)
  126.  
  127.  
  128.  
  129.  
  130. limit_cycle = 1
  131.  
  132. '------------------------------------------- BOSS CYCLE
  133. DO: IF limit_cycle THEN _LIMIT 30
  134.  
  135.     'draw non mover blocks
  136.     FOR tx = -tile_marg TO map_x - 1 + tile_marg: FOR ty = -tile_marg TO map_y - 1 + tile_marg
  137.             IF (tx < 0 OR tx > map_x - 1 OR ty < 0 OR ty > map_y - 1) = 0 THEN IF map(tx, ty) = 1 OR map(tx, ty) = 2 THEN draw_brick_3d tx, ty, 0, 1
  138.             tile_3d tx, ty
  139.     NEXT ty, tx
  140.  
  141.     'draw mover blocks
  142.     FOR amb = 0 TO mb_c - 1: IF mb(amb, 0) THEN draw_brick_3d mb(amb, 1), mb(amb, 2), mb(amb, 5), 1
  143.     NEXT amb
  144.  
  145.     'draw me
  146.     IF (dead = 0 OR (dead AND INT(2 * RND(1)))) AND draw_2d_map THEN draw_brick_3d me(0), me(1), mb(0, 0), me(5)
  147.  
  148.     'draw money
  149.     IF storyline = 0 THEN
  150.         FOR t = 0 TO money_c - 1: IF money(t, 2) = 0 THEN money_3d money(t, 0), money(t, 1)
  151.         NEXT t
  152.     END IF
  153.  
  154.     'moving mover bricks
  155.     FOR amb = 0 TO mb_c - 1: IF mb(amb, 0) = 0 THEN _CONTINUE
  156.         p(0) = CINT(mb(amb, 1) + d(mb(amb, 3), 0) * (mb(amb, 6) + .5))
  157.         p(1) = CINT(mb(amb, 2) + d(mb(amb, 3), 1) * (mb(amb, 6) + .5)): dontgo = 0: letsneg = 0
  158.  
  159.         FOR t = 0 TO mb_c - 1: IF mb(t, 0) = 0 OR t = amb OR dontgo THEN _CONTINUE
  160.             vr = mb(t, 3) MOD 2: vr2 = vr = (mb(amb, 3) MOD 2)
  161.             letsneg = letsneg OR (((ABS(mb(t, 1 + vr) - mb(amb, 1 + vr)) < 1) AND (mb(t, 1 + (vr XOR 1))) = (mb(amb, 1 + (vr XOR 1)))) AND vr2)
  162.         dontgo = dontgo OR ((ABS(p(0) - mb(t, 1)) < 1 AND ABS(p(1) - mb(t, 2)) < 1) AND (vr2 = 0)): NEXT t
  163.  
  164.         mb(amb, 3) = (mb(amb, 3) + ABS(((letsneg) OR map(p(0), p(1)) = 2 OR map(p(0), p(1)) = 3) OR (p(0) = 0 OR p(0) = map_x - 1 OR p(1) = 0 OR p(1) = map_y - 1)) * 2) MOD 4
  165.         mb(amb, 4) = (mb(amb, 4) + ABS(dontgo)) * ABS(dontgo)
  166.         mb(amb, 3) = (mb(amb, 3) + 2 * ABS((mb(amb, 4) > 5 / mb(amb, 6)) AND dontgo)) MOD 4
  167.         mb(amb, 1) = mb(amb, 1) + d(mb(amb, 3), 0) * mb(amb, 6) * ABS(dontgo = 0)
  168.         mb(amb, 2) = mb(amb, 2) + d(mb(amb, 3), 1) * mb(amb, 6) * ABS(dontgo = 0)
  169.     NEXT amb
  170.  
  171.  
  172.     'control me
  173.     mousex = 0: mousey = 0: mw = 0: WHILE _MOUSEINPUT: mousex = mousex + _MOUSEMOVEMENTX: mousey = mousey + _MOUSEMOVEMENTY: mw = mw + _MOUSEWHEEL: WEND
  174.     k_left = _KEYDOWN(19200) OR _KEYDOWN(ASC("a")): k_right = _KEYDOWN(19712) OR _KEYDOWN(ASC("d"))
  175.     k_up = _KEYDOWN(18432) OR _KEYDOWN(ASC("w")) OR _MOUSEBUTTON(1): k_down = _KEYDOWN(20480) OR _KEYDOWN(ASC("s"))
  176.     mouse_act_sens = mouse_sens * (1 - (zoom_3d * .9) * ABS(draw_2d_map = 0))
  177.     me(3) = me(3) + mousex * mouse_act_sens - INT(me(3) / 360) * 360
  178.     me(4) = me(4) + mousey * mouse_act_sens
  179.     IF ABS(me(4)) > 80 THEN me(4) = 80 * SGN(me(4))
  180.     d2m_ang = INT((me(3) + 45) / 90) * 90
  181.     zoom_change = (mw / 30 + (-_KEYDOWN(ASC("-")) + _KEYDOWN(ASC("+"))) / 50)
  182.     zoom_2d = zoom_2d + zoom_change * draw_2d_map
  183.     IF zoom_2d < 0 THEN zoom_2d = 0 ELSE IF zoom_2d > 1 THEN zoom_2d = 1
  184.     zoom_3d = zoom_3d + zoom_change * (draw_2d_map = 0)
  185.     IF zoom_3d < 0 THEN zoom_3d = 0 ELSE IF zoom_3d > 1 THEN zoom_3d = 1
  186.  
  187.     IF dead = 0 THEN
  188.         IF crash_test(me(0), me(1)) THEN
  189.             try_speed = speed_max * 1.1
  190.             try = -1: FOR atry = 0 TO 3
  191.                 IF crash_test(me(0) + d(atry, 0) * try_speed, me(1) + d(atry, 1) * try_speed) = 0 THEN try = atry: EXIT FOR
  192.             NEXT atry: IF try = -1 THEN dead = 1
  193.             IF dead = 0 THEN me(0) = me(0) + d(atry, 0) * try_speed: me(1) = me(1) + d(atry, 1) * try_speed
  194.         END IF
  195.         try_ang_sc = 85
  196.         FOR try_ang = 0 TO try_ang_sc STEP 6: FOR try_ang_dir = 0 TO 1
  197.                 go = me_speed * ABS((k_left + k_right + k_up + k_down) = -1) * (1 / try_ang_sc * (try_ang_sc - try_ang)) ^ .7
  198.                 go_ang = k_down * 180 + 90 * (k_left - k_right) + (me(3) + (try_ang_dir * 2 - 1) * try_ang) * ABS(draw_2d_map = 0) + draw_2d_map * d2m_ang
  199.                 go_x = SIN(go_ang * pip180) * go + me(0): go_y = -COS(go_ang * pip180) * go + me(1)
  200.                 walk_limit_ok = (go_x < -walk_limit OR go_y < -walk_limit OR go_x > map_x - 1 + walk_limit OR go_y > map_y - 1 + walk_limit) = 0
  201.                 IF crash_test(go_x, go_y) = 0 AND walk_limit_ok THEN me(0) = go_x: me(1) = go_y: GOTO ok
  202.         NEXT try_ang_dir, try_ang
  203.         ok:
  204.     END IF
  205.  
  206.  
  207.     'cheats
  208.     inkey2$ = INKEY$: IF inkey2$ = CHR$(27) THEN SYSTEM
  209.     IF cheat_keys THEN
  210.         IF inkey2$ = "r" THEN RUN
  211.         IF inkey2$ = "l" THEN limit_cycle = limit_cycle XOR 1
  212.         IF inkey2$ = "c" THEN crash_test_disable = crash_test_disable XOR 1
  213.         IF inkey2$ = "o" THEN dead = 1 'reborn
  214.         IF inkey2$ = "p" THEN dead = 0 'dead
  215.     END IF
  216.  
  217.     'sky draw
  218.     IF draw_2d_map = 0 THEN
  219.         sky_flash = sky_flash - 0.02: IF sky_flash < 0 THEN sky_flash = 0
  220.         IF sky_flash > 1 THEN sky_flash = 1
  221.         IF dead THEN sky_ind = 490 * SGN(INT(TIMER * 50) AND 1) ELSE sky_ind = INT(490 * sky_flash)
  222.         asky = text_sky(sky_ind)
  223.         _MAPTRIANGLE (0, 0)-(0, 5)-(5, 0), asky TO(-16000, -16000, -10000)-(16000, -16000, -10000)-(-16000, 16000, -10000)
  224.         _MAPTRIANGLE (0, 0)-(0, 5)-(5, 0), asky TO(16000, 16000, -10000)-(16000, -16000, -10000)-(-16000, 16000, -10000)
  225.     END IF
  226.  
  227.     _DISPLAY: CLS
  228.  
  229.     'STORYLINE
  230.     IF storyline = 0 THEN
  231.         FOR t = 0 TO money_c - 1
  232.             find_money = SQR((me(0) - money(t, 0)) ^ 2 + (me(1) - money(t, 1)) ^ 2) < 1.1 AND (money(t, 2) = 0)
  233.             IF find_money THEN money_sum = money_sum + 1: map(money(t, 0), money(t, 1)) = 0: money(t, 2) = 1: sky_flash = 1: set_speed_bricks 1 / money_c * money_sum
  234.         NEXT t
  235.         storyline = storyline + ABS(money_sum = money_c)
  236.     END IF
  237.     IF storyline = 1 AND (me(0) > 0 AND me(0) < map_x - 1 AND me(1) > 0 AND me(1) < map_y - 1) = 0 THEN storyline = 2
  238.  
  239.     SELECT CASE storyline
  240.         CASE 0: s$ = "GET THE MONEY !   " + STR$(money_c) + " /" + STR$(money_sum)
  241.         CASE 1: s$ = "ESCAPE OUTSIDE THE WALL !"
  242.         CASE 2: s$ = "Mission compeleted ! "
  243.     END SELECT
  244.     IF dead THEN s$ = "you dead ,mission incompleted !"
  245.     COLOR _RGB32(255 * RND(1), 255 * RND(1), 255 * RND(1)): LOCATE 3, (monx / 8 - LEN(s$)) / 2: PRINT s$
  246.     COLOR _RGB32(255, 255, 255): LOCATE mony / 16 - 2, 2
  247.  
  248.     IF draw_2d_map THEN
  249.         PRINT "Switch 2D to 3D- space-key      control: arrows            2D zoom: mouse wheel ("; INT(zoom_2d * 100); "%)"
  250.     ELSE
  251.         PRINT "Switch 3D to 2D- space-key      control: WASD + mouse      3D zoom: mouse wheel ("; INT(zoom_3d * 100); "%)"
  252.     END IF
  253.  
  254.  
  255.     'camera fresh
  256.     IF inkey2$ = " " THEN draw_2d_map = draw_2d_map XOR 1: IF draw_2d_map = 0 THEN me(3) = d2m_ang: me(4) = 0: zoom_3d = 0
  257.  
  258.     IF draw_2d_map THEN
  259.         cam(0) = cam(0) + (me(0) - cam(0)) * 0.1
  260.         cam(1) = cam(1) + (me(1) - cam(1)) * 0.1
  261.         cam(2) = cam(2) + ((1.1 + (1 - zoom_2d) * 40) - cam(2)) * 0.1
  262.         cam(3) = cam(3) + (d2m_ang - cam(3)) * 0.5
  263.         cam(4) = cam(4) + (90 - cam(4)) * 0.1
  264.     ELSE
  265.         cam(0) = me(0)
  266.         cam(1) = me(1)
  267.         cam(3) = me(3)
  268.         cam(4) = cam(4) + (me(4) - cam(4)) * (0.05 + 0.45 * ABS(ABS(me(2) - cam(2)) < .5))
  269.         cam(2) = cam(2) + (0.3 - cam(2)) * 0.1
  270.     END IF
  271.  
  272.  
  273. 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
  274.  
  275. FUNCTION crash_test (x, y): IF crash_test_disable THEN EXIT FUNCTION
  276.     FOR myp = 0 TO 3: mx = x + me(5) * .5 * (SGN(myp AND 1) * 2 - 1): my = y + me(5) * .5 * (SGN(myp AND 2) * 2 - 1)
  277.         FOR amb = 0 TO mb_c - 1: IF mb(amb, 0) = 0 THEN _CONTINUE
  278.             IF mx > mb(amb, 1) - .5 AND mx < mb(amb, 1) + .5 AND my > mb(amb, 2) - .5 AND my < mb(amb, 2) + .5 THEN crash_test = 1: EXIT FUNCTION
  279.         NEXT amb
  280.         FOR tx = 0 TO map_x - 1: FOR ty = 0 TO map_y - 1: IF map(tx, ty) = 0 THEN _CONTINUE
  281.                 IF mx > tx - .5 AND mx < tx + .5 AND my > ty - .5 AND my < ty + .5 THEN crash_test = 1: EXIT FUNCTION
  282.     NEXT ty, tx, myp
  283.  
  284. SUB point_3d (x, y, z)
  285.     x = x - cam(0): y = y - cam(2): z = z - cam(1): rotate_2d x, z, -(cam(3) + 180) * pip180: rotate_2d y, z, (cam(4) + 180) * pip180
  286.     x = x * 100: y = y * 100: z = z * (120 - ABS(draw_2d_map = 0) * zoom_3d * 115)
  287.  
  288. SUB draw_brick_3d (x, y, text, relsize)
  289.     DIM p(3, 2), pc(7, 2), sq(3) AS _UNSIGNED _BYTE
  290.     size = size_wall * .5 * relsize
  291.     FOR t = 0 TO 7
  292.         pc(t, 0) = size * (SGN(t AND 1) * 2 - 1) + x: pc(t, 2) = size * (SGN(t AND 2) * 2 - 1) + y: pc(t, 1) = size * SGN(t AND 4) * 2
  293.         point_3d pc(t, 0), pc(t, 1), pc(t, 2)
  294.     NEXT t
  295.  
  296.     FOR t = 0 TO 4
  297.         FOR t2 = 0 TO 3: side = VAL(MID$("-0246-2367-3175-1054-4567", 2 + t * 5 + t2, 1))
  298.         FOR t3 = 0 TO 2: p(t2, t3) = pc(side, t3): NEXT t3, t2
  299.         draw_square p(), text_mb(text, shdw(ABS(INT((p(0, 2) + p(1, 2) + p(2, 2) + p(3, 2)) / 4)) * (draw_2d_map XOR 1)))
  300.     NEXT t
  301.  
  302. SUB tile_3d (x, y)
  303.     DIM p(3, 2)
  304.     FOR t = 0 TO 3
  305.         p(t, 0) = x + (SGN(t AND 1) * 2 - 1) * .5: p(t, 2) = y + (SGN(t AND 2) * 2 - 1) * .5: p(t, 1) = 0
  306.         point_3d p(t, 0), p(t, 1), p(t, 2)
  307.     NEXT t
  308.     IF draw_2d_map THEN shdw = 1000 ELSE shdw = ABS(INT((p(0, 2) + p(1, 2) + p(2, 2) + p(3, 2)) / 4))
  309.     draw_square p(), text_mb(0, shdw(shdw))
  310.  
  311.  
  312. SUB money_3d (x, y)
  313.     DIM p(3, 2)
  314.     FOR t = 0 TO 3
  315.         ang = (TIMER * 2 + _PI * (t AND 1) + x + y) * (((x + y) AND 1) * 2 - 1)
  316.         p(t, 0) = SIN(ang) * .5: p(t, 2) = COS(ang) * .5: p(t, 1) = SGN(t AND 2)
  317.         IF draw_2d_map THEN SWAP p(t, 1), p(t, 2): p(t, 1) = p(t, 1) + .5: p(t, 2) = p(t, 2) - .5
  318.         p(t, 0) = p(t, 0) + x: p(t, 2) = p(t, 2) + y
  319.         point_3d p(t, 0), p(t, 1), p(t, 2)
  320.     NEXT t
  321.     draw_square p(), text_money(INT(10 * RND(1)))
  322.  
  323. SUB draw_square (p(), text)
  324.     wtext = _WIDTH(text) - 1: htext = _HEIGHT(text) - 1
  325.     _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
  326.     _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
  327.  
  328. SUB set_speed_bricks (set_speed)
  329.     FOR amb = 0 TO mb_c - 1: mb(amb, 6) = (speed_min + (speed_max - speed_min) * mb(amb, 7)) * set_speed * ABS(mb(amb, 0)): NEXT amb
  330.  
  331.  

6
QB64 Discussion / _MAPTRIANGLE 3D ----> 2D ?
« on: February 20, 2022, 02:47:26 pm »
Hello !
Can you know from somewhere what formula _MAPTRIANGLE 3D calculates 2D points for?

The principle is this: 3D point is called X, Y, Z, then in this plane (2D) it will be.

FlatX = X / Z
FlatY = Y / Z

I used this a long time ago when _MAPTRIANGLE 3D didn’t exist and I know I had to enter a scaling value to make a proportional look of an object on the screen.
I should know what proportional value you are using. Specifically, I need the formula.

For example, if I wanted to detect the displayed 3D object with the position of the mouse, I would need to know the position of the FlatX and FlatY points.

7
Programs / courtesy cubes :)
« on: February 15, 2022, 05:01:51 pm »
this should make a game :)

Code: QB64: [Select]
  1. mon = _NEWIMAGE(800, 800, 32): SCREEN mon: _DEST mon
  2.  
  3. DIM SHARED temp_color(9) AS _INTEGER64
  4.  
  5. map_x = 30
  6. map_y = 30
  7.  
  8. mb_c = 54: DIM mb(mb_c - 1, 9)
  9.  
  10. DIM map(map_x - 1, map_y - 1)
  11.  
  12. speed = .05
  13. size_block = 23
  14. size_wall = .9
  15.  
  16. cent_x = (_WIDTH(mon) - size_block * map_x) / 2
  17. cent_y = (_HEIGHT(mon) - size_block * map_y) / 2
  18.  
  19.  
  20. DIM d(3, 1) AS _BYTE
  21. d(0, 0) = 0: d(0, 1) = -1
  22. d(1, 0) = 1: d(1, 1) = 0
  23. d(2, 0) = 0: d(2, 1) = 1
  24. d(3, 0) = -1: d(3, 1) = 0
  25.  
  26.  
  27. 'make walls
  28. FOR tx = 0 TO map_x - 1: FOR ty = 0 TO map_y - 1: map(tx, ty) = ABS(tx = 0 OR ty = 0 OR tx = map_x - 1 OR ty = map_y - 1): NEXT ty, tx
  29.  
  30. 'make mover bricks
  31. FOR t = 0 TO mb_c - 1
  32.     DO: mb(t, 1) = INT(1 + (map_x - 2) * RND(1)): mb(t, 2) = INT(1 + (map_y - 2) * RND(1)): mb(t, 3) = INT(4 * RND(1)): busy = 0
  33.         FOR t2 = 0 TO mb_c - 1: IF mb(t2, 0) = 0 THEN _CONTINUE
  34.             busy = busy OR (mb(t2, 1) = mb(t, 1) AND mb(t2, 2) = mb(t, 2))
  35.             sik = (mb(t, 3) MOD 2) = (mb(t2, 3) MOD 2) 'ha egy sikban mozognak
  36.             busy = busy OR ((mb(t2, 1) = mb(t, 1)) AND sik)
  37.             busy = busy OR ((mb(t2, 2) = mb(t, 2)) AND sik)
  38.         NEXT t2
  39.     LOOP WHILE busy
  40.     mb(t, 0) = 1 'lets busy
  41.  
  42. 'mb array
  43. '0 ena/disa
  44. '1,2 XY location
  45. '3 'direction
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54. '------------------------------------------- BOSS CYCLE
  55.     'draw non mover blocks
  56.     FOR tx = 0 TO map_x - 1: xc = tx * size_block + .5 + cent_x
  57.         FOR ty = 0 TO map_y - 1: yc = ty * size_block + .5 + cent_y
  58.             SELECT CASE map(tx, ty)
  59.                 CASE 1
  60.                     size = size_block * size_wall / 2
  61.                     LINE (xc - size, yc - size)-(xc + size, yc + size), _RGB32(255, 50, 50), BF
  62.             END SELECT
  63.     NEXT ty, tx
  64.  
  65.     'draw mover blocks
  66.     FOR amb = 0 TO mb_c - 1: IF mb(amb, 0) = 0 THEN _CONTINUE
  67.         xc = mb(amb, 1) * size_block + .5 + cent_x
  68.         yc = mb(amb, 2) * size_block + .5 + cent_y
  69.         size = size_block * size_wall / 2
  70.         LINE (xc - size, yc - size)-(xc + size, yc + size), _RGB32(50, 255, 50), BF
  71.     NEXT amb
  72.  
  73.     'moving mover bricks
  74.  
  75.     FOR amb = 0 TO mb_c - 1: IF mb(amb, 0) = 0 THEN _CONTINUE
  76.         tx = CINT(mb(amb, 1) + d(mb(amb, 3), 0) * (speed + .5))
  77.         ty = CINT(mb(amb, 2) + d(mb(amb, 3), 1) * (speed + .5))
  78.  
  79.  
  80.         IF map(tx, ty) = 1 THEN mb(amb, 3) = (mb(amb, 3) + 2) MOD 4: _CONTINUE
  81.         dontgo = 0
  82.         FOR t = 0 TO mb_c - 1: IF mb(t, 0) = 0 THEN _CONTINUE
  83.             IF (mb(t, 3) MOD 2) = (mb(amb, 3) MOD 2) THEN _CONTINUE
  84.             tx2 = CINT(mb(t, 1))
  85.             ty2 = CINT(mb(t, 2))
  86.             IF tx = tx2 AND ty = ty2 THEN dontgo = 1: EXIT FOR
  87.         NEXT t
  88.  
  89.  
  90.  
  91.         mb(amb, 1) = mb(amb, 1) + d(mb(amb, 3), 0) * speed * (dontgo XOR 1)
  92.         mb(amb, 2) = mb(amb, 2) + d(mb(amb, 3), 1) * speed * (dontgo XOR 1)
  93.  
  94.  
  95.     NEXT amb
  96.  
  97.  
  98.     _DISPLAY: CLS
  99.  
  100.  
  101.  

8
Programs / Terror in the Maze (graphics enhancement + surround sound)
« on: February 14, 2022, 06:51:05 am »
I figured out a quick shading for _MAPTRIANGLE 3d.
After making the car game, I took out Terror in the maze again and was surprised that the 3D rendering was often incomprehensible. When I made the game, I didn’t see it objectively. After looking at it again for a long time, I saw that there was confusion, not seeing what was happening. Galleon's idea of ​​shading the maze is very good! But only the maze became shaded, not the other elements. The enemies, the hundreds, or occasionally thousands of shrapnel, and the fire of the dragon were not shielded. Not because it would have required a lot of distance measurement, and the display would have stalled due to the many SQRs. In fact, for a thousand items, even a simple multiplication means a lot.
I came up with a good solution. Suppose we use 20 shades of 1 texture. The depth of _MAPTRIANGLE 3d Z is between 0 and -16384. I create an array DIM SHADOW (16384) and populate it proportionally from 0 to 20.
00000000111111111222222222 .... and so on.
This allows the shadow to be read without calculation from the Z value of the existing maptriangle.
De! the problem with that is cheating. If the observed object is not in front of us, but a little to the side, the Z-value will be less, so the object will become lighter, even though the distance from us is the same.
I came up with a solution for this:

 
solut01.jpg


Thus, with no calculations, thousands of textures appear shaded in front of us, creating the best 3D effect.
In addition, many changes:
-I also changed the generation of the maze walls. it’s not even programming, it’s more about color theory. I tried a lot to understand why that lot of color isn’t good, and I learned a lot during the making of the car game.
-as a car game, I also made this for surround sound. in principle it's written for a 4.0 sound system, but I can't try it, but the 2.0 stereo works. It is especially advantageous when we do not yet see the dragon but hear its direction.
-Many little things have been added to the program. I added what I needed and took what I didn’t. For example, the compass made no sense in the game.
-I added a multi-style maze texture to the game. Shown in the video. Everyone can choose which one is more enjoyable to play with.
-the gun gets hot in our hands if we shoot a lot. This will prevent the player from shooting recklessly, but not empty the magazine.
The course of the game has not changed.
Get the next round of ammo. Watch out, because if the monster gets close to you, it will take you away and run away with it! Shoot down every monster that approaches! If you have the ammo, the fairy will take you to the box that contains the dragons. Behind the box is the ammunition needed to blow up the next box. We can detonate the box if we have the ammunition and we will fire a 100% shot with the right mouse button!
Convert the 'starter' and 'titm_game' files to exe. The game starts with 'starter'.



comparison with old graphics before repair:
old:


Download:
https://drive.google.com/file/d/19GsqDs2Jt3m2oRWKZMh_C350rEgEp8nv/view?usp=sharing

9
Programs / '5 ball' - logic game AMOEBA?
« on: January 05, 2022, 06:49:29 pm »
Hi !
You must know that there is a logic game where 5 identical balls have to be unloaded by 2 players. Vertically, horizontally, or diagonally. (OX, othello, 5 ball ???) Known as a lot. We called it “amoeba” because when we played it in the booklet at school, it looked like that.
I found a very simple algorithm. Not professional, but persistent and fun. If you know a professional algorithm, send it to me.
I created an interface for it.

Code: QB64: [Select]
  1. '5 ball MasterGy 2022
  2. DIM SHARED colors(9) AS _INTEGER64, map_s
  3.  
  4.  
  5. '-------- SETTINGS
  6. monx = 1000 'windows X size
  7. colors(0) = _RGB32(255, 50, 50) 'player1 color - ME
  8. colors(1) = _RGB32(50, 50, 255) 'player2 color - COMPUTER
  9. tsq_size = 25 '1 square texture size
  10. ball_rad = .6 'ball size
  11. map_s = 100 'XxX map size
  12. pos_z = 5 'zoom map
  13. near = 3 'test field empty field full field distance
  14. text_h = monx * .05
  15. '------------------
  16.  
  17.  
  18.  
  19. 'MAP_MEM array 0 original balls ,1 winner color foggy area, 2 winner-puppet sin signal
  20.  
  21. txt_text(0) = txt_to_text("I WANT TO PLAY !!!-ENTER       exit-ESC")
  22. txt_text(1) = txt_to_text("BOARD ZOOM - mousewheel   BOARD MOVING - mouse right button and moving")
  23. txt_text(2) = txt_to_text("BACK-backspace TIP-T button EMPTY BOARD-E button")
  24.  
  25.  
  26. 'map texture
  27. temp = _NEWIMAGE(tsq_size, tsq_size, 32): _DEST temp: CLS , _RGB32(100, 100, 200)
  28. marg = tsq_size * .07: LINE (marg, marg)-(tsq_size - marg, tsq_size - marg), _RGB32(200, 200, 200), BF: text(0) = _COPYIMAGE(temp, 33): _FREEIMAGE temp
  29. 'balls and foggy texture
  30. FOR ac = 0 TO 1: temp = _NEWIMAGE(tsq_size, tsq_size, 32): _DEST temp: CLS: PAINT (0, 0), _RGB32(10, 10, 10)
  31.     CIRCLE (tsq_size / 2, tsq_size / 2), tsq_size * ball_rad / 2, colors(ac): PAINT (tsq_size / 2, tsq_size / 2), colors(ac), colors(ac)
  32.     _CLEARCOLOR _RGB32(10, 10, 10): text(1 + ac) = _COPYIMAGE(temp, 33)
  33.     IF ac = 0 THEN _SETALPHA 100, colors(ac), temp: text(9) = _COPYIMAGE(temp, 33)
  34.     _FREEIMAGE temp
  35.  
  36.     temp = _NEWIMAGE(20, 20, 32): _DEST temp: PAINT (0, 0), colors(ac), colors(ac): _SETALPHA 100, colors(ac), temp
  37. text(4 + ac) = _COPYIMAGE(temp, 33): _FREEIMAGE temp: NEXT ac
  38. 'map near texture
  39. temp = _NEWIMAGE(tsq_size, tsq_size, 32): _DEST temp: CLS , _RGB32(100, 100, 200)
  40. marg = tsq_size * .05: LINE (marg, marg)-(tsq_size - marg, tsq_size - marg), _RGB32(100, 100, 100), BF: text(3) = _COPYIMAGE(temp, 33): _FREEIMAGE temp
  41.  
  42.  
  43. 'preparation
  44. DIM steps(map_s * map_s - 1, 2) '0- 1 or 2 ,1-x, 2-y
  45. mony = monx / 16 * 9: mon = _NEWIMAGE(monx, mony, 32): SCREEN mon: pos_x = (monx - (pos_z * map_s)) / 2: pos_y = (mony - (pos_z * map_s)) / 2
  46. REDIM SHARED map_mem(map_s - 1, map_s - 1, 9)
  47.  
  48.  
  49.  
  50. DO: _LIMIT 50: winsin = winsin + .2: winsin_n = SIN(winsin) * pos_z * .1 'winner puppets sin
  51.     'moving and zooming map
  52.     mousew = 0: WHILE _MOUSEINPUT: mousew = mousew + _MOUSEWHEEL: WEND: apos_x = (_MOUSEX - pos_x) / (pos_z * map_s): apos_y = (_MOUSEY - pos_y) / (pos_z * map_s)
  53.     on_the_map = apos_x > 0 AND apos_x < 1 AND apos_y > 0 AND apos_y < 1
  54.     IF on_the_map THEN
  55.         pos_x = pos_x - (move_x - _MOUSEX) * ABS(_MOUSEBUTTON(2) AND mb2_last): pos_y = pos_y - (move_y - _MOUSEY) * ABS(_MOUSEBUTTON(2) AND mb2_last)
  56.         IF _MOUSEBUTTON(2) THEN move_x = _MOUSEX: move_y = _MOUSEY
  57.         mb2_last = _MOUSEBUTTON(2): pos_z = pos_z - mousew * 1.5: IF pos_z < 5 THEN pos_z = 5 ELSE IF pos_z > 60 THEN pos_z = 60
  58.         apos_x2 = (_MOUSEX - pos_x) / (pos_z * map_s): apos_y2 = (_MOUSEY - pos_y) / (pos_z * map_s)
  59.         mousew = (pos_z * map_s) * SGN(ABS(mousew)): pos_x = pos_x + (apos_x2 - apos_x) * mousew: pos_y = pos_y + (apos_y2 - apos_y) * mousew
  60.     END IF
  61.     pos_xa = pos_xa + (pos_x - pos_xa) * .1: pos_ya = pos_ya + (pos_y - pos_ya) * .1: pos_za = pos_za + (pos_z - pos_za) * .1: mon_limit = monx * .05
  62.     IF pos_xa + (map_s - 1) * pos_za < mon_limit THEN pos_xa = mon_limit - ((map_s - 1) * pos_za) + mon_re: pos_x = pos_xa
  63.     IF pos_xa > monx - mon_limit THEN pos_xa = monx - mon_limit - mon_re: pos_x = pos_xa
  64.     IF pos_ya + (map_s - 1) * pos_za < mon_limit THEN pos_ya = mon_limit - ((map_s - 1) * pos_za) + mon_re: pos_y = pos_ya
  65.     IF pos_ya > mony - mon_limit THEN pos_ya = mony - mon_limit - mon_re: pos_y = pos_ya
  66.  
  67.  
  68.     'fill map array
  69.     REDIM SHARED map(map_s - 1, map_s - 1, 9): FOR a = 0 TO steps_c - 1: map(steps(a, 1), steps(a, 2), 0) = steps(a, 0): NEXT a
  70.     FOR a = 0 TO steps_c - 1: FOR tx2 = -near TO near: FOR ty2 = -near TO near: IF tx2 = 0 AND ty2 = 0 THEN _CONTINUE
  71.                 px = tx2 + steps(a, 1): py = ty2 + steps(a, 2): IF px < 0 OR px > map_s - 1 OR py < 0 OR py > map_s - 1 THEN _CONTINUE
  72.     map(px, py, 1) = ABS(map(px, py, 0) = 0) AND ABS(map_mem(px, py, 1) = 0): NEXT ty2, tx2, a
  73.  
  74.     'draw map
  75.     FOR tx = 0 TO map_s - 1: FOR ty = 0 TO map_s - 1
  76.             x1 = pos_xa + tx * pos_za: x2 = x1 + pos_za: y1 = pos_ya + ty * pos_za: y2 = y1 + pos_za: atext = text(0): ww = winsin_n * map_mem(tx, ty, 2)
  77.             _PUTIMAGE (x1, y1)-(x2, y2), atext, , , _SMOOTH
  78.             IF steps_c THEN IF steps(steps_c - 1, 1) = tx AND steps(steps_c - 1, 2) = ty AND ls_step > 0 AND step_flash THEN _CONTINUE
  79.             IF map(tx, ty, 0) THEN _PUTIMAGE (x1 - ww, y1 - ww)-(x2 + ww, y2 + ww), text(map(tx, ty, 0)), , , _SMOOTH
  80.             IF map_mem(tx, ty, 0) THEN _PUTIMAGE (x1 - ww, y1 - ww)-(x2 + ww, y2 + ww), text(map_mem(tx, ty, 0)), , , _SMOOTH
  81.             IF map_mem(tx, ty, 1) THEN _PUTIMAGE (x1, y1)-(x2, y2), text(4 + map_mem(tx, ty, 1) - 1), , , _SMOOTH
  82.     NEXT ty, tx
  83.  
  84.     IF on_the_map THEN real_x = INT(map_s * apos_x): real_y = INT(map_s * apos_y) 'which block is the mouse on?
  85.     REDIM c(2): FOR tx = 0 TO map_s - 1: FOR ty = 0 TO map_s - 1: c(map(tx, ty, 0)) = c(map(tx, ty, 0)) + 1: NEXT ty, tx 'how many balls
  86.  
  87.     'draw putty if need
  88.     IF on_the_map AND c(2) >= c(1) AND connect_game AND _MOUSEBUTTON(2) = 0 THEN
  89.         elt = pos_za / 2 + winsin_n
  90.         _PUTIMAGE (_MOUSEX - elt, _MOUSEY - elt)-(_MOUSEX + elt, _MOUSEY + elt), text(9), , , _SMOOTH
  91.     END IF
  92.  
  93.  
  94.     map(0, 0, 8) = 0: calculation 'calculating the best move for both players
  95.  
  96.     'draw tip
  97.     IF (_KEYDOWN(ASC("t")) OR _KEYDOWN(ASC("T"))) AND INT(2 * RND(1)) AND connect_game THEN
  98.         x1 = pos_xa + map(0, 0, 4) * pos_za: x2 = x1 + pos_za: y1 = pos_ya + map(0, 0, 5) * pos_za: y2 = y1 + pos_za
  99.         _PUTIMAGE (x1, y1)-(x2, y2), text(1), , , _SMOOTH
  100.     END IF
  101.  
  102.  
  103.  
  104.  
  105.  
  106.     IF c(1) > c(2) THEN 'who's next?
  107.         steps(steps_c, 0) = 2: steps(steps_c, 1) = map(0, 0, 6): steps(steps_c, 2) = map(0, 0, 7): steps_c = steps_c + 1 'COMPUTER MOVING
  108.     ELSE
  109.         IF connect_game THEN
  110.             IF on_the_map AND _MOUSEBUTTON(1) AND mb1_last = 0 THEN
  111.                 IF map(real_x, real_y, 0) = 0 AND map_mem(real_x, real_y, 1) = 0 THEN
  112.                     steps(steps_c, 0) = 1: steps(steps_c, 1) = real_x: steps(steps_c, 2) = real_y: steps_c = steps_c + 1
  113.                 END IF
  114.             END IF
  115.             mb1_last = _MOUSEBUTTON(1): IF bill$ = CHR$(8) AND steps_c > 3 THEN steps_c = steps_c - 2
  116.         ELSE
  117.             IF steps_c = 0 THEN
  118.                 empty = 5: DO: x = INT(map_s * RND(1)): y = INT(map_s * RND(1)): no_ok = 0: FOR tx = -empty TO empty: FOR ty = -empty TO empty
  119.                             px = x + tx: py = y + ty: IF px < 0 OR px > map_s - 1 OR py < 0 OR py > map_s - 1 THEN no_ok = 1: _CONTINUE
  120.                 no_ok = no_ok OR SGN(map_mem(px, py, 1)): NEXT ty, tx: LOOP WHILE no_ok
  121.                 steps(steps_c, 0) = 1: steps(steps_c, 1) = x: steps(steps_c, 2) = y: steps_c = steps_c + 1
  122.             ELSE
  123.                 steps(steps_c, 0) = 1: steps(steps_c, 1) = map(0, 0, 4): steps(steps_c, 2) = map(0, 0, 5): steps_c = steps_c + 1
  124.             END IF
  125.         END IF
  126.     END IF
  127.  
  128.  
  129.     'text control
  130.     th = text_h / _HEIGHT(txt_text(1)) * _WIDTH(txt_text(1)): x1 = (monx - th) / 2: x2 = x1 + th: y1 = mony - text_h: y2 = mony
  131.     _PUTIMAGE (x1, y1)-(x2, y2), txt_text(1), , , _SMOOTH
  132.  
  133.     IF connect_game THEN
  134.         th = text_h / _HEIGHT(txt_text(2)) * _WIDTH(txt_text(2)): x1 = (monx - th) / 2: x2 = x1 + th: y1 = 0: y2 = text_h
  135.         _PUTIMAGE (x1, y1)-(x2, y2), txt_text(2), , , _SMOOTH
  136.     ELSE
  137.         th = text_h / _HEIGHT(txt_text(0)) * _WIDTH(txt_text(0)): x1 = (monx - th) / 2: x2 = x1 + th: y1 = 0: y2 = text_h
  138.         _PUTIMAGE (x1, y1)-(x2, y2), txt_text(0), , , _SMOOTH
  139.     END IF
  140.  
  141.  
  142.     _DISPLAY: CLS , _RGB32(30, 0, 0)
  143.  
  144.  
  145.  
  146.     IF map(0, 0, 8) THEN 'one player won!
  147.         fill = 2: FOR tx = 0 TO map_s - 1: FOR ty = 0 TO map_s - 1: IF map(tx, ty, 0) = 0 THEN _CONTINUE
  148.                 map_mem(tx, ty, 0) = map(tx, ty, 0): FOR tx2 = -fill TO fill: FOR ty2 = -fill TO fill
  149.                         px = tx2 + tx: py = ty2 + ty: IF px < 0 OR px > map_s - 1 OR py < 0 OR py > map_s - 1 THEN _CONTINUE
  150.         map_mem(px, py, 1) = map(0, 0, 8): NEXT ty2, tx2, ty, tx: steps_c = 0
  151.         winner_table = winner_table + 1: IF winner_table = 10 THEN winner_table = 0: REDIM SHARED map_mem(map_s - 1, map_s - 1, 9)
  152.     END IF
  153.  
  154.  
  155.     bill$ = LCASE$(INKEY$)
  156.     IF bill$ = CHR$(13) AND connect_game = 0 THEN connect_game = 1: steps_c = 0
  157.     IF bill$ = CHR$(27) THEN IF connect_game THEN connect_game = 0: pos_z = 5: pos_x = (monx - (pos_z * map_s)) / 2: pos_y = (mony - (pos_z * map_s)) / 2 ELSE SYSTEM
  158.     IF bill$ = "e" THEN REDIM SHARED map_mem(map_s - 1, map_s - 1, 9)
  159.  
  160.     'last step flash
  161.     IF steps_c <> l_steps_c THEN ls_step = 10
  162.     l_steps_c = steps_c: ls_step = ls_step - 1: step_flash = step_flash XOR 1
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173. SUB calculation
  174.     REDIM d(3, 1), xval(4), p(1, 4): d(0, 0) = 0: d(0, 1) = 1: d(1, 0) = 1: d(1, 1) = 1: d(2, 0) = 1: d(2, 1) = 0: d(3, 0) = -1: d(3, 1) = 1
  175.     xval(1) = 565: xval(2) = 2130: xval(3) = 7483: xval(4) = 43848
  176.  
  177.     'winning search
  178.     FOR tx = 0 TO map_s - 1: FOR ty = 0 TO map_s - 1: IF map(tx, ty, 0) = 0 THEN _CONTINUE
  179.             FOR ad = 0 TO 3: FOR av = 0 TO 4: REDIM c(2) AS _BYTE: FOR av2 = -4 TO 0
  180.                         p(0, ABS(av2)) = d(ad, 0) * (av + av2) + tx: p(1, ABS(av2)) = d(ad, 1) * (av + av2) + ty
  181.                         IF p(0, ABS(av2)) < 0 OR p(0, ABS(av2)) > map_s - 1 OR p(1, ABS(av2)) < 0 OR p(1, ABS(av2)) > map_s - 1 THEN _CONTINUE
  182.                     c(map(p(0, ABS(av2)), p(1, ABS(av2)), 0)) = c(map(p(0, ABS(av2)), p(1, ABS(av2)), 0)) + 1: NEXT av2: winner = ABS(c(1) = 5) + ABS(c(2) = 5) * 2
  183.                     IF winner THEN FOR ax = 0 TO 4: map_mem(p(0, ax), p(1, ax), 2) = 1: NEXT ax: map(0, 0, 8) = winner: EXIT SUB
  184.     NEXT av, ad, ty, tx
  185.  
  186.     'most effective steps
  187.     REDIM max(1): FOR tx = 0 TO map_s - 1: FOR ty = 0 TO map_s - 1: IF map(tx, ty, 1) = 0 OR map_mem(tx, ty, 1) THEN _CONTINUE
  188.             REDIM line_val(1), lv(1): FOR ad = 0 TO 3: FOR av = 0 TO 4: REDIM c(2) AS _BYTE: FOR av2 = -4 TO 0
  189.                         px = d(ad, 0) * (av + av2) + tx: py = d(ad, 1) * (av + av2) + ty: IF px < 0 OR px > map_s - 1 OR py < 0 OR py > map_s - 1 THEN _CONTINUE
  190.                     c(map(px, py, 0)) = c(map(px, py, 0)) + 1: NEXT av2: IF c(2) THEN lv(0) = 0 ELSE lv(0) = xval(c(1))
  191.                     IF c(1) THEN lv(1) = 0 ELSE lv(1) = xval(c(2))
  192.             line_val(0) = line_val(0) + lv(0): line_val(1) = line_val(1) + lv(1): NEXT av, ad
  193.             FOR ax = 0 TO 1: map(tx, ty, 2 + ax) = line_val(ax) * 1.7 + line_val(ax XOR 1) + 3 * RND(1)
  194.                 IF map(tx, ty, 2 + ax) > max(ax) THEN max(ax) = map(tx, ty, 2 + ax): map(0, 0, 4 + ax * 2) = tx: map(0, 0, 5 + ax * 2) = ty
  195.     NEXT ax, ty, tx
  196.  
  197. FUNCTION txt_to_text (x$): _FONT 16: marg = 10: temp = _NEWIMAGE(8 * LEN(x$) + 2 * marg, 16 + marg * 2, 32): _DEST temp: CLS , _RGBA32(0, 0, 0, 150)
  198. COLOR _RGB32(255, 255, 255), 0: _PRINTSTRING (marg, marg), x$: txt_to_text = _COPYIMAGE(temp, 33): _FREEIMAGE temp: END FUNCTION

 
amoba.jpg


10
Programs / The Big Chase (car-flight race game)
« on: December 25, 2021, 05:35:42 pm »
Hi !
The game is done. I have no more ideas about it, I’ll finish the development.
I opened a new topic for him, I think he deserves so much. Here you can see the finished game and play with it.
I gave him a name, "The Big Chase."
The graphics are just _maptriangle and the sound is stereo.
If you find an error, write it down. I also wonder how tolerable the difficulty is. Since I’ve tried a lot, I can’t judge.



11
QB64 Discussion / 4 speaker rehearsals
« on: December 16, 2021, 03:03:21 pm »
Hi !

I want to ask for a little help!
I want to do the car game with good sounds, engine noise, etc.…
I tried adjusting the balance. The rehearsal works with 2 speakers, so in stereo.
Unfortunately I only have a 2 speaker system.
I would like someone to test with 4 speakers to see if it works that way.
Just enter an mp3 music at the beginning of the program and then the position of the mouse in the circle will give the sound.
Does it work this way with 4 speakers?
Thanks for trying!

Code: QB64: [Select]
  1. sn = _SNDOPEN("engine_01.wav")
  2.  
  3.  
  4. monx = 600
  5.  
  6. cent = monx / 2
  7. rad = monx * .9 / 2
  8.  
  9. mon = _NEWIMAGE(monx, monx, 32): SCREEN mon
  10. CIRCLE (cent, cent), rad
  11. CIRCLE (cent, cent), 5
  12.  
  13.  
  14.  
  15.     IF _SNDPLAYING(sn) = 0 THEN _SNDPLAY sn
  16.  
  17.     'volume
  18.     dis = SQR((cent - _MOUSEX) ^ 2 + (cent - _MOUSEY) ^ 2)
  19.     IF dis > rad THEN dis = rad
  20.     volume = 1 - 1 / rad * dis
  21.     _SNDVOL sn, volume
  22.  
  23.     'balance (left-right)
  24.     disx = cent - _MOUSEX
  25.     IF ABS(disx) > rad THEN disx = rad * SGN(disx)
  26.     disx = -1 / rad * disx
  27.  
  28.     'balance (reae-front)
  29.     disy = cent - _MOUSEY
  30.     IF ABS(disy) > rad THEN disy = rad * SGN(disy)
  31.     disy = -1 / rad * disy
  32.  
  33.  
  34.     _SNDBAL sn, disx, disy, , 1 'left
  35.     _SNDBAL sn, disx, disy, , 2 'right
  36.  
  37.  
  38.  

12
Programs / car simulator
« on: November 14, 2021, 03:49:26 pm »
Hello !
I'm also trying to put a car in the flying game. I used to think about it, but I didn’t get anywhere. In fact, I'm still stuck. What is seen is not much different from the dynamics of the plane. we move an object in a plane that has velocity and direction. We modify the direction vector with the new direction created by the drift. But I got stuck.
I want you to travel in the mountains, on the hills, and the shock absorber would also be useful. I want you to tip over. This, in turn, is a much more complex approach. I would like to ask you for ideas, links, literature to see if anyone can help. where can i find writing about the physics of a car?
I created an environment for experimentation. You can try this, go with it, you can switch between 4 camera views with the C key, the current options will be displayed on the screen.



Code: QB64: [Select]
  1. CONST pip180 = 3.141592 / 180
  2. CONST perlin_pers = 0 '7 'amplitudo
  3. CONST perlin_level = 1 '5 'level of resolution wave
  4. CONST perlin_multiplier = 0.007
  5. CONST perlin_smooth_noise_interpolation_type = 0 '0-none '1-standard
  6. CONST perlin_flat_soil_limit_low = .8 'high value is low area (negate)
  7. CONST perlin_flat_soil_limit_high = .1
  8. CONST flight_array_size = 20: DIM flight_save(flight_array_size - 1)
  9. DIM SHARED rotating(2), cosrotz, sinrotz, cosrotx, sinrotx, map_zoom_xy, map_zoom_distance, see_point, flight(19, flight_array_size), me(19), rotx_bevel
  10. DIM SHARED mouse_sens_xy, mouse_sens_z, position_speed, clmn_rad
  11. DIM SHARED map_x, map_y, perl_setx, perl_sety, map_resolution, map_z, map_dimz, map_dimxy, flight_high_max
  12. monx = 1366 * .8: mony = monx / 16 * 9 'screen size
  13.  
  14. win_marg = monx / 25
  15. flight_high_max = -70
  16.  
  17. auto_precalc = 22
  18. auto_mouse_scale = 120
  19. auto_try_resolution = 22
  20. DIM flight_auto(auto_try_resolution - 1, flight_array_size - 1): DIM auto_efficiency(auto_try_resolution - 1, 5) '0- 1 if crash          '1- target-flight distance
  21.  
  22. pr_temp = 0 'temp pr
  23. text_deep = 30 'make deep shadow pictures
  24.  
  25.  
  26. map_center = 100000 'start of perlin-map
  27. 'text_field$ = "need\field2.bmp"
  28. text_field$ = "need\field1.bmp" 'field map texture
  29. text_multi = 40 'zoom to texture
  30.  
  31. position_speed = .3
  32. map_resolution = 50 'see map resolution
  33. DIM SHARED map_resper2: map_resper2 = INT(map_resolution / 2)
  34.  
  35.  
  36. DIM SHARED max_incli: max_incli = 65 'flight max rotation
  37.  
  38. map_dimxy = 1200 * .8
  39. map_dimz = 250 * .8
  40. DIM SHARED ee: ee = map_dimxy / map_resolution
  41.  
  42. map_zoom_xy = 6 * .2
  43. map_zoom_distance = 15 * .2
  44.  
  45.  
  46. mouse_sens_xy = 1.6
  47. mouse_sens_z = 1
  48.  
  49. me(6) = pip180 * 270
  50.  
  51. me(0) = map_center: me(1) = map_center
  52.  
  53. control_type$(0) = "walking": control_type$(1) = "flying": control_type$(2) = "flying/autopilot"
  54. DIM color_temp(9) AS _INTEGER64
  55. targ_text = _LOADIMAGE("need\target.jpg", 33)
  56.  
  57.  
  58.  
  59.  
  60.  
  61. DIM clmn(1999, 5): clmn_rad = 30: ration_column = 0.0003
  62. ration_column = 0.0003
  63.  
  64.  
  65. 'PREPARATION ---------------------------------------------------------------------------------------------------------------------------------------------------
  66.  
  67. 'create wheel texture
  68. whe_ts = 50: whe_marg = 7: temp = _NEWIMAGE(whe_ts, whe_ts, 32): _DEST temp: CLS , 0: marg = whe_ts * text_size_marg / 100
  69. PAINT (0, 0), _RGBA32(10, 10, 10, 255)
  70. LINE (whe_marg, whe_marg)-(whe_ts - whe_marg, whe_ts - whe_marg), _RGBA32(100, 100, 100, 255), BF
  71. whe_text = _COPYIMAGE(temp, 33): _FREEIMAGE temp
  72.  
  73. 'create pseudo random buffer
  74. DIM SHARED noise_rand_c: noise_rand_c = 10000: DIM SHARED noise_rand(noise_rand_c - 1): FOR t = 0 TO noise_rand_c - 1: noise_rand(t) = RND(1): NEXT t
  75.  
  76. 'vehicle frame texture
  77. vhfr_ts = 30: marg = 5: temp = _NEWIMAGE(vhfr_ts, vhfr_ts, 32): _DEST temp: PAINT (0, 0), _RGBA32(46, 88, 100, 255)
  78. LINE (marg, marg)-(vhfr_ts - marg, vhfr_ts - marg), _RGBA32(255, 166, 50, 255), BF: vhfr_text(0) = _COPYIMAGE(temp, 33): _FREEIMAGE temp
  79. temp = _NEWIMAGE(vhfr_ts, vhfr_ts, 32): _DEST temp: PAINT (0, 0), _RGBA32(255 / 2, 166 / 2, 50 / 2, 255): vhfr_text(1) = _COPYIMAGE(temp, 33): _FREEIMAGE temp
  80. temp = _NEWIMAGE(vhfr_ts, vhfr_ts, 32): _DEST temp: PAINT (0, 0), _RGBA32(150, 150, 255, 50): vhfr_text(2) = _COPYIMAGE(temp, 33): _FREEIMAGE temp
  81. temp = _NEWIMAGE(vhfr_ts, vhfr_ts, 32): _DEST temp: PAINT (0, 0), _RGBA32(233, 94, 61, 255)
  82. marg = 5: LINE (marg, marg)-(vhfr_ts - marg, vhfr_ts - marg), _RGB32(255, 0, 0), BF: _SETALPHA 0, _RGB32(255, 0, 0) TO _RGB32(255, 0, 0)
  83. vhfr_text(3) = _COPYIMAGE(temp, 33): _FREEIMAGE temp
  84.  
  85.  
  86.  
  87. vp$ = "-01010-03010-01020-03020-00031-04031-01052-03052-01072-03072-00081-04081-00101-04101-00090-04090" 'points X(2),Y(2),Z(1)
  88. vl$ = "-0001-0002-0103-0203-0004-0105-0204-0305-0406-0507-0607-0410-0511-0608-0709-0809-0810-0911-1011-1012-1113-1213-1412-1513-1415-0405-0214-0315" '3d lines
  89. sq$ = "-0123-4567-0246-2367-3175-1054" 'cubes points make square
  90. vt$ = "-000102031-000104051-141512131-101112131-040012141-050113151-080910111-141502031" 'bodywork textures
  91. vt$ = vt$ + "-040610082-040509112-040506072-060708092" 'vehicle windows
  92. vp$ = vp$ + "-01081-01101-01092-01102-03081-03101-03092-03102-00092-04092-00102-04102": vt$ = vt$ + "-161718193-202122233-242526270" 'extension air deflector
  93.  
  94.  
  95. 'temporary terrain texture
  96. DIM temp_color(9) AS _INTEGER64
  97. f = 500
  98. terr = _NEWIMAGE(f, f, 32): _DEST terr
  99. PAINT (0, 0), _RGB32(50, 80, 50)
  100. r = 50 * RND(1)
  101. FOR t = 0 TO 200
  102.     x = f * RND(1): y = f * RND(1)
  103.     temp_color(0) = _RGB32(255 * RND(1), 255 * RND(1), 255 * RND(1))
  104.     CIRCLE (x, y), 20, temp_color(0)
  105.     PAINT (x, y), temp_color(0), temp_color(0)
  106.  
  107. text_multi = 20
  108.  
  109.  
  110.  
  111.  
  112.  
  113. 'create texture to map
  114. DIM SHARED mapz_min, mapz_max: DIM texture(text_deep - 1, 5): temp = terr '_LOADIMAGE(text_field$, 32)
  115. FOR t = 0 TO text_deep - 1: dark = (.6 - (1 / (text_deep - 1) * t)): transp = dark * 2000: IF transp > 255 THEN transp = 255
  116.     temp2 = _NEWIMAGE(_WIDTH(temp), _HEIGHT(temp), 32): _SOURCE temp: _DEST temp2: CLS 0, _RGBA32(0, 0, 0, transp)
  117.     FOR tx = 0 TO _WIDTH(temp) - 1: FOR ty = 0 TO _HEIGHT(temp) - 1: temp_color(0) = POINT(tx, ty)
  118.             c1 = _RED32(temp_color(0)) * dark: c2 = _GREEN32(temp_color(0)) * dark: c3 = _BLUE32(temp_color(0)) * dark
  119. PSET (tx, ty), _RGBA32(c1, c2, c3, transp): NEXT ty, tx: texture(t, 0) = _COPYIMAGE(temp2, 33): _FREEIMAGE temp2: NEXT t
  120.  
  121. 'find min/max Z
  122. DIM SHARED mapz_multiplier: mapz_min = 9999999: mapz_max = -mapz_min: FOR t = 0 TO 2999: c = Perlin2D_original(5000 * RND(1), 5000 * RND(1))
  123.     mapz_min = c * ABS(mapz_min > c) + mapz_min * (ABS(mapz_min > c) XOR 1): mapz_max = c * ABS(mapz_max < c) + mapz_max * (ABS(mapz_max < c) XOR 1)
  124. NEXT t: mapz_multiplier = 1 / (mapz_max - mapz_min)
  125.  
  126. 'fill map-buffer
  127. DIM SHARED map(map_resolution - 1, map_resolution - 1, 19): perl_setx = INT(me(0)): perl_sety = INT(me(1))
  128. FOR map_x = 0 TO map_resolution - 1: FOR map_y = 0 TO map_resolution - 1
  129.         map((map_x + perl_setx) MOD map_resolution, (map_y + perl_sety) MOD map_resolution, 0) = perlin2d(perl_setx + map_x, perl_sety + map_y)
  130. map((map_x + perl_setx) MOD map_resolution, (map_y + perl_sety) MOD map_resolution, 6) = noise(map_x, map_y) < ration_column: NEXT map_y, map_x
  131.  
  132. 'calculating shadows
  133. FOR map_x = 0 TO map_resolution - 1: FOR map_y = 0 TO map_resolution - 1
  134.         dis = INT((text_deep - 1) / map_resper2 * SQR((map_x - map_resper2) ^ 2 + (map_y - map_resper2) ^ 2)): IF dis < 0 OR dis > text_deep - 1 THEN _CONTINUE
  135. map(map_x, map_y, 9) = 1: map(map_x, map_y, 8) = dis: NEXT map_y, map_x
  136.  
  137.  
  138.  
  139.  
  140. 'MAP array
  141. '0-perlin Z-data
  142. '1-maptriangle calculate X
  143. '2-maptriangle calculate Y
  144. '3-maptriangle calculate Z
  145. '4-distance from me (color)
  146. '5-texture height scale
  147. '6-is there a column ?
  148. '7-is the point visible?
  149. '8-shadow-table
  150. '9-not used area signal
  151.  
  152. 'ME array
  153. '0-me X location
  154. '1-me Y location
  155. '2-me Z location
  156. '3-vector_x
  157. '4-vector_y
  158. '5-me XY angle CAM3
  159. '6-me XY CAM4
  160. '7-me kanyarodas merteke
  161.  
  162. 'FLIGHT array
  163. '0-active
  164. '1-rotx - kanyarodas merteke
  165. '2-rotx_bevel
  166. '3-location X
  167. '4-location Y
  168. '5-location Z
  169. '6-vector X
  170. '7-vector Y
  171. '8-W gas
  172. '9-S brake
  173. '10-mouseX
  174. '11-mouseZ
  175. '12 cam4  /me6
  176. '13 cam3 /me5
  177. '15 actual speed
  178. '16 column (XY) crash /last step
  179. '17 land (Z) crash /last step
  180.  
  181. 'PREPARATION END ------------------------------------------------------------------------------------------------------------------------------------------
  182. GOSUB new_target
  183. CLS , 0
  184. control_type = 0
  185.  
  186.  
  187.  
  188.  
  189. IF pr_temp THEN _PRINTSTRING (0, 0), "moving:mouse+WASD jump:space walking/fly: F"
  190. DIM wang(20, 2, 1, 1)
  191. veh_posx = map_center
  192. veh_posy = map_center
  193.  
  194. DIM veh(19, 49)
  195. me2_comp = 1.5
  196. old_camera_type = -1
  197. '-------------------------------------------------------- BOSS CYCLE -----------------------------------------------------------------------------------
  198.  
  199.     'keyboard/mouse inputs
  200.     kf = _KEYDOWN(102): k_space = _KEYDOWN(32)
  201.     kw = _KEYDOWN(119): ks = _KEYDOWN(115): mousex = 0: mousey = 0: mw = 0: WHILE _MOUSEINPUT: mousex = mousex + _MOUSEMOVEMENTX: mousey = mousey + _MOUSEMOVEMENTY
  202.         mw = mw + _MOUSEWHEEL
  203.     WEND
  204.     kw = _KEYDOWN(119): ks = _KEYDOWN(115): ka = _KEYDOWN(97): kd = _KEYDOWN(100)
  205.     k_space = _KEYDOWN(32)
  206.     k_left = _KEYDOWN(19200): k_right = _KEYDOWN(19712): k_up = _KEYDOWN(18432): k_down = _KEYDOWN(20480): veh_wheel_sens = 8
  207.     IF ut_kf = 0 AND kf THEN control_type = (control_type + 1) MOD 3
  208.     ut_kf = kf
  209.     me2_comp = me2_comp + mw * .1
  210.     IF _KEYDOWN(45) THEN me2_comp = me2_comp - .2
  211.     IF _KEYDOWN(43) THEN me2_comp = me2_comp + .2
  212.     IF _KEYDOWN(47) THEN dis_comp = dis_comp + .2
  213.     IF _KEYDOWN(42) THEN dis_comp = dis_comp - .2
  214.  
  215.  
  216.  
  217.     '    IF _KEYDOWN(52) THEN veh_rotate2 = veh_rotate2 - .1
  218.     '    IF _KEYDOWN(54) THEN veh_rotate2 = veh_rotate2 + .1
  219.     '    IF _KEYDOWN(56) THEN veh_rotate3 = veh_rotate3 - .1
  220.     '    IF _KEYDOWN(50) THEN veh_rotate3 = veh_rotate3 + .1
  221.  
  222.  
  223.  
  224.  
  225.     'contol
  226.     IF pr_temp THEN _PRINTSTRING (500, 0), "control type : " + control_type$(control_type) + "           "
  227.     control_type = 0
  228.     SELECT CASE control_type '(0-walking 1-flying)
  229.         CASE 0
  230.             walk_speed = .18
  231.             me(3) = 0: me(4) = 0: me(7) = 0: flight(0, 1) = 0
  232.             me(5) = me(5) + mousex * mouse_sens_xy / 200: me(6) = me(6) + mousey * mouse_sens_xy / 200
  233.             go = ABS(ka OR kd OR kw OR ks): direction = (-90 * ABS(ka) + 90 * ABS(kd) + 180 * ABS(ks)) * go * pip180
  234.             go_x = -(SIN(direction + me(5)) * walk_speed) * go: go_y = -(COS(direction + me(5)) * walk_speed) * go
  235.             me(0) = me(0) + go_x: me(1) = me(1) + go_y
  236.             ' me(2) = (map_deep(me(0), me(1)) - .18 + mapzd) * map_dimz
  237.             'IF k_space AND free_jump THEN jump_cf = 15
  238.             rotx_bevel = rotx_bevel * .95: me(2) = me(2) - jump_cf / 4: jump_cf = jump_cf - 1: IF jump_cf < 0 THEN jump_cf = 0
  239.     END SELECT
  240.  
  241.  
  242.     'camera control
  243.  
  244.     IF INKEY$ = "c" THEN camera_type = (camera_type + 1) MOD 4
  245.  
  246.  
  247.     IF camera_type <> old_camera_type THEN
  248.  
  249.  
  250.         LOCATE 1, 1: PRINT "VEHICLE CONTROL: arrow keys ,space-handbrake"
  251.  
  252.         c$(0) = "typical view, camera height adjustment mousewheel, camera distance /,* buttons , and mouse horisontal look"
  253.         c$(1) = "interior view and mouse look around"
  254.         c$(2) = "'cameraman' follows the car. camera height is mousewheel and mouse horisontal look"
  255.         c$(3) = "free walking. WASD + mouse arrow. camera height is mousewheel "
  256.         LOCATE 2, 1: PRINT "camera type :"; camera_type; "(change C button);  "
  257.         LOCATE 3, 1: PRINT c$(camera_type) + SPACE$(120 - LEN(c$(camera_type)))
  258.     END IF
  259.     old_camera_type = camera_type
  260.  
  261.  
  262.  
  263.     SELECT CASE camera_type
  264.         CASE 0
  265.             me(5) = me(5) + (veh_rotate1_counterforce - me(5)) / 20
  266.             dis = 5 + dis_comp
  267.             me(0) = SIN(veh_rotate1) * dis + veh_posx
  268.             me(1) = COS(veh_rotate1) * dis + veh_posy
  269.             me(2) = map_deep(veh_posx, veh_posy) * map_dimz - (.5 + me2_comp) * ee
  270.             ' me(5) = (degree(veh_posx - me(0), veh_posy - me(1)) + 180) * pip180
  271.  
  272.         CASE 1
  273.             me(5) = me(5) + (veh_rotate1_counterforce - me(5)) / 20
  274.             dis = 5 - 5.2 '    dis_comp = -5.2: me2_comp = 0.6
  275.             me(0) = SIN(veh_rotate1) * dis + veh_posx
  276.             me(1) = COS(veh_rotate1) * dis + veh_posy
  277.             me(2) = map_deep(veh_posx, veh_posy) * map_dimz - (.5 + .6) * ee
  278.             ' me(5) = (degree(veh_posx - me(0), veh_posy - me(1)) + 180) * pip180
  279.  
  280.         CASE 2
  281.             medismax = 8: medismin = 3: follow = .01
  282.  
  283.             DO WHILE SQR((me(0) - veh_posx) ^ 2 + (me(1) - veh_posy) ^ 2) > medismax
  284.             me(0) = me(0) + SGN(veh_posx - me(0)) * follow: me(1) = me(1) + SGN(veh_posy - me(1)) * follow: LOOP
  285.  
  286.             DO WHILE SQR((me(0) - veh_posx) ^ 2 + (me(1) - veh_posy) ^ 2) < medismin
  287.             me(0) = me(0) - SGN(veh_posx - me(0)) * follow: me(1) = me(1) - SGN(veh_posy - me(1)) * follow: LOOP
  288.  
  289.             me(5) = (degree(veh_posx - me(0), veh_posy - me(1)) + 180) * pip180
  290.             me(2) = map_deep(veh_posx, veh_posy) * map_dimz - (.5 + me2_comp) * ee
  291.  
  292.         CASE 3
  293.             medis = 25: follow = .01
  294.             IF me(0) <> veh_posx THEN DO WHILE ABS(me(0) - veh_posx) > medis: me(0) = me(0) + SGN(veh_posx - me(0)) * follow: LOOP
  295.             IF me(1) <> veh_posy THEN DO WHILE ABS(me(1) - veh_posy) > medis: me(1) = me(1) + SGN(veh_posy - me(1)) * follow: LOOP
  296.             me(2) = map_deep(veh_posx, veh_posy) * map_dimz - (.5 + me2_comp) * ee
  297.     END SELECT
  298.  
  299.  
  300.  
  301.  
  302.     cosrotz = COS(me(5)): sinrotz = SIN(me(5)): cosrotx = COS(me(6)): sinrotx = SIN(me(6)) 'to rotating angles
  303.  
  304.  
  305.     '------------------------------------------ TERRAIN DRAW --------------------------------------------------------------------------------------------------
  306.  
  307.     'replace the missing row in the buffer line Y
  308.     DO WHILE INT(INT(me(0))) <> perl_setx: dir = -SGN(INT(me(0)) - perl_setx): perl_setx = perl_setx - dir
  309.         temp = INT(perl_setx + ABS(dir = -1) * (map_resolution - 1)): temp_m = INT(temp MOD map_resolution)
  310.         FOR map_y = 0 TO map_resolution - 1: map(temp_m, INT(map_y + perl_sety) MOD map_resolution, 0) = perlin2d(temp, perl_sety + map_y)
  311.     map(temp_m, INT((map_y + perl_sety) MOD map_resolution), 6) = noise(temp, perl_sety + map_y) < ration_column: NEXT map_y: LOOP
  312.  
  313.     'replace the missing row in the buffer line X
  314.     DO WHILE INT(INT(me(1))) <> perl_sety: dir = -SGN(INT(me(1)) - perl_sety): perl_sety = perl_sety - dir
  315.         temp = perl_sety + ABS(dir = -1) * (map_resolution - 1): temp_m = INT(temp MOD map_resolution)
  316.         FOR map_x = 0 TO map_resolution - 1: map(INT((map_x + perl_setx) MOD map_resolution), temp_m, 0) = perlin2d(perl_setx + map_x, temp)
  317.     map(INT(map_x + perl_setx) MOD map_resolution, temp_m, 6) = noise(perl_setx + map_x, temp) < ration_column: NEXT map_x: LOOP
  318.  
  319.     'calculating position and textures
  320.     clmn(0, 0) = 0 'reset column counter
  321.     FOR map_x = 0 TO map_resolution - 1: px = -map_dimxy / 2 + map_dimxy / map_resolution * (map_x - (me(0) - INT(me(0))))
  322.         FOR map_y = 0 TO map_resolution - 1: IF map(map_x, map_y, 9) = 0 THEN _CONTINUE
  323.             py = -map_dimxy / 2 + map_dimxy / map_resolution * (map_y - (me(1) - INT(me(1))))
  324.             read_mapx = INT((map_x + perl_setx) MOD map_resolution): read_mapy = INT((map_y + perl_sety) MOD map_resolution): map_z = map(read_mapx, read_mapy, 0)
  325.             map(map_x, map_y, 7) = 0: pz2 = map_dimz * map_z - me(2): rotate px, py, pz2, 1: IF see_point = 0 THEN _CONTINUE
  326.             map(map_x, map_y, 1) = rotating(0): map(map_x, map_y, 2) = rotating(1): map(map_x, map_y, 3) = rotating(2): map(map_x, map_y, 7) = 1
  327.             map(map_x, map_y, 5) = INT(text_height_scale * map_z): IF map(map_x, map_y, 5) > text_height_scale - 1 THEN map(map_x, map_y, 5) = text_height_scale - 1
  328.             IF map(map_x, map_y, 5) < 0 THEN map(map_x, map_y, 5) = 0
  329.             IF map(read_mapx, read_mapy, 6) THEN clmn(clmn(0, 0) + 1, 2) = map(map_x, map_y, 8): clmn(clmn(0, 0) + 1, 0) = px: clmn(clmn(0, 0) + 1, 1) = py: clmn(0, 0) = clmn(0, 0) + 1
  330.     NEXT map_y, map_x
  331.  
  332.     'do maptriangle from squares !
  333.     FOR map_x = 0 TO map_resolution - 2: FOR map_y = 0 TO map_resolution - 2
  334.             IF (map(map_x, map_y, 7) AND map(map_x + 1, map_y, 7) AND map(map_x, map_y + 1, 7) AND map(map_x + 1, map_y + 1, 7)) = 0 THEN _CONTINUE
  335.             m0x = map(map_x, map_y, 1): m0y = map(map_x, map_y, 2): m0z = map(map_x, map_y, 3)
  336.             m1x = map(map_x + 1, map_y, 1): m1y = map(map_x + 1, map_y, 2): m1z = map(map_x + 1, map_y, 3)
  337.             m2x = map(map_x, map_y + 1, 1): m2y = map(map_x, map_y + 1, 2): m2z = map(map_x, map_y + 1, 3)
  338.             m3x = map(map_x + 1, map_y + 1, 1): m3y = map(map_x + 1, map_y + 1, 2): m3z = map(map_x + 1, map_y + 1, 3)
  339.             atexture = texture(map(map_x, map_y, 8), 0): sx1 = (perl_setx + map_x) * text_multi: sy1 = (perl_sety + map_y) * text_multi: sx2 = sx1 + text_multi: sy2 = sy1 + text_multi
  340.             _MAPTRIANGLE (sx1, sy1)-(sx2, sy1)-(sx1, sy2), atexture TO(m0x, m0y, m0z)-(m1x, m1y, m1z)-(m2x, m2y, m2z)
  341.     _MAPTRIANGLE (sx2, sy2)-(sx2, sy1)-(sx1, sy2), atexture TO(m3x, m3y, m3z)-(m1x, m1y, m1z)-(m2x, m2y, m2z): NEXT map_y, map_x
  342.  
  343.     'TERRAIN DRAW END --------------------------------------------------------------------------------------------------------------------------------------------
  344.  
  345.  
  346.  
  347.  
  348.     'VEHICLE DRAW   -------------------------------------------------------------------------------------------------------
  349.  
  350.  
  351.     v_ratio = .5
  352.     veh_tengelytav = 4 * v_ratio
  353.     veh_kerektav = 4 * v_ratio
  354.     veh_kerekrad = 1 * v_ratio
  355.     veh_kerekszeles = .9 * v_ratio
  356.     veh_posz = map_deep(veh_posx, veh_posy) * map_dimz - veh_kerekrad * ee '- 2
  357.     veh_shockab_scale = .3
  358.     body_cx = .6 * v_ratio
  359.     body_cy = .6 * v_ratio
  360.     body_cz = .8 * v_ratio
  361.     frs = .08 * v_ratio
  362.  
  363.     frs_dis_c = 1.1: body_yadd = -5.5 'frame size (ratio to vp$)
  364.  
  365.     'draw wheel
  366.     wh_r(0) = veh_kerekrad: wh_r(1) = veh_kerekrad * .4: wh_div = 16 'wheel parameters
  367.     FOR a_wheel = 0 TO 3: wh_posy = (SGN(a_wheel AND 1) * 2 - 1) * veh_tengelytav / 2: wh_posx = (SGN(a_wheel AND 2) * 2 - 1) * veh_kerektav / 2
  368.         wheel_ang = (90 + ABS(a_wheel AND 1) * veh_wheel) * pip180
  369.         FOR awh = 0 TO wh_div - 1: ang = (-wheel(a_wheel, 0) + 360 / wh_div * awh) * pip180: x = SIN(ang): y = COS(ang)
  370.             FOR sz = 0 TO 1: wh_z = (sz * 2 - 1) * veh_kerekszeles / 2: FOR whr = 0 TO 1: r1 = x * wh_r(whr): r2 = wh_z: r3 = y * wh_r(whr)
  371.                     rotate_2d r2, r1, wheel_ang: r1 = r1 + wh_posx: r2 = r2 + wh_posy: r3 = r3 + veh_shockab_scale * shockab(a_wheel)
  372.                     rotate_vehicle r1, r2, r3, veh_rotate1, veh_rotate2, veh_rotate3: r1 = r1 + veh_posx: r2 = r2 + veh_posy: r3 = r3 * ee + veh_posz
  373.         rotate (r1 - me(0)) * ee, (r2 - me(1)) * ee, r3 - me(2), 0: FOR t = 0 TO 2: wang(awh, t, whr, sz) = rotating(t): NEXT t, whr, sz, awh
  374.         FOR t1 = 0 TO wh_div - 1: t2 = (t1 + 1) MOD wh_div: FOR t3 = 0 TO 1: FOR t4 = 0 TO 1
  375.                     p00 = t1: p01 = t4: p02 = t4: p10 = t2: p11 = t4: p12 = t4: p20 = t1: p21 = t3: p22 = t3 XOR 1: p30 = t2: p31 = t3: p32 = t3 XOR 1
  376.                     _MAPTRIANGLE (0, 0)-(whe_ts - 1, 0)-(0, whe_ts - 1), whe_text TO(wang(p00, 0, p01, p02), wang(p00, 1, p01, p02), wang(p00, 2, p01, p02))-(wang(p10, 0, p11, p12), wang(p10, 1, p11, p12), wang(p10, 2, p11, p12))-(wang(p20, 0, p21, p22), wang(p20, 1, p21, p22), wang(p20, 2, p21, p22))
  377.                     _MAPTRIANGLE (whe_ts - 1, whe_ts - 1)-(whe_ts - 1, 0)-(0, whe_ts - 1), whe_text TO(wang(p30, 0, p31, p32), wang(p30, 1, p31, p32), wang(p30, 2, p31, p32))-(wang(p10, 0, p11, p12), wang(p10, 1, p11, p12), wang(p10, 2, p11, p12))-(wang(p20, 0, p21, p22), wang(p20, 1, p21, p22), wang(p20, 2, p21, p22))
  378.     NEXT t4, t3, t1, a_wheel
  379.  
  380.     'draw vehicle frame
  381.     FOR t1 = 0 TO LEN(vl$) / 5 - 1: p1 = VAL(MID$(vl$, t1 * 5 + 2, 2)): p2 = VAL(MID$(vl$, t1 * 5 + 4, 2))
  382.         x1 = (VAL(MID$(vp$, p1 * 6 + 2, 2)) - 2) * body_cx: y1 = -(VAL(MID$(vp$, p1 * 6 + 4, 2)) + body_yadd) * body_cy: z1 = -(VAL(MID$(vp$, p1 * 6 + 6, 1))) * body_cz
  383.         x2 = (VAL(MID$(vp$, p2 * 6 + 2, 2)) - 2) * body_cx: y2 = -(VAL(MID$(vp$, p2 * 6 + 4, 2)) + body_yadd) * body_cy: z2 = -(VAL(MID$(vp$, p2 * 6 + 6, 1))) * body_cz
  384.         xc = (x1 + x2) / 2: yc = (y1 + y2) / 2: zc = (z1 + z2) / 2: dis = SQR((x1 - x2) ^ 2 + (y1 - y2) ^ 2 + (z1 - z2) ^ 2) / 2 * frs_dis_c
  385.         angle1 = (-degree(x2 - x1, y2 - y1)) * pip180: angle2 = (degree(y2 - y1, z2 - z1) - 90) * pip180
  386.         FOR t2 = 0 TO 7: p(t2, 0) = (SGN(ABS(t2 AND 1)) * 2 - 1) * frs: p(t2, 1) = (SGN(ABS(t2 AND 2)) * 2 - 1) * dis: p(t2, 2) = (SGN(ABS(t2 AND 4)) * 2 - 1) * frs
  387.             rotate_2d p(t2, 0), p(t2, 1), angle1: rotate_2d p(t2, 1), p(t2, 2), -angle2: p(t2, 0) = p(t2, 0) + xc: p(t2, 1) = p(t2, 1) + yc: p(t2, 2) = p(t2, 2) + zc
  388.             rotate_vehicle p(t2, 0), p(t2, 1), p(t2, 2), veh_rotate1, veh_rotate2, veh_rotate3: r1 = p(t2, 0) + veh_posx: r2 = p(t2, 1) + veh_posy
  389.         r3 = (veh_posz + p(t2, 2) * ee) - me(2): rotate (r1 - me(0)) * ee, (r2 - me(1)) * ee, r3, 0: FOR t = 0 TO 2: p(t2, t) = rotating(t): NEXT t, t2
  390.         FOR t2 = 0 TO 5: FOR t3 = 0 TO 3: sq(t3) = VAL(MID$(sq$, 2 + t2 * 5 + t3, 1)): NEXT t3
  391.             _MAPTRIANGLE (0, 0)-(vhfr_ts - 1, 0)-(0, vhfr_ts - 1), vhfr_text(0) TO(p(sq(0), 0), p(sq(0), 1), p(sq(0), 2))-(p(sq(1), 0), p(sq(1), 1), p(sq(1), 2))-(p(sq(2), 0), p(sq(2), 1), p(sq(2), 2))
  392.             _MAPTRIANGLE (vhfr_ts - 1, vhfr_ts - 1)-(vhfr_ts - 1, 0)-(0, vhfr_ts - 1), vhfr_text(0) TO(p(sq(3), 0), p(sq(3), 1), p(sq(3), 2))-(p(sq(1), 0), p(sq(1), 1), p(sq(1), 2))-(p(sq(2), 0), p(sq(2), 1), p(sq(2), 2))
  393.     NEXT t2, t1
  394.  
  395.     'draw vehicle bodywork textures
  396.     FOR t1 = 0 TO LEN(vt$) / 10 - 1: FOR t = 0 TO 3: vtx(t) = VAL(MID$(vt$, t1 * 10 + (t + 1) * 2, 2)): NEXT t
  397.         FOR t2 = 0 TO 3: vt(t2, 0) = (VAL(MID$(vp$, vtx(t2) * 6 + 2, 2)) - 2) * body_cx: vt(t2, 1) = -(VAL(MID$(vp$, vtx(t2) * 6 + 4, 2)) + body_yadd) * body_cy
  398.             vt(t2, 2) = -(VAL(MID$(vp$, vtx(t2) * 6 + 6, 1))) * body_cz: rotate_vehicle vt(t2, 0), vt(t2, 1), vt(t2, 2), veh_rotate1, veh_rotate2, veh_rotate3
  399.             r1 = vt(t2, 0) + veh_posx: r2 = vt(t2, 1) + veh_posy: r3 = (veh_posz + vt(t2, 2) * ee) - me(2)
  400.         rotate (r1 - me(0)) * ee, (r2 - me(1)) * ee, r3, 0: FOR t = 0 TO 2: vt(t2, t) = rotating(t): NEXT t, t2: atexture = vhfr_text(VAL(MID$(vt$, t1 * 10 + 10, 1)))
  401.         _MAPTRIANGLE (0, 0)-(vhfr_ts - 1, 0)-(0, vhfr_ts - 1), atexture TO(vt(0, 0), vt(0, 1), vt(0, 2))-(vt(1, 0), vt(1, 1), vt(1, 2))-(vt(2, 0), vt(2, 1), vt(2, 2))
  402.         _MAPTRIANGLE (vhfr_ts - 1, vhfr_ts - 1)-(vhfr_ts - 1, 0)-(0, vhfr_ts - 1), atexture TO(vt(3, 0), vt(3, 1), vt(3, 2))-(vt(1, 0), vt(1, 1), vt(1, 2))-(vt(2, 0), vt(2, 1), vt(2, 2))
  403.     NEXT t1
  404.  
  405.  
  406.     'VEHICLE DRAW END ----------------------------------------------------------------------------------------------------------
  407.  
  408.  
  409.  
  410.  
  411.  
  412.     'vehicle control
  413.  
  414.  
  415.  
  416.     veh_speed_max = .3
  417.  
  418.     veh_wheel = veh_wheel + (k_left - k_right) * veh_wheel_sens '/ ((veh_speed + .01) * 5)
  419.     veh_wheel_max = 45: IF ABS(veh_wheel) > veh_wheel_max THEN veh_wheel = SGN(veh_wheel) * veh_wheel_max
  420.  
  421.     veh_speed = SQR(veh_vecx ^ 2 + veh_vecy ^ 2)
  422.  
  423.     IF k_space THEN gg = 3 ELSE gg = 1
  424.     veh_wheel = veh_wheel * (.85 - veh_speed / gg)
  425.  
  426.  
  427.     veh_rotate1 = veh_rotate1 + (veh_speed * veh_wheel) / 120
  428.  
  429.  
  430.     veh_rotate1_counterforce = veh_rotate1
  431.  
  432.     position_accel = .0091: ww = .98: szog_xy = veh_rotate1 '+ weh_wheel * pip180
  433.  
  434.     new_vec_x = SIN(szog_xy) * position_accel * k_up * ABS(k_space = 0)
  435.     new_vec_y = COS(szog_xy) * position_accel * k_up * ABS(k_space = 0)
  436.     vec_x = (veh_vecx * ww + new_vec_x)
  437.     vec_y = (veh_vecy * ww + new_vec_y)
  438.     vec_sum = SQR(vec_x * vec_x + vec_y * vec_y):
  439.     IF vec_sum > veh_speed_max THEN vec_sum = veh_speed_max / vec_sum ELSE vec_sum = 1
  440.  
  441.  
  442.     veh_vecx = vec_x * vec_sum
  443.     veh_vecy = vec_y * vec_sum
  444.     veh_speed = SQR(veh_vecx ^ 2 + veh_vecy ^ 2)
  445.     IF k_up = 0 AND veh_speed < .01 THEN veh_vecx = 0: veh_vecy = 0: veh_speed = 0
  446.     veh_posx = veh_posx + veh_vecx
  447.     veh_posy = veh_posy + veh_vecy
  448.  
  449.  
  450.     IF k_down THEN deacc = .96 ELSE deacc = .9993: IF kw THEN deacc = 1
  451.     IF k_space THEN deacc = .99
  452.     veh_vecx = veh_vecx * deacc
  453.     veh_vecy = veh_vecy * deacc
  454.  
  455.     '    IF INKEY$ = "u" THEN FOR t = 0 TO 3: shockab(t) = RND(1): NEXT t
  456.     '   LOCATE 3, 1: PRINT shockab(3)
  457.  
  458.     'wheels rotation
  459.     FOR a_wheel = 0 TO 3
  460.         wh_posy = (SGN(a_wheel AND 1) * 2 - 1) * veh_tengelytav / 2: wh_posx = (SGN(a_wheel AND 2) * 2 - 1) * veh_kerektav / 2
  461.         rotate_2d wh_posy, wh_posx, veh_rotate1: wheel_ang = (90 + ABS(a_wheel AND 1) * veh_wheel) * pip180
  462.         add = veh_speed: IF add > .2 THEN add = .2
  463.         IF k_space AND ((a_wheel AND 1) = 0) THEN add = 0
  464.     wheel(a_wheel, 0) = wheel(a_wheel, 0) + add * 50: NEXT a_wheel
  465.  
  466.  
  467.  
  468.  
  469.  
  470.  
  471.     _DISPLAY: IF pr_temp THEN _PRINTSTRING (0, 20), SPACE$(160)
  472.  
  473.  
  474. '--------------------------------------------------------------------------- BOSS CYCLE END -------------------------------------------------
  475.  
  476.  
  477. rotating_draw:
  478. rd = .3
  479. _MAPTRIANGLE (0, 0)-(whe_ts - 1, 0)-(0, whe_ts - 1), whe_text TO(rotating(0), rotating(1), rotating(2))-(rotating(0) + rd, rotating(1), rotating(2))-(rotating(0), rotating(1) + rd, rotating(2))
  480.  
  481.  
  482.  
  483. new_target: l = 300: targ(0) = map_center + l / 2 + l * RND(1): targ(1) = map_center + l / 2 + l * RND(1): targ(2) = (map_deep(targ(0), targ(1)) - .1 - targ_size / 2)
  484. new_target_signal = 160: RETURN
  485.  
  486.  
  487.  
  488.  
  489. FUNCTION noise (x, y) 'reading pseudo random buffer
  490.     x2 = INT(x): y2 = INT(y): a = INT(ABS(x2) + ABS(y2)) MOD noise_rand_c: b = ABS(x2) MOD noise_rand_c: c = noise_rand(a) + noise_rand(b): noise = c - INT(c)
  491.  
  492. FUNCTION SmoothNoise (x, y)
  493.     SELECT CASE perlin_smooth_noise_interpolation_type
  494.         CASE 0: SmoothNoise = noise(x, y)
  495.         CASE 1: corners = (noise(x - 1, y - 1) + noise(x + 1, y - 1) + noise(x - 1, y + 1) + noise(x + 1, y + 1)) / 16
  496.             sides = (noise(x - 1, y) + noise(x + 1, y) + noise(x, y - 1) + noise(x, y + 1)) / 8: center = noise(x, y) / 4: SmoothNoise = corners + sides + center
  497.  
  498. FUNCTION Perlin2D_original (x, y): total = 0: FOR t = 0 TO perlin_level - 1: frequency = 2 ^ t * perlin_multiplier: amplitude = perlin_pers ^ t
  499.     total = total + InterpolatedNoise(x * frequency, y * frequency) * amplitude: NEXT t: Perlin2D_original = total
  500.  
  501. FUNCTION perlin2d (x, y): perlin2dx = mapz_multiplier * (Perlin2D_original(x, y) - mapz_min)
  502.     '    perlin2d = 0: EXIT FUNCTION
  503.     IF perlin2dx > perlin_flat_soil_limit_low THEN perlin2dx = perlin_flat_soil_limit_low
  504.     IF perlin2dx < perlin_flat_soil_limit_high THEN perlin2dx = perlin_flat_soil_limit_high
  505.     perlin2d = perlin2dx
  506.  
  507. FUNCTION InterpolatedNoise (x, y): integer_X = INT(x): fractional_X = x - integer_X: integer_y = INT(y): fractional_Y = y - integer_y
  508.     v1 = SmoothNoise(integer_X, integer_y): v2 = SmoothNoise(integer_X + 1, integer_y)
  509.     v3 = SmoothNoise(integer_X, integer_y + 1): v4 = SmoothNoise(integer_X + 1, integer_y + 1)
  510. i1 = Interpolate(v1, v2, fractional_X): i2 = Interpolate(v3, v4, fractional_X): InterpolatedNoise = Interpolate(i1, i2, fractional_Y): END FUNCTION
  511.  
  512. FUNCTION Interpolate (a, b, x): Interpolate = a * (1 - x) + b * x: END FUNCTION
  513.  
  514. SUB rotate (px, py, pz2, see_analysis)
  515.     px3 = px * cosrotz - py * sinrotz: py2 = px * sinrotz + py * cosrotz: py3 = py2 * cosrotx - pz2 * sinrotx: pz3 = -(py2 * sinrotx + pz2 * cosrotx)
  516.     see_point = pz3 < 200: IF see_point = 0 AND see_analysis THEN EXIT SUB
  517. rotate_2d px3, py2, rotx_bevel: rotating(0) = px3 * map_zoom_xy: rotating(1) = -py3 * map_zoom_xy: rotating(2) = pz3 * map_zoom_distance: END SUB
  518.  
  519. 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
  520.  
  521. SUB flight_control (af)
  522.  
  523.     rotx = flight(af, 1): me0 = flight(af, 3): me1 = flight(af, 4): me2 = flight(af, 5): me3 = flight(af, 6): me4 = flight(af, 7): kw = ABS(flight(af, 8))
  524.     ks = ABS(flight(af, 9)): mousey = flight(af, 11): mousex = flight(af, 10): me6 = flight(af, 12): me5 = flight(af, 13): rotx_bevel3 = flight(af, 2)
  525.     rotx = (rotx + mousex * .005) * .95: IF ABS(rotx) > (max_incli * pip180) THEN rotx = max_incli * pip180 * SGN(rotx)
  526.  
  527.     actual_speed = 1 / position_speed * SQR(me3 * me3 + me4 * me4): rotx_bevel2 = rotx * actual_speed * kw
  528.     rotx_bevel3 = rotx_bevel3 + (rotx_bevel2 - rotx_bevel3) * .05: me5 = me5 + rotx / 20: me6 = me6 + mousey / 100: lim_fy = 65: temp = me6 / pip180
  529.     IF temp > 270 + lim_fy THEN temp = 270 + lim_fy
  530.     IF temp < 270 - lim_fy THEN temp = 270 - lim_fy
  531.     me6 = temp * pip180: me2 = me2 + COS(-me6) * actual_speed * 5 * kw + 1 * ABS(ks AND actual_speed < .05) 'calculating Z
  532.     actual_deep = (map_deep(me0, me1) - .1) * map_dimz
  533.     IF me2 > actual_deep - .1 THEN me2 = actual_deep - .1 - actual_speed / 4: me3 = me3 * .9: me4 = me4 * .9: flight(af, 17) = 1 ELSE flight(af, 17) = 0
  534.     IF me2 < flight_high_max THEN me2 = flight_high_max
  535.     position_accel = .02: ww = .9999: szog_xy = me5 + rotx 'calculating XY
  536.  
  537.     new_vec_x = -SIN(szog_xy) * position_accel * kw: new_vec_y = -COS(szog_xy) * position_accel * kw: vec_x = (me3 * ww + new_vec_x): vec_y = (me4 * ww + new_vec_y)
  538.     vec_sum = SQR(vec_x * vec_x + vec_y * vec_y): IF vec_sum > position_speed THEN vec_sum = position_speed / vec_sum ELSE vec_sum = 1
  539.     me3 = vec_x * vec_sum: me4 = vec_y * vec_sum: me0 = me0 + me3: me1 = me1 + me4: IF ks THEN deacc = .96 ELSE deacc = .99: IF kw THEN deacc = 1
  540.     me3 = me3 * deacc: me4 = me4 * deacc: flight(af, 16) = 0
  541.  
  542.     IF crash_to_column(me0, me1) THEN
  543.         IF ABS(me3 < .05) THEN me0 = flight(af, 3)
  544.         IF ABS(me4 < .05) THEN me1 = flight(af, 4)
  545.         flight(af, 16) = 1: me3 = -me3 * .7: me4 = -me4 * .7: DO: me0 = me0 + me3: me1 = me1 + me4: LOOP WHILE crash_to_column(me0, me1)
  546.     END IF
  547.     flight(af, 1) = rotx: flight(af, 3) = me0: flight(af, 4) = me1: flight(af, 5) = me2: flight(af, 6) = me3: flight(af, 7) = me4: flight(af, 2) = rotx_bevel3
  548.     flight(af, 12) = me6: flight(af, 13) = me5: flight(af, 15) = actual_speed
  549.  
  550.  
  551. FUNCTION map_deep (x, y)
  552.     read_mapx1 = INT(x + map_resper2) MOD map_resolution: read_mapx2 = INT(x + map_resper2 + 1) MOD map_resolution
  553.     read_mapy1 = INT(y + map_resper2) MOD map_resolution: read_mapy2 = INT(y + map_resper2 + 1) MOD map_resolution
  554.     mapx1 = Interpolate(map(read_mapx1, read_mapy1, 0), map(read_mapx2, read_mapy1, 0), x - INT(x))
  555.     mapx2 = Interpolate(map(read_mapx1, read_mapy2, 0), map(read_mapx2, read_mapy2, 0), x - INT(x))
  556. map_deep = Interpolate(mapx1, mapx2, y - INT(y)): END FUNCTION
  557.  
  558.  
  559. FUNCTION crash_to_column (x1, y1): EXIT FUNCTION
  560.     pixs_column = INT(map_dimxy / map_resolution / clmn_rad) + 2
  561.     FOR tx = -pixs_column TO pixs_column: FOR ty = -pixs_column TO pixs_column
  562.             read_mapx = INT(x1 + map_resper2 + tx) MOD map_resolution: read_mapy = INT(y1 + map_resper2 + ty) MOD map_resolution
  563.             IF map(read_mapx, read_mapy, 6) THEN crash_to_column = 1: EXIT FUNCTION
  564. NEXT ty, tx: END FUNCTION
  565.  
  566. FUNCTION degree (a, b): degreex = ATN((a + .00001) / (b + .00001)) / pip180: degreex = degreex - 180 * ABS(0 > b): degreex = degreex - 360 * (degreex < 0)
  567. degree = degreex: END FUNCTION
  568.  
  569. SUB rotate_vehicle (p0, p1, p2, a1, a2, a3): rotate_2d p2, p1, a3 + 180 * pip180: rotate_2d p0, p2, a2 + 180 * pip180: rotate_2d p0, p1, -a1: END SUB
  570.  
  571.  
  572.  
  573.  

13
Programs / Flight simulator
« on: November 03, 2021, 09:14:35 pm »
Hello !
I'm thinking of a game. I’ve tried a shooter-like game before, now I want something that shows the speed. I was thinking of a fighter simulator. (I really want a car game, but to this day I can't approach the physics of the car)
Because the plane is fast and a trajectory flies over quickly, I generated the seemingly random ground from a function.
I searched the net for a solution and found a very interesting solution to the real-time endless trajectory: Perlin noise. I used this.
Check it out, it’s interesting, and it can be used for a lot of things.
https://www.arendpeter.com/Perlin_Noise.html
We're just racing for now. By turning the whole thing left and right, we turn and “turn” with the A-D keys. If you become an enemy, it may be interesting to shoot him.
The source code is concise, but whoever cares will disassemble it.

Code: QB64: [Select]
  1. 'mikrolepes
  2.  
  3. Const pip180 = 3.141592 / 180
  4. Const perlin_pers = 7 'amplitudo
  5. Const perlin_level = 5 'level of resolution wave
  6. Const perlin_multiplier = 0.006
  7. Const perlin_smooth_noise_interpolation_type = 0 '0-none '1-standard
  8. Const perlin_flat_soil_limit = .8
  9. monx = _DesktopWidth * .7: mony = monx / 16 * 9 'screen size
  10.  
  11. map_shadow = 18
  12. position_speed = .7
  13. map_resolution = 70
  14.  
  15. map_dimxy = 1200
  16. map_dimz = 250
  17.  
  18. map_zoom_xy = 6
  19. map_zoom_distance = 15
  20. mouse_sens_xy = .01
  21. mouse_sens_z = .01
  22.  
  23. cam(4) = pip180 * 270
  24.  
  25. me(0) = 2000: me(1) = 2000
  26.  
  27. 'create pseudo random buffer
  28. Dim Shared noise_rand_c: noise_rand_c = 10000: Dim Shared noise_rand(noise_rand_c - 1): For t = 0 To noise_rand_c - 1: noise_rand(t) = Rnd(1): Next t
  29.  
  30. 'create texture
  31. Dim color_temp As _Integer64: Dim Shared mapz_min, mapz_max
  32. text_size = 8: text_size_marg = 8: text_deep = 40: text_height_scale = 15: Dim texture(text_height_scale - 1, text_deep - 1)
  33. For t = 0 To text_deep - 1: For t2 = 0 To text_height_scale - 1
  34.     dark = 1 - (1 / text_deep * t)
  35.     color_temp = _RGB32((255 * dark), (100 * dark), ((255 / text_height_scale * t2)) * dark)
  36.     temp = _NewImage(text_size, text_size, 32): _Dest temp: Cls: marg = text_size * text_size_marg / 100
  37. Line (marg, marg)-(text_size - marg, text_size - marg), color_temp, BF: texture(t2, t) = _CopyImage(temp, 33): _FreeImage temp: Next t2, t
  38.  
  39. 'find min/max Z
  40. mapz_min = 9999999: mapz_max = -mapz_min: For t = 0 To 1999: c = Perlin2D(1000 * Rnd(1), 1000 * Rnd(1))
  41.     If mapz_min > c Then mapz_min = c
  42.     If mapz_max < c Then mapz_max = c
  43.  
  44.  
  45. 'fill map-buffer
  46. Dim map(map_resolution - 1, map_resolution - 1, 5): perl_setx = Int(me(0)): perl_sety = Int(me(1))
  47. For map_x = 0 To map_resolution - 1: For map_y = 0 To map_resolution - 1: map_z = Perlin2D(perl_setx + map_x, perl_sety + map_y)
  48. map((map_x + perl_setx) Mod map_resolution, (map_y + perl_sety) Mod map_resolution, 0) = 1 / (mapz_max - mapz_min) * (map_z - mapz_min): Next map_y, map_x
  49.  
  50.  
  51. mon = _NewImage(monx, mony, 32): Screen mon: _FullScreen: _MouseHide
  52.  
  53. 'MAP array
  54. '0-perlin Z-data
  55. '1-maptriangle calculate X
  56. '2-maptriangle calculate Y
  57. '3-maptriangle calculate Z
  58. '4-distance from me (color)
  59.  
  60.  
  61.  
  62.  
  63.     mousex = 0: mousey = 0: While _MouseInput: mousex = mousex + _MouseMovementX: mousey = mousey + _MouseMovementY: Wend
  64.     'cam(3) = cam(3) + mousex * mouse_sens_xy
  65.     cam(4) = cam(4) + mousey * mouse_sens_z
  66.     '    cam(3) = mouse_sens * .1
  67.     rotx = rotx + mousex / 100
  68.     max_incli = 60: If Abs(rotx) > (max_incli * pip180) Then rotx = max_incli * pip180 * Sgn(rotx)
  69.     cam(3) = cam(3) + rotx / 40
  70.  
  71.     'control position
  72.     kw = _KeyDown(119)
  73.     kw = -1
  74.     ks = _KeyDown(115): ka = _KeyDown(97): kd = _KeyDown(100): new_direction = (Abs(ka Or kd Or kw) Or -Abs(ks)) * position_speed
  75.  
  76.     deg_XY = -90 * Abs(ka) + 90 * Abs(kd)
  77.  
  78.     szog_xy = cam(3) + deg_XY * pip180
  79.  
  80.     '   szog_z = cam(4)
  81.  
  82.     me(0) = me(0) - Sin(szog_xy) * Cos(szog_z) * new_direction
  83.     me(1) = me(1) - Cos(szog_xy) * Cos(szog_z) * new_direction
  84.     '    me(2) = me(2) + SIN(szog_z) * new_direction '* ABS(ka = 0 AND kd = 0)
  85.  
  86.     '    cam(2) = me(2)
  87.     '    LOCATE 1, 1: PRINT cam(2)
  88.  
  89.  
  90.  
  91.     'replace the missing row in the buffer line Y
  92.     Do While Int(Int(me(0))) <> perl_setx: dir = -Sgn(Int(me(0)) - perl_setx): perl_setx = perl_setx - dir
  93.         For map_y = 0 To map_resolution - 1: temp = perl_setx + Abs(dir = -1) * (map_resolution - 1): map_z = Perlin2D(temp, perl_sety + map_y)
  94.     map(temp Mod map_resolution, (map_y + perl_sety) Mod map_resolution, 0) = 1 / (mapz_max - mapz_min) * (map_z - mapz_min): Next map_y: Loop
  95.  
  96.     'replace the missing row in the buffer line X
  97.     Do While Int(Int(me(1))) <> perl_sety: dir = -Sgn(Int(me(1)) - perl_sety): perl_sety = perl_sety - dir
  98.         For map_x = 0 To map_resolution - 1: temp = perl_sety + Abs(dir = -1) * (map_resolution - 1): map_z = Perlin2D(perl_setx + map_x, temp)
  99.     map((map_x + perl_setx) Mod map_resolution, temp Mod map_resolution, 0) = 1 / (mapz_max - mapz_min) * (map_z - mapz_min): Next map_x: Loop
  100.  
  101.  
  102.  
  103.     cosrotz = Cos(cam(3)): sinrotz = Sin(cam(3)): cosrotx = Cos(cam(4)): sinrotx = Sin(cam(4))
  104.  
  105.     'calculating position and textures
  106.     '    e1 = perl_setx - INT(perl_setx)
  107.  
  108.     '   e2 = perl_sety - INT(perl_sety)
  109.     For map_x = 0 To map_resolution - 1: px = -map_dimxy / 2 + map_dimxy / map_resolution * (map_x - e1) - cam(0)
  110.         For map_y = 0 To map_resolution - 1: py = -map_dimxy / 2 + map_dimxy / map_resolution * (map_y - e2) - cam(1)
  111.             map_z = map((map_x + perl_setx) Mod map_resolution, (map_y + perl_sety) Mod map_resolution, 0)
  112.             If map_z > perlin_flat_soil_limit Then map_z = perlin_flat_soil_limit
  113.             pz2 = map_dimz * map_z - cam(2)
  114.             px3 = px * cosrotz - py * sinrotz: py2 = px * sinrotz + py * cosrotz: py3 = py2 * cosrotx - pz2 * sinrotx: pz3 = py2 * sinrotx + pz2 * cosrotx
  115.             px4 = (px3 * Cos(rotx)) - (py3 * Sin(rotx)): py4 = (px3 * Sin(rotx)) + (py3 * Cos(rotx))
  116.             map(map_x, map_y, 1) = -px4 * map_zoom_xy: map(map_x, map_y, 2) = -py4 * map_zoom_xy: map(map_x, map_y, 3) = -pz3 * map_zoom_distance
  117.             map(map_x, map_y, 4) = Int(Sqr(px3 * px3 + py3 * py3 + pz3 * pz3) / map_shadow)
  118.             If map(map_x, map_y, 4) > text_deep - 1 Then map(map_x, map_y, 4) = text_deep - 1
  119.             map(map_x, map_y, 5) = Int(text_height_scale * map_z)
  120.             If map(map_x, map_y, 5) > text_height_scale - 1 Then map(map_x, map_y, 5) = text_height_scale - 1
  121.             If map(map_x, map_y, 5) < 0 Then map(map_x, map_y, 5) = 0
  122.     Next map_y, map_x
  123.  
  124.     'do maptriangle from squares !
  125.     For map_x = 0 To map_resolution - 2: For map_y = 0 To map_resolution - 2
  126.         m0x = map(map_x, map_y, 1): m0y = map(map_x, map_y, 2): m0z = map(map_x, map_y, 3)
  127.         m1x = map(map_x + 1, map_y, 1): m1y = map(map_x + 1, map_y, 2): m1z = map(map_x + 1, map_y, 3)
  128.         m2x = map(map_x, map_y + 1, 1): m2y = map(map_x, map_y + 1, 2): m2z = map(map_x, map_y + 1, 3)
  129.         m3x = map(map_x + 1, map_y + 1, 1): m3y = map(map_x + 1, map_y + 1, 2): m3z = map(map_x + 1, map_y + 1, 3)
  130.         atexture = texture(map(map_x, map_y, 5), map(map_x, map_y, 4))
  131.         _MapTriangle (0, 0)-(text_size - 1, 0)-(0, text_size - 1), atexture To(m0x, m0y, m0z)-(m1x, m1y, m1z)-(m2x, m2y, m2z)
  132.         _MapTriangle (0, 0)-(text_size - 1, 0)-(0, text_size - 1), atexture To(m3x, m3y, m3z)-(m1x, m1y, m1z)-(m2x, m2y, m2z)
  133.     Next map_y, map_x
  134.  
  135.     _Display: Cls
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142. Function noise (x, y) 'reading pseudo random buffer
  143.     x2 = Int(x): y2 = Int(y): a = Int(Abs(x2) + Abs(y2)) Mod noise_rand_c: b = Abs(x2) Mod noise_rand_c: c = noise_rand(a) + noise_rand(b): noise = c - Int(c)
  144.  
  145. Function SmoothNoise (x, y)
  146.     Select Case perlin_smooth_noise_interpolation_type
  147.         Case 0: SmoothNoise = noise(x, y)
  148.         Case 1: corners = (noise(x - 1, y - 1) + noise(x + 1, y - 1) + noise(x - 1, y + 1) + noise(x + 1, y + 1)) / 16
  149.             sides = (noise(x - 1, y) + noise(x + 1, y) + noise(x, y - 1) + noise(x, y + 1)) / 8: center = noise(x, y) / 4: SmoothNoise = corners + sides + center
  150.     End Select
  151.  
  152. Function Perlin2D (x, y): total = 0: For t = 0 To perlin_level - 1: frequency = 2 ^ t * perlin_multiplier: amplitude = perlin_pers ^ t
  153.     total = total + InterpolatedNoise(x * frequency, y * frequency) * amplitude: Next t: Perlin2D = total
  154.  
  155. Function InterpolatedNoise (x, y): integer_X = Int(x): fractional_X = x - integer_X: integer_y = Int(y): fractional_Y = y - integer_y
  156.     v1 = SmoothNoise(integer_X, integer_y): v2 = SmoothNoise(integer_X + 1, integer_y)
  157.     v3 = SmoothNoise(integer_X, integer_y + 1): v4 = SmoothNoise(integer_X + 1, integer_y + 1)
  158.     i1 = Interpolate(v1, v2, fractional_X): i2 = Interpolate(v3, v4, fractional_X): InterpolatedNoise = Interpolate(i1, i2, fractional_Y)
  159.  
  160. Function Interpolate (a, b, x): Interpolate = a * (1 - x) + b * x: End Function
  161.  
  162.  

14
QB64 Discussion / computer program
« on: August 21, 2021, 07:22:53 pm »
Hello ! I wrote a computer program! I developed it for 8 years, but it's not ready yet!
I want to give my mother a gift, I do not know her sixth birthday!
I got to the point of saying "hello mother!"
But unfortunately I'm stuck here.
I really want you to write it out in the middle of the screen and the caption will be red. I also want it to flash !!!
I promised my mother to show it! Be let down!
I would like to expand my collective knowledge base with my existing knowledge, I am sure you will appreciate it!
Yeah, the code:
conts one = 1
conts 0 = false ’this is important !!!!!!!!!!!!!!
print "mother"
I can't go on from here! Please help !!!!

15
Programs / Terror in the Maze - folk judgment
« on: July 20, 2021, 02:00:28 pm »
Hello !
I’ve been here on the forum for 2 years, but I don’t seem to have used the forum well. Anyone I’m not unfamiliar with knows that I only wrote in the “discussion” group. I don’t know why, maybe because it was in the first place.
I would like to expose the game “Terror it the Maze” to the “games” group with the kind moderators so that it can be maintained for posterity and new ones can see what technical possibilities there are in QB64.
In order for this to happen, positive feedback is needed here in the “programs” group, because only on the basis of the answers and feedback appearing in the “programs” group can the moderator judge whether the program is suitable for publication. (I do not understand either)
The game is ready for about 1 month. It's free and includes the source code. Many game distributors have been happy to expose you, but here you need it and your feedback.
I’m not asking you to just write positively. If you write, it should be an objective opinion.
Thank you !

-------------------------

It also has strategy in it, but not in the sense of a logic game.
The younger generation, who love FPS games, may find them easier to understand, use, and enjoy.

I intentionally made the video in HARD mode to show who can get out! You have to feel it and you will enjoy it!
In EASY mode, I think the one who doesn't get used to FPS games will get out.

The gameplay shows that in HARD mode it takes up to 10 minutes to complete.



download:
https://drive.google.com/drive/folders/1L34MThy8K6JLdyRd2pchC-COiXnjGbkW?usp=sharing

About half a year of work, I really want as many people as possible to try it!

TERROR IN THE MAZE
The course of the game needs no special explanation, but in short:
This is an FPS-like 3D shooting game.
Main goal: to get out of the maze. From the monsters, you need to get the ammo needed to blow up the next box. Exploding the box if we have the ammunition: with 100% fireball (use the right mouse button to shoot) Behind the box is the key to the next box, but at the same time as the box is detonated, fire-killing dragons are released. They have to be done.
Caution! If we have ammunition, you have to be careful with the monsters, because they can take the key and run away with it. Don't let them get close to you!
During the game, the fairy takes us on the right path.
When we run out of energy, stop for a “first aid” block!

important: no OPENGL in it! what you see is just _MAPTRIANGLE!

Some thoughts about the program:
The game is written in BASIC (under QB64 1.3). GOOGLE helped with the graphics. Animated monster gifs, dragons, maze textures. I used PaintS Shop Pro 5 and Virtualdub to edit the images and animations.
YOUTUBE helped with the sound effects. For example, with the keywords “explosion effect”, “dragon music”, “monster voice” you can find a lot of good sound samples.
I calculate the shortest distance (fairy) between two points in the maze using the Dijkstra algorithm.
No two games are alike. At startup, the program generates a randomly arranged maze with varied textures.
Game history:
3D MAZE
First, I created a simple, random 3D maze-generating program that can be navigated like in a typical FPS game. This can't be called a game, it's just interesting.
Found in the game folder: "archive_and_history / real_3d_maze"
4D MAZE
As I dealt with the geometry of 3D space, a curiosity arose in me. What would happen if the position of 1 point were given by the intersection of 4 planes instead of 3? The representation would of course remain 3-dimensional, but we could see the space from several views as a section of any 3 planes arbitrarily selected from the 4 planes. As well as real-time simultaneously in differently used planes. How can the structure and arrangement of the same 4-dimensional space change if we create it as sections of different 3 planes? The program visualizes this curiosity.
Found in the game folder: "archive_and_history / real_4d_maze_4windows_real_time"
Once I liked the game’s 3D display options, I made this game.

Pages: [1] 2 3 4