Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (595) Games in Android Showcase (168) games submitted by our members Games in WIP (646) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
 Home Help Search Login Register
Pages: [1]
 ignore  |  Print
 Jumping in a platformer  (Read 4096 times) 0 Members and 1 Guest are viewing this topic.
zparticle

Senior Devvie

Thick As A Brick

 « Posted 2002-12-17 00:42:59 »

I'm working on a platformer (Mario Bros. esq) and have a question. When character jumps I current have his vertical velocity decreasing as he goes up and then increasing as he comes down.  While this seems correct the feel of it is strange. What do most platformer type game do for this?

Harley Rana

Junior Devvie

Java games rock!

 « Reply #1 - Posted 2002-12-17 05:41:46 »

Hi i think you just need to use acceleration.

Having a accel[4], which contains the acceleration for each direction.  Then you can find the resulting movement from the remainder between the 2 opposite accelerations,  and at each frame when you process key presses you add the right accel_step to each direction.

int accel_y = acceleration[2] - acceleration[0];
int accel_x = acceleration[1] - acceleration[3];

x += (int)(accel_x * time_step);
y += (int)(accel_y * time_step);

I used this in a space shooter to get a nice accleration feeling.  Instead of moving at a constant speed, you accelerate and deccelerate properly.

Hope that helps.  Harley.
JuddMan

Senior Devvie

Medals: 1

 « Reply #2 - Posted 2002-12-18 09:45:21 »

Assuming that up is positive, you need to start with a high velocity, and decrease it constantly... when it gets to zero that's when your character is at the top of his jump, and then it will still be decreasing into negative velocity meaning he'll be starting to come down.

here is my really bad implementation of Mario Bros... it uses very bad system to draw the images but a reasonable movement one although the clipping not too good. (collision detection)

http://members.austarmetro.com.au/~juddman/files/java/
 Games published by our own members! Check 'em out!
zparticle

Senior Devvie

Thick As A Brick

 « Reply #3 - Posted 2002-12-18 14:26:23 »

I can't get the guy to move. I hit the go button and he appeared but then the button retains the focus.

JuddMan

Senior Devvie

Medals: 1

 « Reply #4 - Posted 2002-12-19 01:32:41 »

sorry about that, but the keylistener class i made doesnt seem to work in 1.4

i wrote it in java 1.3... anyone know why? also you might try adding that keylistener to the go button if it retains focus, or you could add mainFrame.requestFocus to the go buttons actionlistener but as i dont have 1.4 yet i cant really test this.

edit: x and z for run and jump

i'm going to be rewriting the whole program soon. that file is the final working one, at the moment i have started over entirely.

edit: Ok i installed 1.4 and to fix it temporarily you can modify the line 160: this.addKeyListener(keys);

and it works... it's a little diferent to 1.3,  it runs faster...
JuddMan

Senior Devvie

Medals: 1

 « Reply #5 - Posted 2002-12-19 02:40:56 »

for those too lazy or cant be bothered editing the source there's a new reecompiled exe at
http://members.austarmetro.com.au/~juddman/files/java/
zparticle

Senior Devvie

Thick As A Brick

 « Reply #6 - Posted 2002-12-19 12:23:06 »

Matzon

JGO Knight

Medals: 19
Projects: 1

I'm gonna wring your pants!

 « Reply #7 - Posted 2002-12-19 12:53:44 »

you need the zip too - extract it, and copy the fixed exe inside

JuddMan

Senior Devvie

Medals: 1

 « Reply #8 - Posted 2002-12-19 14:02:56 »

Thanks for telling him

i'm just wondering, are these .exe files more or less convenient?

double clicking the jar usually does the same as opening the exe without error reporting

ZParticle, i hope this has helped you with your platformer. how far have you got with it? could you post a screenshot? more people should post screenshots of their games to the board.

zparticle

Senior Devvie

Thick As A Brick

 « Reply #9 - Posted 2002-12-19 18:47:34 »

Well I'll post post something up when I feel better about it, right now I'm still waiting to see if a number of people that offered to work on the graphics are going to come through or not. I suspect they won't. The system and the basic game structure are in place and running well I simply need decent graphics and level ideas.

I implemented the jump in the manner you suggested but there is still something about it that bothers me. It just doesn't feel right where he stops going up and then starts dropping.

 Games published by our own members! Check 'em out!
Harley Rana

Junior Devvie

Java games rock!

 « Reply #10 - Posted 2002-12-19 21:15:28 »

Hey check out
http://www.gamedev.net/reference/articles/article437.asp

Its really an old falling body physics question.
The real equation is newSpeed = oldSpeed * vel * time + 1/2 ^a*time2

which is correct but not really useable in the game.

Now this it probally what you have already, but this seems to work.

float up_accel = 0.0f;

if(jump){
up_accel = 1.0f;
jump = false;
}
int y = (int)(py - up_accel * speed);

if(up_accel > 0.0){
up_accel -= gravity;
}
py = y;

you can just tweak gravity and speed to change how fast you go down and up.  gravity's a float 0-1, speed is an it like 8;

Hope that actually helps!  Harley.
JuddMan

Senior Devvie

Medals: 1

 « Reply #11 - Posted 2002-12-20 01:21:24 »

i admit i am no phycisist, but having the sprite accellerate up off the ground would sort of look like he's being pulled up on an invisible rope? the accelleration should always be downwards, and the velocity should start at a high number and get set back to zero when he hits the ground.

ZP, what sort of graphics? If it's a rip off of mariobros, you can use mine if you want   or if you tell us a little about the character, the plot, and a bit of other stuff, i could try make up some little sprites and post them. i'll probably be changing the graphics on my game when it's finished.

at the moment i have managed to dig out the JLabels and first changed them to JComponents with their own Paint methods, but that didn't seem much faster than the label, so i've started now on working on the paint method of the panel that displays the sprites, adding them to it's own bufferedimage. it seems a lot faster but there are a few bugs i have to work out like the artifacts left in the wake of any image. ATM my game would not be playable. i am intent on getting the graphics system for it working at a playable level before i start adding anything else to it and it's a headache.
zparticle

Senior Devvie

Thick As A Brick

 « Reply #12 - Posted 2002-12-20 02:51:45 »

Juddman and Harley, please join me at http://www.scottshaver2000.com/forum under the Jumping Jimmy topic. I realy appreciate your input.

rgeimer

Senior Newbie

 « Reply #13 - Posted 2002-12-20 12:11:22 »

I agree with JuddMan. Start with an initial up velocity, say 3 pixels / tick, then decrement it with each tick. Stop falling when your feet collide with something.

ticks | velocity | total up distance
0        0           0
0        3           3
1        2           5
2        1           6
3        0           6 (pauses in midair like Michael Jordan)
4       -1           5
5       -2           3
6       -3           0 (hits the ground)

Rick

zparticle

Senior Devvie

Thick As A Brick

 « Reply #14 - Posted 2002-12-20 15:42:19 »

JuddMan the project description can be found at http://www.scottshaver2000.com/projects/jnj.html

Harley Rana

Junior Devvie

Java games rock!

 « Reply #15 - Posted 2002-12-21 02:01:55 »

Hey, JuddMan an myself are really talking about the same thing.  "you need to start with a high velocity, and decrease it constantly... ", i just called it acceleration.

The method i posted actually worked (i tested it with a ball ), but i haven't made a platformer game.  For this application velocity and acceleration are pretty much the same thing.  As it isn't the real equations, but a simplifed version it doesn't make a difference.

Harley.
zparticle

Senior Devvie

Thick As A Brick

 « Reply #16 - Posted 2002-12-21 02:18:26 »

Thank you both very much for your input.

leknor

Junior Devvie

ROCK!!!

 « Reply #17 - Posted 2002-12-21 02:20:50 »

At first I was of the impression that an acceleration formula should be used but I'm not so sure any more. Think about this, your character jump off of a high platform. Do we want it to continue to accelerate until it lands or should it max out at about the same velocity as the jump was started at. I think that I would prefer a cap on the character's fall velocity and I think I'd like a slight hover at the top of a jump. IMO a precalculated jump velocity table would be the way to go. That said, I haven't written a platformer so I could be wrong, maybe I should refresh my memory: http://www.mame.net/
zparticle

Senior Devvie

Thick As A Brick

 « Reply #18 - Posted 2002-12-21 19:06:57 »

Another question:

In platformer type games do you all like the idea of a limited time to complete a level or the idea of player lives?

Remember that this is targeted for children.

leknor

Junior Devvie

ROCK!!!

 « Reply #19 - Posted 2002-12-21 22:08:01 »

Quote
do you all like the idea of a limited time to complete a level or the idea of player lives?

Is the level a rich enviroment? If there is little more to do in a level than get through it than a timer would be acceptable, but if there are hidden blocks, items, etc than a time would discourage exploration.

Outside the context of a coin operated game lives don't serve much of a purpose, plus what's the point if you can load a saved game. One thing you do see is "continues" which basicly let you resume playing with little loss of progress instead of having to start from the last save point.
zparticle

Senior Devvie

Thick As A Brick

 « Reply #20 - Posted 2002-12-22 15:32:37 »

JuddMan for screen shots you can go to:

http://www.scottshaver2000.com/forum

look in the Jumping Jimmy forum. Note that these shots are temporary graphics. Look at the "work continues" threads.

JuddMan

Senior Devvie

Medals: 1

 « Reply #21 - Posted 2002-12-30 08:19:39 »

hey sorry i was away, actually i still am... on holidays, just checking back. Velocity and accelleration arent the same thing in platformers, and some of the things in them are also related to physics.

edit: hey that guy looks like the one on the nes game Impossible Mission!
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 deepthought (47 views) 2015-06-30 15:39:44 deepthought (50 views) 2015-06-30 15:39:09 deepthought (62 views) 2015-06-30 15:36:52 Za\'Anzabar (36 views) 2015-06-29 05:44:54 TritonDreyja (46 views) 2015-06-24 17:10:40 CopyableCougar4 (46 views) 2015-06-23 00:34:45 BurntPizza (51 views) 2015-06-21 20:36:46 cookiecompiler (93 views) 2015-06-11 15:42:53 cookiecompiler (55 views) 2015-06-11 15:41:14 NegativeZero (79 views) 2015-06-11 09:49:18
 princec 30x wessles 22x BurntPizza 19x CopyableCougar4 19x opiop65 17x Riven 16x nsigma 15x EgonOlsen 14x ags1 14x theagentd 12x KaiHH 12x SauronWatchesYou 11x KevinWorkman 11x Archive 11x sunburn 11x NegativeZero 10x
 How Do I Expand My Game?by bashfrog2015-06-14 11:34:43List of Learning Resources2015-05-31 05:37:30Intersection Methodsby Roquen2015-05-29 08:19:33List of Learning Resources2015-05-05 10:20:32How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org