Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help with Sidescroller Game (Jumping specifically)
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
recneps




PostPosted: Thu Feb 19, 2004 5:45 pm   Post subject: Help with Sidescroller Game (Jumping specifically)

Ok, im gonna try to make a "mario style" game where its sidescroller and you can jump and such. Anyways, i cant figure out a way to get the person to jump and it look ok. Can anyone suggest something? heres what ive got. (Its really craptacular.)

code:
var bulletx, bullety, x, y : int
bulletx := 0
bullety := 0
x := 25
y := 50
var keys : array char of boolean
var right : char := chr (205)
var left : char := chr (203)
var space : char := chr (32)
var enter : char := chr (10)
var esc : char := chr (26)
var bulletmove, movex, movey : int
movex := 0
movey := 0
bulletmove := 0
var show := false

put "Use arrow keys to move, Space to jump, and enter to shoot."
delay(1000)
cls

setscreen ("offscreenonly")
loop
    if show = true then
        drawfilloval (bulletx, bullety, 2, 2, 7)
    end if
    if bulletx > maxx then
        show := false
    end if
    drawoval (x, y, 10, 10, 7)
    Input.KeyDown (keys)
    if keys (right) then
        if y > 50 then
            movex := 0
            movex := movex + 2
        else
            movex := 0
            x := x + 5
        end if
    elsif keys (left) then
        if y > 50 then
            movex := 0
            movex := movex - 2
        else
            movex := 0
            x := x - 5
        end if
    elsif keys (space) then
        if y = 50 then
            movey := 0
            movey := movey + 5
        end if
    elsif keys (enter) then
        bulletx := x + 5
        bullety := y
        show := true
    end if
    if y > 200 then
        movey := -movey
    elsif y < 50 then
        y := 50
        movey := 0
        movex := 0
    end if
    if x < 0 then
        x := 0
    elsif x > maxx then
        x := maxx
    end if
    y := movey + y
    x := movex + x
    delay (25)
    bulletx := bulletx + 5
    View.Update
    cls
    exit when keys (esc)
end loop


Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Feb 19, 2004 5:51 pm   Post subject: (No subject)

to make it look "ok" you got to make it jump in a parabula shape, not in straight lines. Meaning you would need to jump using negative acceleration.

or what do you mean? Confused
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Paul




PostPosted: Thu Feb 19, 2004 7:46 pm   Post subject: (No subject)

Alot of games jump like that, mario also jumps straight up when your not moving. But I think you have to work on getting it to move then jump, like holding the right arrow, then at the same time jump. There it would look like a parabola.
poly




PostPosted: Thu Feb 19, 2004 7:54 pm   Post subject: (No subject)

Quote:
like holding the right arrow, then at the same time jump. There it would look like a parabola.
was gonna say something pretty similiar... anyway its looking great, just get the images in there and wala
Cervantes




PostPosted: Thu Feb 19, 2004 8:24 pm   Post subject: (No subject)

you fail paul :p A parabala would be an arc. What you are talking about (jumping like he has it in that code while moving forward) would be a triangle

__/\__

^marios movement Razz

Here's how Homer has done it!

code:

type player_t :
    record
        x, y, w, v, t : real
    end record

var player_1 : player_t

player_1.x := 100
player_1.y := 100
player_1.v := 50
player_1.w := 10
player_1.t := 0

var bjump_1 := false
procedure Jump (var obj : player_t)
    obj.y := (obj.v * sind (90) * obj.t - (obj.w) * obj.t ** 2 / 2) + 100
    obj.t += .1
end Jump

var chars : array char of boolean
setscreen ("offscreenonly")
loop

    if bjump_1 then
        Jump (player_1)
        if player_1.y < 100 then
            bjump_1 := false
            player_1.t := 0
            player_1.y := 100
        end if
    end if

    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) then
        bjump_1 := true
    end if
    drawfilloval (round (player_1.x), round (player_1.y), 30, 30, 9)
    View.Update
    delay (10)
    drawfilloval (round (player_1.x), round (player_1.y), 30, 30, white)
end loop
Paul




PostPosted: Thu Feb 19, 2004 8:31 pm   Post subject: (No subject)

Hmm, would the jumping in Worms be like a parabola? I remeber playing Super Mario World 3 on SNES, and it kinda looked like a sharp parabola, hard to distinguish though.
Cervantes




PostPosted: Fri Feb 20, 2004 4:34 pm   Post subject: (No subject)

you can always just do it the cheap way and have a series of steps for the jump.

code:

var objy : int := 100
proc draw
    drawfilloval (100, objy, 20, 20, black)
    View.Update
    delay (5)
    drawfilloval (100, objy, 20, 20, white)
end draw
proc jump
    for i : 1 .. 12
        objy += 5
        draw
    end for
    for i : 1 .. 10
        objy += 4
        draw
    end for
    for i : 1 .. 8
        objy += 3
        draw
    end for
    for i : 1 .. 6
        objy += 2
        draw
    end for
    for i : 1 .. 4
        objy += 1
        draw
    end for
    for i : 1 .. 2
        objy += 0
        draw
    end for
    for i : 1 .. 4
        objy -= 1
        draw
    end for
    for i : 1 .. 6
        objy -= 2
        draw
    end for
    for i : 1 .. 8
        objy -= 3
        draw
    end for
    for i : 1 .. 10
        objy -= 4
        draw
    end for
    for i : 1 .. 12
        objy -= 5
        draw
    end for
end jump
setscreen ("offscreenonly")
loop
    jump
end loop



Works very well actually. it does take a lot of code though Thinking
recneps




PostPosted: Fri Feb 20, 2004 4:40 pm   Post subject: (No subject)

Ok, now that someone showed me that jump code (that i understand about half of Very Happy) can someone suggest a way to make it move a bit more realistically? Very Happy
code:
type player_t :
    record
        x, y, w, v, t : real
    end record

var player_1 : player_t

player_1.x := 100
player_1.y := 100
player_1.v := 50
player_1.w := 10
player_1.t := 0

var bjump_1 := false
procedure Jump (var obj : player_t)
    obj.y := (obj.v * sind (90) * obj.t - (obj.w) * obj.t ** 2 / 2) + 100
    obj.t += .1
end Jump

var chars : array char of boolean
setscreen ("offscreenonly")
loop

    if bjump_1 then
        Jump (player_1)
        if player_1.y < 100 then
            bjump_1 := false
            player_1.t := 0
            player_1.y := 100
        end if
    end if

    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) then
        bjump_1 := true
    end if
    if chars (KEY_RIGHT_ARROW) then
        player_1.x += 5
     elsif chars (KEY_LEFT_ARROW) then
        player_1.x -= 5
        end if
    if player_1.x > maxx - 30 then
        player_1.x := maxx - 30
    elsif player_1.x < 0 + 30 then
        player_1.x := 0 + 30
    end if
    if chars (chr(27)) then
    return
    end if
    drawfilloval (round (player_1.x), round (player_1.y), 30, 30, 9)
    View.Update
    delay (10)
    drawfilloval (round (player_1.x), round (player_1.y), 30, 30, white)
end loop
Cervantes




PostPosted: Fri Feb 20, 2004 4:54 pm   Post subject: (No subject)

That is realistically. You can play around with the values however.

The values you should play around with:
(values I thought were good in () )

player_1.v (100)
player_1.w (25)
obj.t (.1) <--- found in the jump procedure. obj.t = obj time. It's basically speeds up everything. Its kinda like the inverse of delay. The bigger the # the faster things go. I'd just leave this one as it is, though you can alter it if you want Confused
recneps




PostPosted: Fri Feb 20, 2004 8:42 pm   Post subject: (No subject)

i mean the left right stuff :\ the up down is good Smile
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: