Fügt Leben zum Spieler, ein HealthItem und eine Healthbar hinzu.
This commit is contained in:
+18
-6
@@ -8,6 +8,9 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
||||
*/
|
||||
public class Player extends Actor
|
||||
{
|
||||
int MAX_HEALTH = 3;
|
||||
int health = MAX_HEALTH;
|
||||
|
||||
int jumpBoostDuration = -1;
|
||||
int jumpBoostStrength = 5;
|
||||
|
||||
@@ -30,6 +33,7 @@ public class Player extends Actor
|
||||
fall();
|
||||
handlePowerUps();
|
||||
shootProjectile();
|
||||
checkHealth();
|
||||
|
||||
//Check ob der Spieler am unteren Fensterrand ist
|
||||
if (getY()+1 >= getWorld().getHeight()){
|
||||
@@ -106,16 +110,20 @@ public class Player extends Actor
|
||||
}
|
||||
}
|
||||
|
||||
public boolean collision(){
|
||||
public void collision(){
|
||||
if (getIntersectingObjects(Projectile.class).size()>0
|
||||
|| getIntersectingObjects(Enemy.class).size()>0)
|
||||
{
|
||||
Greenfoot.setWorld(new GameOverWorld());
|
||||
return true;
|
||||
health--;
|
||||
getWorld().removeObjects(getIntersectingObjects(Projectile.class));
|
||||
getWorld().removeObjects(getIntersectingObjects(Enemy.class));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void checkHealth(){
|
||||
if (health <= 0){
|
||||
Greenfoot.setWorld(new GameOverWorld());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,6 +143,10 @@ public class Player extends Actor
|
||||
currentJumpStrength = defaultJumpStrength;
|
||||
currentJumpStrength += jumpBoostStrength;
|
||||
jumpBoostDuration = duration;
|
||||
case "Heal":
|
||||
if (health < MAX_HEALTH){
|
||||
health++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user