Der Spieler kann nun Projectile schießen

This commit is contained in:
2026-09-16 10:40:42 +02:00
parent 8fad77b878
commit 963fa43986
9 changed files with 69 additions and 6 deletions
Binary file not shown.
+1 -1
View File
@@ -8,7 +8,7 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
*/
public class JumpBoostItem extends PowerUps
{
int duration = 60*30;
int duration = 60*60;
public void act()
{
touchedByPlayer();
Binary file not shown.
+7 -5
View File
@@ -10,9 +10,11 @@ comment3.target=void\ jump()
comment4.params=
comment4.target=void\ fall()
comment5.params=
comment5.target=boolean\ collision()
comment5.target=void\ shootProjectile()
comment6.params=
comment6.target=void\ handlePowerUps()
comment7.params=duration\ type
comment7.target=void\ reveivePowerUp(int,\ java.lang.String)
numComments=8
comment6.target=boolean\ collision()
comment7.params=
comment7.target=void\ handlePowerUps()
comment8.params=duration\ type
comment8.target=void\ reveivePowerUp(int,\ java.lang.String)
numComments=9
+18
View File
@@ -11,6 +11,8 @@ public class Player extends Actor
int jumpBoostDuration = -1;
int jumpBoostStrength = 5;
boolean projectileReady = false;
int projectileTimer;
private int speed = 6;
private int currentJumpStrength;
@@ -27,6 +29,7 @@ public class Player extends Actor
jump();
fall();
handlePowerUps();
shootProjectile();
//Check ob der Spieler am unteren Fensterrand ist
if (getY()+1 >= getWorld().getHeight()){
@@ -86,6 +89,21 @@ public class Player extends Actor
} onGround = landed;
}
public void shootProjectile(){
projectileTimer++;
MouseInfo mouse = Greenfoot.getMouseInfo();
if (Greenfoot.mousePressed(null)){
PlayerProjectile playerProjectile = new PlayerProjectile();
getWorld().addObject(playerProjectile, getX(), getY());
playerProjectile.turnTowards(Greenfoot.getMouseInfo().getX(), Greenfoot.getMouseInfo().getY());
projectileReady = false;
}
if (projectileTimer >= 10){
projectileReady = true;
projectileTimer = 0;
}
}
public boolean collision(){
if (getIntersectingObjects(Projectile.class).size()>0)
{
Binary file not shown.
+9
View File
@@ -0,0 +1,9 @@
#BlueJ class context
comment0.target=PlayerProjectile
comment0.text=\r\n\ Write\ a\ description\ of\ class\ PlayerProjectile\ 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()
comment1.text=\r\n\ Act\ -\ do\ whatever\ the\ PlayerProjectile\ wants\ to\ do.\ This\ method\ is\ called\ whenever\r\n\ the\ 'Act'\ or\ 'Run'\ button\ gets\ pressed\ in\ the\ environment.\r\n
comment2.params=
comment2.target=boolean\ isProjectileOnScreen()
numComments=3
+34
View File
@@ -0,0 +1,34 @@
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class PlayerProjectile here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class PlayerProjectile extends Actor
{
/**
* Act - do whatever the PlayerProjectile wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move(7);
if (!isProjectileOnScreen()){
getWorld().removeObject(this);
}
}
public boolean isProjectileOnScreen(){
//Check Y-Value
if (getY() <= 0 || getY() >= getWorld().getHeight()-1){
return false;
}
//Check X-Value
if (getX() <= 0 || getX() >= getWorld().getHeight()-1){
return false;
}
return true;
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 776 B