Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"5-line" engine
#30
I added a convenience function. If there is a wall between the mouse cursor and the puppet, the puppet cannot go to the desired location. In the innovation, I used the 'Dijkstra' algorithm to find the way between the puppet and the mouse cursor, so he finds the way.
It is no longer good for the challenge, because it has been extended by a few lines, so I will stop it.
It's more of a curiosity.

Code: (Select All)
en = 9: gold = 12: c0 = 219: c1 = 46: c2 = 36: c3 = 35: c4 = 2: r(0) = 80: r(1) = 45: For t = 0 To 1: r(2 + t) = Int(r(t) / 2): p(t) = r(2 + t): d(t) = p(t): Next t: Randomize Timer: Screen _NewImage(r(0), r(1), 0): _FullScreen
_ControlChr Off: Color 6: _PrintString (1, 1), String$(r(0) * r(1), Chr$(c0)): For c = 1 To 4000: _PrintString (d(0), d(1)), Chr$(c1): t = Int(4 * Rnd): f = 0: For a = 0 To 1: b = a * 2: l = t = b + 1
    d(a) = (t = b Or l) * (l * 2 + 1) + d(a): f = f Or d(a) = 1 Or d(a) = r(a) - 1: Next a: For t = 0 To 1: d(t) = r(t + 2) * -f + d(t) * (-f Xor 1): Next t, c: Color 14: For c = 1 To gold: Do: For t = 0 To 1
        g(t) = Int((r(t) - 10) * Rnd) + 5: Next t: Loop While Screen(g(1), g(0), 0) <> c1 Or g(0) = r(2): _PrintString (g(0), g(1)), Chr$(c2): Next c: For c = 0 To en - 1: Do: For t = 0 To 1: en(c, t) = Int((r(t) - 10) * Rnd) + 5
    Next t: Loop Until Screen(en(c, 1), en(c, 0), 0) = c1 And Screen(en(c, 1), en(c, 0) + 1, 0) = c0: Next c: Do: Color 6: _PrintString (p(0), p(1)), Mid$(Chr$(c1), 1, c): die = die Or Screen(p(1), p(0), 0) = c3
    ReDim di(r(0) - 1, r(1) - 1) As _Byte: For x = 1 To r(0) - 2: For y = 1 To r(1) - 2: di(x, y) = Screen(y, x, 0) = c0: Next y, x: While _MouseInput: Wend: e = 0: k = 1: di(_MouseX, _MouseY) = k: j = 15: Do Until e Or k > j
        mdis = 100: For x1 = -1 To 1: For y1 = -1 To 1: x2 = p(0) + x1: y2 = p(1) + y1: dis = Abs(x2 - _MouseX) + Abs(y2 - _MouseY): n = ((di(p(0) + x1, p(1)) = -1) And (di(p(0), p(1) + y1) = -1) And x1 And y1) = 0
            q = Abs(di(x2, y2) = k And dis < mdis And n): e = e Or q: d1 = d1 * (q Xor 1) + x1 * q: d2 = d2 * (q Xor 1) + y1 * q: mdis = mdis * (q Xor 1) + dis * q: Next y1, x1: For x = 1 To r(0) - 2: For y = 1 To r(1) - 2: f = 0
                For x1 = -1 To 1: For y1 = -1 To 1: n = ((di(x + x1, y) = -1) And (di(x, y + y1) = -1) And x1 And y1) = 0: f = f Or ((di(x + x1, y + y1) = k) And (x1 Or y1) And n): Next y1, x1: f = Abs(f And di(x, y) = 0)
        di(x, y) = (k + 1) * f + di(x, y) * (f Xor 1): Next y, x: k = k + 1: Loop: m(0) = d1 + p(0): m(1) = d2 + p(1): m = Abs(d1 Or d2) * st: c = Abs(m And Screen(m(1), m(0), 0) <> c0): For t = 0 To 1: p(t) = m(t) * c + p(t) * (c Xor 1)
    Next t: fg = -(Screen(p(1), p(0), 0) = c2): mygold = mygold + fg: Sound 2000, .6 * fg: die = die Or Screen(p(1), p(0), 0) = c3: Color 15: _PrintString (p(0), p(1)), Left$(Chr$(c4), 1 + (k > j) * j3): j3 = j3 Xor 1: m = 0
    For c = 0 To en - 1: die = die Or Screen(en(c, 1), en(c, 0), 0) = c4: ti = c Mod 3: t = en(c, 2) - (ti = 0) * 2: Do: t = t + (ti = 0): For w = 0 To 1: b = (t + 16 + w) Mod 4
        d(w) = en(c, w) + (((b And 1) = 0) * ((b = 0) * 2 + 1)) * (ti <> 1) - (Sgn(t And (1 + w)) * 2 - 1) * (ti = 1): Next w: u = Screen(d(1), d(0), 0): z = -(u = c0): t = (t - Int(4 * Rnd) * (z And (ti > 0))) Mod 4: Loop While z
        Color 6: _PrintString (en(c, 0), en(c, 1)), Mid$(Chr$(c1), 1, en(c, 3)): en(c, 0) = d(0): en(c, 1) = d(1): en(c, 2) = t: en(c, 3) = -(u = c1): Color 2: _PrintString (d(0), d(1)), Mid$(Chr$(c3), 1, en(c, 3))
    die = die Or (u = c4) Or (m(0) = en(c, 0) And m(1) = en(c, 1)): Next c: Do Until _MouseButton(1) Or st: _PrintString (1, 1), "Press left mouse button to start": t = _MouseInput: Loop: st = 1: Color 6
_PrintString (1, 1), String$(50, Chr$(c0)): _Limit 8: _Display: Loop Until _KeyDown(27) Or gold = mygold Or die: Color 15: Print Left$("you dead", -8 * die); Left$("congratulation!", -15 * (gold = mygold))
Reply


Messages In This Thread
"5-line" engine - by James D Jarvis - 02-06-2024, 02:13 PM
RE: "5-line" engine - by SMcNeill - 02-06-2024, 02:40 PM
RE: "5-line" engine - by James D Jarvis - 02-06-2024, 05:43 PM
RE: "5-line" engine - by bplus - 02-06-2024, 06:27 PM
RE: "5-line" engine - by GareBear - 02-06-2024, 10:42 PM
RE: "5-line" engine - by JRace - 02-07-2024, 01:30 AM
RE: "5-line" engine - by MasterGy - 02-07-2024, 02:31 PM
RE: "5-line" engine - by TerryRitchie - 02-07-2024, 02:46 PM
RE: "5-line" engine - by JRace - 02-07-2024, 05:25 PM
RE: "5-line" engine - by MasterGy - 02-07-2024, 08:27 PM
RE: "5-line" engine - by GareBear - 02-08-2024, 12:00 AM
RE: "5-line" engine - by SMcNeill - 02-08-2024, 12:15 AM
RE: "5-line" engine - by JRace - 02-08-2024, 03:43 AM
RE: "5-line" engine - by GareBear - 02-08-2024, 01:27 PM
RE: "5-line" engine - by SMcNeill - 02-08-2024, 05:13 PM
RE: "5-line" engine - by MasterGy - 02-08-2024, 05:22 PM
RE: "5-line" engine - by SMcNeill - 02-08-2024, 06:03 PM
RE: "5-line" engine - by SMcNeill - 02-08-2024, 07:12 PM
RE: "5-line" engine - by MasterGy - 02-08-2024, 11:01 PM
RE: "5-line" engine - by GareBear - 02-09-2024, 02:35 PM
RE: "5-line" engine - by SMcNeill - 02-09-2024, 03:23 PM
RE: "5-line" engine - by madscijr - 02-10-2024, 12:25 AM
RE: "5-line" engine - by GareBear - 02-09-2024, 05:48 PM
RE: "5-line" engine - by bplus - 02-09-2024, 08:42 PM
RE: "5-line" engine - by MasterGy - 02-09-2024, 09:24 PM
RE: "5-line" engine - by MasterGy - 02-09-2024, 09:51 PM
RE: "5-line" engine - by SMcNeill - 02-09-2024, 10:36 PM
RE: "5-line" engine - by MasterGy - 02-09-2024, 11:55 PM
RE: "5-line" engine - by bplus - 02-10-2024, 12:04 AM
RE: "5-line" engine - by MasterGy - 02-11-2024, 01:28 AM
RE: "5-line" engine - by SMcNeill - 02-11-2024, 01:35 AM
RE: "5-line" engine - by MasterGy - 02-11-2024, 04:22 PM
RE: "5-line" engine - by johannhowitzer - 02-12-2024, 02:41 AM
RE: "5-line" engine - by James D Jarvis - 02-15-2024, 06:59 PM
RE: "5-line" engine - by Pete - 02-16-2024, 10:05 AM
RE: "5-line" engine - by Jack - 02-16-2024, 11:06 AM



Users browsing this thread: 4 Guest(s)