Computer Science Canada

Make a animation Jump

Author:  X2_star [ Mon Apr 07, 2008 3:17 pm ]
Post subject:  Make a animation Jump

Hello, I need to know how to make a picture for a small animation video jump.

Author:  Mackie [ Mon Apr 07, 2008 3:47 pm ]
Post subject:  RE:Make a animation Jump

Post some code we can help you with. Otherwise how are we supposed to help?

Author:  DaveAngus [ Tue Apr 08, 2008 8:20 am ]
Post subject:  RE:Make a animation Jump

Is this what your looking for?

code:

% some constants, tweak this to your liking
const GROUND_HEIGHT := 40
const PLATFORM_HIEGHT := 200
const PLATFORM_HIEGHT2 := 350
const RUN_SPEED := 10
const FAST_SPEED := 13
const JUMP_SPEED := 30
const GRAVITY := 2

var win := Window.Open ("graphics:1200;600,offscreenonly")
var chars : array char of boolean

% player position and velocity
var posx, posy, gx, gx2, rx, lx : int
var velx, vely : real

posx := 200
velx := 0
posy := 400
vely := 0
gx := 10
gx2 := 10000
rx := 500
lx := 400

loop
    Input.KeyDown (chars)
    if chars ('q') then
        exit
    end if

    % to make the player move
    if chars (KEY_LEFT_ARROW) and chars (KEY_CTRL) then
        velx := -FAST_SPEED
    elsif chars (KEY_RIGHT_ARROW) and chars (KEY_CTRL) then
        velx := FAST_SPEED
    elsif chars (KEY_LEFT_ARROW) then
        velx := -RUN_SPEED
    elsif chars (KEY_RIGHT_ARROW) then
        velx := RUN_SPEED
    else
        velx := 0
    end if


    % remember, in order to jump you MUST be on the ground when pressing UP
    if (chars (KEY_UP_ARROW) and posy = GROUND_HEIGHT) or (chars (KEY_UP_ARROW) and posy = PLATFORM_HIEGHT and posx >= gx + 300 and posx <= gx + 400) or (chars (KEY_UP_ARROW) and posy =
            PLATFORM_HIEGHT2 and posx >= gx + 500 and posx <= gx + 600) then
        vely := JUMP_SPEED
    end if

    if posx >= rx and chars (KEY_RIGHT_ARROW) and rx < gx2 - (maxx - rx) then
        gx -= round (velx)
        gx2 -= round (velx)
        posx := rx
        posx := rx
    end if

    if posx <= lx and chars (KEY_LEFT_ARROW) and lx > gx + lx - 5 then
        gx -= round (velx)
        gx2 -= round (velx)
        posx := lx
        posx := lx
    end if

    % subtract your "gravity" constant from the velocity EACH frame
    vely := vely - GRAVITY
    posx := posx + round (velx)
    posy := posy + round (vely)

    /*if vely < -25 then
     vely := -25
     end if
     */
    % simple "collision" check. just makes sure the player stays above ground
    if posy < GROUND_HEIGHT and (posx < gx + 800 or posx > gx + 1000) then
        posy := GROUND_HEIGHT
        vely := 0
    end if
 
    if posy <0 then
        posy :=0
    end if

    if posy <= PLATFORM_HIEGHT and posy >= PLATFORM_HIEGHT - 20 and posx >= gx + 300 and posx <= gx + 400 and vely <= 0 then
        posy := PLATFORM_HIEGHT
        vely := 0
        /*elsif posy <= PLATFORM_HIEGHT and posy >= PLATFORM_HIEGHT - 22 and posx >= gx + 300 and posx <= gx + 400 and vely > 0 then
         vely := 1*/
    end if

    if posy <= PLATFORM_HIEGHT2 and posy >= PLATFORM_HIEGHT2 - 20 and posx >= gx + 500 and posx <= gx + 600 and vely <= 0 then
        posy := PLATFORM_HIEGHT2
        vely := 0
        /*elsif posy <= PLATFORM_HIEGHT2 and posy >= PLATFORM_HIEGHT2 - 22 and posx >= gx + 500 and posx <= gx + 600 and vely > 0 then
         vely := 0*/
    end if

    %makes the square move across the screen when it reaches a certain point
    if posx < gx + 10 then
        posx := gx + 10

    elsif posx > gx2 - 10 then
        posx := gx2 - 10
    end if

    % different colours just to illustrate whether or not you may jump

    drawline (gx, GROUND_HEIGHT, gx2, GROUND_HEIGHT, blue)
    drawline (gx + 500, PLATFORM_HIEGHT + 150, gx + 600, PLATFORM_HIEGHT + 150, blue)
    drawline (gx + 300, PLATFORM_HIEGHT, gx + 400, PLATFORM_HIEGHT, blue)
    drawline (gx, GROUND_HEIGHT, gx, maxy - 10, blue)
    drawline (gx, maxy - 10, gx2, maxy - 10, blue)
    drawline (gx2, maxy - 10, gx2, GROUND_HEIGHT, blue)
    drawfill (1, 1, gray, blue)
    drawfill (1, maxy - 1, gray, blue)
    drawfillbox (gx + 800, 0, gx + 1000, GROUND_HEIGHT, 0)

    if posy = GROUND_HEIGHT then
        drawfillbox (posx - 10, posy, posx + 10, posy + 20, green)
    elsif posy = PLATFORM_HIEGHT and posx >= gx + 300 and posx <= gx + 400 then
        drawfillbox (posx - 10, posy, posx + 10, posy + 20, green)
    else
        drawfillbox (posx - 10, posy, posx + 10, posy + 20, red)
    end if

    View.Update
   
    exit when posy <=0
   
    delay (25)
    cls
end loop
delay (1000)
cls
locatexy (round (maxx/2), round (maxy/2))
put "you lose"

Author:  Mackie [ Tue Apr 08, 2008 10:21 am ]
Post subject:  RE:Make a animation Jump

DaveAngus! Don't do his work for him! It's not that hard of a concept to comprehend. Why do you keep doing this!

Author:  Zampano [ Tue Apr 08, 2008 10:36 am ]
Post subject:  Re: Make a animation Jump

Somehow I think Mazer would have regretted making that tutorial thread. It has been abused mercilessly.
If you really want to understand the code Angus gave you, X2Star, you should think of how basic game procedures such as jumping should modify coordinates. When a person jump, their y is greater. Specifically, because gravity causes their velocity is a downwards direction to increase constantly, jumping is simply a matter of having a set amount to increment by and then taking some away from is each time to account for the gravity.

Author:  DaveAngus [ Tue Apr 08, 2008 12:19 pm ]
Post subject:  RE:Make a animation Jump

Makie im not doing any work for him.
I gave him a completely erelivant program that Makie made.
If he was to use that, he would have to change all of the variables and would have to know whats going on.
Sometimes its nice to be able to visualize things.
If he knew what was going on he wouldnt ask the question.
Just saying yea you have to do blah blah blah,
Hes still stuck because he has no idea how to do it.
Sometimes a little visual is nice!
Chillll ouuuuuttttttt.

Author:  X2_star [ Tue Apr 08, 2008 5:38 pm ]
Post subject:  RE:Make a animation Jump

Thx for the help but, its a video animation, so i cant push any keys to jump, the program has to do it by itself, just use delay?

Author:  DaveAngus [ Wed Apr 09, 2008 7:17 am ]
Post subject:  RE:Make a animation Jump

Ok so you have to look the program to make the ball go from point a to point b.
You will have to use a for loop
declare i
you will want to add a clear screen so that you dont get 1000 characters on your screen where ever it moved
then add your 'character'
and there you have it.
add your View.Update and delay and its done.
Hopefully I helped a bit!
Let me know if i assisted you at all!

Take care and have fun with this!
-Dave

code:

setscreen ("graphics")

for i : 1 .. 20
cls
    drawfilloval (100 + 25 * i, 100, 25, 25, red)
    View.Update
    delay (50)
end for

Author:  X2_star [ Thu Apr 10, 2008 7:35 am ]
Post subject:  RE:Make a animation Jump

yeah it did somewhat thank you


: