Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Questions about old games
#22
If you define the ground as a couple of connected lines, you can quite easily calculate the height at any x:

Code:
set window "test", 640, 480
set redraw off

' Create an array of connected lines that cover the width of the window.
lines = []
x0 = 0
y0 = 400
while x0 < 640
    x1 = x1 + 16 + rnd(64); y1 = 400 + rnd(80) - 40
    lines[sizeof(lines)] = [x0, y0, x1, y1]
    x0 = x1; y0 = y1
wend

' Loop until excape is pressed.
while not keydown(KEY_ESCAPE, true)
    set color 0, 0, 0
    cls
   
    ' Draw the lines.
    set color 255, 255, 255
    for i = 0 to sizeof(lines) - 1
        draw line lines[i][0], lines[i][1], lines[i][2], lines[i][3]
    next
   
    ' Mark the y coordinate of the ground at mouse x.
    x = mousex()
    y = GetY(lines, x)
    set color 0, 255, 0
    draw line x, y - 16, x, y
   
    redraw
    fwait 60
wend

function GetY(lines, x)
    y = 480
    for i = 0 to sizeof(lines) - 1
        if x >= lines[i][0] and x < lines[i][2]
            k = (x - lines[i][0])/(lines[i][2] - lines[i][0])
            y = lines[i][1] + k*(lines[i][3] - lines[i][1])
            break
        endif
    next
    return y
endfunc

I still haven't read through this thread yet, sorry. Maybe this is similar to what kevin did?
Reply


Messages In This Thread
Questions about old games - by johnno56 - 03-28-2024, 11:16 PM
RE: Questions about old games - by kevin - 03-29-2024, 04:28 AM
RE: Questions about old games - by johnno56 - 03-29-2024, 05:48 AM
RE: Questions about old games - by kevin - 03-29-2024, 07:40 AM
RE: Questions about old games - by kevin - 03-29-2024, 09:00 AM
RE: Questions about old games - by johnno56 - 03-29-2024, 10:57 AM
RE: Questions about old games - by kevin - 03-29-2024, 11:12 AM
RE: Questions about old games - by Marcus - 03-29-2024, 04:04 PM
RE: Questions about old games - by johnno56 - 03-29-2024, 05:21 PM
RE: Questions about old games - by Marcus - 03-29-2024, 05:43 PM
RE: Questions about old games - by kevin - 03-29-2024, 06:02 PM
RE: Questions about old games - by johnno56 - 03-29-2024, 06:49 PM
RE: Questions about old games - by kevin - 03-29-2024, 08:17 PM
RE: Questions about old games - by johnno56 - 03-29-2024, 08:35 PM
RE: Questions about old games - by johnno56 - 03-30-2024, 10:57 AM
RE: Questions about old games - by kevin - 03-30-2024, 12:48 PM
RE: Questions about old games - by johnno56 - 03-30-2024, 08:25 PM
RE: Questions about old games - by kevin - 03-31-2024, 09:52 AM
RE: Questions about old games - by 1micha.elok - 04-01-2024, 12:06 AM
RE: Questions about old games - by johnno56 - 04-01-2024, 05:11 AM
RE: Questions about old games - by 1micha.elok - 04-02-2024, 08:50 AM
RE: Questions about old games - by johnno56 - 03-31-2024, 11:08 AM
RE: Questions about old games - by Marcus - 04-01-2024, 11:44 AM
RE: Questions about old games - by kevin - 04-01-2024, 03:30 PM
RE: Questions about old games - by johnno56 - 04-02-2024, 09:45 AM
RE: Questions about old games - by Marcus - 04-02-2024, 10:09 AM
RE: Questions about old games - by johnno56 - 04-02-2024, 11:17 AM
RE: Questions about old games - by Marcus - 04-02-2024, 04:04 PM
RE: Questions about old games - by johnno56 - 04-02-2024, 06:13 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)