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

2017/1/2

User Input - Storage

1
2
3
4
5
6
JulianYoung JulianYoung

2017/1/4

#
I have other world used as menu and the like and they still run just not that one. hmm still looking will gt back in a few mins
JulianYoung JulianYoung

2017/1/4

#
ok i have commeted out lots of the work and now is working. i will start adding it again and see at what point an error is caused.
JulianYoung JulianYoung

2017/1/4

#
Not sure what is causing the error. I think its something to do with the chests and bandits and their creation creation. i have attached the run button the game world (with the sections commented that dont work).
import greenfoot.*;

/**
 * Write a description of class Game here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Game extends World
{
  public Move_Sideways horizontalRangeBox, verticalRangeBox;
  
   public static Actor chest;
    /**
     * Constructor for objects of class Game.
     * 
     */
    public Game()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(500, 500, 1); 
        Player player = new Player();
        addObject(player, 125,125 );

        Chest_counter ccounter = new Chest_counter();
        addObject(ccounter, 45,150 );

        Money_Counter MOcounter = new Money_Counter();
        addObject(MOcounter, 45,250 );

        Move_Counter Mcounter = new Move_Counter();
        addObject(Mcounter, 45,300 );        

        Bandit_counter bcounter = new Bandit_counter();

        Up_Down up = new Up_Down();
        addObject(up, 133,75 );
        Sideways side = new Sideways();
        addObject(side, 133,25 );
        addObject(bcounter, 45,200 );

        Run_Button rbutton = new Run_Button();
        addObject(rbutton, 375,50 );

        Run run = new Run();
        addObject(run, 450,50 );
/*
        for(int b =1; b<11;b++){
            int g = Greenfoot.getRandomNumber(8);
            int c = Greenfoot.getRandomNumber(8);
            g=(g+1)*50+75;
            c=(c+1)*50+75;
            // starting place for player is 125,125
            if(g==125&&c==125){
                g=g+50;
                c=c+50;

            }
            if (getObjectsAt(g, c, Chest.class).isEmpty())
            {
                Chest chest = new Chest();
                addObject(chest, g, c);
            }
            else b--;                                                           
        }

        for(int d =1; d<6;d++){
            int e= Greenfoot.getRandomNumber(8);
            int f = Greenfoot.getRandomNumber(8);
            e=(e+1)*50+75;
            f=(f+1)*50+75;
            if(e==125&&f==125){
                e=e+50;
                f=f+50;

            }
            if (getObjectsAt(e, f, Bandit.class).isEmpty())
            {
                Bandit bandit = new Bandit();
                addObject(bandit, e, f);
            }
            else d--;                                                           
        }
*/
        horizontalRangeBox = new Move_Sideways();
        addObject(horizontalRangeBox,250,75);
       verticalRangeBox = new Move_Sideways();

        addObject(verticalRangeBox,250,25);

    }
}

run button
import greenfoot.*;

/**
 * Write a description of class Run_Button here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Run_Button extends Actor
{
    /**
     * Act - do whatever the Run_Button wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        if (Greenfoot.mouseClicked(this)) {

            Player.a=1;
            Move_Counter.moves=Move_Counter.moves+1;
            Game world = (Game)getWorld();
            
              
            //Move_Sideways horizontalRangeBox = world.horizontalRangeBox;
           // Move_Sideways verticalRangeBox = world.verticalRangeBox;
            //System.out.println("\nHorizontal range given: '"+horizontalRangeBox.getValue()+"'\nVertical range given: '"+verticalRangeBox.getValue()+"'");

            // x and y and the value to change position of player.
          
             // Player.x=horizontalRangeBox.getValue()
             // player y=verticalRangeBox.getValue()
             

        }
    }    
}
JulianYoung JulianYoung

2017/1/4

#
okay i have narrowed it down. when i took out the lines that make sure the actors don't spawn on each other it works. i have reattached them below and they are still in my one above.
  if (getObjectsAt(g, c, Chest.class).isEmpty())
            {
                Chest chest = new Chest();
                addObject(chest, g, c);
            }
            else b--;  

if (getObjectsAt(e, f, Bandit.class).isEmpty())
            {
                Bandit bandit = new Bandit();
                addObject(bandit, e, f);
            }
            else d--;                                                           
        }
help would be greatly appreciated. thanks
JulianYoung JulianYoung

2017/1/4

#
Also now that its working i was able to test being able to use the user inputs elsewhere and it works great! Thanks for that.
JulianYoung JulianYoung

2017/1/4

#
Also can i add an image without using an image link as i want to add a picture of what it looks like but its a snipping tool image.
danpost danpost

2017/1/4

#
JulianYoung wrote...
can i add an image without using an image link as i want to add a picture of what it looks like but its a snipping tool image.
If you are referring to adding an image to a post on this discussion thread, the image must be uploaded to an active webpage and its url (of the image -- not the page) needs to be linked via 'image' tags. There are several places that you can upload an image. Two of these are 'tinypic.com' and 'imgur.com'.
JulianYoung JulianYoung

2017/1/4

#
OK. Also do you know why that code was not working or if you dont are there any alternative pieces of code i can put in to make them not spawn on each other
danpost danpost

2017/1/4

#
Okay, you narrowed it down to the code I supplied. You have 64, well -- 63, places for 10 chests. I cannot see how that would cause any issues unless your chest images are huge (the rectangular frame of the images). What is the size of the image used by your Chest objects?
JulianYoung JulianYoung

2017/1/4

#
here is how its looking so far. Work so far
JulianYoung JulianYoung

2017/1/4

#
danpost wrote...
Okay, you narrowed it down to the code I supplied. You have 64, well -- 63, places for 10 chests. I cannot see how that would cause any issues unless your chest images are huge (the rectangular frame of the images). What is the size of the image used by your Chest objects?
okay i know where the problem might be then. The image its self is huge so to compensate in my chest section have this code.
 GreenfootImage image = getImage();  
        image.scale(30, 30);       
        setImage(image);
could it be this causing the problem?
danpost danpost

2017/1/4

#
Try resizing the image externally so that you can remove the scaling code given above. (like, load it into Paint and reduce the size there and save it) Then try it to see if it was the problem.
JulianYoung JulianYoung

2017/1/4

#
YAY! It works!!!!!!!! i resized the image of the original chest and now its working fine and i have put back the code and all is good!
JulianYoung JulianYoung

2017/1/4

#
Also for some reason my hit detection with the person hitting the chest has started to work. YAY! . I don't think i have any more problems but if i do i will post them. Thank you very much for your help!
danpost danpost

2017/1/4

#
I thought it might work. My last suggestion about Paint was not good. Paint does not have a resizing feature. Photoshop may, however. What did you use?
There are more replies on the next page.
1
2
3
4
5
6