I would like to create an invisible square in which it would act as an out of bounds area that once my frog was in he would be removed. Can i have help in how i would code that??
import greenfoot.*;
public class Boundary extends Actor
{
/** giving the actorr an invisible image */
public Boundary()
{
setImage(new GreenfootImage(5, 400)); // adjust size as needed
}
/** removing an intersecting frog */
public void act()
{
if (isTouching(Frog.class)) removeTouching(Frro.class));
}
}getImage().fill();
public boolean OnLog()
{
if (isTouching(Log1.class) || isTouching(Log2.class) || isTouching(Log3.class))
{
return true;
} else
{
return false;
}
} if (isTouching(Frog.class)&&frog.OnLog() == true)
{
return;
}
else
{
removeTouching(Frog.class);
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Frog here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Frog extends Actor
{
private String[] move = {"frogup1.png","frogup2.png","frogup3.png","frogup4.png","frogup5.png","frogup6.png"};
private int frameCounterMove = 0;
private int reload;
int lives = 3;
Lives life = new Lives();
/**
* Act - do whatever the Frog wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move();
removeWhenTouching();
OnLog();
}
public void move()
{
if (Greenfoot.isKeyDown("up"))
{
setLocation(getX(), getY()-5);
setRotation(360);
animateOnMove();
}
else if (Greenfoot.isKeyDown("left"))
{
setLocation(getX()-5, getY());
setRotation(270);
animateOnMove();
}
else if (Greenfoot.isKeyDown("right"))
{
setLocation(getX()+5, getY());
setRotation(90);
animateOnMove();
}
else if (Greenfoot.isKeyDown("down"))
{
setLocation(getX(), getY()+5);
setRotation(180);
animateOnMove();
}
}
public void animateOnMove()
{
reload++;
if(reload==3)
{
setImage(move[frameCounterMove]);
frameCounterMove++;
if(frameCounterMove >= move.length)
frameCounterMove=0;
reload = 0;
}
}
public int getLives()
{
return lives;
}
public void loseLife()
{
lives = lives - 1;
}
public void removeWhenTouching()
{
if(isTouching(Car1.class))
{
removeTouching(Frog.class);
if(getLives() == 0)
{
}else{
loseLife();
}
reset();
}
if(isTouching(Car2.class))
{
removeTouching(Frog.class);
if(getLives() == 0)
{
}else{
loseLife();
}
reset();
}
if(isTouching(Car3.class))
{
removeTouching(Frog.class);
if(getLives() == 0)
{
}else{
loseLife();
}
reset();
}
}
public void reset()
{
if(this.getWorld() instanceof MyWorld)
{
((MyWorld) this.getWorld()).reset();
}
}
public boolean OnLog()
{
if (isTouching(Log1.class) || isTouching(Log2.class) || isTouching(Log3.class))
{
return true;
} else
{
return false;
}
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
* Write a description of class Boundary here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Boundary extends Actor
{
Frog frog = new Frog();
/** giving the actorr an invisible image */
public Boundary()
{
setImage(new GreenfootImage(1000, 300)); // size of the boundary
// getImage().fill(); //used to position the boundary
}
/** removing an intersecting frog */
public void act()
{
if (isTouching(Frog.class)&&frog.OnLog() == true)
{
return;
}
else
{
removeTouching(Frog.class);
}
}
}