View.Set ("graphics:max,max, offscreenonly")
 
var x1, y1, x2, y2, meX, meY, distance : int
 
var m, b : real
 
var tX, tY : int
 
var controls : array char of boolean
 
% The line works fine on a straight or steep slope but screws up on a small slope
 
x1 := 200
 
y1 := 300
 
x2 := 500
 
y2 := 400
 
 
meX := 300
 
meY := 400
 
fcn wallDETECTION (x1_, y1_, x2_, y2_, charX_, charY_ : int, m_, b_ : real) : boolean
 
    var x, y, ratio : real
 
    var angle : int
 
    for i : x1_ .. x2_
 
        x := i
 
        y := (m_ * x) + b_
 
        drawdot (round (x), round (y), black)
 
        /*if (charX_ - round (x)) not= 0 then
 
         ratio := (charY_ - round (y)) / (charX_ - round (x))
 
         else
 
         ratio := (charY_ - round (y)) / 0.001
 
         end if
 
         angle := round (arctand (abs (ratio)))
 
         if (charX_ - round (x)) < 0 then
 
         angle := 180 - angle
 
         end if
 
         if (charY_ - round (y)) < 0 then
 
         angle := 360 - angle
 
         end if
 
         locate (1, 1)
 
         put angle ..*/
 
        if Math.Distance (x, y, charX_, charY_) <= 5 then %and angle >= 0 and angle <= 180 then
 
            %if angle = 27 or angle = 180 then
 
            %    meY += 5
 
            %end if
 
            %put "HIT:" ..
 
            result true
 
        end if
 
    end for
 
    result false
 
end wallDETECTION
 
 
proc initialize (x1_, y1_, x2_, y2_ : int)
 
    x1 := x1_
 
    x2 := x2_
 
    y1 := y1_
 
    y2 := y2_
 
    if x2 - x1 <= 0 then
 
        m := (y2 - y1) / 0.0000001
 
    else
 
        m := (y2 - y1) / (x2 - x1)
 
    end if
 
    b := (m * x1 - y1) * -1
 
    distance := round (sqrt ((x2 - x1) ** 2 + (y2 - y1) ** 2))
 
end initialize
 
 
proc move
 
    Input.KeyDown (controls)
 
% PROBLEM AREA
 
    % The t variables represents the line and the balls position shifted up by 5
 
    % The me variables is the ball shifted up 5, cept that it descends down into the t's trajectory. 
 
    if controls (KEY_RIGHT_ARROW) then
 
        if wallDETECTION (x1, y1, x2, y2, meX, meY, m, b) = true then
 
            meX += 5
 
            tX := meX
 
            meY := round ((m * intreal (meX)) + b) + 5
 
            tY := round ((m * intreal (meX)) + b)
 
        else
 
            meX += 5
 
        end if
 
    elsif controls (KEY_LEFT_ARROW) then
 
        if wallDETECTION (x1, y1, x2, y2, meX, meY, m, b) = true then
 
            meX -= 5
 
            tX := meX
 
            meY := round ((m * intreal (meX)) + b) + 5
 
            tY := round ((m * intreal (meX)) + b)
 
        else
 
            meX -= 5
 
        end if
 
    end if
 
    if controls (KEY_UP_ARROW) then
 
        meY += 10
 
    end if
 
    if wallDETECTION (x1, y1, x2, y2, meX, meY, m, b) = false then
 
        meY -= 5
 
        tX := meX
 
        tY := meY
 
    end if
 
end move
 
 
initialize (x1, y1, x2, y2)
 
 
loop
 
    move
 
    View.Update
 
    cls
 
    drawline (x1, y1, x2, y2, black)
 
    drawoval (meX, meY, 5, 5, red)
 
    drawoval (meX, meY - 5, 5, 5, 1)
 
    drawoval (tX, tY, 5, 5, green)
 
    delay (10)
 
    locate (1, 1)
 
    put meX, " ", meY ..
 
    locate (2, 1)
 
    put meX, " ", meY - 5 ..
 
end loop
 
% Need to check for Steep slopes and change so that movement falls better :D
 
  |