Author Topic: Spider animation  (Read 4756 times)

0 Members and 1 Guest are viewing this topic.

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
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.  

FellippeHeitor

  • Guest
Re: Spider animation
« Reply #1 on: March 07, 2022, 10:14:26 am »
That sure looks cool!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Spider animation
« Reply #2 on: March 07, 2022, 11:08:42 am »
+1 very good! You might have a bug :)

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: Spider animation
« Reply #3 on: March 07, 2022, 02:25:43 pm »
THX ! :)

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: Spider animation
« Reply #4 on: March 07, 2022, 02:31:45 pm »
He's here for now. Spiders in 3d. You can watch them at the start of the program. Not recommended for arachnophobics! They are still passive now, but they will be dangerous!

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. spider_c = 8 * room_c 'how many spiders should be in the game?
  8. diamant_c = 10 'average number of diamonds / room
  9. room_doormin = 2 'there must be at least as many doors in a room
  10. room_doormax = 3 'there should be a maximum of this number of doors in a room
  11. me_speed = .15 'my speed
  12. mouse_sens = .5
  13.  
  14.  
  15.  
  16.  
  17.  
  18. '-----ADVANCED SETTINGS ----------------------------------------------------------------------------------------------------------------
  19. diamant_speed_min = .05 'diamant speed 1. room
  20. diamant_speed_max = .15 'diamant speed last room
  21. room_buffsize = 100
  22. room_relsize = 20
  23. room_boxmin_c = 4
  24. room_boxmax_c = 6
  25. shdw_c = 40
  26.  
  27. Const pip180 = 3.141592 / 180
  28. cheat_active = 1
  29.  
  30. 'make colors
  31. 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
  32. Dim temp_color(9) As _Integer64
  33. Dim Shared crash_active
  34.  
  35. 'shadows
  36. 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
  37. shdw(t) = ashdw: Next t
  38.  
  39. 'make textures
  40. dia_text_c = 20: Dim dia_text(dia_text_c - 1, shdw_c - 1), sp_text(shdw_c - 1, 1)
  41. dt_c = 10
  42. marg = .12: Dim Shared text_tile(room_c - 1, shdw_c - 1) As _Integer64: Dim door_text(dt_c - 1, shdw_c - 1)
  43. 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
  44.     stand_temp = _NewImage(size, size, 32): _Dest stand_temp: Cls , _RGB32(50, 50, 50) 'frame color
  45.     Line (size * marg, size * marg)-(size - size * marg, size - size * marg), _RGB32(180, 180, 180), BF: _Source stand_temp
  46.     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)
  47.         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)
  48.     Next ty, tx
  49.  
  50.     'make wall
  51.     For t2 = 0 To room_c - 1: temp = _CopyImage(stand_temp, 32): _Dest temp
  52.         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)
  53.         _Source trans: _Dest temp: _Blend temp: _PutImage: _FreeImage trans: 'tile coloring
  54.         trans = _NewImage(5, 5, 32): _Dest trans: Cls , _RGBA32(0, 0, 0, (1 - dark) * 255)
  55.         _Source trans: _Dest temp: _PutImage: _FreeImage trans 'tile darking
  56.     text_tile(t2, t) = _CopyImage(temp, 33): _FreeImage temp: Next t2: _FreeImage stand_temp
  57.  
  58.     'make door-flash
  59.     temp_color(0) = _RGB32(255, 100, 100): temp_color(1) = _RGB32(100, 100, 255) 'door 2 colors
  60.     For t2 = 0 To dt_c - 1: a = 1 / (dt_c - 1) * t2: temp = _NewImage(3, 3, 32): _Dest temp: m = .5 * dark
  61.         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
  62.         cb = (_Blue32(temp_color(0)) * a + _Blue32(temp_color(1)) * (1 - a)) * m: Cls , _RGB32(cr, cg, cb)
  63.     door_text(t2, t) = _CopyImage(temp, 33): _FreeImage temp: Next t2
  64.  
  65.     'make diamants
  66.     tmax = 100: tmin = 40: size = Int(tmax - (tmax - tmin) / (shdw_c - 1) * t)
  67.     For t2 = 0 To dia_text_c - 1: temp = _NewImage(size, size, 32): _Dest temp: _Source temp
  68.         temp_color(0) = _RGB32(2 + dark * 186 * Rnd(1), 2 + dark * 186 * Rnd(1), 2 + dark * 186 * Rnd(1))
  69.         Color temp_color(0): Circle (size / 2, size / 2), size / 2 * .95: Paint (size / 2, size / 2), temp_color(0), temp_color(0)
  70.     _ClearColor Point(0, 0): dia_text(t2, t) = _CopyImage(temp, 33): _FreeImage temp: Next t2
  71.  
  72.     'make spider textures
  73.     temp_color(0) = _RGB32(63, 63, 63): temp_color(1) = _RGB32(255, 255, 194) 'spiders 2 colors
  74.     sidex = 20: sidey = 100: temp = _NewImage(sidex, sidey, 32): _Dest temp: For tx = 0 To sidex - 1: col = Int(tx / 7) And 1
  75.         Color _RGB32(_Red32(temp_color(col)) * dark, _Green32(temp_color(col)) * dark, _Blue32(temp_color(col)) * dark)
  76.     Line (tx, 0)-(tx, sidey): Next tx: sp_text(t, 0) = _CopyImage(temp, 33): _FreeImage temp
  77.  
  78.  
  79. 'white flash
  80. wf_c = 20: Dim wf_text(wf_c - 1): sizex = Int(monx * .3): sizey = Int(mony * .3)
  81. 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
  82.     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)
  83. Next ty, tx: wf_text(t) = _CopyImage(temp, 33): _FreeImage temp: Next t
  84.  
  85.  
  86. Dim d(7, 1) As _Byte 'directions array
  87. d(0, 1) = -1: d(1, 0) = 1: d(1, 1) = -1: d(2, 0) = 1: d(3, 0) = 1: d(3, 1) = 1
  88. d(4, 1) = 1: d(5, 0) = -1: d(5, 1) = 1: d(6, 0) = -1: d(7, 0) = -1: d(7, 1) = -1
  89.  
  90. 'ROOM array
  91. '0,1,2,3 x1,y1,x2,y2 position in room_map array
  92. '4 number of doors
  93. '20+ ,21+  door coordinates (step5)
  94. '22+ door exit direction
  95.  
  96. 'ROOM_MAP array  (room,x,y)
  97. 'nothing
  98. 'bit 0-walking area
  99. 'bit 1,2,3,4-wall
  100. 'bit 5 door
  101. Dim Shared me(9), cam(9) '0,1,2 XYZ 3,4 angAB , 5 room
  102.  
  103. 'make rooms
  104. Dim Shared room(room_c - 1, 99), room_map(room_c - 1, room_buffsize - 1, room_buffsize - 1) As _Unsigned _Byte
  105.  
  106. mapsize0 = 20: room(0, 1) = mapsize0: room(0, 3) = mapsize0: For tx = 0 To mapsize0 - 1: For ty = 0 To mapsize0 - 1
  107. room_map(0, tx, ty) = 1 + Abs(tx = 0 Or tx = mapsize0 - 1 Or ty = 0 Or ty = mapsize0 - 1) * 3: Next ty, tx
  108.  
  109. For ar = 0 To room_c - 1
  110.     If ar Then
  111.         room_map(ar, Int(room_buffsize / 2), Int(room_buffsize / 2)) = 1: reg_minmax_reset 0: reg_minmax_reset 1
  112.         For t = 0 To Int(randscale(room_boxmin_c, room_boxmax_c)) - 1
  113.             For t2 = 0 To 1: box(t2) = Int(randscale(Int(room_relsize * (.4 + .2 * t2)), Int(room_relsize * (.5 + .2 * t2)))): Next t2
  114.             If Int(2 * Rnd(1)) Then Swap box(0), box(1)
  115.             Do: px = Int(room_buffsize * Rnd(1)): py = Int(room_buffsize * Rnd(1)): Loop Until room_map(ar, px, py)
  116.             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
  117.         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
  118.         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
  119.         'make doors
  120.         room(ar, 4) = Int(randscale(room_doormin, room_doormax)): For ad = 0 To room(ar, 4) - 1: agent = 0
  121.             Do: px = Int((room_buffsize - 2) * Rnd(1)) + 1: py = Int((room_buffsize - 2) * Rnd(1)) + 1: ReDim cnt(1, 1): dis_nook = 0
  122.                 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
  123.                 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))
  124.                     agent = agent + 1: If agent > 100000 Then room(ar, 4) = ad + 0: agent2 = 1: GoTo exitroom
  125.             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
  126.             room(ar, 20 + ad * 5) = px: room(ar, 21 + ad * 5) = py
  127.         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
  128.         exitroom:
  129.         'make wall type
  130.         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
  131.             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)
  132.         Next t, ty, tx
  133.     End If
  134.  
  135.     'add door to the room interior
  136.     If ar Then add_room_c = Int(3 * Rnd(1)): Else add_room_c = 1
  137.     If add_room_c Then
  138.         For t = 0 To add_room_c - 1: agent = 0
  139.             Do: For t2 = 0 To 1: box(t2) = randscale(room(ar, t2 * 2), room(ar, 1 + t2 * 2) - 1): Next t2: room_ok = 1
  140.                 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
  141.                 Next ty, tx: agent = agent + 1: If agent > 500000 Then GoTo exitroom2
  142.             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
  143.             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
  144.             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
  145.         room(ar, 4) = room(ar, 4) + 1: Next t
  146.     End If
  147.     exitroom2:
  148.  
  149.     'doors to map
  150.     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
  151. Next ar
  152.  
  153. 'spider install
  154. Dim Shared spani$: Dim spider(spider_c - 1, 19), xy(1) 'SPIDER array '0-active 1-room 2,3,4 XYZ 5,6 ANG A,B
  155. spani$ = "LNKOJKGJDKMNMNQLROSQNNOOPKSMSPPNPNUMWOYRLNKOJKGKDMMNMONJNNNPNNOOOKPMPPPNQNTKXNZPLNKOJLHNFQMNMOLKKNLPNNOOOKNONQPNQOSLXMZPLNKOILGOGRMNMNLJILIO"
  156. spani$ = spani$ + "NNOOOLPOPRPNQNQKUNUQLNKOJKHOIRMNMNMKJMHPNNOORKUNURPNPOQKTNSQLNKOILHOIRMNMOLKKOJQNNPORLUOVRPNQOQKRNRRLNLOJMIOKRMNMOLKLOMRNNNOLMK"
  157. spani$ = spani$ + "PMRPNQORLRORRLNLOLKHMHOMNMNOJPNOQNNNONLJMJPPNPNSLUOTRLNLOKLGKFNMNMNPKQNQRNNPOQKTMTPPNPNTLWNXQ"
  158. For asp = 0 To spider_c - 1: spider(asp, 8) = randscale(.2, 1): spider(asp, 5) = 360 * Rnd(1): spider(asp, 1) = 0 'INT(room_c * RND(1))
  159.     Do: For t = 0 To 1: spider(asp, 2 + t) = randscale(room(spider(asp, 1), t * 2), room(spider(asp, 1), 1 + t * 2)): Next t
  160. Loop Until room_map(spider(asp, 1), spider(asp, 2), spider(asp, 3)) = 1: spider(asp, 4) = 4: spider(asp, 0) = 1: Next asp
  161.  
  162. 'draw sphere function
  163. da = 15: db = 5: Dim Shared spk_c: spk_c = da * db: Dim Shared spk_p(spk_c - 1, 9), sqs(spk_c - 1, 7)
  164. For da2 = 0 To da - 1: dega = 360 / (da - 1) * da2 * pip180: For db2 = 0 To db - 1: degb = 180 / (db - 1) * db2 * pip180: ap = da2 * db + db2
  165. spk_p(ap, 0) = Sin(degb) * Cos(dega): spk_p(ap, 1) = Sin(degb) * Sin(dega): spk_p(ap, 2) = Cos(degb): Next db2, da2
  166. For da2 = 0 To da - 2: For db2 = 0 To db - 2: sqa = da2 * db + db2
  167. sqs(sqa, 0) = sqa: sqs(sqa, 1) = sqs(sqa, 0) + 1: sqs(sqa, 2) = sqs(sqa, 0) + db: sqs(sqa, 3) = sqs(sqa, 2) + 1: Next db2, da2
  168.  
  169. 'diamants location
  170. 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
  171.     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
  172.     Loop Until room_map(dia(ad, 3), dia(ad, 0), dia(ad, 1)) = 1: dia(ad, 2) = .5
  173.     dv = (1 + Rnd(1)) * (diamant_speed_min + (diamant_speed_max - diamant_speed_min) / (room_c - 1) * dia(ad, 3))
  174.     dega = 360 * Rnd(1) * pip180: degb = 360 * Rnd(1) * pip180: dia(ad, 8) = 1
  175. 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
  176.  
  177. 'my start position
  178. me(5) = 0: 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
  179.  
  180. 'allocation of doors
  181. Dim adoor(room_c - 1, room_doormax + 10, 9) '9-present 0-trans to room 1-trans to door,8 -the only route
  182. For ar = 0 To room_c - 2 'create only route
  183.     Do: door1 = Int(room(ar, 4) * Rnd(1)): Loop While adoor(ar, door1, 9)
  184.     Do: door2 = Int(room(ar + 1, 4) * Rnd(1)): Loop While adoor(ar + 1, door2, 9)
  185.     adoor(ar, door1, 0) = ar + 1: adoor(ar, door1, 1) = door2: adoor(ar, door1, 8) = 1: adoor(ar, door1, 9) = 1
  186. adoor(ar + 1, door2, 0) = ar: adoor(ar + 1, door2, 1) = door1: adoor(ar + 1, door2, 9) = 1: Next ar
  187.  
  188. For ar = 1 To room_c - 1: For ad = 0 To room(ar, 4) - 1: If adoor(ar, ad, 9) Then _Continue
  189. 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
  190.  
  191. '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
  192. '        IF adoor(ar, ad, 8) THEN COLOR _RGB32(255, 255, 255) ELSE COLOR _RGB32(100, 100, 100)
  193. 'PRINT ar; ".room,"; ad; ".door   TRANS TO  room:"; adoor(ar, ad, 0); ",door:"; adoor(ar, ad, 1): NEXT ad: PRINT: NEXT ar
  194. 'COLOR _RGB32(50, 50, 50): PRINT "Press any key !": DO: _LIMIT 30: LOOP WHILE INKEY$ = ""
  195.  
  196.  
  197.  
  198.  
  199. mon = _NewImage(monx, mony, 32): Screen mon: '_FREEIMAGE mon2
  200. door_clip_d = 1: crash_active = 1: me(2) = .2 'my height in the game 0-1
  201.  
  202.  
  203. '----------------------------------------- BOSS CYCLE -------------------------------------------------------------------------
  204. Do: If boss_limit = 0 Then _Limit 50
  205.     inkey2$ = InKey$
  206.     'cheat keys
  207.     boss_limit = boss_limit Xor Abs(cheat_active And inkey2$ = "l"): crash_active = crash_active Xor Abs(cheat_active And inkey2$ = "c")
  208.     me(2) = me(2) + (_KeyDown(Asc("+")) - _KeyDown(Asc("-"))) * .05 * cheat_active
  209.  
  210.     'control me
  211.     mousex = 0: mousey = 0: mw = 0: While _MouseInput: mousex = mousex + _MouseMovementX: mousey = mousey + _MouseMovementY: mw = mw + _MouseWheel: Wend
  212.     k_left = _KeyDown(19200) Or _KeyDown(Asc("a")): k_right = _KeyDown(19712) Or _KeyDown(Asc("d"))
  213.     k_up = _KeyDown(18432) Or _KeyDown(Asc("w")) Or _MouseButton(1): k_down = _KeyDown(20480) Or _KeyDown(Asc("s")) Or _MouseButton(2)
  214.     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))
  215.  
  216.     try_ang_sc = 85: For try_ang = 0 To try_ang_sc Step 6: For try_ang_dir = 0 To 1
  217.         go = me_speed * Abs((k_left + k_right + k_up + k_down) = -1) * (1 / try_ang_sc * (try_ang_sc - try_ang))
  218.         go_ang = k_down * 180 + 90 * (k_left - k_right) + (me(3) + (try_ang_dir * 2 - 1) * try_ang): kit = .2
  219.         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)
  220.         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
  221.     Next try_ang_dir, try_ang
  222.     ok:
  223.  
  224.     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
  225.  
  226.     'draw objects
  227.     For tx = 0 To room(me(5), 1) - room(me(5), 0): For ty = 0 To room(me(5), 3) - room(me(5), 2)
  228.         l = room_map(me(5), room(me(5), 0) + tx, room(me(5), 2) + ty)
  229.         If l = 1 Or l = 32 Then 'TILE
  230.             roof = 0 '(1 - ABS(me(5) = 0))
  231.             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
  232.                 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))))
  233.                 Next t2
  234.             End If
  235.             If l / 2 And 15 Then draw_brick_3d tx, ty 'WALL
  236.             If l And 32 Then 'GATE
  237.                 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))
  238.                     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
  239.                     rotate_2d p(t, 0), p(t, 2), 90 * pip180 * Sgn(dt And 2)
  240.                     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)
  241.                 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))))
  242.             End If
  243.     Next ty, tx
  244.  
  245.     'SPIDER array '0-active 1-room 2,3,4-XYZ 5,6-ANGA,B 7-animation 8-size 9-abdomen size
  246.  
  247.     'draw spiders
  248.     For asp = 0 To spider_c - 1: If spider(asp, 0) = 0 Or spider(asp, 1) <> me(5) Then _Continue
  249.  
  250.         sp_thick = 2.5 * spider(asp, 8): sp_width = .2 * spider(asp, 8): sp_zoom = .09 * spider(asp, 8)
  251.  
  252.  
  253.         If spider(asp, 4) > .5 * spider(asp, 8) Then spider(asp, 4) = spider(asp, 4) - .1
  254.  
  255.  
  256.  
  257.         spider(asp, 7) = spider(asp, 7) + (1 - spider(asp, 8)) * .8
  258.         spider(asp, 5) = spider(asp, 5) + 0
  259.  
  260.         For side = 0 To 1: For leg = 0 To 3: For bre = 0 To 3: For p = 0 To 1: sl_read xy(), spider(asp, 7) + side * 4.5, leg, bre + p
  261.             p(p, 0) = xy(0) * sp_zoom: p(p, 1) = -xy(1) * sp_zoom: p(p, 2) = (bre + p) * sp_width * (side * 2 - 1)
  262.             rotate_2d p(p, 0), p(p, 2), spider(asp, 5) * pip180
  263.             p(p, 0) = p(p, 0) + spider(asp, 2): p(p, 1) = p(p, 1) + spider(asp, 4): p(p, 2) = p(p, 2) + spider(asp, 3)
  264.             point_3d p(p, 0), p(p, 1), p(p, 2): Next p
  265.             For t1 = 0 To 1: For t2 = 0 To 2: p(t1, t2) = p(t1, t2) - sp_thick * .5: p(2 + t1, t2) = p(t1, t2) + sp_thick: Next t2, t1
  266.                 draw_square p(), sp_text(shdw(Abs(Int((p(0, 2) + p(1, 2) + p(2, 2) + p(3, 2)) / 4))), 0)
  267.         Next bre, leg, side
  268.  
  269.         spider(asp, 9) = spider(asp, 9) + (1 - spider(asp, 8)) * (.2 - (spider(asp, 9) > 0) * .15)
  270.         size = .22 * spider(asp, 8) * (1 + .2 * Abs(Sin(spider(asp, 9))))
  271.         draw_sphere spider(asp, 2), spider(asp, 3), spider(asp, 4), size, sp_text(shdw(Abs(Int((p(0, 2) + p(1, 2) + p(2, 2) + p(3, 2)) / 4))), 0), spider(asp, 5)
  272.  
  273.     Next asp
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.     'white flash
  286.     mindis = 999999: For ad = 0 To room(me(5), 4) - 1: dis = Sqr((me(0) - (room(me(5), 20 + 5 * ad))) ^ 2 + (me(1) - (room(me(5), 21 + 5 * ad))) ^ 2)
  287.         If dis < mindis Then mindis = dis: trans_door = ad
  288.     Next ad: If mindis > .8 Then awf_add = -.5: trans_door = -1
  289.     awf = awf + awf_add: If Int(awf) < 0 Then awf = 0 Else If Int(awf) > wf_c - 1 Then awf = wf_c - 1
  290.     _PutImage , wf_text(Int(awf))
  291.  
  292.  
  293.     'near door / trans to another room
  294.     If trans_door <> -1 Then
  295.         ndoor = adoor(me(5), trans_door, 1): me(5) = adoor(me(5), trans_door, 0)
  296.         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
  297.         me(3) = -degree(q(0), q(1)) + 180: awf = wf_c - 1
  298.     End If
  299.  
  300.     'draw diamants
  301.     'DIAMANT array
  302.     '0,1,2 XYZ-location
  303.     '3,room-location
  304.     '4,5,6 XYZ vector
  305.     '8 active status 1-active
  306.  
  307.     diar = 10
  308.     For ad = 0 To dia_c - 1: If dia(ad, 3) <> me(5) Or dia(ad, 8) = 0 Then _Continue
  309.         'catch
  310.         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
  311.         If catch Then dia(ad, 8) = 0: awf = (wf_c - 1) * .6: _Continue
  312.  
  313.         'diamants move
  314.         newpos = dia(ad, 2) + dia(ad, 6): If newpos < 0 Or newpos > 1 Then dia(ad, 6) = -dia(ad, 6)
  315.         newpos = dia(ad, 0) + dia(ad, 4): If room_map(me(5), newpos, dia(ad, 1)) <> 1 Then dia(ad, 4) = -dia(ad, 4)
  316.         newpos = dia(ad, 1) + dia(ad, 5): If room_map(me(5), dia(ad, 0), newpos) <> 1 Then dia(ad, 5) = -dia(ad, 5)
  317.         For t = 0 To 2: dia(ad, t) = dia(ad, t) + dia(ad, 4 + t): Next t
  318.  
  319.         'diamants draw
  320.         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
  321.         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
  322.         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))))
  323.     Next ad
  324.  
  325.  
  326.     'stroryline
  327.     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
  328.  
  329.     For ar = 0 To room_c - 1: Color _RGB32(255, 255, 255), b_colors(ar): Locate 2 + ar, 2
  330.         If ar = 0 Then Print "START ROOM"; Else If sum(ar) Then Print ar; ".room :"; sum(ar); " diamant"; Else Print ar; ".room is OK !";
  331.         If ar = me(5) Then Color _RGB32(255, 255, 255), 0: Print "    <-- YOU ARE HERE"
  332.     Next ar
  333.  
  334.     If my_dia Then mess$ = "Get all diamant !" Else If me(5) = 0 Then mess$ = "CONGRATULATION !" Else mess$ = "Go back to the START-ROOM !"
  335.     Locate mony / 16 - 2, 2: Color _RGB32(255, 255, 255), 0: Print mess$
  336.  
  337.     _Display: Cls , 0
  338.  
  339.  
  340.  
  341. 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
  342. Function randscale (a, b): randscale = a + (b - a) * Rnd(1): End Function
  343. Sub reg_minmax_reset (n): rm(n, 0) = 9999999: rm(n, 1) = -rm(n, 0): End Sub
  344. 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
  345. 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
  346. 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
  347.  
  348. 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
  349. rotate_2d x, z, -(cam(3) + 180) * pip180: rotate_2d y, z, (cam(4) + 180) * pip180: End Sub
  350.  
  351. Sub draw_square (p(), text)
  352.     wtext = _Width(text) - 1: htext = _Height(text) - 1
  353.     _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
  354.     _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
  355.  
  356. Sub draw_brick_3d (x, y)
  357.     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
  358.         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))
  359.         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))))
  360.     Next t
  361.  
  362. 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
  363. 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
  364.  
  365. Sub draw_sphere (x, z, y, size, text, rotate_a)
  366.     For ap = 0 To spk_c - 1: spk_p(ap, 3) = spk_p(ap, 2) * size: spk_p(ap, 4) = spk_p(ap, 1) * size: spk_p(ap, 5) = spk_p(ap, 0) * size * 1.2
  367.         rotate_2d spk_p(ap, 3), spk_p(ap, 5), rotate_a * pip180: spk_p(ap, 3) = spk_p(ap, 3) + x: spk_p(ap, 4) = spk_p(ap, 4) + y
  368.     spk_p(ap, 5) = spk_p(ap, 5) + z: point_3d spk_p(ap, 3), spk_p(ap, 4), spk_p(ap, 5): Next ap
  369.     For ap = 0 To spk_c - 1: For p2 = 0 To 3: For p1 = 0 To 2: p(p2, p1) = spk_p(sqs(ap, p2), 3 + p1): Next p1, p2: draw_square p(), text: Next ap
  370.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Spider animation
« Reply #5 on: March 07, 2022, 06:22:50 pm »
Red and white spider prison!

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Spider animation
« Reply #6 on: March 08, 2022, 02:03:09 am »
Any more realistic in movement and I'm going to be reaching for a rolled up newspaper or a can of bug spray!! Very cool...!!
Logic is the beginning of wisdom.

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Spider animation
« Reply #7 on: March 08, 2022, 06:06:25 am »
Can't wait to see how it looks when you install the vicious factor.