SpaceShooter

SpaceShooter is a simple game where you are a Jet and you have to maneuver and shoot your way through the rockets that are coming at you, the player uses “W” to go up, “A” to go left, “S” to go down, and “D” to go right, and pressing the space bar fires the missiles.

gameplay

The enemies come down at the player from the top of the screen and more are progressively spawned in as time goes on, if the player hits an enemy, the player dies and the game stops.

Collision:

public void hitDetection()
{
Actor a = getOneIntersectingObject(Enemy.class);
if (a != null)
{
getWorld().removeObject(this);
}
}

Spawning:

public void createenemy()
{
Random generator = new Random();
Random r = new Random();
Random numGen =new Random();
int randomInt;
randomInt = generator.nextInt(2)+1;
GravityWorld gworld = (GravityWorld) getWorld();
if (gworld.getTime() % 1000 == 0)
{
gworld.addObject(new Enemy(),gworld.getWidth()-20,gworld.getHeight()-250);
spawnfactor -=1;
}
gworld.incTime();
}

The player(Jet) can fire missiles from both wings of the jet at the enemy which will kill the enemies and remove itself from the world when they collide.

Firing:

public void shoot(){
if (frameCounter>=15){
if (Greenfoot.isKeyDown("space")){
Bullet b = new Bullet(this.getRotation());
Bullet c = new Bullet(this.getRotation());
getWorld().addObject(b, getX()+20, getY()+20);
getWorld().addObject(c, getX()-20, getY()+20);
}
frameCounter=0;
}

The world or background of the game is just a picture of clouds to make you feel high up while playing the game.

OLYMPUS DIGITAL CAMERA

The player has 2 different pictures associated with it, the normal jet picture, and one with flames behind it which activates when you press “W” on the keyboard.

SmallerShip2(flames)

SmallerShip2

and the code for changing the picture:

private GreenfootImage w = new GreenfootImage("SmallerShip2(flames)(border).png");
private GreenfootImage default = new GreenfootImage("SmallShip.png");

if (Greenfoot.isKeyDown(“w”))
{
setLocation(getX(),getY()-the);
setImage(w);
}
else
{
setImage(Default);
}

Link to the game:
SpaceShooter2

Leave a Reply

Your email address will not be published. Required fields are marked *