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

2017/4/23

I NEED IMMEDIATE HELP

1
2
3
4
5
danpost danpost

2017/4/23

#
Change 'Laser' to 'LaserWall' and correct the spelling of 'connectdLaser'.
Xmin_Terminator Xmin_Terminator

2017/4/23

#
I don't know what names I have, I made some names but when I put hem it came with an error, so could you tell me how to change the names.
danpost danpost

2017/4/23

#
Xmin_Terminator wrote...
I don't know what names I have, I made some names but when I put hem it came with an error, so could you tell me how to change the names.
I cannot give you the names of your files -- you have to provide them. Right click on a class and select the 'set image...' options. Then browse down the images on the left until you spot them. The names should show with them.
Xmin_Terminator Xmin_Terminator

2017/4/24

#
I have gone for an approach without deactivated lasers as they are making it too complicated for me. But I need help. I want to re-position or remove a specific laser when the player touches a specific button, please can you help me.
Xmin_Terminator Xmin_Terminator

2017/4/24

#
public class Player extends Actor
{
   public void act()
   {
       movement();
   }
    
    public Player()
   {
        GreenfootImage myImage = getImage();
        int myNewHeight = (int)myImage.getHeight()/3;
        int myNewWidth = (int)myImage.getWidth()/3;
        myImage.scale(myNewWidth, myNewHeight);
    }
   
    public void movement() 
    {
        if(Greenfoot.isKeyDown("right"))
        {
            setRotation(0);
            if(getOneObjectInFront(Wall.class)==null)
            if(getOneObjectInFront(Maze.class)==null)
            if(getOneObjectInFront(LaserWall.class)==null)
            move(5);
        }
        if(Greenfoot.isKeyDown("left"))
        {
            setRotation(180);
            if(getOneObjectInFront(Wall.class)==null)
            if(getOneObjectInFront(Maze.class)==null)
            if(getOneObjectInFront(LaserWall.class)==null)
            move(5);
        }
        if(Greenfoot.isKeyDown("up"))
        {
            setRotation(270);
            if(getOneObjectInFront(Wall.class)==null)
            if(getOneObjectInFront(Maze.class)==null)
            if(getOneObjectInFront(LaserWall.class)==null)
            move(5);
        }
        if(Greenfoot.isKeyDown("down"))
        {
            setRotation(90);
            if(getOneObjectInFront(Wall.class)==null)
            if(getOneObjectInFront(Maze.class)==null)
            if(getOneObjectInFront(LaserWall.class)==null)
            move(5);
        }
   }
   
   private Actor getOneObjectInFront(Class c)
   {
       GreenfootImage myImage = getImage();
       int distanceToFront = myImage.getWidth();
       int xOffset = (int)Math.ceil(distanceToFront*Math.cos(Math.toRadians(getRotation()))); 
       int yOffset = (int)Math.ceil(distanceToFront*Math.sin(Math.toRadians(getRotation())));
       return (getOneObjectAtOffset(xOffset, yOffset, c));
   }
}
THIS IS THE PLAYER CODE
Xmin_Terminator Xmin_Terminator

2017/4/24

#
The player is the only actor with code, apart from some of the other actors only have code to re-size them.
Xmin_Terminator Xmin_Terminator

2017/4/24

#
I have added the maze with individual blocks for the maze and outer rim, and I have added 20 lasers, and buttons. That is the only code in the world sub-class
Xmin_Terminator Xmin_Terminator

2017/4/24

#
All the lasers and buttons that are added from 1 sub class like you said should be done, not individual actors for each number. I hope you can help me. Maybe even tell me how to upload a scenario, then you can see it for yourself and show me how to sort out the problem. Just a question, are you a sort of official greenfoot helper, you spend your time helping everybody here. I noticed you reply to a lot of people very quickly and lots of people have come out fixing their problem after you help them
danpost danpost

2017/4/24

#
With the following LaserButton class:
import greenfoot.*;

public class LaserButton extends Actor
{
    private static final GreenfootImage locked = new GreenfootImage("lock.png");
    private static final GreenfootImage opened = new GreenfootImage("open.png");
    private LaserWall laser;

    public LaserButton(LaserWall actor)
    {
        laser = actor;
        setImage(locked);
    }

    public void act()
    {
        if (laser.getWorld() != null && isTouching Player.class))
        {
            getWorld().removeObject(laser);
            setImage(opened);
        }
    }
}
you can add objects into the world with code like this:
LaserWall laser = new LaserWall();
addObject(laser, << wherever >>);
LaserButton button = new LaserButton(laser);
addObject(button, << wherever >>); // this button will remove laser added to world two lines up
Repeat with similar code for each set of button and laser to be in your world.
Xmin_Terminator Xmin_Terminator

2017/4/24

#
what is meant by LaserButton, I only have a LaserWall and Button. Do I put it into the LaserWall section?
danpost danpost

2017/4/24

#
I changed the name from Button to LaserButton because the button is specific to controlling the lasers. Also the name of the image files may need adjusting.
Xmin_Terminator Xmin_Terminator

2017/4/24

#
When I put this code in, I get an error saying invalid method declaration; return type required for line 9 of your code underlining the La part of LaserButton
Xmin_Terminator Xmin_Terminator

2017/4/24

#
what are the names that you put that I have to change
Xmin_Terminator Xmin_Terminator

2017/4/24

#
Ok let me rename the button and hen put the code in the button and see where that goes
danpost danpost

2017/4/24

#
For now, you can put double slashes '//' at the beginning of lines 5, 6, 12 and 20 to comment them out .
There are more replies on the next page.
1
2
3
4
5