PowerUps/JumpBoost
neue Klassen: PowerUps, JumpBoostItem Die aktivieren und das deaktivieren der PowerUps wird im Player durchgeführt.
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,8 @@
|
|||||||
|
#BlueJ class context
|
||||||
|
comment0.target=JumpBoostItem
|
||||||
|
comment0.text=\r\n\ Write\ a\ description\ of\ class\ JumpBoostItem\ 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
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write a description of class JumpBoostItem here.
|
||||||
|
*
|
||||||
|
* @author (your name)
|
||||||
|
* @version (a version number or a date)
|
||||||
|
*/
|
||||||
|
public class JumpBoostItem extends PowerUps
|
||||||
|
{
|
||||||
|
int duration = 60*5;
|
||||||
|
public void act()
|
||||||
|
{
|
||||||
|
touchedByPlayer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override void collect(){
|
||||||
|
Player player = getIntersectingObjects(Player.class).get(0);
|
||||||
|
player.reveivePowerUp(duration, "JumpBoost");
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -11,4 +11,8 @@ comment4.params=
|
|||||||
comment4.target=void\ fall()
|
comment4.target=void\ fall()
|
||||||
comment5.params=
|
comment5.params=
|
||||||
comment5.target=boolean\ collision()
|
comment5.target=boolean\ collision()
|
||||||
numComments=6
|
comment6.params=
|
||||||
|
comment6.target=void\ handlePowerUps()
|
||||||
|
comment7.params=duration\ type
|
||||||
|
comment7.target=void\ reveivePowerUp(int,\ java.lang.String)
|
||||||
|
numComments=8
|
||||||
|
|||||||
+27
-2
@@ -8,8 +8,13 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
|||||||
*/
|
*/
|
||||||
public class Player extends Actor
|
public class Player extends Actor
|
||||||
{
|
{
|
||||||
|
int jumpBoostDuration = -1;
|
||||||
|
int jumpBoostStrength = 5;
|
||||||
|
|
||||||
|
|
||||||
private int speed = 6;
|
private int speed = 6;
|
||||||
private int jumpStrength = 20;
|
private int currentJumpStrength;
|
||||||
|
private int defaultJumpStrength = 15;
|
||||||
private int gravity = 1;
|
private int gravity = 1;
|
||||||
|
|
||||||
private int verticalSpeed = 0;
|
private int verticalSpeed = 0;
|
||||||
@@ -21,6 +26,7 @@ public class Player extends Actor
|
|||||||
moveLeftAndRight();
|
moveLeftAndRight();
|
||||||
jump();
|
jump();
|
||||||
fall();
|
fall();
|
||||||
|
handlePowerUps();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bewegung nach links und rechts
|
// Bewegung nach links und rechts
|
||||||
@@ -42,7 +48,7 @@ public class Player extends Actor
|
|||||||
{
|
{
|
||||||
if (Greenfoot.isKeyDown("space") && onGround)
|
if (Greenfoot.isKeyDown("space") && onGround)
|
||||||
{
|
{
|
||||||
verticalSpeed = -jumpStrength;
|
verticalSpeed = -currentJumpStrength;
|
||||||
onGround = false;
|
onGround = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,4 +107,23 @@ public class Player extends Actor
|
|||||||
return false;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -19,6 +19,7 @@ public class PlayerTestWorld extends World
|
|||||||
super(600, 400, 1);
|
super(600, 400, 1);
|
||||||
prepare();
|
prepare();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare the world for the start of the program.
|
* Prepare the world for the start of the program.
|
||||||
* That is: create the initial objects and add them to the world.
|
* That is: create the initial objects and add them to the world.
|
||||||
@@ -29,5 +30,7 @@ public class PlayerTestWorld extends World
|
|||||||
addObject(ground,260,375);
|
addObject(ground,260,375);
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
addObject(player,264,237);
|
addObject(player,264,237);
|
||||||
|
JumpBoostItem jumpBoostItem = new JumpBoostItem();
|
||||||
|
addObject(jumpBoostItem,206,200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -0,0 +1,10 @@
|
|||||||
|
#BlueJ class context
|
||||||
|
comment0.target=PowerUps
|
||||||
|
comment0.text=\r\n\ Write\ a\ description\ of\ class\ PowerUps\ 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\ touchedByPlayer()
|
||||||
|
comment3.params=
|
||||||
|
comment3.target=void\ collect()
|
||||||
|
numComments=4
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write a description of class PowerUps here.
|
||||||
|
*
|
||||||
|
* @author (your name)
|
||||||
|
* @version (a version number or a date)
|
||||||
|
*/
|
||||||
|
public class PowerUps extends Actor
|
||||||
|
{
|
||||||
|
int duration;
|
||||||
|
public void act()
|
||||||
|
{
|
||||||
|
touchedByPlayer();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void touchedByPlayer(){
|
||||||
|
if (getIntersectingObjects(Player.class).size() > 0){
|
||||||
|
collect();
|
||||||
|
getWorld().removeObject(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void collect(){
|
||||||
|
Player player = getIntersectingObjects(Player.class).get(0);
|
||||||
|
player.reveivePowerUp(duration, "dummy");
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
@@ -1,25 +1,44 @@
|
|||||||
#Greenfoot project file
|
#Greenfoot project file
|
||||||
class.Ground.image=weave.jpg
|
class.Ground.image=weave.jpg
|
||||||
|
class.JumpBoostItem.image=mushroom.png
|
||||||
class.Player.image=ppl2.png
|
class.Player.image=ppl2.png
|
||||||
dependency1.from=PlayerTestWorld
|
dependency1.from=PlayerTestWorld
|
||||||
dependency1.to=Ground
|
dependency1.to=Ground
|
||||||
dependency1.type=UsesDependency
|
dependency1.type=UsesDependency
|
||||||
|
dependency10.from=MovingPlattform
|
||||||
|
dependency10.to=MyWorld
|
||||||
|
dependency10.type=UsesDependency
|
||||||
dependency2.from=PlayerTestWorld
|
dependency2.from=PlayerTestWorld
|
||||||
dependency2.to=Player
|
dependency2.to=Player
|
||||||
dependency2.type=UsesDependency
|
dependency2.type=UsesDependency
|
||||||
dependency3.from=MyWorld
|
dependency3.from=MyWorld
|
||||||
dependency3.to=Player
|
dependency3.to=Player
|
||||||
dependency3.type=UsesDependency
|
dependency3.type=UsesDependency
|
||||||
dependency4.from=Player
|
dependency4.from=MyWorld
|
||||||
dependency4.to=Ground
|
dependency4.to=Projectile
|
||||||
dependency4.type=UsesDependency
|
dependency4.type=UsesDependency
|
||||||
editor.fx.0.height=737
|
dependency5.from=Player
|
||||||
|
dependency5.to=GameOverWorld
|
||||||
|
dependency5.type=UsesDependency
|
||||||
|
dependency6.from=Player
|
||||||
|
dependency6.to=Ground
|
||||||
|
dependency6.type=UsesDependency
|
||||||
|
dependency7.from=Player
|
||||||
|
dependency7.to=Projectile
|
||||||
|
dependency7.type=UsesDependency
|
||||||
|
dependency8.from=Plattform
|
||||||
|
dependency8.to=MyWorld
|
||||||
|
dependency8.type=UsesDependency
|
||||||
|
dependency9.from=Plattform
|
||||||
|
dependency9.to=Player
|
||||||
|
dependency9.type=UsesDependency
|
||||||
|
editor.fx.0.height=672
|
||||||
editor.fx.0.width=814
|
editor.fx.0.width=814
|
||||||
editor.fx.0.x=332
|
editor.fx.0.x=456
|
||||||
editor.fx.0.y=64
|
editor.fx.0.y=64
|
||||||
height=736
|
height=830
|
||||||
package.numDependencies=4
|
package.numDependencies=10
|
||||||
package.numTargets=4
|
package.numTargets=11
|
||||||
project.charset=UTF-8
|
project.charset=UTF-8
|
||||||
publish.hasSource=false
|
publish.hasSource=false
|
||||||
publish.locked=true
|
publish.locked=true
|
||||||
@@ -41,29 +60,78 @@ target1.type=ClassTarget
|
|||||||
target1.width=120
|
target1.width=120
|
||||||
target1.x=0
|
target1.x=0
|
||||||
target1.y=0
|
target1.y=0
|
||||||
|
target10.height=70
|
||||||
|
target10.name=MyWorld
|
||||||
|
target10.showInterface=false
|
||||||
|
target10.type=ClassTarget
|
||||||
|
target10.width=120
|
||||||
|
target10.x=0
|
||||||
|
target10.y=0
|
||||||
|
target11.height=70
|
||||||
|
target11.name=Projectile
|
||||||
|
target11.showInterface=false
|
||||||
|
target11.type=ClassTarget
|
||||||
|
target11.width=120
|
||||||
|
target11.x=0
|
||||||
|
target11.y=0
|
||||||
target2.height=70
|
target2.height=70
|
||||||
target2.name=Ground
|
target2.name=MovingPlattform
|
||||||
target2.showInterface=false
|
target2.showInterface=false
|
||||||
target2.type=ClassTarget
|
target2.type=ClassTarget
|
||||||
target2.width=120
|
target2.width=120
|
||||||
target2.x=0
|
target2.x=0
|
||||||
target2.y=0
|
target2.y=0
|
||||||
target3.height=70
|
target3.height=70
|
||||||
target3.name=PlayerTestWorld
|
target3.name=Ground
|
||||||
target3.showInterface=false
|
target3.showInterface=false
|
||||||
target3.type=ClassTarget
|
target3.type=ClassTarget
|
||||||
target3.width=120
|
target3.width=120
|
||||||
target3.x=0
|
target3.x=0
|
||||||
target3.y=0
|
target3.y=0
|
||||||
target4.height=70
|
target4.height=70
|
||||||
target4.name=MyWorld
|
target4.name=PowerUps
|
||||||
target4.showInterface=false
|
target4.showInterface=false
|
||||||
target4.type=ClassTarget
|
target4.type=ClassTarget
|
||||||
target4.width=120
|
target4.width=120
|
||||||
target4.x=0
|
target4.x=0
|
||||||
target4.y=0
|
target4.y=0
|
||||||
|
target5.height=70
|
||||||
|
target5.name=JumpBoostItem
|
||||||
|
target5.showInterface=false
|
||||||
|
target5.type=ClassTarget
|
||||||
|
target5.width=120
|
||||||
|
target5.x=0
|
||||||
|
target5.y=0
|
||||||
|
target6.height=70
|
||||||
|
target6.name=BreakingPlattform
|
||||||
|
target6.showInterface=false
|
||||||
|
target6.type=ClassTarget
|
||||||
|
target6.width=120
|
||||||
|
target6.x=0
|
||||||
|
target6.y=0
|
||||||
|
target7.height=70
|
||||||
|
target7.name=GameOverWorld
|
||||||
|
target7.showInterface=false
|
||||||
|
target7.type=ClassTarget
|
||||||
|
target7.width=120
|
||||||
|
target7.x=0
|
||||||
|
target7.y=0
|
||||||
|
target8.height=70
|
||||||
|
target8.name=PlayerTestWorld
|
||||||
|
target8.showInterface=false
|
||||||
|
target8.type=ClassTarget
|
||||||
|
target8.width=120
|
||||||
|
target8.x=0
|
||||||
|
target8.y=0
|
||||||
|
target9.height=70
|
||||||
|
target9.name=Plattform
|
||||||
|
target9.showInterface=false
|
||||||
|
target9.type=ClassTarget
|
||||||
|
target9.width=120
|
||||||
|
target9.x=0
|
||||||
|
target9.y=0
|
||||||
version=3.1.0
|
version=3.1.0
|
||||||
width=856
|
width=1550
|
||||||
world.lastInstantiated=PlayerTestWorld
|
world.lastInstantiated=PlayerTestWorld
|
||||||
xPosition=509
|
xPosition=0
|
||||||
yPosition=133
|
yPosition=0
|
||||||
|
|||||||
Reference in New Issue
Block a user