Merge remote-tracking branch 'origin/main'
# Conflicts: # SMIMS-Game/MyWorld.class # SMIMS-Game/MyWorld.java # SMIMS-Game/Player.class # SMIMS-Game/Player.ctxt # SMIMS-Game/project.greenfoot
@@ -1,9 +1,11 @@
|
||||
#BlueJ class context
|
||||
comment0.target=BreakingPlattform
|
||||
comment0.text=\r\n\ Write\ a\ description\ of\ class\ BreakingPlattform\ 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\ BreakingPlattform\ wants\ to\ do.\ This\ method\ is\ called\ whenever\r\n\ the\ 'Act'\ or\ 'Run'\ button\ gets\ pressed\ in\ the\ environment.\r\n
|
||||
comment1.params=pBreakingCountdown
|
||||
comment1.target=BreakingPlattform(int)
|
||||
comment2.params=
|
||||
comment2.target=void\ breakPlattform()
|
||||
numComments=3
|
||||
comment2.target=void\ act()
|
||||
comment2.text=\r\n\ Act\ -\ do\ whatever\ the\ BreakingPlattform\ wants\ to\ do.\ This\ method\ is\ called\ whenever\r\n\ the\ 'Act'\ or\ 'Run'\ button\ gets\ pressed\ in\ the\ environment.\r\n
|
||||
comment3.params=
|
||||
comment3.target=void\ breakPlattform()
|
||||
numComments=4
|
||||
|
||||
@@ -8,25 +8,40 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
||||
*/
|
||||
public class BreakingPlattform extends Plattform
|
||||
{
|
||||
boolean IsBreaking= false;
|
||||
boolean IsBreaking= false;
|
||||
int BreakingCountdown;
|
||||
public BreakingPlattform(int pBreakingCountdown)
|
||||
{
|
||||
BreakingCountdown=pBreakingCountdown;
|
||||
}
|
||||
|
||||
/**
|
||||
* Act - do whatever the BreakingPlattform wants to do. This method is called whenever
|
||||
* the 'Act' or 'Run' button gets pressed in the environment.
|
||||
*/
|
||||
public void act()
|
||||
{
|
||||
super.act();
|
||||
if(this.PlayerOnPlattform() && IsBreaking==false)
|
||||
{
|
||||
IsBreaking= true;
|
||||
IsBreaking= true;
|
||||
//Greenfoot.playSound("...")
|
||||
this.setImage("BreakingPlattform2.png"); //untested
|
||||
|
||||
}
|
||||
if(IsBreaking)
|
||||
{
|
||||
BreakingCountdown--;
|
||||
if(BreakingCountdown==0)
|
||||
{
|
||||
this.breakPlattform();
|
||||
}
|
||||
}
|
||||
super.act();
|
||||
}
|
||||
|
||||
public void breakPlattform()
|
||||
{
|
||||
if(this.PlayerOnPlattform())
|
||||
{
|
||||
|
||||
}
|
||||
//Animation
|
||||
geloescht=true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -22,17 +22,17 @@ public class MovingPlattform extends Plattform
|
||||
public void act()
|
||||
{
|
||||
// Add your action code here.
|
||||
super.act();
|
||||
this.bewege();
|
||||
super.act();
|
||||
}
|
||||
|
||||
public void bewege()
|
||||
{
|
||||
MyWorld theWorld= (MyWorld) this.getWorld();
|
||||
move(speed);
|
||||
if(this.getX()<5 || this.getX()<=theWorld.getWidth())
|
||||
this.setLocation(this.getX()+speed, this.getY());
|
||||
if(this.getX()<5 || this.getX()>=theWorld.getWidth()-5)
|
||||
{
|
||||
this.loescheMich();
|
||||
speed=speed*(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,10 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
||||
*/
|
||||
public class MyWorld extends World
|
||||
{
|
||||
int PlattformCountdown;
|
||||
int timer = 200; //Zeit, bevor das erste Projektil auftaucht
|
||||
//kann später noch beliebig angepasst werden
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for objects of class MyWorld.
|
||||
*
|
||||
@@ -30,16 +31,35 @@ public class MyWorld extends World
|
||||
Player player = new Player();
|
||||
addObject(player,302,320);
|
||||
}
|
||||
|
||||
public void act(){
|
||||
if(timer > 0){
|
||||
timer = timer - 1;
|
||||
public void act()
|
||||
{
|
||||
if(PlattformCountdown==0) //Damit in regelmäßigen Abständen auf jeden Fall eine Plattform auftaucht
|
||||
{
|
||||
addObject(new Plattform(), Greenfoot.getRandomNumber(400), 5);
|
||||
PlattformCountdown=100;
|
||||
}
|
||||
PlattformCountdown--;
|
||||
if(Greenfoot.getRandomNumber(100000)>=99800)
|
||||
{
|
||||
addObject(new Plattform(), Greenfoot.getRandomNumber(400), 5);
|
||||
}
|
||||
if(Greenfoot.getRandomNumber(100000)>=99900)
|
||||
{
|
||||
addObject(new MovingPlattform(2), Greenfoot.getRandomNumber(400), 6); //Nach Rechts bewegende Plattform
|
||||
}
|
||||
if(Greenfoot.getRandomNumber(100000)>=99900)
|
||||
{
|
||||
addObject(new MovingPlattform(-2), Greenfoot.getRandomNumber(400), 6); //Nach Links bewegende Plattform
|
||||
}
|
||||
else{
|
||||
Projectile projectile = new Projectile();
|
||||
addObject(projectile,Greenfoot.getRandomNumber(300)+50,0);
|
||||
timer = 200; //zeitlicher Abstand
|
||||
if(Greenfoot.getRandomNumber(100000)>=99750)
|
||||
{
|
||||
addObject(new BreakingPlattform(50), Greenfoot.getRandomNumber(400), 6); //Nach Links bewegende Plattform
|
||||
}
|
||||
//zwischen den x Werten 50 und 350 spawnen die Projektile (anpassbar)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
||||
*/
|
||||
public class Plattform extends Actor
|
||||
{
|
||||
boolean geloescht= false;
|
||||
/**
|
||||
* Act - do whatever the Plattform wants to do. This method is called whenever
|
||||
* the 'Act' or 'Run' button gets pressed in the environment.
|
||||
@@ -15,6 +16,10 @@ public class Plattform extends Actor
|
||||
public void act()
|
||||
{
|
||||
this.scrollNachUnten();
|
||||
if(geloescht)
|
||||
{
|
||||
this.loescheMich();
|
||||
}
|
||||
// Add your action code here.
|
||||
}
|
||||
|
||||
@@ -24,7 +29,7 @@ public class Plattform extends Actor
|
||||
setLocation(this.getX(),this.getY()+2); // Nach unten turnen
|
||||
if(this.getY()>= welt.getHeight()-5 ||this.getY()<=0)
|
||||
{
|
||||
this.loescheMich();
|
||||
geloescht= true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,12 +40,12 @@ public class Plattform extends Actor
|
||||
|
||||
public boolean PlayerOnPlattform()
|
||||
{
|
||||
Actor Spieler= getOneObjectAtOffset(0, 5, Player.class);
|
||||
if(Spieler!= null)
|
||||
Player Spieler= (Player) getOneIntersectingObject(Player.class);
|
||||
if(this.isTouching(Player.class))
|
||||
{
|
||||
if(Spieler.equals(Player.class))
|
||||
if(Spieler.getY()<this.getY()-20)
|
||||
{
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -51,5 +56,6 @@ public class Plattform extends Actor
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,4 +11,14 @@ comment4.params=
|
||||
comment4.target=void\ fall()
|
||||
comment5.params=
|
||||
comment5.target=boolean\ collision()
|
||||
comment6.params=
|
||||
comment6.target=void\ handlePowerUps()
|
||||
comment7.params=duration\ type
|
||||
comment7.target=void\ reveivePowerUp(int,\ java.lang.String)
|
||||
numComments=8
|
||||
comment3.target=void\ jump()
|
||||
comment4.params=
|
||||
comment4.target=void\ fall()
|
||||
comment5.params=
|
||||
comment5.target=boolean\ collision()
|
||||
numComments=6
|
||||
|
||||
@@ -8,8 +8,13 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
||||
*/
|
||||
public class Player extends Actor
|
||||
{
|
||||
private int speed = 4;
|
||||
private int jumpStrength = 12;
|
||||
int jumpBoostDuration = -1;
|
||||
int jumpBoostStrength = 5;
|
||||
|
||||
|
||||
private int speed = 6;
|
||||
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,32 +48,43 @@ public class Player extends Actor
|
||||
{
|
||||
if (Greenfoot.isKeyDown("space") && onGround)
|
||||
{
|
||||
verticalSpeed = -jumpStrength;
|
||||
verticalSpeed = -currentJumpStrength;
|
||||
onGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Schwerkraft und Boden-Kollision
|
||||
// Schwerkraft
|
||||
private void fall()
|
||||
{
|
||||
int oldY = getY();
|
||||
|
||||
verticalSpeed += gravity;
|
||||
|
||||
int newY = getY() + verticalSpeed;
|
||||
|
||||
// Prüfen, ob wir auf Ground landen
|
||||
setLocation(getX(), newY);
|
||||
|
||||
Actor ground = getOneIntersectingObject(Ground.class);
|
||||
|
||||
if (ground != null)
|
||||
if (ground != null && verticalSpeed >= 0)
|
||||
{
|
||||
// Wenn wir fallen, stehen wir auf dem Ground
|
||||
if (verticalSpeed >= 0)
|
||||
{
|
||||
int groundTop = ground.getY() - ground.getImage().getHeight() / 2;
|
||||
int characterHalfHeight = getImage().getHeight() / 2;
|
||||
int groundTop = ground.getY()
|
||||
- ground.getImage().getHeight() / 2;
|
||||
|
||||
setLocation(getX(), groundTop - characterHalfHeight);
|
||||
int characterBottom = getY()
|
||||
+ getImage().getHeight() / 2;
|
||||
|
||||
// Nur landen, wenn der Spieler vorher über dem Boden war
|
||||
int oldCharacterBottom = oldY
|
||||
+ getImage().getHeight() / 2;
|
||||
|
||||
if (oldCharacterBottom <= groundTop &&
|
||||
characterBottom >= groundTop)
|
||||
{
|
||||
setLocation(
|
||||
getX(),
|
||||
groundTop - getImage().getHeight() / 2
|
||||
);
|
||||
|
||||
verticalSpeed = 0;
|
||||
onGround = true;
|
||||
@@ -90,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ public class PlayerTestWorld extends World
|
||||
super(600, 400, 1);
|
||||
prepare();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the world for the start of the program.
|
||||
* 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);
|
||||
Player player = new Player();
|
||||
addObject(player,264,237);
|
||||
JumpBoostItem jumpBoostItem = new JumpBoostItem();
|
||||
addObject(jumpBoostItem,206,200);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 167 B |
|
After Width: | Height: | Size: 981 B |
|
After Width: | Height: | Size: 6.9 KiB |
|
After Width: | Height: | Size: 971 B |
|
After Width: | Height: | Size: 610 B |
|
After Width: | Height: | Size: 167 B |
|
After Width: | Height: | Size: 1.7 KiB |
@@ -8,9 +8,13 @@ class.Projectile.image=Projectile1.png
|
||||
class.StartWorld.image=StartBackground.png
|
||||
dependency1.from=GameOverWorld
|
||||
dependency1.to=Button
|
||||
dependency1.from=PlayerTestWorld
|
||||
dependency1.to=Ground
|
||||
dependency1.type=UsesDependency
|
||||
dependency2.from=StartWorld
|
||||
dependency2.to=Button
|
||||
dependency2.from=PlayerTestWorld
|
||||
dependency2.to=Player
|
||||
dependency2.type=UsesDependency
|
||||
dependency3.from=MyWorld
|
||||
dependency3.to=Player
|
||||
@@ -37,6 +41,19 @@ editor.fx.0.y=65
|
||||
height=736
|
||||
package.numDependencies=8
|
||||
package.numTargets=7
|
||||
dependency3.from=MyWorld
|
||||
dependency3.to=Player
|
||||
dependency3.type=UsesDependency
|
||||
dependency4.from=Player
|
||||
dependency4.to=Ground
|
||||
dependency4.type=UsesDependency
|
||||
editor.fx.0.height=737
|
||||
editor.fx.0.width=814
|
||||
editor.fx.0.x=360
|
||||
editor.fx.0.y=26
|
||||
height=830
|
||||
package.numDependencies=4
|
||||
package.numTargets=4
|
||||
project.charset=UTF-8
|
||||
publish.hasSource=false
|
||||
publish.locked=true
|
||||
@@ -67,6 +84,7 @@ target2.x=0
|
||||
target2.y=0
|
||||
target3.height=70
|
||||
target3.name=Button
|
||||
target3.name=PlayerTestWorld
|
||||
target3.showInterface=false
|
||||
target3.type=ClassTarget
|
||||
target3.width=120
|
||||
@@ -100,8 +118,19 @@ target7.type=ClassTarget
|
||||
target7.width=120
|
||||
target7.x=0
|
||||
target7.y=0
|
||||
target4.height=70
|
||||
target4.name=MyWorld
|
||||
target4.showInterface=false
|
||||
target4.type=ClassTarget
|
||||
target4.width=120
|
||||
target4.x=0
|
||||
target4.y=0
|
||||
version=3.1.0
|
||||
width=856
|
||||
world.lastInstantiated=StartWorld
|
||||
xPosition=652
|
||||
yPosition=76
|
||||
width=1550
|
||||
world.lastInstantiated=PlayerTestWorld
|
||||
xPosition=0
|
||||
yPosition=0
|
||||
|
||||