
-----------------------------------
Flea
Wed Oct 27, 2004 8:31 pm

Jumping
-----------------------------------
Hi, I'm making a game.  I;'ve already got about 650 essential lines of code just for the menu and character saving/loading and customization.  anyway, i started the actual "doing stuff" part of the program.  its a 2-d megaman/castlevania style.  i try not to ask too many questions cause most stuff can be figured out without wasting everyones time  :lol: 

anyway heres a part of my basic code i whipped up in a minute for "gravity" and walking lol:

loop
    Input.KeyDown (chars)
    if chars (KEY_RIGHT_ARROW) then
        mage1x := mage1x + 1
        boo := false
    elsif chars (KEY_LEFT_ARROW) then
        mage1x := mage1x - 1
        boo := true
    end if
    if whatdotcolour (mage1x, mage1y - 5) = 7 then
        mage1y := mage1y - 1
    end if
    if boo = true then
        Pic.Draw (mage1, mage1x, mage1y, picCopy)
    else
        Pic.Draw (mage2, mage1x, mage1y, picCopy)
    end if
    delay (10)
end loop

I cant figure out jumping though.  I tried doing a little

    if jumpcount > 10 then
        jumpcount:= jumpcount + 1
        mage1y := mage1y + 2
    else
        jumpcount:= 0
        mage1y := mage1y - 10
    end if

but thats not working and ive tried it many differnt ways within the above loop.  :?  i apologize if you dont understand my variable names, but i can always clear that up if you need me to.

ill ask that if anyone can directly post some simple code, that would be great.  if you can explain it well, then thats good too.  dont worry this aint for school, its just been my lifelong dream to make this game, and jumping is kinda essential lol. =)[/code]

-----------------------------------
Delos
Wed Oct 27, 2004 8:50 pm


-----------------------------------
Okies...

If you want realistic jumping then you need to use vectors.

If you don't know, for any moving object, it's movement and speed can be broken down into horizontal and vertical vectors.

Eg.
An object moving left to right:
vX = +1
vY = 0

An object falling:
vX = -1
vY = 0

An object moving up an elevator (R - L):
vX = -1
vY = +1

Of course I've just used unit values here...you can change then as you need.

Now, for acceleration.
Same idea.  An object has vertical and horizontal acceleration.  An object that jumps, in this case, has only negative vertical acceleration, this is as the only force acting on it is gravity.
So, if you jump, you only have the force that you exerted at the time you jump - you never gain any more upward acceleration during your flight.
Simple physics...hehehe.

So, for you jumping object, you will consider the horiztonal acceleration however you want (usually zero so the object moves at the same speed while jumping as they did while walking...no speeding up or slowing down).
Vertical acceleration is a constant at a negative value (on Earth it would be about -9.8 m-s^-2).

Object jumps from left to right.
vX = +1
vY = variable...starts at +1, but ends at -1
aX = 0
aY = -1...so every time unit, 1 is subtracted from the velocity (vY), in effect slowing it down.  Once it gets negative, the object moves in the opposite direction from which it was initially!)

Want to know more?  Look around for particle systems, and study the code.

-----------------------------------
Flea
Thu Oct 28, 2004 7:27 am


-----------------------------------
Cool stuff Delos!! That was useful.  =D

Okay i got my jumping system down, except one little bug.  It's with keydown. (little off topic, but its my thread anyway  :D)
    
if chars (KEY_UP_ARROW) then
jumpcheck := true

I want jumpcheck to stay true permanently, cause the rest of my jump code only works when jumpcheck is true.  What's happening is its relying on me holding down the button instead of just pressing it, as you might have guessed.  I tried calling a procedure that has jumpcheck :=true in it but that solves nothing.

I thought of doing

if (up key isnt down) and jumpcheck =true then
jumpcheck := false

but that would just create otehr problems.

I suppose I could use getch but i want my program to stay consistent.

-----------------------------------
Cervantes
Thu Oct 28, 2004 9:00 am


-----------------------------------
wherever you have your if statement to determine whether your character is touching the ground, inside that structure, make jumpcheck false.


if mage1y 