I'm making a tower defense game and I am still on the first level here are a few things that I would like to know as well as my inquiries regarding the games and my code.
- Since our game works in levels how do I add a stage clear option wherein the random number of enemies STOPS and the game notices that the stage has been cleared and moves on to the next map along with spawning the 2 more characters and more enemies.
- I want to add a random spawn for monsters moving from the right side of the screen to the castle gate: how do I make an AI system that makes the enemy spawn and attack the castle's health? (The castle is part of the background though)
-How do I also make a bullet delay so that the bullet doesn't shoot like railgun but almost like a regular pistol with a delay of 3 secs and how the heck do I make the bullet come out of the gun and not the guy's mouth
-How do I also put a "Game Start" option as well as add a character instantaneously after the word "LEVEL 1" shows up much like the supermario games or pacman.
Attached are my codes and picture of the program so far
here is the Infantry code
Here is for the bullet
I have no code for the enemy yet.
here is what it looks like when I run the game

import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Infantry here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Infantry extends Actor
{
public Infantry()
{
GreenfootImage image = getImage();
image.scale(150, 150);
setImage(image);
}
private double lastShot;
public void act()
{
MouseInfo m = Greenfoot.getMouseInfo();
if(m != null) {
int mouseX = m.getX();
int mouseY = m.getY();
turnTowards(mouseX, mouseY);
}
bulletfeed();
checkFire();
//leave the rest of your player's act method alone
}
public void checkFire()
{
if(Greenfoot.isKeyDown("space"))
{
Bullet b = new Bullet(getRotation());
getWorld().addObject(b, getX(), getY());
b.setRotation(getRotation());
b.move(5);
}
}
public void bulletfeed()
{
if (Greenfoot.isKeyDown("space") && System.currentTimeMillis()>lastShot+3000)
{
getWorld().addObject(new Bullet(getRotation()), getX(), getY());
lastShot = System.currentTimeMillis();
}
}
}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 Bullet()
{
GreenfootImage image = getImage();
image.scale(image.getWidth() - 50, image.getHeight() - 50);
setImage(image);
}
private int direction,speed;
public Bullet(int dir)
{
direction = dir;
speed = 1;
}
//int time=10;
public boolean atWorldEdge()
{
if(getX() < 10 || getX() > getWorld().getWidth() - 10)
return true;
if(getY() < 10 || getY() > getWorld().getHeight() - 10)
return true;
else
return false;
}
private double lastShot;
public void act()
{
setRotation(direction);
move(speed);
move(3);
if (Greenfoot.isKeyDown("space") && System.currentTimeMillis()>lastShot+3000)
{
getWorld().addObject(new Bullet(getRotation()), getX(), getY());
lastShot = System.currentTimeMillis();
}
/*destroyEnemies ();
move(9);
kill();
*/
if (this.atWorldEdge())
{
getWorld().removeObject(this);
}
}
public void destroyEnemies()
{
//"Enemy" can be any class that you want the bullet to destroy.
Actor enemy = getOneIntersectingObject(Enemy.class);
if(enemy != null) {
getWorld().removeObject(enemy);
getWorld().removeObject(this);
}
}
}



