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

2012/3/30

Greenfoot Help Radius

Moritz Moritz

2012/3/30

#
Hey, My English is not so good - I come from Germany - sorry =)) I have a little problem. Maybe someone could help me: I have code a program. It´s a game and it´s a sort of a mario-game. But the "Mario" is a snake and it has to find bananas in the jugle =)). The snake can jump onto blocks to achieve the bananas. When the snake don´t "land" on a platform it will fall down. -> it will land on the bottom of the jungle. Now there´s my problem: I have code the "falling snake" with a acceleration- so it looks a little bit more realistical. So , when the snake starts to fall , it will accelerats with one pixel. In the first stap it fall 1 pixel , then 2 pixel, then 3 pixel ... I use this code for it: public void onGroundEins() { Block block =(Block) getOneIntersectingObject(Block.class); if (block !=null) { acceleration = 0; vSpeed = 0; dx=block.dx; dy=block.dy; if (Greenfoot.isKeyDown("up")) { jump(); } } else acceleration = 1; } So the snake stops falling when it fall onto the ground. But mostly the snake falls a little bit to long an it hides behind the bottom. I know the problem - but I don´t know who to discribe it in English. I can try it: I think the problem is the acceleration , because when the snake knows that there is a block under it, it will stop to acceleration. But it could be that the value of the acceleration is (for example) 13, so the snake will move 13 pixel, because it will stop. Do anybody knows who I can make it correct? So the snake has to stop when it knows that there is a block under it ? Thank you =))
Moritz Moritz

2012/3/30

#
Sorry I mean "But it could be that the value of the acceleration is (for example) 13, so the snake will move 13 pixel, ere it will stop. "
mik mik

2012/3/30

#
I think the easiest way to solve this is to fix it after the fact. That is: Do the falling just as you do now. Stop when you detect the ground. At that point the snake may have fallen a bit too far. Detect that the fall has just finished (for example by having a boolean falling=true, so when falling==true and block!=null, you have just landed). In that case, just adjust the snake Y-position to the top of the ground. In short: falling too far and then fixing it (by moving to the correct position) is much easier than trying not to fall too far.
Moritz Moritz

2012/3/30

#
Thank you very much - I will try it =))
Moritz Moritz

2012/3/30

#
-
Moritz Moritz

2012/3/30

#
Ok it is running =) thank you - But there is still an other problem: When I want the snake to jump and I push the "jump key" two or more times while the snake is jumping for the first time, it also will jump two or more times after landing - also when I don´t push the "jump key".
You need to login to post a reply.