Merge remote-tracking branch 'origin/main'
# Conflicts: # SMIMS-Game/Player.class # SMIMS-Game/Player.ctxt # SMIMS-Game/Player.java # SMIMS-Game/project.greenfoot
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,9 @@
|
||||
#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
|
||||
comment2.params=
|
||||
comment2.target=void\ breakPlattform()
|
||||
numComments=3
|
||||
@@ -0,0 +1,32 @@
|
||||
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
||||
|
||||
/**
|
||||
* Write a description of class BreakingPlattform here.
|
||||
*
|
||||
* @author (your name)
|
||||
* @version (a version number or a date)
|
||||
*/
|
||||
public class BreakingPlattform extends Plattform
|
||||
{
|
||||
boolean IsBreaking= false;
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
||||
public void breakPlattform()
|
||||
{
|
||||
if(this.PlayerOnPlattform())
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,11 @@
|
||||
#BlueJ class context
|
||||
comment0.target=MovingPlattform
|
||||
comment0.text=\r\n\ Write\ a\ description\ of\ class\ MovingPlattform\ here.\r\n\ \r\n\ @author\ (your\ name)\ \r\n\ @version\ (a\ version\ number\ or\ a\ date)\r\n
|
||||
comment1.params=pSpeed
|
||||
comment1.target=MovingPlattform(int)
|
||||
comment2.params=
|
||||
comment2.target=void\ act()
|
||||
comment2.text=\r\n\ Act\ -\ do\ whatever\ the\ MovingPlattform\ 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\ bewege()
|
||||
numComments=4
|
||||
@@ -0,0 +1,38 @@
|
||||
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
||||
|
||||
/**
|
||||
* Write a description of class MovingPlattform here.
|
||||
*
|
||||
* @author (your name)
|
||||
* @version (a version number or a date)
|
||||
*/
|
||||
public class MovingPlattform extends Plattform
|
||||
{
|
||||
int speed;
|
||||
|
||||
public MovingPlattform(int pSpeed)
|
||||
{
|
||||
speed= pSpeed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Act - do whatever the MovingPlattform wants to do. This method is called whenever
|
||||
* the 'Act' or 'Run' button gets pressed in the environment.
|
||||
*/
|
||||
public void act()
|
||||
{
|
||||
// Add your action code here.
|
||||
super.act();
|
||||
this.bewege();
|
||||
}
|
||||
|
||||
public void bewege()
|
||||
{
|
||||
MyWorld theWorld= (MyWorld) this.getWorld();
|
||||
move(speed);
|
||||
if(this.getX()<5 || this.getX()<=theWorld.getWidth())
|
||||
{
|
||||
this.loescheMich();
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,13 @@
|
||||
#BlueJ class context
|
||||
comment0.target=Plattform
|
||||
comment0.text=\r\n\ Write\ a\ description\ of\ class\ Plattform\ 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\ Plattform\ 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\ scrollNachUnten()
|
||||
comment3.params=
|
||||
comment3.target=void\ loescheMich()
|
||||
comment4.params=
|
||||
comment4.target=boolean\ PlayerOnPlattform()
|
||||
numComments=5
|
||||
@@ -0,0 +1,55 @@
|
||||
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
||||
|
||||
/**
|
||||
* Write a description of class Plattform here.
|
||||
*
|
||||
* @author (your name)
|
||||
* @version (a version number or a date)
|
||||
*/
|
||||
public class Plattform extends Actor
|
||||
{
|
||||
/**
|
||||
* Act - do whatever the Plattform wants to do. This method is called whenever
|
||||
* the 'Act' or 'Run' button gets pressed in the environment.
|
||||
*/
|
||||
public void act()
|
||||
{
|
||||
this.scrollNachUnten();
|
||||
// Add your action code here.
|
||||
}
|
||||
|
||||
public void scrollNachUnten()
|
||||
{
|
||||
MyWorld welt= (MyWorld) getWorld();
|
||||
setLocation(this.getX(),this.getY()+2); // Nach unten turnen
|
||||
if(this.getY()>= welt.getHeight()-5 ||this.getY()<=0)
|
||||
{
|
||||
this.loescheMich();
|
||||
}
|
||||
}
|
||||
|
||||
public void loescheMich()
|
||||
{
|
||||
getWorld().removeObject(this);
|
||||
}
|
||||
|
||||
public boolean PlayerOnPlattform()
|
||||
{
|
||||
Actor Spieler= getOneObjectAtOffset(0, 5, Player.class);
|
||||
if(Spieler!= null)
|
||||
{
|
||||
if(Spieler.equals(Player.class))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -7,6 +7,4 @@ comment2.params=
|
||||
comment2.target=void\ player_movement()
|
||||
comment3.params=
|
||||
comment3.target=boolean\ onGround()
|
||||
comment4.params=
|
||||
comment4.target=boolean\ collision()
|
||||
numComments=5
|
||||
numComments=4
|
||||
|
||||
+66
-23
@@ -8,44 +8,87 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
||||
*/
|
||||
public class Player extends Actor
|
||||
{
|
||||
int velocityY = 0;
|
||||
int speed = 5;
|
||||
private int speed = 4;
|
||||
private int jumpStrength = 12;
|
||||
private int gravity = 1;
|
||||
|
||||
private int verticalSpeed = 0;
|
||||
private boolean onGround = false;
|
||||
|
||||
public void act()
|
||||
{
|
||||
player_movement();
|
||||
collision();
|
||||
moveLeftAndRight();
|
||||
jump();
|
||||
fall();
|
||||
}
|
||||
|
||||
public void player_movement(){
|
||||
if (Greenfoot.isKeyDown("D")){
|
||||
setLocation(getX()+speed, getY());
|
||||
|
||||
// Bewegung nach links und rechts
|
||||
private void moveLeftAndRight()
|
||||
{
|
||||
if (Greenfoot.isKeyDown("a"))
|
||||
{
|
||||
setLocation(getX() - speed, getY());
|
||||
}
|
||||
if (Greenfoot.isKeyDown("A")){
|
||||
setLocation(getX()-speed, getY());
|
||||
|
||||
if (Greenfoot.isKeyDown("d"))
|
||||
{
|
||||
setLocation(getX() + speed, getY());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean onGround(){
|
||||
int height = getImage().getHeight();
|
||||
|
||||
Actor floor = getOneObjectAtOffset(
|
||||
0,
|
||||
height / 2 + 1,
|
||||
Ground.class
|
||||
);
|
||||
|
||||
return floor != null;
|
||||
|
||||
// Springen
|
||||
private void jump()
|
||||
{
|
||||
if (Greenfoot.isKeyDown("space") && onGround)
|
||||
{
|
||||
verticalSpeed = -jumpStrength;
|
||||
onGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Schwerkraft und Boden-Kollision
|
||||
private void fall()
|
||||
{
|
||||
verticalSpeed += gravity;
|
||||
|
||||
int newY = getY() + verticalSpeed;
|
||||
|
||||
// Prüfen, ob wir auf Ground landen
|
||||
setLocation(getX(), newY);
|
||||
|
||||
Actor ground = getOneIntersectingObject(Ground.class);
|
||||
|
||||
if (ground != null)
|
||||
{
|
||||
// Wenn wir fallen, stehen wir auf dem Ground
|
||||
if (verticalSpeed >= 0)
|
||||
{
|
||||
int groundTop = ground.getY() - ground.getImage().getHeight() / 2;
|
||||
int characterHalfHeight = getImage().getHeight() / 2;
|
||||
|
||||
setLocation(getX(), groundTop - characterHalfHeight);
|
||||
|
||||
verticalSpeed = 0;
|
||||
onGround = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
onGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean collision(){
|
||||
if (getIntersectingObjects(Projectile.class).size()>0)
|
||||
{
|
||||
Greenfoot.setWorld(new GameOverWorld());
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,10 @@
|
||||
#BlueJ class context
|
||||
comment0.target=PlayerTestWorld
|
||||
comment0.text=\r\n\ Write\ a\ description\ of\ class\ PlayerTestWorld\ here.\r\n\ \r\n\ @author\ (your\ name)\ \r\n\ @version\ (a\ version\ number\ or\ a\ date)\r\n
|
||||
comment1.params=
|
||||
comment1.target=PlayerTestWorld()
|
||||
comment1.text=\r\n\ Constructor\ for\ objects\ of\ class\ PlayerTestWorld.\r\n\ \r\n
|
||||
comment2.params=
|
||||
comment2.target=void\ prepare()
|
||||
comment2.text=\r\n\ Prepare\ the\ world\ for\ the\ start\ of\ the\ program.\r\n\ That\ is\:\ create\ the\ initial\ objects\ and\ add\ them\ to\ the\ world.\r\n
|
||||
numComments=3
|
||||
@@ -0,0 +1,33 @@
|
||||
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
||||
|
||||
/**
|
||||
* Write a description of class PlayerTestWorld here.
|
||||
*
|
||||
* @author (your name)
|
||||
* @version (a version number or a date)
|
||||
*/
|
||||
public class PlayerTestWorld extends World
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor for objects of class PlayerTestWorld.
|
||||
*
|
||||
*/
|
||||
public PlayerTestWorld()
|
||||
{
|
||||
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
|
||||
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.
|
||||
*/
|
||||
private void prepare()
|
||||
{
|
||||
Ground ground = new Ground();
|
||||
addObject(ground,260,375);
|
||||
Player player = new Player();
|
||||
addObject(player,264,237);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
@@ -1,27 +1,19 @@
|
||||
#Greenfoot project file
|
||||
class.GameOverWorld.image=bluerock.jpg
|
||||
class.Ground.image=weave.jpg
|
||||
class.Player.image=ppl2.png
|
||||
class.Projectile.image=Projectile1.png
|
||||
dependency1.from=MyWorld
|
||||
dependency1.to=Player
|
||||
dependency1.type=UsesDependency
|
||||
dependency2.from=MyWorld
|
||||
dependency2.to=Projectile
|
||||
dependency2.from=Player
|
||||
dependency2.to=Ground
|
||||
dependency2.type=UsesDependency
|
||||
dependency3.from=Player
|
||||
dependency3.to=Ground
|
||||
dependency3.type=UsesDependency
|
||||
dependency4.from=Player
|
||||
dependency4.to=Projectile
|
||||
dependency4.type=UsesDependency
|
||||
editor.fx.0.height=737
|
||||
editor.fx.0.width=814
|
||||
editor.fx.0.x=360
|
||||
editor.fx.0.y=26
|
||||
editor.fx.0.height=0
|
||||
editor.fx.0.width=0
|
||||
editor.fx.0.x=0
|
||||
editor.fx.0.y=0
|
||||
height=736
|
||||
package.numDependencies=4
|
||||
package.numTargets=5
|
||||
package.numDependencies=2
|
||||
package.numTargets=3
|
||||
project.charset=UTF-8
|
||||
publish.hasSource=false
|
||||
publish.locked=true
|
||||
@@ -51,26 +43,12 @@ target2.width=120
|
||||
target2.x=0
|
||||
target2.y=0
|
||||
target3.height=70
|
||||
target3.name=GameOverWorld
|
||||
target3.name=MyWorld
|
||||
target3.showInterface=false
|
||||
target3.type=ClassTarget
|
||||
target3.width=120
|
||||
target3.x=0
|
||||
target3.y=0
|
||||
target4.height=70
|
||||
target4.name=MyWorld
|
||||
target4.showInterface=false
|
||||
target4.type=ClassTarget
|
||||
target4.width=120
|
||||
target4.x=0
|
||||
target4.y=0
|
||||
target5.height=70
|
||||
target5.name=Projectile
|
||||
target5.showInterface=false
|
||||
target5.type=ClassTarget
|
||||
target5.width=120
|
||||
target5.x=0
|
||||
target5.y=0
|
||||
version=3.1.0
|
||||
width=856
|
||||
world.lastInstantiated=MyWorld
|
||||
|
||||
Reference in New Issue
Block a user