SPACE SHOOTER

MORE ENEMIES

ADDING A NEW ENEMY

NEW TAB

Copy The Evil Square Tab

Let's get started by making a new tab for your new class. Think about a good, descriptive name for your enemy. In our example, we'll call it BadCircle. Do not use that name; use a good and descriptive name for your enemy! Copy the code from EvilSquare to this tab.

Go through the code and change all the names. You'll need to change code both in this new tab and in values. There should only be references to this new class's name.

Art

Make sure all the images from Piskel are in your project's data folder. You can check your folder by pressing CTRL-K, or looking on the menu bar for Sketch --> Show Sketch Folder.

In the media tab, you'll need to both declare and initialize the new PImage.


PImage redCircle;


public void loadImages()

{

redCircle = loadImage("redCircle.png");

}

Spawning

  • Go to your main tab and look at the code we used to add EvilSquares. You can do the same for your new enemy type!

DIAGONAL SHOTS

BAD CIRCLE

Making a Projectile with Parameters

  • Create a new projectile class in the Projectiles tab.

  • Give it a name and images as you desire. You can use the RedShot projectile as a reference for enemies, and PlayerShotBasic for the player.

  • Modify the constructor:

    • It should take two additional parameters, xSpeed and ySpeed

    • It should pass those values on using the last two parameters of the super() call


FancyShot(float x, float y, float xSpeed, float ySpeed)

{

super(x, y, fancyShot.width, fancyShot.height, xSpeed, ySpeed);

/* other code */

}


  • In your enemy when you create a bullet, provide it with two additional parameters. For instance, an enemy that makes FancyShots that move diagonally down/left and down/right would be:

objects.add(new FancyShot(x+w/2, y+h, -3, 5);

objects.add(new FancyShot(x+w/2, y+h, 3, 5);


Take a moment to think about each shot's starting starting x and y coordinates. Do you want it coming from the center of the enemy? Left? Right?

For small enemies with fast shots, it's hard to tell. But for big enemies it may make a difference.

ATTACK AND MOVE STYLE IDEAS


Attacking Style

Fires straight line

★★ Fires a shot that accelerates over time

★★ Fires a shot that grows in size over time

★★ Instead of firing shots, it creates enemy ships

★★★ Fires a shot that splits into other shots

★★★ Fires a burst of shots then waits (uses multiple timers)

★★★ Fires at the player

★★★★ Fires shots in an arc or curve

Basic Movement

Moves in a straight line

★★ Periodically move in a random direction

★★ Periodically teleports randomly, but otherwise stationary

★★★ Accelerate or decelerate over time

★★★ Move toward the player


Edge of Screen

Bounce off the edges of the screen

Wrap from one side of the screen to another

★★ Hug the edges of the screen by turning left at each side