It makes me frustate T_T
public void map(){
if(isTouching(Goa.class)){
Counter counter = ((FarmWorld)getWorld()).getCounter();
GoldWorld gw = new GoldWorld();
Greenfoot.setWorld(gw);
}
}
public class Counter extends Actor
{
private int count = 100;
public Counter(){
setImage(new GreenfootImage("Gold : 100", 20, Color.WHITE, Color.BLACK));
}
/**
* Act - do whatever the Counter wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void walkCount (int amount)
{
// Add your action code here.
count += amount;
setImage(new GreenfootImage("Gold : " + count,20, Color.WHITE, Color.BLACK));
}
public int getValue(){
return count;
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Petani here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Petani extends Actor
{
private int speed = 1;
private GreenfootImage Bawah1 = new GreenfootImage("Bawah1.png");
private GreenfootImage Bawah2 = new GreenfootImage("Bawah2.png");
private GreenfootImage Bawah3 = new GreenfootImage("Bawah3.png");
private GreenfootImage Atas1 = new GreenfootImage("Atas1.png");
private GreenfootImage Atas2 = new GreenfootImage("Atas2.png");
private GreenfootImage Atas3 = new GreenfootImage("Atas3.png");
private GreenfootImage Kiri1 = new GreenfootImage("Kiri1.png");
private GreenfootImage Kiri2 = new GreenfootImage("Kiri2.png");
private GreenfootImage Kiri3 = new GreenfootImage("Kiri3.png");
private GreenfootImage Kanan1 = new GreenfootImage("Kanan1.png");
private GreenfootImage Kanan2 = new GreenfootImage("Kanan2.png");
private GreenfootImage Kanan3 = new GreenfootImage("Kanan3.png");
private int frame = 1;
private int animationCounter = 0;
/**
* Act - do whatever the Petani 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.
checkKey();
touchWall();
map();
animationCounter++;
}
public void touchWall(){
if(isTouching(Tembok1.class) || (isTouching(Tembok2.class)) || (isTouching(Barrel.class)) ||
(isTouching(Harta.class)) || (isTouching(Tanda.class)) || (isTouching(Bendera.class)) || (isTouching(Crystal.class)) ||
(isTouching(Jerami.class))){
if(Greenfoot.isKeyDown("S")){
this.setLocation(getX(), getY()-speed);
}
if(Greenfoot.isKeyDown("W")){
this.setLocation(getX(), getY()+speed);
}
if(Greenfoot.isKeyDown("A")){
this.setLocation(getX()+speed, getY());
}
if(Greenfoot.isKeyDown("D")){
this.setLocation(getX()-speed, getY());
}
}
}
public void checkKey(){
if(Greenfoot.isKeyDown("S")){
moveDown();
}
else if(Greenfoot.isKeyDown("W")){
moveUp();
}
else if(Greenfoot.isKeyDown("A")){
moveLeft();
}
else if(Greenfoot.isKeyDown("D")){
moveRight();
}
}
public void map(){
if(isTouching(Goa.class)){
Counter counter = ((FarmWorld)getWorld()).getCounter();
GoldWorld gw = new GoldWorld();
Greenfoot.setWorld(gw);
}
else if(isTouching(Perkebunan.class)){
Greenfoot.setWorld(new Board1());
}
else if(isTouching(Peternakan.class)){
Greenfoot.setWorld(new Board2());
}
}
public void moveDown(){
Counter counter = null;
this.setLocation(getX(), getY()+speed);
if (getWorld() instanceof FarmWorld) {
counter = ((FarmWorld)getWorld()).getCounter();
if(animationCounter % 25 == 0){
animatedBawah();
counter.walkCount(1);
}
}
else if(getWorld() instanceof GoldWorld){
counter = ((GoldWorld)getWorld()).getCounter();
if(animationCounter % 25 == 0){
animatedBawah();
counter.walkCount(2);
}
}
}
public void moveUp(){
Counter counter = null;
this.setLocation(getX(), getY()-speed);
if (getWorld() instanceof FarmWorld) {
counter = ((FarmWorld)getWorld()).getCounter();
if(animationCounter % 25 == 0){
animatedAtas();
counter.walkCount(1);
}
}
else if(getWorld() instanceof GoldWorld){
counter = ((GoldWorld)getWorld()).getCounter();
if(animationCounter % 25 == 0){
animatedAtas();
counter.walkCount(2);
}
}
}
public void moveLeft(){
Counter counter = null;
this.setLocation(getX()-speed, getY());
if (getWorld() instanceof FarmWorld) {
counter = ((FarmWorld)getWorld()).getCounter();
if(animationCounter % 25 == 0){
animatedKiri();
counter.walkCount(1);
}
}
else if(getWorld() instanceof GoldWorld){
counter = ((GoldWorld)getWorld()).getCounter();
if(animationCounter % 25 == 0){
animatedKiri();
counter.walkCount(2);
}
}
}
public void moveRight(){
Counter counter = null;
this.setLocation(getX()+speed, getY());
if (getWorld() instanceof FarmWorld) {
counter = ((FarmWorld)getWorld()).getCounter();
if(animationCounter % 25 == 0){
animatedKanan();
counter.walkCount(1);
}
}
else if(getWorld() instanceof GoldWorld){
counter = ((GoldWorld)getWorld()).getCounter();
if(animationCounter % 25 == 0){
animatedKanan();
counter.walkCount(2);
}
}
}
public void animatedKanan(){
if(frame == 1){
setImage(Kanan1);
}
else if(frame == 2){
setImage(Kanan2);
}
else if(frame == 3){
setImage(Kanan3);
frame = 1;
return;
}
frame++;
}
public void animatedKiri(){
if(frame == 1){
setImage(Kiri1);
}
else if(frame == 2){
setImage(Kiri2);
}
else if(frame == 3){
setImage(Kiri3);
frame = 1;
return;
}
frame++;
}
public void animatedAtas(){
if(frame == 1){
setImage(Atas1);
}
else if(frame == 2){
setImage(Atas2);
}
else if(frame == 3){
setImage(Atas3);
frame = 1;
return;
}
frame++;
}
public void animatedBawah(){
if(frame == 1){
setImage(Bawah1);
}
else if(frame == 2){
setImage(Bawah2);
}
else if(frame == 3){
setImage(Bawah3);
frame = 1;
return;
}
frame++;
}
}
public void map(){
if(isTouching(Goa.class)){
Counter counter = ((FarmWorld)getWorld()).getCounter();
GoldWorld gw = new GoldWorld();
Greenfoot.setWorld(gw);
}
}GoldWorld gw = new GoldWorld(); gw.getCounter().setValue(counter.getValue()); Greenfoot.setWorld(gw);
public void map(){
if(isTouching(Goa.class)){
Counter counter = ((FarmWorld)getWorld()).getCounter();
GoldWorld gw = new GoldWorld();
gw.getCounter().setValue(counter.getValue());
Greenfoot.setWorld(gw);
}
public void map(){
if(isTouching(Goa.class)){
Counter counter = ((FarmWorld)getWorld()).getCounter();
GoldWorld gw = new GoldWorld();
gw.getCounter().walkCount(counter.getValue());
Greenfoot.setWorld(gw);
}