Class InvadersWorld

java.lang.Object
  extended by World
      extended by InvadersWorld

public class InvadersWorld
extends World

InvadersWorld: A styled and fun Space Invaders clone. Special feature: multiplayer mode: two humans can play with one keyboard, sending waves of spaceships into battle against each other.


Field Summary
protected static int BAR_HEIGHT
          Health bars' height.
protected static int BAR_WIDTH
          Health bars' width.
static int BLACK
           
protected  HealthBar blackBar
           
 int[] chance
          Array[N_SIDES]: Denominator for probability P for spaceship creation.
 int[] coll_chance
          Array[N_SIDES]: Denominator for probability P for collectible creation.
protected  CollectibleFactory[] collFactory
           
protected  java.util.ArrayList destroyList
          List containing objects that need destruction at the start of the next turn.
protected static int DISTANCE
          Distance of health bars to game field edges.
protected  SpaceshipFactory[] factory
           
protected static int HEIGHT
          Game field height.
protected static boolean MULTIPLAYER
          Magic variable altering the game's behavior.
static int N_SIDES
          Number of sides participating in the game.
protected  int next_turn_winner
          if it is clear that one side wins or loses (within a Greenfoot turn), this variable is set to the side of the winner.
 boolean[] player
          Array[N_SIDES]: true if the corresponding side is a human player, false if they're AI.
 boolean[] player_generates_spaceships
          Array[N_SIDES]: true if the corresponding side should generate & send out autonomous spaceships.
protected static int STARTING_ZONE
          Size of the zone at the upper and lower edge of the playfield where new spaceships can be created.
static int WHITE
           
protected  HealthBar whiteBar
           
protected static int WIDTH
          Game field width.
 
Constructor Summary
InvadersWorld()
           
InvadersWorld(int worldWidth, int worldHeight, int cellSize)
          InvadersWorld constructor.
 
Method Summary
 void act()
          Actions that a world just has to perform.
 void addObjectToDestroy(QuantumObject obj)
           
 void createCollectible(int x, int y, int c_side)
          Uses the side's collectible factory to get a random collectible.
 void gameOver(int winner)
          Called when the game is totally over, this method displays an end screen.
 void gameOverNextTurn(int winner)
           
 void maybeCreateCollectible(int x, int y, int c_side)
          Usually called by dying spaceships, this rolls a dice and maybe creates a collectible at that very place.
 void setHealthBar(int side, int value)
           
 void setHealthBar(int side, int value, int max_value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MULTIPLAYER

protected static final boolean MULTIPLAYER
Magic variable altering the game's behavior. If set to true, multi-player mode is enabled!

See Also:
Constant Field Values

WIDTH

protected static final int WIDTH
Game field width.

See Also:
Constant Field Values

HEIGHT

protected static final int HEIGHT
Game field height.

See Also:
Constant Field Values

BAR_WIDTH

protected static final int BAR_WIDTH
Health bars' width.

See Also:
Constant Field Values

BAR_HEIGHT

protected static final int BAR_HEIGHT
Health bars' height.

See Also:
Constant Field Values

DISTANCE

protected static final int DISTANCE
Distance of health bars to game field edges.

See Also:
Constant Field Values

STARTING_ZONE

protected static final int STARTING_ZONE
Size of the zone at the upper and lower edge of the playfield where new spaceships can be created.

See Also:
Constant Field Values

WHITE

public static final int WHITE
See Also:
Constant Field Values

BLACK

public static final int BLACK
See Also:
Constant Field Values

N_SIDES

public static final int N_SIDES
Number of sides participating in the game. Usually 2, still written as a constant for clearer code.

See Also:
Constant Field Values

factory

protected SpaceshipFactory[] factory

collFactory

protected CollectibleFactory[] collFactory

player

public boolean[] player
Array[N_SIDES]: true if the corresponding side is a human player, false if they're AI.


player_generates_spaceships

public boolean[] player_generates_spaceships
Array[N_SIDES]: true if the corresponding side should generate & send out autonomous spaceships. Usually true for the computer enemy or for both sides in 2-player mode.

See Also:
act()

chance

public int[] chance
Array[N_SIDES]: Denominator for probability P for spaceship creation. I. e., chance for a spaceship being generated each turn is 1/chance[side].

See Also:
act()

coll_chance

public int[] coll_chance
Array[N_SIDES]: Denominator for probability P for collectible creation. I. e., chance for a collectible being generated for each destroyed spaceship is 1/coll_chance[side].

See Also:
maybeCreateCollectible(int x, int y, int c_side), createCollectible(int x, int y, int c_side)

destroyList

protected java.util.ArrayList destroyList
List containing objects that need destruction at the start of the next turn. (Currently unused, if I am informed correctly.)


blackBar

protected HealthBar blackBar

whiteBar

protected HealthBar whiteBar

next_turn_winner

protected int next_turn_winner
if it is clear that one side wins or loses (within a Greenfoot turn), this variable is set to the side of the winner. InvadersWorld.act() will act thereafter.

See Also:
act()
Constructor Detail

InvadersWorld

public InvadersWorld()

InvadersWorld

public InvadersWorld(int worldWidth,
                     int worldHeight,
                     int cellSize)
InvadersWorld constructor. Creates and initializes all objects that are necessary for gameplay. The section that creates the two manually controlled spaceships might be of special interest. They're marked in the source code.

Method Detail

setHealthBar

public void setHealthBar(int side,
                         int value)

setHealthBar

public void setHealthBar(int side,
                         int value,
                         int max_value)

act

public void act()
Actions that a world just has to perform. Main things: 1. Create random spaceships. 2. Delete objects in the deletion list. 3. End the game if necessary. TODO: Increase difficulty (i. e. ship levels, probabilities) over time.


maybeCreateCollectible

public void maybeCreateCollectible(int x,
                                   int y,
                                   int c_side)
Usually called by dying spaceships, this rolls a dice and maybe creates a collectible at that very place.


createCollectible

public void createCollectible(int x,
                              int y,
                              int c_side)
Uses the side's collectible factory to get a random collectible.

See Also:
CollectibleFactory

addObjectToDestroy

public void addObjectToDestroy(QuantumObject obj)

gameOverNextTurn

public void gameOverNextTurn(int winner)

gameOver

public void gameOver(int winner)
Called when the game is totally over, this method displays an end screen. TODO: scoring.