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

2017/12/12

||ERROR|| Class, interface, or enum expected ||ERROR||

Max64751 Max64751

2017/12/12

#
Trying to build a engery blask (named kiBlast) for my game im making and I keep getting that errior My code for the kiBlast class
import greenfoot.*;
public KiBlast extends Actor
{
   public void act()
   {
       setLocation(getX() + speed, getY());
       checkBoundaries();
       destroyEnemies();
    }
   public void checkBoundaries()
   {
       if(getX() > getWorld().getWidth() - 1) 
       {
            getWorld().removeObject(this);
        }
       else if(getX() < 1) 
       {
            getWorld().removeObject(this);
        }
       if(getY() > getWorld().getHeight() - 1) 
       {  
       getWorld().removeObject(this);
       }
       else if(getY() < 1) 
       {
            getWorld().removeObject(this);
       }
   }
   
My Player Class (named Goku):
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)


public class Goku extends Actor
{
    private int vSpeed = 0;
    private int acceleration = 1;
    private int jumpStrength = 20;
    GifImage moveRight = new GifImage("moveRight.gif");
    GifImage moveLeft = new GifImage("moveLeft.gif");
    
    
        
    public void act() 
    {
       
        checkFall();
        checkFire();
         if (Greenfoot.isKeyDown ("right"))
         {
            move(5); 
            setImage (moveRight.getCurrentImage());
         }
         if (Greenfoot.isKeyDown ("left"))
         {
            move(-5);
            setImage (moveLeft.getCurrentImage());
         }
         if(Greenfoot.isKeyDown("up") && Greenfoot.isKeyDown("right"))
         {
             if(onGround())
             {
                  jump();
             }
             else
             {
                 
             }
             
         }   
         
         if(Greenfoot.isKeyDown("up") && Greenfoot.isKeyDown("left"))
         {
             if(onGround())
             {
                  jump();
             }
             else
             {
             }
             
         }   
         if(Greenfoot.isKeyDown("up"))
         {
             if(onGround())
             {
                  jump();
             }
             else
             {
                 
             }
             
         }   
        }
   public void fall()
    {
        setLocation(getX(), getY() + vSpeed);
        vSpeed = vSpeed + acceleration;
        
    }
    public void checkFire()
   {
       if(Greenfoot.isKeyDown("space")) 
   {
       getWorld().addObject(new kiBlast(), getX(), getY());
    }
    }
   public boolean onGround()
   {
        int spriteHeight = getImage().getHeight();
        int lookForGround = spriteHeight/2;
        
        Actor ground = getOneObjectAtOffset(0, lookForGround, Ground.class);
        
        if(ground == null)
        {
            return false;
        }
        else
        {
            return true;
        }
   }

   public void checkFall()
   {
       if(onGround())
        {
            vSpeed = 0;
        }
        else
        {
            fall();
        }
    }
    
    public void jump()
    {
        vSpeed = -jumpStrength;
        fall();
    }
}
my Ground class is empty and my World class is:
import greenfoot.*;
public class Earth extends World
{

    /**
     * Constructor for objects of class Namek.
     * 
     */
    public Earth()
    {    
        super(1056, 683, 1); 
        addObject( new Goku(), 40, 480);
        addObject( new Ground(), 528, 600);
        addObject( new kiBlast());
    }
}
Yehuda Yehuda

2017/12/12

#
You didn't mention where you have a problem.
danpost danpost

2017/12/13

#
Line 2 should start 'public class'.
You need to login to post a reply.