Merge remote-tracking branch 'origin/main'
# Conflicts: # SMIMS-Game/MyWorld.class # SMIMS-Game/MyWorld.java # SMIMS-Game/project.greenfoot
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,7 @@
|
|||||||
|
#BlueJ class context
|
||||||
|
comment0.target=GameOverWorld
|
||||||
|
comment0.text=\r\n\ Write\ a\ description\ of\ class\ GameOverWorld\ here.\r\n\ \r\n\ @author\ (your\ name)\ \r\n\ @version\ (a\ version\ number\ or\ a\ date)\r\n
|
||||||
|
comment1.params=
|
||||||
|
comment1.target=GameOverWorld()
|
||||||
|
comment1.text=\r\n\ Constructor\ for\ objects\ of\ class\ GameOverWorld.\r\n\ \r\n
|
||||||
|
numComments=2
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write a description of class GameOverWorld here.
|
||||||
|
*
|
||||||
|
* @author (your name)
|
||||||
|
* @version (a version number or a date)
|
||||||
|
*/
|
||||||
|
public class GameOverWorld extends World
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for objects of class GameOverWorld.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public GameOverWorld()
|
||||||
|
{
|
||||||
|
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
|
||||||
|
super(400, 600, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
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.
+1
-28
@@ -8,7 +8,7 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
|||||||
*/
|
*/
|
||||||
public class MyWorld extends World
|
public class MyWorld extends World
|
||||||
{
|
{
|
||||||
int PlattformCountdown=20;
|
|
||||||
/**
|
/**
|
||||||
* Constructor for objects of class MyWorld.
|
* Constructor for objects of class MyWorld.
|
||||||
*
|
*
|
||||||
@@ -19,7 +19,6 @@ public class MyWorld extends World
|
|||||||
super(400, 600, 1);
|
super(400, 600, 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,30 +28,4 @@ public class MyWorld extends World
|
|||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
addObject(player,302,320);
|
addObject(player,302,320);
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
if(Greenfoot.getRandomNumber(100000)>=99750)
|
|
||||||
{
|
|
||||||
addObject(new BreakingPlattform(50), Greenfoot.getRandomNumber(400), 6); //Nach Links bewegende Plattform
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -1,5 +1,6 @@
|
|||||||
#BlueJ class context
|
#BlueJ class context
|
||||||
comment0.target=Player
|
comment0.target=Player
|
||||||
|
comment0.text=\r\n\ Write\ a\ description\ of\ class\ Player\ here.\r\n\ \r\n\ @author\ (your\ name)\ \r\n\ @version\ (a\ version\ number\ or\ a\ date)\r\n
|
||||||
comment1.params=
|
comment1.params=
|
||||||
comment1.target=void\ act()
|
comment1.target=void\ act()
|
||||||
comment2.params=
|
comment2.params=
|
||||||
@@ -8,4 +9,10 @@ comment3.params=
|
|||||||
comment3.target=void\ jump()
|
comment3.target=void\ jump()
|
||||||
comment4.params=
|
comment4.params=
|
||||||
comment4.target=void\ fall()
|
comment4.target=void\ fall()
|
||||||
numComments=5
|
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
|
||||||
|
|||||||
+69
-14
@@ -1,19 +1,32 @@
|
|||||||
import greenfoot.*;
|
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write a description of class Player here.
|
||||||
|
*
|
||||||
|
* @author (your name)
|
||||||
|
* @version (a version number or a date)
|
||||||
|
*/
|
||||||
public class Player extends Actor
|
public class Player extends Actor
|
||||||
{
|
{
|
||||||
private int speed = 4;
|
int jumpBoostDuration = -1;
|
||||||
private int jumpStrength = 12;
|
int jumpBoostStrength = 5;
|
||||||
private int gravity = 1;
|
|
||||||
|
|
||||||
|
|
||||||
|
private int speed = 6;
|
||||||
|
private int currentJumpStrength;
|
||||||
|
private int defaultJumpStrength = 15;
|
||||||
|
private int gravity = 1;
|
||||||
|
|
||||||
private int verticalSpeed = 0;
|
private int verticalSpeed = 0;
|
||||||
private boolean onGround = false;
|
private boolean onGround = false;
|
||||||
|
|
||||||
public void act()
|
public void act()
|
||||||
{
|
{
|
||||||
|
collision();
|
||||||
moveLeftAndRight();
|
moveLeftAndRight();
|
||||||
jump();
|
jump();
|
||||||
fall();
|
fall();
|
||||||
|
handlePowerUps();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bewegung nach links und rechts
|
// Bewegung nach links und rechts
|
||||||
@@ -35,32 +48,43 @@ public class Player extends Actor
|
|||||||
{
|
{
|
||||||
if (Greenfoot.isKeyDown("space") && onGround)
|
if (Greenfoot.isKeyDown("space") && onGround)
|
||||||
{
|
{
|
||||||
verticalSpeed = -jumpStrength;
|
verticalSpeed = -currentJumpStrength;
|
||||||
onGround = false;
|
onGround = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Schwerkraft und Boden-Kollision
|
// Schwerkraft
|
||||||
private void fall()
|
private void fall()
|
||||||
{
|
{
|
||||||
|
int oldY = getY();
|
||||||
|
|
||||||
verticalSpeed += gravity;
|
verticalSpeed += gravity;
|
||||||
|
|
||||||
int newY = getY() + verticalSpeed;
|
int newY = getY() + verticalSpeed;
|
||||||
|
|
||||||
// Prüfen, ob wir auf Ground landen
|
|
||||||
setLocation(getX(), newY);
|
setLocation(getX(), newY);
|
||||||
|
|
||||||
Actor ground = getOneIntersectingObject(Ground.class);
|
Actor ground = getOneIntersectingObject(Ground.class);
|
||||||
|
|
||||||
if (ground != null)
|
if (ground != null && verticalSpeed >= 0)
|
||||||
{
|
{
|
||||||
// Wenn wir fallen, stehen wir auf dem Ground
|
int groundTop = ground.getY()
|
||||||
if (verticalSpeed >= 0)
|
- ground.getImage().getHeight() / 2;
|
||||||
{
|
|
||||||
int groundTop = ground.getY() - ground.getImage().getHeight() / 2;
|
|
||||||
int characterHalfHeight = 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;
|
verticalSpeed = 0;
|
||||||
onGround = true;
|
onGround = true;
|
||||||
@@ -71,4 +95,35 @@ public class Player extends Actor
|
|||||||
onGround = false;
|
onGround = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean collision(){
|
||||||
|
if (getIntersectingObjects(Projectile.class).size()>0)
|
||||||
|
{
|
||||||
|
Greenfoot.setWorld(new GameOverWorld());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
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.
@@ -0,0 +1,9 @@
|
|||||||
|
#BlueJ class context
|
||||||
|
comment0.target=Projectile
|
||||||
|
comment0.text=\r\n\ Write\ a\ description\ of\ class\ Projectile\ 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\ Projectile\ 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=void\ falling()
|
||||||
|
numComments=3
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write a description of class Projectile here.
|
||||||
|
*
|
||||||
|
* @author (your name)
|
||||||
|
* @version (a version number or a date)
|
||||||
|
*/
|
||||||
|
public class Projectile extends Actor
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Act - do whatever the Projectile wants to do. This method is called whenever
|
||||||
|
* the 'Act' or 'Run' button gets pressed in the environment.
|
||||||
|
*/
|
||||||
|
public void act()
|
||||||
|
{
|
||||||
|
falling();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void falling(){
|
||||||
|
setLocation(getX(), getY() + 5);
|
||||||
|
if(getY() > getWorld().getHeight() -5){
|
||||||
|
getWorld().removeObject(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.9 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.6 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
@@ -1,40 +1,25 @@
|
|||||||
#Greenfoot project file
|
#Greenfoot project file
|
||||||
class.BreakingPlattform.image=Unbenannt2.png
|
|
||||||
class.Ground.image=weave.jpg
|
class.Ground.image=weave.jpg
|
||||||
class.MovingPlattform.image=Unbenannt.png
|
|
||||||
class.Plattform.image=Plattform.png
|
|
||||||
class.Player.image=ppl2.png
|
class.Player.image=ppl2.png
|
||||||
dependency1.from=MyWorld
|
dependency1.from=PlayerTestWorld
|
||||||
dependency1.to=Player
|
dependency1.to=Ground
|
||||||
dependency1.type=UsesDependency
|
dependency1.type=UsesDependency
|
||||||
dependency2.from=MyWorld
|
dependency2.from=PlayerTestWorld
|
||||||
dependency2.to=Plattform
|
dependency2.to=Player
|
||||||
dependency2.type=UsesDependency
|
dependency2.type=UsesDependency
|
||||||
dependency3.from=MyWorld
|
dependency3.from=MyWorld
|
||||||
dependency3.to=MovingPlattform
|
dependency3.to=Player
|
||||||
dependency3.type=UsesDependency
|
dependency3.type=UsesDependency
|
||||||
dependency4.from=MyWorld
|
dependency4.from=Player
|
||||||
dependency4.to=BreakingPlattform
|
dependency4.to=Ground
|
||||||
dependency4.type=UsesDependency
|
dependency4.type=UsesDependency
|
||||||
dependency5.from=Player
|
editor.fx.0.height=737
|
||||||
dependency5.to=Ground
|
editor.fx.0.width=814
|
||||||
dependency5.type=UsesDependency
|
editor.fx.0.x=360
|
||||||
dependency6.from=Plattform
|
editor.fx.0.y=26
|
||||||
dependency6.to=MyWorld
|
height=830
|
||||||
dependency6.type=UsesDependency
|
package.numDependencies=4
|
||||||
dependency7.from=Plattform
|
package.numTargets=4
|
||||||
dependency7.to=Player
|
|
||||||
dependency7.type=UsesDependency
|
|
||||||
dependency8.from=MovingPlattform
|
|
||||||
dependency8.to=MyWorld
|
|
||||||
dependency8.type=UsesDependency
|
|
||||||
editor.fx.0.height=811
|
|
||||||
editor.fx.0.width=816
|
|
||||||
editor.fx.0.x=1009
|
|
||||||
editor.fx.0.y=241
|
|
||||||
height=736
|
|
||||||
package.numDependencies=8
|
|
||||||
package.numTargets=6
|
|
||||||
project.charset=UTF-8
|
project.charset=UTF-8
|
||||||
publish.hasSource=false
|
publish.hasSource=false
|
||||||
publish.locked=true
|
publish.locked=true
|
||||||
@@ -57,42 +42,28 @@ target1.width=120
|
|||||||
target1.x=0
|
target1.x=0
|
||||||
target1.y=0
|
target1.y=0
|
||||||
target2.height=70
|
target2.height=70
|
||||||
target2.name=MovingPlattform
|
target2.name=Ground
|
||||||
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=Ground
|
target3.name=PlayerTestWorld
|
||||||
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=BreakingPlattform
|
target4.name=MyWorld
|
||||||
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=Plattform
|
|
||||||
target5.showInterface=false
|
|
||||||
target5.type=ClassTarget
|
|
||||||
target5.width=120
|
|
||||||
target5.x=0
|
|
||||||
target5.y=0
|
|
||||||
target6.height=70
|
|
||||||
target6.name=MyWorld
|
|
||||||
target6.showInterface=false
|
|
||||||
target6.type=ClassTarget
|
|
||||||
target6.width=120
|
|
||||||
target6.x=0
|
|
||||||
target6.y=0
|
|
||||||
version=3.1.0
|
version=3.1.0
|
||||||
width=856
|
width=1550
|
||||||
world.lastInstantiated=MyWorld
|
world.lastInstantiated=PlayerTestWorld
|
||||||
xPosition=652
|
xPosition=0
|
||||||
yPosition=76
|
yPosition=0
|
||||||
|
|||||||
Reference in New Issue
Block a user