
-----------------------------------
iker
Mon May 01, 2006 7:41 pm

Basic platformer
-----------------------------------
Here's a little platforming action I put together, all turing graphics, and great collision detection. 

Keys:
LEFT & RIGHT arrows - move left and right
SPACE                      - jump
CTRL                        - crouch

Functions:
Walking - left, right, jump, crouch
Hanging - left, right, jump up (jump), fall (crouch)

There's nothing but simple platform movement, no baddies, no weapons, no health, just movement.


setscreen ("graphics,offscreenonly")
var x, y, ang, bodyLength, maxYSpeed : int := 15
var ySpeed : real := 0
ySpeed := 0
var key : array char of boolean
var inAir, yGood, left, hang : boolean := false

proc walkLeft
    if key (KEY_LEFT_ARROW) then
        ang -= 7
        x -= 3
        left := true
        for i : 1 .. 15
            if View.WhatDotColor (x, y + i) = black then
                y += 1
            end if
        end for
    end if
end walkLeft

proc walkRight
    if key (KEY_RIGHT_ARROW) then
        ang += 7
        x += 3
        for i : 1 .. 15
            if View.WhatDotColor (x, y + i) = black then
                y += 1
            end if
        end for
        left := false
    end if
end walkRight

proc jump
    if hang = false then
        if bodyLength = 33 and key (' ') and inAir = false then
            y -= 2
        elsif key (' ') and inAir = false then
            ySpeed := 10
        end if
    else
        if key (' ') and inAir = false then
            ySpeed := 13
        end if
    end if
end jump

proc crouch
    if key (KEY_CTRL) then
        bodyLength := 33
    else
        bodyLength := 45
    end if
end crouch

proc gravityAndCheck
    if View.WhatDotColor (x, y) ~= black and hang = false then
        inAir := true
    end if
    hang := false
    yGood := false
    if ySpeed > 0 then
        y += round (ySpeed)
    elsif ySpeed < 0 then
        for decreasing i : 0 .. round (ySpeed)
            if View.WhatDotColor (x, y + i) ~= black and yGood = false then
                if View.WhatDotColor (x, y + bodyLength + i + 15) = black then
                    yGood := true
                    inAir := false
                    ySpeed := 0
                    hang := true
                else
                    hang := false
                end if
                if hang = false then
                    y -= 1
                end if
            else
                yGood := true
                inAir := false
                ySpeed := 0
            end if
        end for
    end if
    if View.WhatDotColor (x, y) ~= black then
        ySpeed -= 1.25
    end if
end gravityAndCheck

proc drawScreen
    Draw.ThickLine (0, 5, maxx, 5, 2, black)
    %platforms
    for yi : 50 .. 250 by 50
        Draw.ThickLine (yi, yi, yi + 60, yi, 2, black)
    end for
    Draw.ThickLine (300, 300, maxx, 300, 2, black)
end drawScreen

proc drawGuy
    drawline (x, y + 20, x, y + bodyLength, black)
    %legs
    drawline (x, y + 20, x + round (sind (ang) * 5), y + 20 + round (cosd (ang) * 10), black)
    drawline (x, y + 20, x + round (sind (ang + 180) * 5), y + 20 + round (cosd (ang + 180) * 10), black)
    drawline (x + round (sind (ang) * 5), y + 20 + round (cosd (ang) * 10), x + round (sind (ang) * 5), y + 5 + round (cosd (ang) * 10), black)
    drawline (x + round (sind (ang + 180) * 5), y + 20 + round (cosd (ang + 180) * 10), x + round (sind (ang + 180) * 5), y + 5 + round (cosd (ang + 180) * 10), black)
    %arms
    ang += 90
    drawline (x, y + bodyLength - 2, x + round (sind (ang) * 5), y + bodyLength - 2 + round (cosd (ang) * 10), black)
    drawline (x, y + bodyLength - 2, x + round (sind (ang + 180) * 5), y + bodyLength - 2 + round (cosd (ang + 180) * 10), black)
    if hang = false then
        if left = true then
            drawline (x + round (sind (ang) * 5), y + bodyLength - 2 + round (cosd (ang) * 10), x + round (sind (ang) * 5) - 7, y + bodyLength - 10 + round (cosd (ang) * 10), black)
            drawline (x + round (sind (ang + 180) * 5), y + bodyLength - 2 + round (cosd (ang + 180) * 10), x + round (sind (ang + 180) * 5) - 7, y + bodyLength - 10 + round (cosd (ang + 180) * 10),
                black)
        else
            drawline (x + round (sind (ang) * 5), y + bodyLength - 2 + round (cosd (ang) * 10), x + round (sind (ang) * 5) + 7, y + bodyLength - 10 + round (cosd (ang) * 10), black)
            drawline (x + round (sind (ang + 180) * 5), y + bodyLength - 2 + round (cosd (ang + 180) * 10), x + round (sind (ang + 180) * 5) + 7, y + bodyLength - 10 + round (cosd (ang + 180) * 10),
                black)
        end if
        ang -= 90
    else
        if left = true then
            drawline (x + round (sind (ang) * 5), y + bodyLength - 2 + round (cosd (ang) * 10), x + round (sind (ang) * 5), y + bodyLength + 10 + round (cosd (ang) * 10), black)
            drawline (x + round (sind (ang + 180) * 5), y + bodyLength - 2 + round (cosd (ang + 180) * 10), x + round (sind (ang + 180) * 5), y + bodyLength + 10 + round (cosd (ang + 180) * 10),
                black)
        else
            drawline (x + round (sind (ang) * 5), y + bodyLength - 2 + round (cosd (ang) * 10), x + round (sind (ang) * 5), y + bodyLength + 10 + round (cosd (ang) * 10), black)
            drawline (x + round (sind (ang + 180) * 5), y + bodyLength - 2 + round (cosd (ang + 180) * 10), x + round (sind (ang + 180) * 5), y + bodyLength + 10 + round (cosd (ang + 180) * 10),
                black)
        end if
        ang -= 90
    end if
    %head
    drawoval (x, y + bodyLength + 5, 5, 5, black)
    drawfilloval (x, y + bodyLength + 5, 4, 4, white)
end drawGuy

loop
    Input.KeyDown (key)
    drawScreen
    jump
    crouch
    gravityAndCheck
    walkLeft
    walkRight
    drawGuy
    ang := ang mod 360
    View.Update
    delay (10)
    cls
    if x < 0 or x > maxx or y < 0 or y > maxy then
        x := 5
        y := 5
    end if
end loop


-----------------------------------
Cervantes
Mon May 01, 2006 8:04 pm


-----------------------------------
Crouch & Jump seems to push me back to the start (bottom left corner). If I'm on a platform at that time, I seem to fall through the platform, first.

Pretty cool graphics!

-----------------------------------
codemage
Tue May 02, 2006 8:03 am


-----------------------------------
Unless that's on purpose to let you jump down from a platform (just as CTRL lets you drop down when you're hanging).

I like the hanging bit.  The whole thing is very "stickman sam" without the shooting.

-----------------------------------
BenLi
Tue May 02, 2006 3:31 pm


-----------------------------------
I like it, just more levels, and you'll be in bussiness

-----------------------------------
MattyGG
Tue May 02, 2006 5:48 pm


-----------------------------------
problem...when i jump while trying to go off-screen to the left, it disables the jump for the rest of the time using the program

-----------------------------------
iker
Tue May 02, 2006 7:43 pm


-----------------------------------
Fixed it up a bit, added some better graphics, made it more of a "game". 3 levels, and you can make levels easily. In a future version that I'm making, I'm adding in a level timer, to actualy make it a game. Don't fall too much or you'll die (just restart that level). 

After you finish the last level it just crashes unless you have another level made... so make some levels and post them here so the game can continue forever... and ever... and when I actualy make the game, I'll add in some of your best levels.

Anyways, have some fun with making some challenging levels. I will have a level maker in the next post, to make it alot easier. Remember that you can climb across, and yes, crouching and jumping is supposed to make you fall through. 

one last thing, try to make it out the far left exit in the first level, if you can figure out how (and yes, there is a way)

-----------------------------------
iker
Tue May 02, 2006 8:48 pm


-----------------------------------
mapmaker, works with anything if modded (go for it)
make sure you save it to the same directory as the game


setscreen ("graphics:550;450,offscreenonly,nobuttonbar")
var font1 : int := Font.New ("serif:25")
var mx, my, mb, Level, fileNo, info, current, count : int := 0
var tiles : array 0 .. 9 of int
var xy : array 0 .. 19, 0 .. 15 of int
for i : 0 .. 9
    tiles (i) := Pic.FileNew ("images/fore0" + intstr (i) + ".bmp")
end for
for x : 0 .. 19
    for y : 0 .. 14
        xy (x, y) := 1
    end for
end for

proc exportLevel
    get Level
    count := 1
    open : fileNo, "levels/level" + intstr (Level) + ".txt", put
    for decreasing y : 14 .. 0
        for x : 0 .. 19
            info := xy (x, y)
            put : fileNo, info
        end for
    end for
    close : fileNo
end exportLevel

proc importLevel
    get Level
    open : fileNo, "levels/level" + intstr (Level) + ".txt", get
    for decreasing y : 14 .. 0
        for x : 0 .. 19
            get : fileNo, info
            xy (x, y) := info
        end for
    end for
    close : fileNo
end importLevel

proc drawScreen
    Font.Draw ("L", 0 + 2, 17 * 25, font1, red)
    Font.Draw ("S", 25 + 3, 17 * 25, font1, red)
    drawbox (0, 17 * 25, 25, 18 * 25, black)
    drawbox (25, 17 * 25, 50, 18 * 25, black)
    Pic.Draw (tiles (current), 0, 0, picMerge)
    drawbox (0, 0, 25, 25, black)
    for i : 0 .. 9
        Pic.Draw (tiles (i), i * 25 + 50, 0, picMerge)
        drawbox (i * 25 + 50, 0, i * 25 + 25 + 50, 25, black)
    end for
    for x : 0 .. 19
        for y : 0 .. 14
            Pic.Draw (tiles (xy (x, y)), x * 25 + 25, y * 25 + 50, picMerge)
        end for
    end for
end drawScreen

proc setTile
    if my = 0 and mb = 1 then
        if mx = 2 then
            current := 0
        elsif mx = 3 then
            current := 1
        elsif mx = 4 then
            current := 2
        elsif mx = 5 then
            current := 3
        elsif mx = 6 then
            current := 4
        elsif mx = 7 then
            current := 5
        elsif mx = 8 then
            current := 6
        elsif mx = 9 then
            current := 7
        elsif mx = 10 then
            current := 8
        elsif mx = 11 then
            current := 9
        end if
    end if
end setTile

proc setXYOnMap
    mx := mx - 1
    my := my - 2
    if mb = 1 and mx >= 1 and my >= 1 and mx 