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

2015/4/12

Setting certain osition by field & how to make actor appear in another world stepping on certain place !

1
2
Noa´RyiKarOOzo Noa´RyiKarOOzo

2015/4/12

#
Hello everyone, I was wondering on how to make an object appear on ceratin place by field, you know just to give him a position on scenario by adding him into a field . For example i would like to have an free path (0), an actor (1), multiple blocks that represent a wall (2), multiple traps (3) and also a finish that will take my actor into another world and there would be the same . I can´t figure out how can do this all. I´ve recently started working with greenfoot so i might be bad atunderstanding. Sorry if i might be confused from any advise that you might give me. Have a nice day and thanks for any help ! Noa´RyiKarOOzo
danpost danpost

2015/4/12

#
My JerrooFoot Application scenario has an example of using maps and arrays to build a world with.
Noa´RyiKarOOzo Noa´RyiKarOOzo

2015/4/12

#
Hello danpost, Thank you for your help. I was wondering about it. Really thank you Sir.
Noa´RyiKarOOzo Noa´RyiKarOOzo

2015/4/12

#
Maybe it will sound strange and it maybe is, but how can i make it work in GreenFoot?
danpost danpost

2015/4/12

#
Noa´RyiKarOOzo wrote...
Maybe it will sound strange and it maybe is, but how can i make it work in GreenFoot?
Actually, that linked scenario is in Greenfoot. It just acts similar to the Jeroo java learning app. The Map class is the main concern for you and how the JerooWorld uses it to create its worlds.
Noa´RyiKarOOzo Noa´RyiKarOOzo

2015/4/12

#
Oh, i see now. Thank you for the knowledge, but i am afraid i can´t see it working. I just can´t run the program correctly. Would you be so kind and post the code here? It would help me a lot if it is not bothering you. I am really sorry about that.
danpost danpost

2015/4/12

#
Just click the big green "Open in Greenfoot" button just above and to the right of the scenario window and "Save" it. Move it from your 'downloads' folder to your greenfoot 'scenarios' folder. Open the Greenfoot IDE and from the menubar select 'Scenarios>Open...' and select the jar file. It will unzip it and allow you to see the codes for each of the classes within the project.
Noa´RyiKarOOzo Noa´RyiKarOOzo

2015/4/18

#
Hello, Could you help me with a little project of mine? It is quite simple i promise. I am making a game where you are in world 1. You have to approach a path between walls and move around traps, if you get to a certain place (it is elevator picture) you get to another "world", let´s say world 2 and there you have to get to the same Picture. As you get there it shows how much healthbars you lost (you have maximum of 3 heathbars) and what time did it také you to get there throught these two worlds. Could you please help me with this, i have got something prepared but it will probably need correction.
Noa´RyiKarOOzo Noa´RyiKarOOzo

2015/4/18

#

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

/**
 * Write a description of class Svet1 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Svet1 extends World
{
    private PocZiv Zivoty;
    public PocZiv getZivoty(){
        return Zivoty;
    }
    /**
     * Constructor for objects of class Svet1.
     * 
     */
    public Svet1()

    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(1300, 900, 1); 
        
        Hrac h = new Hrac ();
        
         this.addObject (h, 1200,800);
         
        Past p = new Past ();
        
        Blok b = new Blok ();
        
        Cil  c = new Cil  ();
        
        Zivoty z = new Zivoty ();
        
        PocZiv pz = new PocZiv ();
        
        Zivoty = new PocZiv ("Počet zbývajících životů :");
        
        addObject(Zivoty,100,10);
        
             for (int i = 0; i< 40; i++){
                       
             int X = Greenfoot.getRandomNumber (getX());
             int Y = Greenfoot.getRandomNumber (getY());
          
            
            this.addObject(new Bod(),(i+1)*X,(i+1)*Y);       
     
            if (i/2 ==0){

            int alpha = Greenfoot.getRandomNumber (getX()); ;
            int beta = Greenfoot.getRandomNumber (getY());;
            this.addObject(new Bod(),(i+1)*alpha/10,(i+1)*beta/10);      
     
       }
    }
   }
}
Noa´RyiKarOOzo Noa´RyiKarOOzo

2015/4/18

#
This is the wordl 1 called Svet 1 in my native language, Hrac is an actor (it means gamer), Past is simply a trap, Blok is wall. Also there are some other types like Zivoty - your health bars, PocZiv - these are the numbers of it (the healthbars) and than Cil - the place where it will "move you" to the world 2 - Svet 2
Noa´RyiKarOOzo Noa´RyiKarOOzo

2015/4/18

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

/**
 * Write a description of class PocZiv here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class PocZiv extends Actor
{   public void kresli (){
        setImage(new GreenfootImage (text - hodnota, 20, Color.RED, Color. GREEN));
     }
    public int snizeniHodnoty (int oKolik){
        hodnota -= oKolik;
        return hodnota;
        kresli();
    }
    public void Počitadlo(String text){
        hodnota = 5;
        this.text = text;
         kresli();
    }
    /**
     * Act - do whatever the PocZiv 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.
      
      }    
}
Noa´RyiKarOOzo Noa´RyiKarOOzo

2015/4/18

#
This is my PocZiv class - i created it for purpose of showing the number of the healthbars you currently have.
Noa´RyiKarOOzo Noa´RyiKarOOzo

2015/4/18

#
Than there is the Hrac (actor, gamer) class. It is simple.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Hrac here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Hrac extends Actor
{
    /**
     * Act - do whatever the Hrac 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.
        
        if(Greenfoot.isKeyDown("right")) {
            //move(3);
            setLocation(getX()+3, getY());
       }    
      
       if(Greenfoot.isKeyDown("left")) {
           //move(-3);
           setLocation(getX()-3, getY());
       }
       if(Greenfoot.isKeyDown("up")) {
           //move(-3);
             setLocation(getX(), getY()-3);
       }
       if(Greenfoot.isKeyDown("down")) {
             //move(-3);
            setLocation(getX(), getY()+3);
       }
        
         if(isTouching(Past.class)){
       PocZiv--;
       removeTouching(Past.class);
       
       
    }    
    }    
}
Noa´RyiKarOOzo Noa´RyiKarOOzo

2015/4/18

#
The last class i have code in is the Healt class (Zivoty)
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Zivoty here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Zivoty extends Actor
{
    /**
     * Act - do whatever the Zivoty 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.
         Zivot z = new Zivot ();
         int X = Greenfoot.getRandomNumber (getX());
             int Y = Greenfoot.getRandomNumber (getY());
             
        if (isTouching(Hrac.class)){
              
                removeTouching(Zivoty.class);
              PocZiv++;
        
              }
    }    
}
Noa´RyiKarOOzo Noa´RyiKarOOzo

2015/4/18

#
All othere classes i have mentioned are created, but nothing is in them at the moment. If i will et on to something i will try to post it.
There are more replies on the next page.
1
2