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

2017/4/23

I NEED IMMEDIATE HELP

6
7
8
9
10
11
Xmin_Terminator Xmin_Terminator

2017/5/3

#
danpost gave me code to do something, you can view the code above, we were working on the walls, where I used his code, maybe you can find a problem of how I put it in.
Xmin_Terminator Xmin_Terminator

2017/5/3

#
Oh greenfoot seemed to save an old version just before I put the code, probably due to errors
danpost danpost

2017/5/3

#
Xmin_Terminator wrote...
Oh greenfoot seemed to save an old version just before I put the code, probably due to errors
Once you get your glitch figured out, you can do similarly with the Maze objects like we did with the Wall objects here. I carefully looked over the code I provided and did not see anything that would cause any compiling issues. It may be something you did (or did not do) while implementing the code I provided.
Xmin_Terminator Xmin_Terminator

2017/5/4

#
maybe it interfered with what I did, and my code caused a problem
Xmin_Terminator Xmin_Terminator

2017/5/4

#
Why does the scoreCounter not stop when the player reaches the end of the game (touches the endPad) the player stops moving using the same variable I have made, but that variable isn't stopping the actCycles, which is meaning that the actCycles is making the player keep on loosing score even after they complete the game.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
 * Write a description of class Player here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Player extends Actor
{
   public int stopMoving = 0;
   public void endTheGame()
   {
       Actor EndPad = getOneObjectInFront(EndPad.class);
       if(EndPad != null)
       {
          stopMoving = 1;
       }
   }
   
   public void act()
   {
       movement();
       getPoints();
       endTheGame();
   }
    
   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)
          if(stopMoving == 0)
          move(3);
       }
       if(Greenfoot.isKeyDown("left"))
       {
          setRotation(180);
          if(getOneObjectInFront(Wall.class)==null)
          if(getOneObjectInFront(Maze.class)==null)
          if(getOneObjectInFront(LaserWall.class)==null)
          if(stopMoving == 0)
          move(3);
       }
       if(Greenfoot.isKeyDown("up"))
       {
          setRotation(270);
          if(getOneObjectInFront(Wall.class)==null)
          if(getOneObjectInFront(Maze.class)==null)
          if(getOneObjectInFront(LaserWall.class)==null)
          if(stopMoving == 0)
          move(3);
       }
       if(Greenfoot.isKeyDown("down"))
       {
          setRotation(90);
          if(getOneObjectInFront(Wall.class)==null)
          if(getOneObjectInFront(Maze.class)==null)
          if(getOneObjectInFront(LaserWall.class)==null)
          move(3);
       }
   }
   
   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));
   }
   
   public void getPoints()
    {
       Actor Points = getOneIntersectingObject(Points.class);
       if(Points != null)
       {
          World myWorld = getWorld();
          myWorld.removeObject(Points);
          Background1 background1 = (Background1)myWorld;
          ScoreCounter scoreCounter = background1.getScoreCounter();
          scoreCounter.addScore();
       }
   }  
}
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
 * Write a description of class Background1 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Background1 extends World
{
    ScoreCounter scoreCounter = new ScoreCounter();
    public int stopMoving;
    public int actCycles = -300;
    public void countingCycles() 
    {
        actCycles++;
        if (actCycles == 30)
        {
            getScoreCounter().loseScore();
            actCycles = 0;
            if(stopMoving == 1)
            {
                actCycles = 31;
            }
        }
    }   
    
    public void act()
    {
        countingCycles(); 
    }
   
    /**
     * Adds objects for background1.
     */
    public Background1()
    {    
        super(1400, 800, 1);
        outlineOfMaze();
        mazeParts();
        addLaserWalls();
        prepare();
        addCharacters();
        addPoints();
    }
    
    public ScoreCounter getScoreCounter()
    {
        return scoreCounter;
    }
As you know the rest of the world is adding actors to it.
Xmin_Terminator Xmin_Terminator

2017/5/4

#
When I put ur code in it still comes up with the infinite loop error, I don't know what to do?
danpost danpost

2017/5/4

#
Xmin_Terminator wrote...
Why does the scoreCounter not stop when the player reaches the end of the game (touches the endPad) the player stops moving using the same variable I have made, but that variable isn't stopping the actCycles, which is meaning that the actCycles is making the player keep on loosing score even after they complete the game.
Because the 'stopMoving' field in your Background class is not the same field as the one in your Player class. They have the same name, but are two distinctly different fields. Remove lines 11 from the Background class and change line 20 to;
if (((Playeer)getObjects(Player.class).get(0)).stopMoving == 1)
danpost danpost

2017/5/4

#
Xmin_Terminator wrote...
When I put ur code in it still comes up with the infinite loop error, I don't know what to do?
Show how you put the code in. Show the revised method in the world class and the constructor of what you are creating within that method.
Xmin_Terminator Xmin_Terminator

2017/5/4

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Wall here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Wall extends Actor
{
    public Wall()
    {
        GreenfootImage myImage = getImage();
        int myNewHeight = (int)myImage.getHeight()/2;
        int myNewWidth = (int)myImage.getWidth()/2;
        myImage.scale(myNewWidth, myNewHeight);
    }
    
    public Wall(int count, boolean inverted)
    {
        GreenfootImage tile = getImage();
        tile.scale(25, 25);
        int x = 1, y = 1;
        if (inverted) y = count; else x = count;
        GreenfootImage image = new GreenfootImage(x*25, y*25);
        for (int j=0; j<y; j++) for (int i=0; i<x; x++) image.drawImage(tile, i*25, j*25);
        setImage(image);
    }
    
    /**
     * Act - do whatever the Wall wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        // Add your action code here.
    }    
}
this is the world class,
private void outlineOfMaze()
    {
        addObject(new Wall(55, false), (0+55)*25/2, 12+0*25);
        addObject(new Wall(55, false), (1+56)*25/2, 12+31*25);
        addObject(new Wall(31, true), 12*0*25, (0+31)*25/2);
        addObject(new Wall(31, true), 12*55*25, (1+32)*25/2);
    }
and I have put outlineofmaze in the world class, I think it is called calling the method or something like that.
/**
     * Adds objects for background1.
     */
    public Background1()
    {    
        super(1400, 800, 1);
        outlineOfMaze();
        mazeParts();
        addLaserWalls();
        prepare();
        addCharacters();
        addPoints();
    }
danpost danpost

2017/5/4

#
I found the problem with my code. In the Wall class, at line 26, change 'x++' to 'i++'.
Xmin_Terminator Xmin_Terminator

2017/5/4

#
I am not having problem with multiple actors, I believe the problem was that I downloaded some scenarios from the website to play around an get some ideas, and that filled space. I will use your code that adds the multiple objects in without the huge amount of lines.
Xmin_Terminator Xmin_Terminator

2017/5/4

#
oh ok let me try that then, just in case
Xmin_Terminator Xmin_Terminator

2017/5/4

#
the co-ordinates are not on point but I think I can adjust them
danpost danpost

2017/5/4

#
You can use this:
public void outlineOfMaze()
{
    addObject(new Wall(55, false), (0+55)*25/2, 12+0*25);
    addObject(new Wall(55, false), (1+56)*25/2, 12+31*25);
    addObject(new Wall(31, true), 12+0*25, (1+32)*25/2);
    addObject(new Wall(31, true), 12+55*25, (0+31)*25/2);
}
Xmin_Terminator Xmin_Terminator

2017/5/4

#
Oh, just fixed it...... I just changed the number a but to adjust, trying to understand it myself
There are more replies on the next page.
6
7
8
9
10
11