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

2015/9/26

Chain Factory, greenfoot

sophievangemert sophievangemert

2015/9/26

#
Hello everybody, for a school project I have to make the game Chain Factory. I'm really bad at coding. I already have the lay out, but when I click on 'run' al my balls disappear because they fall into each other. I tried some things with getOneObjectAtOffset but I still don't really know what I'm doing. Does anybody know how to make sure the balls don't fall into each other and stay where they are because they know they don't have to move? Thanks a lot!
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class bal1 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class bal1 extends Actor
{
    /**
     * Act - do whatever the bal1 wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
       setLocation (getX() , getY()+1);
       Actor bal1;
       bal1 = getOneObjectAtOffset(0, 0, bal1.class);
    }  


   
    
    
}
Super_Hippo Super_Hippo

2015/9/26

#
Replace lines 18 and 19 with this:
if (isTouching(bal1.class)) setLocation(getX(), getY()-1);
You need to login to post a reply.