
-----------------------------------
Mayb123
Tue Nov 20, 2007 1:13 pm

Adding initial horizontal motion into a jumping procedure
-----------------------------------
i am trying to allow for horizontal running velocity to be incorporated into the jump procedure giving a trajectory with a slight 2-3 pixel restraint on how much you can affect the trajectory by holding down the a or d keys (wasd controls). for example's sake, i took out the variables that require external files and replaced the character with a dot. any help would be greatly appreciated. thanks

setscreen ("offscreenonly")
setscreen ("nobuttonbar")
setscreen ("graphics:640;480")
var key : array char of boolean
var chief : array 1 .. 5 of int
var ground, vcap, x, y, vx, vy, ax, g, charx, chary, carvx : real
const gravity := 0.06
const decel := 0.95
const mcrad := 5
var platformx1 : array 1 .. 6 of int := init (50, 100, 150, 200, 250, 300)
var platformx2 : array 1 .. 6 of int := init (60, 110, 160, 210, 260, 310)
var platformy1 : array 1 .. 6 of int := init (50, 100, 150, 200, 250, 300)
var platformy2 : array 1 .. 6 of int := init (60, 110, 160, 210, 260, 310)


var pos : int := 3
% chief (1) := Pic.FileNew ("MC sprite lsiderun.bmp")
% chief (2) := Pic.FileNew ("MC sprite lside.bmp")
% chief (3) := Pic.FileNew ("MC sprite.bmp")
% chief (4) := Pic.FileNew ("MC sprite rside.bmp")
% chief (5) := Pic.FileNew ("MC sprite rsiderun.bmp")
x := 10
y := 10
vx := 0
ax := .5
vy := 0


% PROCEDURES

procedure samplelevel
    for i : 1 .. 6
        drawfillbox (platformx1 (i), platformy1 (i), platformx2 (i), platformy2 (i), black)
    end for
end samplelevel
procedure movement
    if key ('d') and vx = -5 and y = 10 then
        vx -= 0.059
        pos := 2
    else
        vx *= decel
    end if
end movement
procedure velocity
    x += vx
    y += vy
end velocity
procedure jump %fix this part by adding horizontal motion
    if y > mcrad then
        vy -= gravity
    else
        vy := 0
    end if
    if vy = 0 and key ('w') then
        vy := 2
    end if
    % if key ('w') then
    %     vy += ax
    %
    % % end if
    % % if round (y) > 10 then
    % %     ax += gravity %Fix these
    % % end if
    % if round (y) = 633 and round (x) 