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

2017/11/1

Problem with positioning

diablo95 diablo95

2017/11/1

#
I have the problem that some of the bats that are generated in the lower part of my world appear half cut, that I have to modify to limit the lower part in my code //world
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Mundo here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Mundo extends World
{
    Tablero puntos;
    BossLife lifeboss;

    /**
     * Constructor for objects of class Mundo.
     * 
     */
    public Mundo()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        
        super(600, 400, 1); 
        
        // Crear un Angel en el mundo
        Angel angel= new Angel();
        
        // AƱadir angel a el mundo
        addObject(angel, 100, getHeight()/2);
        
        
        
        puntos=new Tablero(0,"");
        addObject(puntos,186,89);
    }   
    public void terminarJuego() {
       
        Greenfoot.playSound("game-over.wav");
        Greenfoot.stop();
    }
    
    public void ponerJefe()
    {
        
        nave2 boss=new nave2();
        addObject(boss,getWidth()-80,(getHeight()/2)+20);
        lifeboss=new BossLife(100,0,0,20);
        addObject(lifeboss,750,85);

    }
    
    public void act()
    {
        if(puntos.obtenerValor()>=0 ){
          if (Greenfoot.getRandomNumber(50) ==0)
           {
            addObject(new Murcielago(), 600, 50+Greenfoot.getRandomNumber(500));
           
           }
        }
        
        
    }//
}
// bat code
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Roca here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Murcielago extends Actor
{
    


    /**
     * Act - do whatever the Alien wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    
    
    public void move() {
        setLocation(getX()-1, getY());
        if (this.getX() == 0) {
            getWorld().removeObject(this);
        }
        
    }
    
    public void hit() {
        getWorld().removeObject(this);

    }
    
    public void intentarDestruirAngel() {
        Actor actor = getOneObjectAtOffset(0, 0, Angel.class);
        if( actor != null ) {
            GameOver gameOver = new GameOver();
            getWorld().addObject(gameOver, getWorld().getWidth()/2,getWorld().getHeight()/2);
            ((Mundo)getWorld()).terminarJuego();
            
        }
    }
    
    public void act(){
        intentarDestruirAngel(); 
        move(); // Add your action code here.
    }  
}
danpost danpost

2017/11/1

#
On line 56, change '500' to '300'.
You need to login to post a reply.