This site requires JavaScript, please enable it in your browser!
Greenfoot back
Yuuki
Yuuki wrote ...

2020/1/24

How i do get this acotr to spawn a set distance away from another actor, but that "area" has to get closer over time :p

Yuuki Yuuki

2020/1/24

#
Uhh, *input Jojo refrence here *
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
This is my code for my attac

public class atacc extends Actor
{
    public void act() 
    {
    
        if (Greenfoot.getRandomNumber(100) < 100 && !getWorld().getObjects(Soul.class).isEmpty())  
     {  
     Soul det = (Soul) getWorld().getObjects(Soul.class).get(0);  
     turnTowards(det.getX(), det.getY());  
     }  
     move(15);
             Actor det = getOneIntersectingObject(Soul.class);
     if (det != null){ 
      getWorld().removeObject(det);
      getWorld().removeObject(this);
       }
     else{
     checkBoundaries();
    }
    }    
    public void checkBoundaries(){
    if(getX() > getWorld().getWidth() -2)
        getWorld().removeObject(this);
    else if (getX() < 1)
        getWorld().removeObject(this);
    else if (getY() > getWorld().getHeight() - 2)
        getWorld().removeObject(this);
    else if (getY() < 1)
        getWorld().removeObject(this);
    }
   public void test(){
    Actor Spear = new atacc();
    getWorld().addObject(Spear, getX(), getY());
    Spear.setRotation(getRotation());
    turn(90);
    move(10);
    turn(-90);
    move(5);
   }
}
my player is here
public class Soul extends Actor
{
    private int timer;
    private int holdTimer = 1;
    public Soul(){
        GreenfootImage image = getImage();
        image.scale(image.getWidth() - 10, image.getHeight()-10);
        setImage("SoulDetermination.png");
  }
    public void act() 
  {
    MouseInfo pointer = Greenfoot.getMouseInfo();
    if(pointer != null)
    {
        int mouseX = pointer.getX();
        int mouseY = pointer.getY();
        turnTowards(mouseX, mouseY);
        int button = pointer.getButton();
         move(20);
         if(timer > 0) timer--;
         if(timer == 0 && Greenfoot.isKeyDown("1"))
         {
        checkFire();
        timer = 1;
        }
        if (holdTimer == 1) { GreenfootImage image = getImage();
         image.scale(image.getWidth() + 1, image.getHeight() + 1);
         setImage(image); } 
        else holdTimer--;
    }
  } 
   public void checkFire()
    {
        if(Greenfoot.isKeyDown("1"))
        {    
            defend nife = new defend();
            getWorld().addObject(nife,getX(), getY());
            nife.turn(this.getRotation());
        }
    }
}
While I'm here, ill explain the problems that i have, one is that the actor grows but it loss its original shape, how can i change that, and my second question is how do i get my attac to spawn at random times, here is the other codes if you need it.
public class Background extends World
{
  private int timer = 100000;
    /**
     * Constructor for objects of class Background.
     */
   public Background()
    {
        super(900, 900, 1);
        Soul det = new Soul();
        addObject (new Soul(), 450,450);
  }
  public void act(){
     RandomSpawn();
     timer--;
     showText(""+timer,50 ,50);
     if(timer<=0){
         Greenfoot.stop();
        }
     if (getObjects(Soul.class).isEmpty()){
         Greenfoot.stop();
        }
   }
  public void RandomSpawn(){
      if ((Greenfoot.getRandomNumber(100) < 5))
      {
          atacc hit = new atacc();
          addObject(hit, Greenfoot.getRandomNumber(900),Greenfoot.getRandomNumber(900));
        }
    } 
}
and my defend code
public class defend extends Actor
{
    /**
     * Act - do whatever the defend wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */ 
    private int timer;
    
    public void act() 
    {
        move(speed);
        destroyAttack();
        if(getWorld() != null)
        {
        checkBoundaries();
        }
        else{
        }
    }
    public void checkBoundaries(){
    if(getX() > getWorld().getWidth() -2)
        getWorld().removeObject(this);
    else if (getX() < 1)
        getWorld().removeObject(this);
    else if (getY() > getWorld().getHeight() - 2)
        getWorld().removeObject(this);
    else if (getY() < 1)
        getWorld().removeObject(this);
    }
    public void destroyAttack()
    {
        Actor attack = getOneIntersectingObject(atacc.class);
        if(attack != null){
            getWorld().removeObject(attack);
            getWorld().removeObject(this);
        }
    }
    private int speed = 15;
} 
Ok, use your stando powers and help me please thank you.
You need to login to post a reply.