PowerUps/JumpBoost

neue Klassen: PowerUps, JumpBoostItem

Die aktivieren und das deaktivieren der PowerUps wird im Player durchgeführt.
This commit is contained in:
2026-09-15 11:33:47 +02:00
parent 81fb707beb
commit 9cef598196
13 changed files with 183 additions and 16 deletions
+27 -2
View File
@@ -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;
}
}
}