Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c188985e02 | |||
| 07c5614d44 |
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.
@@ -7,4 +7,6 @@ comment1.text=\r\n\ Constructor\ for\ objects\ of\ class\ MyWorld.\r\n\ \r\n
|
|||||||
comment2.params=
|
comment2.params=
|
||||||
comment2.target=void\ prepare()
|
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
|
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
|
comment3.params=
|
||||||
|
comment3.target=void\ act()
|
||||||
|
numComments=4
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
|||||||
*/
|
*/
|
||||||
public class MyWorld extends World
|
public class MyWorld extends World
|
||||||
{
|
{
|
||||||
|
int timer = 200;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for objects of class MyWorld.
|
* Constructor for objects of class MyWorld.
|
||||||
@@ -28,4 +29,15 @@ 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(timer > 0){
|
||||||
|
timer = timer - 1;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
Projectile projectile = new Projectile();
|
||||||
|
addObject(projectile,Greenfoot.getRandomNumber(300)+50,0);
|
||||||
|
timer = 200;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
#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=
|
||||||
comment2.target=void\ moveLeftAndRight()
|
comment2.target=void\ player_movement()
|
||||||
comment3.params=
|
comment3.params=
|
||||||
comment3.target=void\ jump()
|
comment3.target=boolean\ onGround()
|
||||||
comment4.params=
|
numComments=4
|
||||||
comment4.target=void\ fall()
|
|
||||||
numComments=5
|
|
||||||
|
|||||||
+21
-1
@@ -1,5 +1,11 @@
|
|||||||
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;
|
private int speed = 4;
|
||||||
@@ -11,6 +17,8 @@ public class Player extends Actor
|
|||||||
|
|
||||||
public void act()
|
public void act()
|
||||||
{
|
{
|
||||||
|
player_movement();
|
||||||
|
collision();
|
||||||
moveLeftAndRight();
|
moveLeftAndRight();
|
||||||
jump();
|
jump();
|
||||||
fall();
|
fall();
|
||||||
@@ -71,4 +79,16 @@ 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
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 |
@@ -1,25 +1,19 @@
|
|||||||
#Greenfoot project file
|
#Greenfoot project file
|
||||||
class.Ground.image=weave.jpg
|
class.Ground.image=weave.jpg
|
||||||
class.Player.image=ppl2.png
|
class.Player.image=ppl2.png
|
||||||
dependency1.from=PlayerTestWorld
|
dependency1.from=MyWorld
|
||||||
dependency1.to=Ground
|
dependency1.to=Player
|
||||||
dependency1.type=UsesDependency
|
dependency1.type=UsesDependency
|
||||||
dependency2.from=PlayerTestWorld
|
dependency2.from=Player
|
||||||
dependency2.to=Player
|
dependency2.to=Ground
|
||||||
dependency2.type=UsesDependency
|
dependency2.type=UsesDependency
|
||||||
dependency3.from=MyWorld
|
editor.fx.0.height=0
|
||||||
dependency3.to=Player
|
editor.fx.0.width=0
|
||||||
dependency3.type=UsesDependency
|
editor.fx.0.x=0
|
||||||
dependency4.from=Player
|
editor.fx.0.y=0
|
||||||
dependency4.to=Ground
|
height=736
|
||||||
dependency4.type=UsesDependency
|
package.numDependencies=2
|
||||||
editor.fx.0.height=737
|
package.numTargets=3
|
||||||
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
|
project.charset=UTF-8
|
||||||
publish.hasSource=false
|
publish.hasSource=false
|
||||||
publish.locked=true
|
publish.locked=true
|
||||||
@@ -49,21 +43,14 @@ 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=MyWorld
|
||||||
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.name=MyWorld
|
|
||||||
target4.showInterface=false
|
|
||||||
target4.type=ClassTarget
|
|
||||||
target4.width=120
|
|
||||||
target4.x=0
|
|
||||||
target4.y=0
|
|
||||||
version=3.1.0
|
version=3.1.0
|
||||||
width=1550
|
width=856
|
||||||
world.lastInstantiated=PlayerTestWorld
|
world.lastInstantiated=MyWorld
|
||||||
xPosition=0
|
xPosition=652
|
||||||
yPosition=0
|
yPosition=76
|
||||||
|
|||||||
Reference in New Issue
Block a user