All pastes #28855 Raw Edit

Basic Sidescroller

public text v1 · immutable
#28855 ·published 2005-11-16 00:41 UTC
rendered paste body
View.Set ("graphics:max,max")
var x, y, groundy, layery, jumpup, jumpheight, shotx, shoty, scrollm, test : int
var jumpFlag, dblJumpFlag, dashFlag, shootFlag : boolean := false
var direction : boolean := true
shotx := 0
shoty := 0
scrollm := 0
x := 200
y := 54
jumpup := 20
jumpheight := jumpup
groundy := 50
layery := groundy
test := Font.New ("Verdana:6")

View.Set ("offscreenonly")
var chars : array char of boolean

proc ground
    %drawfill (1, groundy + 1, blue, black)
    drawline (0, layery, maxx, layery, black)
    Draw.DashedLine (50, 0, 50, maxy, drawDot, red)
    Draw.DashedLine (maxx - 50, 0, maxx - 50, maxy, drawDot, red)
    Draw.DashedLine (100, 0, 100, maxy, drawDot, red)
    Draw.DashedLine (maxx - 100, 0, maxx - 100, maxy, drawDot, red)
end ground


proc scroll
    if x >= maxx - 100 then
        scrollm := scrollm + 10
    elsif
            x <= 100 then
        scrollm := scrollm - 10
    end if
    if x >= maxx - 50 then
        scrollm := scrollm + 30
    elsif
            x <= 50 then
        scrollm := scrollm - 30
    end if


    %Draws a Background
    drawline (1300 - scrollm, layery, 1325 - scrollm, 100, black)
    drawline (1325 - scrollm, 100, 1350 - scrollm, layery, black)
    drawoval (1400 - scrollm, layery + 500, 50, 50, black)
    drawfill (1401 - scrollm, layery + 501, yellow, black)

    % Platform Test
    drawbox (500 - scrollm, 30 + layery, 600 - scrollm, 40 + layery, black)
    
    if x > 500 - scrollm + 5 and x > 600 - scrollm + 5 then %and y > layery then %and y-4 < groundy then
        groundy := layery
        y := layery
    elsif x < 500 - scrollm + 5 and x < 600 - scrollm + 5 then      %and y > layery then %and y-4 < groundy then
        groundy := layery
        y := layery
    elsif x > 500 - scrollm and x < 600 - scrollm then     %and y > 40 + layery then
        groundy := layery + 40

    end if
end scroll

proc jump
    if jumpFlag = true then
        y += jumpup
        jumpup -= 1
        if y <= jumpheight then
            jumpFlag := false
            y := groundy + 4
            jumpup := 20
        end if
    end if
end jump


proc dblJump
    if dblJumpFlag = true then
        y += jumpup * 2
        jumpup -= 1

        if y <= jumpheight then
            dblJumpFlag := false
            y := groundy + 4
            jumpup := 20
        end if
    end if

end dblJump


proc dash
    if dashFlag = true then
        if direction = true then
            x += 20
        elsif direction = false then
            x -= 20
        end if
    end if
    dashFlag := false
end dash

proc shoot
    if shootFlag = true then
        shotx := x
        shoty := y
        if direction = true then
            shotx += 10
            drawfilloval (shotx, shoty, 4, 2, yellow)
            %drawline(shotx, shoty,maxx,shoty,yellow)
            Draw.DashedLine (shotx, shoty, maxx, shoty, drawDot, red)
            shootFlag := false
        elsif direction = false then
            shotx -= 10
            drawfilloval (shotx, shoty, 4, 2, yellow)
            %drawline(shotx, shoty,0,shoty,yellow)
            Draw.DashedLine (shotx, shoty, 0, shoty, drawDot, red)
            shootFlag := false
        end if
        if shotx >= maxx and shotx <= 0 then
            shootFlag := false
        end if
    end if
    %shootFlag := false
end shoot



proc move

    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) and jumpFlag = false then
        jumpFlag := true
    end if
    if chars (KEY_RIGHT_ARROW) then
        x := x + 5
        direction := true
    end if
    if chars (KEY_LEFT_ARROW) then
        x := x - 5
        direction := false
    end if
    if chars (KEY_DOWN_ARROW) then     %and y >= groundy + 9 then
        %y := y - 5
        dashFlag := true
    end if
    if chars (KEY_CTRL) then
        shootFlag := true
    end if
    if chars (KEY_SHIFT) then
        dblJumpFlag := true
    end if

end move


loop
    scroll
    ground
    move
    dash
    dblJump
    jump
    shoot
    drawoval (x, y, 4, 4, red)
    delay (10)
    View.Update
    cls
    locate (1, 1)
    put jumpFlag, " ", dblJumpFlag, " ", direction, " ", scrollm ..
    locate (2, 1)
    put x, " x", y, " y", "layery", layery, "groundy", groundy ..

end loop