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

2020/1/20

Collecting 3 key, avoiding enemies, and creating a labyrinth

Jaisdreval Jaisdreval

2020/1/20

#
So I have to finish this game pretty much right now. Problem is.. I don't know how to program. I want to make a labyrinth in which you navigate a Gecko named Oitka, who collects 3 keys to finish the level while avoiding guards. However, I only know how to make it so Oitka moves. I literally cannot begin to understand how to do anything else, especially not making the walls stand in their place immediately, making the game show all the coins, or even restarting the game when Oitka touches a guard. I really don't want to ask random people online to make a whole game for me but I just really need help here. I can't let me and my two partners who literally hava no time right now and don't know anything about this either fail the class because of this. This is what I have so far: World:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class School here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class School extends World
{

    /**
     * Constructor for objects of class School.
     * 
     */
    public School()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(800, 600, 1); 
    }
}
Oitka:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Oitka here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Oitka extends Actor
{
    /**
     * Act - do whatever the Oitka wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act()
    {
        if(Greenfoot.isKeyDown("A"))
        {
            turn(-50);
    }
        if(Greenfoot.isKeyDown("D"))
        {
            turn(50);
    }
        if(Greenfoot.isKeyDown("W"))
        {
            move(-50);
    }
        if(Greenfoot.isKeyDown("S"))
        {
            move(50);
    }
}
}
Key:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Key here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Key extends Actor
{
    /**
     * Act - do whatever the Key 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.
    }    
}
Wall: 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 { private int steigung; public Wall() { steigung = Greenfoot.getRandomNumber(30)+31; } public int getSteigung() { return steigung; } /** * 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. } } I would be enternally grateful for any help!!
danpost danpost

2020/1/21

#
This tutorial page has a section on Saving the World, which allows your actors to be immediately initialized.
You need to login to post a reply.