Skip to content
Snippets Groups Projects
Commit 9aaa5c70 authored by Sarah's avatar Sarah
Browse files

Funktion des Spitters und Erzeugen von Spit-Objekten

parent 64fb2dca
Branches
Tags v1.6.2
No related merge requests found
import greenfoot.*;
public class Interactables extends Actor
{
public void disappear() {
public void disappear()
{
if (isAtEdge()) {
getWorld().removeObject(this);
}
......@@ -11,4 +12,18 @@ public class Interactables extends Actor
Actor actor = getOneObjectAtOffset(0, 0, clss);
return actor != null;
}
public void moveRight() {
setLocation(getX() + 3, getY());
}
public void moveLeft() {
setLocation(getX() - 3, getY());
}
public void move(int speed)
{
double angle = Math.toRadians( getRotation()-90 );
int x = (int) Math.round(getX() + Math.cos(angle) * speed);
int y = (int) Math.round(getY() + Math.sin(angle) * speed);
setLocation(x, y);
}
}
\ No newline at end of file
......@@ -12,9 +12,16 @@ public class Spit extends Spitter
* Act - do whatever the Spit wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public Spit()
{
//turn(90);
turn(Greenfoot.getRandomNumber(180-20)+20);
}
public void act()
{
//moveLeft();
//turn(Greenfoot.getRandomNumber(180));
move(-5);
disappear();
}
}
\ No newline at end of file
......@@ -15,6 +15,13 @@ public class Spitter extends Enemy
public void act()
{
disappear();
cough();
}
private void cough()
{
if(Greenfoot.getRandomNumber(100)<5)
{
getWorld().addObject(new Spit(),(getX()-10),(getY()-40));
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment