diff --git a/Interactables.java b/Interactables.java index fb81fb3f87426bbbc8ad78553d460a8bc5c31d72..e880fcb7bd374cfe032566f0dfa77a862061a48d 100644 --- a/Interactables.java +++ b/Interactables.java @@ -1,7 +1,8 @@ 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 diff --git a/Spit.java b/Spit.java index 3760016aa8667be6e372dceb7035e88a850634c0..615aa13abe54c47f208e01ad0c50c9d33ca666a4 100644 --- a/Spit.java +++ b/Spit.java @@ -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 diff --git a/Spitter.java b/Spitter.java index d71949455baa37edf145891f44fb362bc6a62d3c..985c953b0430554c5b47861557ba4dd28ff7568a 100644 --- a/Spitter.java +++ b/Spitter.java @@ -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)); + } + } }