Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bb987610a2 | |||
| 44f7382b6f |
Binary file not shown.
+22
-11
@@ -8,8 +8,8 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
||||
*/
|
||||
public class Player extends Actor
|
||||
{
|
||||
private int speed = 4;
|
||||
private int jumpStrength = 12;
|
||||
private int speed = 6;
|
||||
private int jumpStrength = 20;
|
||||
private int gravity = 1;
|
||||
|
||||
private int verticalSpeed = 0;
|
||||
@@ -48,27 +48,38 @@ public class Player extends Actor
|
||||
}
|
||||
}
|
||||
|
||||
// Schwerkraft und Boden-Kollision
|
||||
// Schwerkraft
|
||||
private void fall()
|
||||
{
|
||||
int oldY = getY();
|
||||
|
||||
verticalSpeed += gravity;
|
||||
|
||||
int newY = getY() + verticalSpeed;
|
||||
|
||||
// Prüfen, ob wir auf Ground landen
|
||||
setLocation(getX(), newY);
|
||||
|
||||
Actor ground = getOneIntersectingObject(Ground.class);
|
||||
|
||||
if (ground != null)
|
||||
if (ground != null && verticalSpeed >= 0)
|
||||
{
|
||||
// Wenn wir fallen, stehen wir auf dem Ground
|
||||
if (verticalSpeed >= 0)
|
||||
{
|
||||
int groundTop = ground.getY() - ground.getImage().getHeight() / 2;
|
||||
int characterHalfHeight = getImage().getHeight() / 2;
|
||||
int groundTop = ground.getY()
|
||||
- ground.getImage().getHeight() / 2;
|
||||
|
||||
setLocation(getX(), groundTop - characterHalfHeight);
|
||||
int characterBottom = getY()
|
||||
+ getImage().getHeight() / 2;
|
||||
|
||||
// Nur landen, wenn der Spieler vorher über dem Boden war
|
||||
int oldCharacterBottom = oldY
|
||||
+ getImage().getHeight() / 2;
|
||||
|
||||
if (oldCharacterBottom <= groundTop &&
|
||||
characterBottom >= groundTop)
|
||||
{
|
||||
setLocation(
|
||||
getX(),
|
||||
groundTop - getImage().getHeight() / 2
|
||||
);
|
||||
|
||||
verticalSpeed = 0;
|
||||
onGround = true;
|
||||
|
||||
Reference in New Issue
Block a user