This is my code for the dolphin(the actor shooting the projectile)
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Dolphin here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Dolphin extends Actor
{
/**
* Act - do whatever the Dolphin wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if(Greenfoot.isKeyDown("W"))
{
setLocation(getX(), getY()-6);
}
if(Greenfoot.isKeyDown("S"))
{
setLocation(getX(), getY()+6);
}
if (Greenfoot.isKeyDown("space"))
{
Shoot();
}
}
/**
* Shoot - shoots projectile straight out from dolphin's position.
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void Shoot()
{
getWorld().addObject(new Bubble(), getX(), getY());
}
}
And this is my code for the bubble(the projectile)
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class bubble here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Bubble extends Actor
{
/**
* Act - do whatever the bubble wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
setLocation(getX() + 10, getY());
}
}
