I want the bullets to shoot at in interval. Something like the binding of isaac. How can I make that? This is my code
And this is the bullet subclass
I dont know how to make it so that it moves at in interval because I have seen some suggestions, but I have a diferent kind of bullet code and i just simply cannot make it work on my own. Please help!
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class player extends Actor
{
public void act()
{
if(Greenfoot.isKeyDown("w"))
{
int x = getX();
int y = getY();
int ny = getY()-2;
setLocation(x,ny) ;
setImage("player sus1.png");
}
if(Greenfoot.isKeyDown("s"))
{
int x = getX();
int y = getY();
int ny = getY()+2;
setLocation(x,ny) ;
setImage("player jos1.png");
}
if(Greenfoot.isKeyDown("a"))
{
int x = getX()-2;
int y = getY();
int ny = getY();
setLocation(x,ny) ;
setImage("player stanga1.png");
}
if(Greenfoot.isKeyDown("d"))
{
int x = getX()+2;
int y = getY();
int ny = getY();
setLocation(x,ny) ;
setImage("player dreapta1.png");
}
if (Greenfoot.isKeyDown("up"))
{
firew();
}
if (Greenfoot.isKeyDown("down"))
{
fires();
}
if (Greenfoot.isKeyDown("left"))
{
firea();
}
if (Greenfoot.isKeyDown("right"))
{
fired();
}
}
private void firew()
{
bullet bullet = new bullet();
getWorld().addObject(bullet, getX(), getY());
bullet.setRotation(270);
}
private void fires()
{
bullet bullet = new bullet();
getWorld().addObject(bullet, getX(), getY());
bullet.setRotation(90);
}
private void firea()
{
bullet bullet = new bullet();
getWorld().addObject(bullet, getX(), getY());
bullet.setRotation(180);
}
private void fired()
{
bullet bullet = new bullet();
getWorld().addObject(bullet, getX(), getY());
bullet.setRotation(0);
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class bullet here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class bullet extends Actor
{
public void act()
{
move(5);
}
}
