Greenfoot Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

How do you register a key input?

A
public void movement()
if (Greenfoot.isKeyDown("x"))
{
   //code
}
x = right, left, up, down
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you create and call on functions to public void act?

A
Make it =  public void anthingYouWant() 
{
   //code
}

Call on it in public void act = anythingYouWant();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you add movement?

A
public void movement()
{
if(Greenfoot.isKeyDown("right"))
{
    setLocation(getx()+3,getY());
    //or
    setRotation();
    move(5);
}
if(Greenfoot.isKeyDown("left"))
{
   setLocation(getX() -3,getY());
   //or
   setRotation(180);
   move(5);
}
if(Greenfoot.isKeyDown("down"))
{
  setLocation(getX(),getY()+3)
  //or
  setRotation(270);
  move(5);
}
if(Greenfoot.isKeyDown("up"))
{
 setLocation(getX(),getY()-3))
  //or
  setRotation(90);
  move(5);
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to add hit detection? And how to make an object disappear.

A
if (isTouching(x.class))
{
    removeTouching(x.class);
}
x = name of the class you want to remove
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to get a random number generator (RNG).

A
move(Greenfoot.getRandomNumber(20));
turn(Greenfoot.getRandomNumber(180)-90);
//these numbers can be changed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to add sound?

A

Greenfoot.playSound(“pop.wav”);
pop = name of file
wav = file types, could be MP3 ect…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Very complex and annoying random movement

A
if (Greenfoot.getRandomNumber(2) < 1)
        {
            move(1);
        }
        if (Greenfoot.getRandomNumber(10)< 1)
        {
            turn(Greenfoot.getRandomNumber(90)-45);
        }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you add boarder collision?

A
if (getX() == 7)
        {
            turn(180);
        }
        if (getX() == 0)
        {
            turn(180);
        }
        if (getY() == 7)
        {
            turn(180);
        }
        if (getY() == 0)
        {
            turn(180);
        }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you add a scoring system?

A
EXAMPLE
//In counter
public x()
    {
        setImage(new GreenfootImage("0", 20, Color.WHITE, Color.BLACK));
    }
public void x(int amount)
    {
        totalCount += amount;
        setImage(new GreenfootImage("" + totalCount, 20, Color.WHITE, Color.BLACK));
    }
//In player
if (isTouching(Iceberg.class))
        {
            x counter =(x) getWorld().getObjects(x.class).get(0);
            counter.y(1);
    }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the superclass?

A

It’s the main name and the route of other items
They are the:
“World”
“Actor”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the class?

A

The items in the code.
“Ants”
“Rockets”
“Points”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a private property?

A
A single of data that only one class cam use. 
E.g. totalCount; (For a counter)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a comment?

A

Anything with a /** before it and */ after

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a method that runs each frame?

A

The “act()” method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly