diff --git a/SMIMS-Game/HealthItem.class b/SMIMS-Game/HealthItem.class new file mode 100644 index 0000000..7910582 Binary files /dev/null and b/SMIMS-Game/HealthItem.class differ diff --git a/SMIMS-Game/HealthItem.ctxt b/SMIMS-Game/HealthItem.ctxt new file mode 100644 index 0000000..e664fe0 --- /dev/null +++ b/SMIMS-Game/HealthItem.ctxt @@ -0,0 +1,8 @@ +#BlueJ class context +comment0.target=HealthItem +comment0.text=\r\n\ Write\ a\ description\ of\ class\ HealthItem\ here.\r\n\ \r\n\ @author\ (your\ name)\ \r\n\ @version\ (a\ version\ number\ or\ a\ date)\r\n +comment1.params= +comment1.target=void\ act() +comment2.params= +comment2.target=void\ collect() +numComments=3 diff --git a/SMIMS-Game/HealthItem.java b/SMIMS-Game/HealthItem.java new file mode 100644 index 0000000..a927d50 --- /dev/null +++ b/SMIMS-Game/HealthItem.java @@ -0,0 +1,21 @@ +import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) + +/** + * Write a description of class HealthItem here. + * + * @author (your name) + * @version (a version number or a date) + */ +public class HealthItem extends PowerUps +{ + int duration = 60*60; + public void act() + { + touchedByPlayer(); + } + + @Override void collect(){ + Player player = getIntersectingObjects(Player.class).get(0); + player.reveivePowerUp(duration, "Heal"); + } +} diff --git a/SMIMS-Game/Healthbar.class b/SMIMS-Game/Healthbar.class new file mode 100644 index 0000000..e21b03d Binary files /dev/null and b/SMIMS-Game/Healthbar.class differ diff --git a/SMIMS-Game/Healthbar.ctxt b/SMIMS-Game/Healthbar.ctxt new file mode 100644 index 0000000..e8b2d68 --- /dev/null +++ b/SMIMS-Game/Healthbar.ctxt @@ -0,0 +1,8 @@ +#BlueJ class context +comment0.target=Healthbar +comment0.text=\r\n\ Write\ a\ description\ of\ class\ Healthbar\ here.\r\n\ \r\n\ @author\ (your\ name)\ \r\n\ @version\ (a\ version\ number\ or\ a\ date)\r\n +comment1.params= +comment1.target=void\ act() +comment2.params= +comment2.target=void\ draw_health() +numComments=3 diff --git a/SMIMS-Game/Healthbar.java b/SMIMS-Game/Healthbar.java new file mode 100644 index 0000000..bfac032 --- /dev/null +++ b/SMIMS-Game/Healthbar.java @@ -0,0 +1,20 @@ +import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) + +/** + * Write a description of class Healthbar here. + * + * @author (your name) + * @version (a version number or a date) + */ +public class Healthbar extends Actor +{ + public void act() + { + draw_health(); + } + + public void draw_health(){ + Player player = getWorld().getObjects(Player.class).get(0); + setImage(new GreenfootImage("Health:" + player.health, 24, Color.WHITE, Color.BLACK)); + } +} diff --git a/SMIMS-Game/MyWorld.class b/SMIMS-Game/MyWorld.class index e1c9b02..f6c7f75 100644 Binary files a/SMIMS-Game/MyWorld.class and b/SMIMS-Game/MyWorld.class differ diff --git a/SMIMS-Game/MyWorld.java b/SMIMS-Game/MyWorld.java index 2d78cda..32b7712 100644 --- a/SMIMS-Game/MyWorld.java +++ b/SMIMS-Game/MyWorld.java @@ -50,6 +50,8 @@ public class MyWorld extends World plattform2.setLocation(320,367); plattform2.setLocation(312,371); plattform2.setLocation(308,382); + Healthbar healthbar = new Healthbar(); + addObject(healthbar,50,50); } public void act() diff --git a/SMIMS-Game/Player.class b/SMIMS-Game/Player.class index f00f6aa..d43e31d 100644 Binary files a/SMIMS-Game/Player.class and b/SMIMS-Game/Player.class differ diff --git a/SMIMS-Game/Player.ctxt b/SMIMS-Game/Player.ctxt index 5fff3f3..330efd4 100644 --- a/SMIMS-Game/Player.ctxt +++ b/SMIMS-Game/Player.ctxt @@ -12,9 +12,11 @@ comment4.target=void\ fall() comment5.params= comment5.target=void\ shootProjectile() comment6.params= -comment6.target=boolean\ collision() +comment6.target=void\ collision() comment7.params= -comment7.target=void\ handlePowerUps() -comment8.params=duration\ type -comment8.target=void\ reveivePowerUp(int,\ java.lang.String) -numComments=9 +comment7.target=void\ checkHealth() +comment8.params= +comment8.target=void\ handlePowerUps() +comment9.params=duration\ type +comment9.target=void\ reveivePowerUp(int,\ java.lang.String) +numComments=10 diff --git a/SMIMS-Game/Player.java b/SMIMS-Game/Player.java index 0fbc75f..a0f6c36 100644 --- a/SMIMS-Game/Player.java +++ b/SMIMS-Game/Player.java @@ -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++; + } } } } diff --git a/SMIMS-Game/images/herz.png b/SMIMS-Game/images/herz.png new file mode 100644 index 0000000..cee6422 Binary files /dev/null and b/SMIMS-Game/images/herz.png differ diff --git a/SMIMS-Game/project.greenfoot b/SMIMS-Game/project.greenfoot index 8426964..c10bfd7 100644 --- a/SMIMS-Game/project.greenfoot +++ b/SMIMS-Game/project.greenfoot @@ -5,6 +5,7 @@ class.Enemy.image=bee.png class.EnemyProjectile.image=yellow-draught.png class.GameOverWorld.image=GameOverBackground.png class.Ground.image=weave.jpg +class.HealthItem.image=herz.png class.JumpBoostItem.image=mushroom.png class.MovingPlattform.image=Unbenannt.png class.MyWorld.image=GameBackground.png @@ -138,9 +139,9 @@ editor.fx.0.height=737 editor.fx.0.width=814 editor.fx.0.x=360 editor.fx.0.y=26 -height=581 +height=830 package.numDependencies=39 -package.numTargets=21 +package.numTargets=22 project.charset=UTF-8 publish.hasSource=false publish.locked=true @@ -163,70 +164,70 @@ target1.width=120 target1.x=0 target1.y=0 target10.height=70 -target10.name=StartWorld +target10.name=PlayerTestWorld target10.showInterface=false target10.type=ClassTarget target10.width=120 target10.x=0 target10.y=0 target11.height=70 -target11.name=Plattform +target11.name=StartWorld target11.showInterface=false target11.type=ClassTarget target11.width=120 target11.x=0 target11.y=0 target12.height=70 -target12.name=TargetingProjectile +target12.name=Plattform target12.showInterface=false target12.type=ClassTarget target12.width=120 target12.x=0 target12.y=0 target13.height=70 -target13.name=Projectile +target13.name=TargetingProjectile target13.showInterface=false target13.type=ClassTarget target13.width=120 target13.x=0 target13.y=0 target14.height=70 -target14.name=Score +target14.name=Projectile target14.showInterface=false target14.type=ClassTarget target14.width=120 target14.x=0 target14.y=0 target15.height=70 -target15.name=Button +target15.name=Score target15.showInterface=false target15.type=ClassTarget target15.width=120 target15.x=0 target15.y=0 target16.height=70 -target16.name=EnemyProjectile +target16.name=Button target16.showInterface=false target16.type=ClassTarget target16.width=120 target16.x=0 target16.y=0 target17.height=70 -target17.name=PowerUps +target17.name=EnemyProjectile target17.showInterface=false target17.type=ClassTarget target17.width=120 target17.x=0 target17.y=0 target18.height=70 -target18.name=Enemy +target18.name=PowerUps target18.showInterface=false target18.type=ClassTarget target18.width=120 target18.x=0 target18.y=0 target19.height=70 -target19.name=PlayerProjectile +target19.name=Enemy target19.showInterface=false target19.type=ClassTarget target19.width=120 @@ -240,19 +241,26 @@ target2.width=120 target2.x=0 target2.y=0 target20.height=70 -target20.name=SpikedPlattform +target20.name=PlayerProjectile target20.showInterface=false target20.type=ClassTarget target20.width=120 target20.x=0 target20.y=0 target21.height=70 -target21.name=MyWorld +target21.name=SpikedPlattform target21.showInterface=false target21.type=ClassTarget target21.width=120 target21.x=0 target21.y=0 +target22.height=70 +target22.name=MyWorld +target22.showInterface=false +target22.type=ClassTarget +target22.width=120 +target22.x=0 +target22.y=0 target3.height=70 target3.name=MovingPlattform target3.showInterface=false @@ -275,28 +283,28 @@ target5.width=120 target5.x=0 target5.y=0 target6.height=70 -target6.name=JumpBoostItem +target6.name=HealthItem target6.showInterface=false target6.type=ClassTarget target6.width=120 target6.x=0 target6.y=0 target7.height=70 -target7.name=BreakingPlattform +target7.name=JumpBoostItem target7.showInterface=false target7.type=ClassTarget target7.width=120 target7.x=0 target7.y=0 target8.height=70 -target8.name=GameOverWorld +target8.name=BreakingPlattform target8.showInterface=false target8.type=ClassTarget target8.width=120 target8.x=0 target8.y=0 target9.height=70 -target9.name=PlayerTestWorld +target9.name=GameOverWorld target9.showInterface=false target9.type=ClassTarget target9.width=120 @@ -306,4 +314,4 @@ version=3.1.0 width=1550 world.lastInstantiated=MyWorld xPosition=0 -yPosition=123 +yPosition=0