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

Report as inappropriate.

Moritz
Moritz presents ...

2012/7/31

Question

Hey,
That´s not really a scenario – I have a question on how to code that and
I don´t know how to describe it without the scenario at the bottom:
You can see an Elephant that can jump on the blocks. I code it this way:
When the Elephant comes in contact with the block, the Elephant takes over
the Y-value of the object and subtracts 46 -> so the Elephant lands on the block.
The problem: if the Elephant jumps from the bottom against the block the Elephant
takes over the Y – value ; subtract 46 ; and the Elephant will stand on the block.
but when the Elephant jumps from the bottom against the block the animal has to
fall back …
the same problem with the side… if the Elephant jumps against the right side the
Elephant is not allowed to continue to go right – the same with the left side – when the
Elephant jumps against the left side the Elephant is not allowed to continue
to go left…
I hope you understand my problem =)
Can somebody help me?
Thank you=)

2783 views / 703 in the last 7 days

Tags: demo with-source

open in greenfoot
Your browser is ignoring the <APPLET> tag.
yedefeiyedefei

2012/7/31

I have just post a scenario to give you some tips.
MoritzMoritz

2012/7/31

thank you - that´s what I wanted to do =)) but now the Elephant is 'trembling' when it stands on the block and sometimes the elephant falls through the blocks (for example when you set the location of the Elephant to (410, 4)) - is that normal when you code it this way? or can you change it?
yedefeiyedefei

2012/7/31

In fact the codes I’ve used are mostly from scenario CG2(http://www.greenfoot.org/scenarios/5740),you may find your answer there
yedefeiyedefei

2012/8/7

I've solved your question and update the answer there http://www.greenfoot.org/scenarios/5747 。 help yourself please!
MoritzMoritz

2012/8/7

oh thank you soo much =))
yedefeiyedefei

2012/8/7

not at all! I just recode it ,and it may be more clear for reuse!

Want to leave a comment? You must first log in.

Who likes this?

No votes yet.