the score isn't adding , nothing is happening
if (isTouching (KrabbyPatty.class))
{
removeTouching (KrabbyPatty.class);
((Level1) getWorld()).counter.setScore();
}
}}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* This class MrKrabs allows the user to move Mr. Krabs through the level.
*
* Jacqueline Reilly
* January 18, 2017
*/
public class MrKrabs extends Actor
{
public MrKrabs()
{
GreenfootImage image = getImage ();
image.scale (image.getWidth ()-675, image.getHeight () -780);
setImage (image);
}
private int vSpeed =0;
private int acceleration =1;
private boolean jumping;
private int jumpStrength =16;
private int speed =4;
/**
* Act - do whatever the MrKrabs wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
//Checkiing the platform is secure
checkKey ();
checkFall ();
platformAbove ();
}
public void checkKey ()
{
if (Greenfoot.isKeyDown ("right"))
{
//direction =1;
setLocation (getX()+speed, getY());
}
if (Greenfoot.isKeyDown ("left"))
{
//direction =-1l
setLocation (getX() - speed, getY());
}
if (Greenfoot.isKeyDown("up") && jumping == false)
{
jump ();
}
}
public boolean platformAbove ()
{
int spriteHeight = getImage ().getHeight ();
int yDistance = (int) (spriteHeight/-2);
Actor ceiling = getOneObjectAtOffset (0, yDistance, Platform.class);
if (ceiling != null)
{
vSpeed = 1;
bopHead (ceiling);
return true;
}
else
{
return false;
}
}
public void bopHead (Actor ceiling)
{
int ceilingHeight = ceiling.getImage ().getHeight ();
int newY = ceiling.getY () + (ceilingHeight + getImage ().getHeight())/2;
setLocation (getX(), newY);
}
public void fall()
{
setLocation (getX(), getY() + vSpeed);
if (vSpeed <=9)
{
vSpeed = vSpeed + acceleration;
}
jumping = true;
}
public boolean onGround ()
{
int spriteHeight = getImage ().getHeight();
int yDistance = (int)(spriteHeight/2) + 5;
Actor ground = getOneObjectAtOffset (0, getImage ().getHeight()/2, Platform.class);
if (ground == null)
{
jumping = true;
return false;
}
else
{
moveToGround (ground);
return true;
}
}
public void moveToGround (Actor ground)
{
int groundHeight = ground.getImage ().getHeight();
int newY = ground.getY () - (groundHeight + getImage().getHeight())/2;
setLocation (getX (), newY);
jumping = false;
}
public void checkFall()
{
if (onGround ())
{
vSpeed = 0;
}
else
{
fall ();
}
}
public void jump ()
{
vSpeed = vSpeed - jumpStrength;
jumping = true;
fall ();
}
//(Colin. J helped with this)
public void kill(){
if(isTouching(KrabbyPatty.class)){
eat(KrabbyPatty.class);
}}
//Collecting the krabby patty's
public void eat(Class clss)
{
Actor KrabbyPatty = getOneIntersectingObject(KrabbyPatty.class);
if(KrabbyPatty != null) {
World w = getWorld();
w.removeObject(KrabbyPatty);
// (Altobelli) create an instance of the BACKROUND class (casting the world
// as the BACKROUND class
Level1 b = (Level1)w;
// creates an instance of the counter by getting it from the BACKROUND class
// and then call the setScore method in the BACKROUND class to increment score
Counter c = b.getCounter();
c.setScore();
}
if (isTouching (KrabbyPatty.class))
{
removeTouching (KrabbyPatty.class);
((Level1) getWorld()).counter.setScore();
}
}} if(isTouching(KrabbyPatty.class)){
eat(KrabbyPatty.class);kill();
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* This class MrKrabs allows the user to move Mr. Krabs through the level.
*
* Jacqueline Reilly
* January 18, 2017
*/
public class MrKrabs extends Actor
{
public MrKrabs()
{
GreenfootImage image = getImage ();
image.scale (image.getWidth ()-675, image.getHeight () -780);
setImage (image);
}
private int vSpeed =0;
private int acceleration =1;
private boolean jumping;
private int jumpStrength =16;
private int speed =4;
/**
* Act - do whatever the MrKrabs wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
//Checkiing the platform is secure
checkKey ();
checkFall ();
platformAbove ();
kill ();
}
public void checkKey ()
{
if (Greenfoot.isKeyDown ("right"))
{
//direction =1;
setLocation (getX()+speed, getY());
}
if (Greenfoot.isKeyDown ("left"))
{
//direction =-1l
setLocation (getX() - speed, getY());
}
if (Greenfoot.isKeyDown("up") && jumping == false)
{
jump ();
}
}
public boolean platformAbove ()
{
int spriteHeight = getImage ().getHeight ();
int yDistance = (int) (spriteHeight/-2);
Actor ceiling = getOneObjectAtOffset (0, yDistance, Platform.class);
if (ceiling != null)
{
vSpeed = 1;
bopHead (ceiling);
return true;
}
else
{
return false;
}
}
public void bopHead (Actor ceiling)
{
int ceilingHeight = ceiling.getImage ().getHeight ();
int newY = ceiling.getY () + (ceilingHeight + getImage ().getHeight())/2;
setLocation (getX(), newY);
}
public void fall()
{
setLocation (getX(), getY() + vSpeed);
if (vSpeed <=9)
{
vSpeed = vSpeed + acceleration;
}
jumping = true;
}
public boolean onGround ()
{
int spriteHeight = getImage ().getHeight();
int yDistance = (int)(spriteHeight/2) + 5;
Actor ground = getOneObjectAtOffset (0, getImage ().getHeight()/2, Platform.class);
if (ground == null)
{
jumping = true;
return false;
}
else
{
moveToGround (ground);
return true;
}
}
public void moveToGround (Actor ground)
{
int groundHeight = ground.getImage ().getHeight();
int newY = ground.getY () - (groundHeight + getImage().getHeight())/2;
setLocation (getX (), newY);
jumping = false;
}
public void checkFall()
{
if (onGround ())
{
vSpeed = 0;
}
else
{
fall ();
}
}
public void jump ()
{
vSpeed = vSpeed - jumpStrength;
jumping = true;
fall ();
}
//(Colin. J helped with this)
public void kill(){
if(isTouching(KrabbyPatty.class)){
eat(KrabbyPatty.class);
}
}}