Skip to content
Snippets Groups Projects
Commit a6df44cb authored by sn3-qsk-u1's avatar sn3-qsk-u1
Browse files
parents 5ad67766 fd862dd8
No related branches found
No related tags found
No related merge requests found
import greenfoot.*; import greenfoot.*;
public class Interactables extends Actor public class Interactables extends Actor
{ {
public void disappear() { public void disappear()
{
if (isAtEdge()) { if (isAtEdge()) {
getWorld().removeObject(this); getWorld().removeObject(this);
} }
...@@ -11,4 +12,18 @@ public class Interactables extends Actor ...@@ -11,4 +12,18 @@ public class Interactables extends Actor
Actor actor = getOneObjectAtOffset(0, 0, clss); Actor actor = getOneObjectAtOffset(0, 0, clss);
return actor != null; 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 ...@@ -12,9 +12,16 @@ public class Spit extends Spitter
* Act - do whatever the Spit wants to do. This method is called whenever * Act - do whatever the Spit wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment. * the 'Act' or 'Run' button gets pressed in the environment.
*/ */
public Spit()
{
//turn(90);
turn(Greenfoot.getRandomNumber(180-20)+20);
}
public void act() public void act()
{ {
//moveLeft();
//turn(Greenfoot.getRandomNumber(180));
move(-5);
disappear(); disappear();
} }
} }
\ No newline at end of file
...@@ -15,6 +15,13 @@ public class Spitter extends Enemy ...@@ -15,6 +15,13 @@ public class Spitter extends Enemy
public void act() public void act()
{ {
disappear(); 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