I have a main actor in my world( and there will only be one) and that actor has an updating variable. how do i use that variable. I tried but it doesn't update. any ideas?
Actor actor = new Actor();
Actor actor = new Actor();
Actor actor = new Actor();
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.*; /** * Write a description of class Pman here. * * @author (your name) * @version (a version number or a date) */ public class Pman extends Actor { private GreenfootImage img; public Pman() { img = new GreenfootImage(200,200); img.setColor(Color.YELLOW); img.drawOval(0,0,0,0); img.fillOval(0,0,200,200); setImage(img); } public void act() { check(); } public boolean up, down, left, right; public void check() { if(getOneObjectAtOffset(-1,0, Wall.class) != null) { left = true; } if(getOneObjectAtOffset(1,0, Wall.class) != null) { right = true; } if(getOneObjectAtOffset(0,1, Actor.class) != null) { down = true; } if(getOneObjectAtOffset(0,-1, Wall.class) != null) { up = true; } } public void move() { if(k("up") == true) setLocation(getX(),getY() - 1); if(k("down") == true) setLocation(getX(),getY() + 1); if(k("left") == true) setLocation(getX()-1,getY()); if(k("right") == true) setLocation(getX()+1,getY()); } public boolean k(java.lang.String key) { boolean x = false; if(Greenfoot.isKeyDown(key)) x = true; return x; } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Thing here. * * @author (your name) * @version (a version number or a date) */ public class Thing extends Actor { /** * Act - do whatever the Thing 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. } private int c1 = 5; public void work() { c1 --; if(c1 <= 0) { if(k("up") == true) { setLocation(getX(), getY() +1); c1 = 10; } if(k("down") == true) { setLocation(getX(), getY() -1); c1 = 10; } if(k("left") == true) { setLocation(getX() + 1, getY()); c1 = 10; } if(k("right") == true) { setLocation(getX() - 1 , getY()); c1 = 10; } c1 = 5; } } public boolean k(java.lang.String key) { boolean x = false; if(Greenfoot.isKeyDown(key)) x = true; return x; } }