Class World

All Implemented Interfaces:
ActionListener, KeyListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible

public class World extends JPanel implements ActionListener, KeyListener
Represents the world where actors interact. This class extends JPanel and implements ActionListener, KeyListener. The world has a fixed size and a black border, and can display a background image.
Version:
1.4.0
Author:
Knivier
See Also:
  • Constructor Details

    • World

      public World(int width, int height, int cellSize)
      Constructor for the World class. Initializes the world with the given width, height, and cell size. Sets the preferred size, background color, and border. Initializes the list of actors, images, and sounds. Creates a timer for updating the world. Loads properties and sets debug mode and dynamic lighting. Adds a debug button and a terminate button to the world. Adds key listener and sets focus to the world.
      Parameters:
      width - The width of the world in cells.
      height - The height of the world in cells.
      cellSize - The size of each cell in pixels.
  • Method Details

    • getFPS

      public static int getFPS()
      Returns targeting FPS
      Returns:
      int
    • setFPS

      public static void setFPS(int fpsValue)
      Parameters:
      fpsValue - Targeted FPS value
    • defaultFPS

      public static void defaultFPS()
      Sets default FPS value for Activerse (60)
    • getTicksDone

      public static int getTicksDone()
      Gets ticks done in the engine
      Returns:
      int Ticks done
    • setBackgroundImage

      public void setBackgroundImage(String imagePath)
      Sets background image of world subclasses
      Parameters:
      imagePath - Relative path for image to load as background image
    • update

      public void update()
      Updates the world by calling the act method of each actor at a tick interval Updates memory tracker
      See Also:
    • addObject

      public void addObject(Actor actor, int x, int y)
      Adds an actor to the world at the specified location
      Parameters:
      actor - The actor to add to the world
      x - The x-coordinate of the actor
      y - The y-coordinate of the actor
      See Also:
    • removeObject

      public void removeObject(Actor actor)
      Removes an actor from the world
      Parameters:
      actor - The actor to remove from the world
      See Also:
    • addSound

      public void addSound(ActiverseSound sound)
      Adds a sound to the world
      Parameters:
      sound - The sound to add to the world
      See Also:
    • start

      public void start()
      Starts the world timer
      See Also:
    • stop

      public void stop()
      Stops the world timer
      See Also:
    • pause

      public void pause()
      Pauses the world timer
      See Also:
    • resume

      public void resume()
      Resumes the world timer
      See Also:
    • showText

      public void showText(int x, int y, String text)
      Shows text on the world at the specified location
      Parameters:
      x - The x-coordinate of the text
      y - The y-coordinate of the text
      text - The text to display
    • calculateDistance

      public float calculateDistance(int x1, int y1, int x2, int y2)
      Calculates the distance between two points, based on the Euclidean distance formula. This method is useful for determining how far apart two points are in the world. You're welcome to create your own distance calculation method, but this one is provided for convenience. Access via: `World.calculateDistance(int x1, int y1, int x2, int y2)`. If you do not have a set world, you can create a "empty" world with `new World(0, 0, 1)` and use this method.
      Parameters:
      x1 -
      y1 -
      x2 -
      y2 -
      Returns:
      int Distance between two points as an Activerse unit relative
    • actionPerformed

      public void actionPerformed(ActionEvent e)
      Updates the world and repaints it
      Specified by:
      actionPerformed in interface ActionListener
    • keyPressed

      public void keyPressed(KeyEvent e)
      Handles key presses
      Specified by:
      keyPressed in interface KeyListener
    • keyReleased

      public void keyReleased(KeyEvent e)
      Handles key releases
      Specified by:
      keyReleased in interface KeyListener
    • keyTyped

      public void keyTyped(KeyEvent e)
      Handles key typing
      Specified by:
      keyTyped in interface KeyListener
    • getActors

      public List<Actor> getActors()
      Returns the list of actors in the world
      Returns:
      The list of actors in the world
      See Also:
    • getPreferredSize

      public Dimension getPreferredSize()
      Returns the list of loaded images in the world
      Overrides:
      getPreferredSize in class JComponent
      Returns:
      The list of loaded images in the world