PowerUps/JumpBoost
neue Klassen: PowerUps, JumpBoostItem Die aktivieren und das deaktivieren der PowerUps wird im Player durchgeführt.
This commit is contained in:
+27
-2
@@ -8,8 +8,13 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
||||
*/
|
||||
public class Player extends Actor
|
||||
{
|
||||
int jumpBoostDuration = -1;
|
||||
int jumpBoostStrength = 5;
|
||||
|
||||
|
||||
private int speed = 6;
|
||||
private int jumpStrength = 20;
|
||||
private int currentJumpStrength;
|
||||
private int defaultJumpStrength = 15;
|
||||
private int gravity = 1;
|
||||
|
||||
private int verticalSpeed = 0;
|
||||
@@ -21,6 +26,7 @@ public class Player extends Actor
|
||||
moveLeftAndRight();
|
||||
jump();
|
||||
fall();
|
||||
handlePowerUps();
|
||||
}
|
||||
|
||||
// Bewegung nach links und rechts
|
||||
@@ -42,7 +48,7 @@ public class Player extends Actor
|
||||
{
|
||||
if (Greenfoot.isKeyDown("space") && onGround)
|
||||
{
|
||||
verticalSpeed = -jumpStrength;
|
||||
verticalSpeed = -currentJumpStrength;
|
||||
onGround = false;
|
||||
}
|
||||
}
|
||||
@@ -101,4 +107,23 @@ public class Player extends Actor
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void handlePowerUps(){
|
||||
if (jumpBoostDuration >= 0){
|
||||
jumpBoostDuration -= 1;
|
||||
} else if (jumpBoostDuration <= -1){
|
||||
currentJumpStrength = defaultJumpStrength;
|
||||
}
|
||||
}
|
||||
|
||||
public void reveivePowerUp(int duration, String type){
|
||||
switch(type){
|
||||
case "dummy":
|
||||
break;
|
||||
case "JumpBoost":
|
||||
currentJumpStrength = defaultJumpStrength;
|
||||
currentJumpStrength += jumpBoostStrength;
|
||||
jumpBoostDuration = duration;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user