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

2012/2/27

New to Greenfoot, please help!

1
2
Dave Dave

2012/2/27

#
Hello, I am completely new to Greenfoot. I have been asked to use this software during my object orientated game design assignment. I need to create a game with at least three levels, a menu explaining the game controls and also some form of power ups, we are allowed to use some existing scenarios built into Greenfoot. Today I tried to modify the Lunar landing scenario, after hours and hours I realised that there is not much support for greenfoot at all! I managed to make an object (Bear) move across the screen and make the rocket disappear when they touch thus creating an enemy by using the tutorial on this site. I am now trying to make the bear travel back across the screen when it reaches the end of the world, however I found I need an animal class for this and I can not find out how to create one of these. (VERY FRUSTRATING) I also obviously need to create a menu and extra levels... this too is proving very difficult due to the simple fact that I am unable to find any information on this. If anyone has any Ideas, Code, Support or answers to my question then PLEASE post as I need as much help as I can possibly get. Thank you very much for your time. Dave.
Omniscience Omniscience

2012/2/27

#
Can you show me the code you use to move the bear? I will be able to help you thereafter.
danpost danpost

2012/2/27

#
You do not "NEED" an Animal class, as you already have a Bear class, which can be modified to make the bear go back and forth across the screen. As far as a menu, check out my scenarios; one is a re-usable menu class. Just copy/paste the two Menu and two SubMenu class files from its folder into your scenario folder to use it. Before doing so, open it up and look at the code in the world class, and see how to create and implement the menu(s); also, look at the different methods within the Menu class to see what public methods are available (most of them are used in the world class somewhere), and maybe play around with it a bit.
Dave Dave

2012/2/28

#
Thanks for your reply guys , like I said any help is appreciated. I will check out some of your scenarios danpost (if you could give me the exact name of the scenario you are recommending to me that would be great). Here is the code I used to move the bear Omniscience: move(4); Actor lander; lander = getOneObjectAtOffset(0, 0, Lander.class); if (lander !=null) { World world; world = getWorld(); world.removeObject(lander); Do you guys also know how to add extra levels? I can probably get away with something simple such as adding more bears on the screen to increase the difficulty on each level. Much appreciated, Dave
Duta Duta

2012/2/28

#
Dave, I recommend (if you haven't already) working through the tutorials - also if this is an assignment the teacher might be able to help you. There is also (as you've obviously discovered) these forums. As for adding extra levels, it really depends (there's more than one way to go about it). What level of course are you doing? (just so I can get some idea of how much detail is needed) EDIT: I'm knackered, so will check this thread tomorrow. Night, world
danpost danpost

2012/2/28

#
In the Bear class, declare an instance integer variable for speed and set it to 4, with
public int speed = 4;
Then before the code you posted for moving the bear, add the following statements
if (getX() < getImage().getWidth() / 2 || getX() > getWorld().getWidth() - getImage().getWidth() / 2) 
{
    speed = -speed; // reverse the direction
    GreenfootImage img = getImage(); // reverse the image
    img.mirrorVertically();
    setImage(img);
} // end of addition
move(speed); // beginning of your code
Lander lander = (Lander) getOneIntersectingObject(Lander.class);
if (lander != null) getWorld().removeObject(lander);
This should work, unless you are adding the bear object real close to the left edge of the window, where it will just shimmy back and forth.
Dave Dave

2012/2/28

#
Thanks you very much danpost! I will be trying this later today as I'm just about to go out the door. I am on BTEC extended diploma in I.T level 3 Duta, I have recently had a college transfer so I am rather behind at the moment and have just been given this game design assignment and that's why I'm panicking. So I thought I would certainly get much better support from you nice people on the forums. Thanks, Dave.
Dave Dave

2012/2/28

#
Hello again guys. I have to thank you danpost for all your help as I can confirm that the code to move the bear back and forth WORKS! (Wooohooo) I also implemented your menu into my game as you recommended but I do have some questions. 1) Is there a way of linking the menu into the game properly because at the moment I can only go onto the menu and back to the game by right clicking on one of the sub world classes and selecting either "new Moon()" or "new MenuWorld" if that makes sense? 2) I know Duta said that there is more than one way of adding levels. Could any of you try and explain to me a simple way of doing this? I am just thinking of adding more teddy bears on the screen for higher levels and making them move even faster somehow as I hope this will be enough for my assignment. As for powerups... I have no idea how to go about that at the moment but will continue with my research. Once again, thank you all for your help! Kind regards, Dave
danpost danpost

2012/2/28

#
Somehow you added the whole scenario into yours. You only wanted to add the JAVA files for the Menu and SubMenu classes. These are: 'Menu JAVA file', and 'SubMenu JAVA file' The 'Menu class' should end up a sub-class of Actor, and the 'SubMenu class' should end up a sub-class of Menu. Use your windows browser and delete the 'MenuWorld' files (should be three of them) within YOUR scenario. (You might be able to just right click on the MenuWorld button and select remove).
Dave Dave

2012/2/29

#
Ok, well what I did was is I pasted the menu code into my scenario but if this is a big problem then I will have to try and add the files after deleting the menu classes I have already made. Do I add the files by going to "My computer"? Thanks, Dave
danpost danpost

2012/2/29

#
The only thing that is a problem is that somehow, you ended up with the world class MenuWorld, which you should not have. You can right click on it and select 'remove', or you can use your windows browser (by going to 'My Computer', go to your scenarios folder, select the 'Moon' scenario (or whatever it is called) and delete the three files that start with 'MenuWorld'. Then, the only thing that needs done is, in your world class 'Moon', create a menu by
menu = new Menu("Menu Label");
menu.add("First item");
menu.add("Second item");
// etc.
addObject(menu, x, y);
// best to place menu close to the top of the screen
This can be done in the world constructor, or when an action takes place to initiate the menu. Do not forget to add a reference to the menu as an instance world object variable
public Menu menu = null;
or the first line above will cause a compilation error (probably something to the effect of not being able to find symbol - variable 'menu'). At this point, you can compile, right click on the Menu object and look at the various methods that are available to change to size, colors, etc. and add what code you desire before the addObject(menu...) line.
Dave Dave

2012/3/1

#
Ok danpost I have deleted the Menuworld files and have added the Menu and Submenu JAVA files, I am now trying to add the code you provided into my "moon" world class. However I keep getting error messages after I try and compile the 5 lines of code you provided me, the error says "class,interface or enum expected" and highlights whichever line of code is on top. I clearly am not putting this code in the right place or order? Sorry about this, I really appreciate your help and I believe I am learning. Dave
danpost danpost

2012/3/1

#
The single line of code I provided should be located as follows
import greenfoot.*
// other imports you may have

public class Moon extends World
{
    public Menu menu = null;
    // other world instance variables you may have

    public Moon()
    {
        // code within your world constructor
        // which may or my not contain the code
        // to create the menu
    }

    // other methods, if any
}
Putting the first line of code in the right place will allow the world to access the menu object at any time (on any act cycle, and with any world method), without having to re-define it.
Dave Dave

2012/3/1

#
Right I managed to put the "public Menu menu = null;" exactly where you said and I put the another 3 lines of code at the bottom here: private void prepare() { menu = new Menu("Menu Label"); menu.add("First item"); menu.add("Second item"); Enemy enemy = new Enemy(); addObject(enemy, 60, 349); Now that just leaves the "addObject(menu, x, y);" which I believed you said to try and place at the top of the screen well I have tried adding this line of code to in almost every place and I normally get the error message stating "cannot find symbol - variable x" Could you just explain to me where I add this final piece of code? Many thanks, Dave
danpost danpost

2012/3/2

#
The line 'addObject(menu, x, y);' can be put anywhere in your code. Normally right after the last Menu method call (in this case, 'menu.add("Second item");'). The x and y in this statement are to be replaced with the x and y coordinates in your world where you want to object to be located (just like the Strings '"Menu Label"', '"First item"', and '"Second item"' are to be replaced with meaningful labels for what you want the menu to do). And what I meant by placing it at the top of the screen is this, choose a 'y' value that is low so that the menu itself appears near the top of your world window. That way, when the 'Main label' is clicked on, it has room to drop down the menu items.
There are more replies on the next page.
1
2