This site requires JavaScript, please enable it in your browser!
Greenfoot back
arthat
arthat wrote ...

2015/6/26

How do you make something jump?

1
2
arthat arthat

2015/6/26

#
I am making a battle game and need to have a program to make something jump.
danpost danpost

2015/6/26

#
arthat wrote...
I am making a battle game and need to have a program to make something jump.
This is to general of a question. The answer would be to track the vertical speed of the actor, increase the speed each act cycle for gravity and set the speed to some nominal negative number to initiate a jump. If you have issues with any of these (1) specify which one (2) show what code you tried (3) explain what adverse behavior you are getting -- etc.
arthat arthat

2015/6/27

#
I am a beginner so I do not understand what you mean. Do you have a different way of explaining it?
danpost danpost

2015/6/27

#
arthat wrote...
I am a beginner so I do not understand what you mean. Do you have a different way of explaining it?
Gravity pulls your character downward -- in the direction where the y-coordinate will increase. When gravity is constantly applied, the speed of the character, if allowed to move freely, will increase as time passes if falling (and decrease if rising). So, if you have a field to track the speed along the vertical axis, you would add a constant to it every act cycle and then move the character according to the new speed value. Normally, if an obstacle or the bottom edge of the world is encountered the vertical location of the character would be adjusted so as to stop the movement at the contact point and the speed value will be zeroed. When jumping, you need the speed value to be some negative number (going upward the coordinate along the vertical decreases) so that the character will rise each act with decreasing speeds as gravity is applied.
arthat arthat

2015/6/27

#
So, how would I make a field to track the vertical axis. All I know to do is to make the crab game listed as an example in documentation. BTW. Thanks a lot for your help. I really appreciate it.
danpost danpost

2015/6/27

#
arthat wrote...
So, how would I make a field to track the vertical axis. All I know to do is to make the crab game listed as an example in documentation. BTW. Thanks a lot for your help. I really appreciate it.
Similar to how you make a 'wormsEaten' field. You may have to refer to Mik's blog A first look at variables (the Joy of Code video #14) to see how you work with fields. You could also refer to the Java tutorial's page on variables.
arthat arthat

2015/6/27

#
Is there a way that you could just give me the program?
danpost danpost

2015/6/27

#
arthat wrote...
Is there a way that you could just give me the program?
You could look at the code of my Jump and Run Demo w/Moving Platform scenario.
arthat arthat

2015/6/27

#
I cannot figure out where to look. Can you just command-c/control-c it on the reply?
danpost danpost

2015/6/27

#
arthat wrote...
I cannot figure out where to look. Can you just command-c/control-c it on the reply?
Just run the scenario and click the 'Who' button at the bottom of the screen.
arthat arthat

2015/6/27

#
Can I just copy the whole program?
danpost danpost

2015/6/28

#
arthat wrote...
Can I just copy the whole program?
That would not be right. The code is shown so that you can learn from it -- not so that you can copy it.
arthat arthat

2015/6/28

#
You gave the complete program to The Invinity Scrolling guy (Jaki). Why don't you give me a program. Please just give me the whole Program and I will leave you alone.
Super_Hippo Super_Hippo

2015/6/28

#
He won't give you "the program". Stop begging like that and use the advices that he gave you to make your character jump. Learning by doing! Try to understand what and how you are programming instead of copying other's code.
arthat arthat

2015/6/28

#
Now your in this?
There are more replies on the next page.
1
2