Class World

Direct Known Subclasses:
Grid

public class World extends Screen
World Class - Used to describe the screen of a pixel-based game Subclass of a Screen, includes an ArrayList of Sprite objects
  • Constructor Details

    • World

      public World(processing.core.PApplet p, String screenName, processing.core.PImage bgImg)
      World Constructor #1: Creates a World with the specificed background image
      Parameters:
      p - Processing applet
      screenName - String to track Screens
      bgImg - stationary background image
    • World

      public World(processing.core.PApplet p, String screenName)
      World Constructor #2: Creates a World with no background image
      Parameters:
      p - Processing applet
      screenName - String to track Screens
    • World

      public World(processing.core.PApplet p)
      World Constructor #3: Creates a default World
      Parameters:
      p - Processing applet
    • World

      public World(processing.core.PApplet p, String screenName, String movingBgFile, float scale, float x, float y)
      World Constructor #4 for Moveable Backgrounds Image can be scaled to be bigger so the background doesn't run out too quickly
      Parameters:
      p - Processing applet
      screenName - String to track Screens
      movingBgFile - filename for the background image to move
      scale - float that multiplies the size of the image to display
      x - sets the initial left edge of the background
      y - sets the intial top edge of the background
  • Method Details

    • getSprites

      public ArrayList<Sprite> getSprites()
      Returns:
      ArrayList all Sprites added to the World
    • addSprite

      public void addSprite(Sprite sprite)
      Adds a Sprite to the World
      Parameters:
      sprite -
    • addSpriteCopy

      public void addSpriteCopy(Sprite sprite)
      Adds a copy of a Sprite to the World
      Parameters:
      sprite -
    • addSpriteCopyTo

      public void addSpriteCopyTo(Sprite sprite, float x, float y)
      Adds a copy of a Sprite to a specific coordinate in the World
      Parameters:
      sprite -
      x -
      y -
    • addSpriteCopyTo

      public void addSpriteCopyTo(Sprite sprite, float x, float y, float aSpeed)
      Adds a copy of an Animated Sprite to a specific coordinate in the World
      Parameters:
      sprite -
      x -
      y -
      aSpeed -
    • getNumSprites

      public int getNumSprites()
      Returns:
      int number of Sprites in a World
    • getSprite

      public Sprite getSprite(int index)
      Gets a specific Sprite based on its index
      Parameters:
      index - order that a Sprite was added to the World
      Returns:
      Sprite
    • removeSprite

      public void removeSprite(Sprite sprite)
      Removes a Sprite from the world
      Parameters:
      sprite -
    • removeSprite

      public Sprite removeSprite(int index)
      Removes a sprite from the World based on its index in the ArrayList
      Parameters:
      index - order that a Sprite was added to the World
      Returns:
      Sprite
    • clearAllSprites

      public void clearAllSprites()
      Removes all current Sprites from World (useful for restarting a level)
    • showWorldSprites

      public void showWorldSprites()
      Displays all the Sprites on the screen
    • showSprites

      @Deprecated public void showSprites()
      Deprecated.
    • show

      public void show()
      Displays all World + Screen visuals
      Overrides:
      show in class Screen
    • printWorldSprites

      public void printWorldSprites()
      Prints out list of Sprites
    • printSprites

      @Deprecated public void printSprites()
      Deprecated.
    • getColliders

      protected ArrayList<Sprite> getColliders(Sprite checkSprite)
      Checks all Sprites for collisions with one specific Sprite
      Parameters:
      checkSprite - Sprite to compare all others to
      Returns:
      ArrayList all the Sprites that are currently colliding with a specific Sprite
    • update

      public void update()
      Updates all Sprites in the World each cycle