Class World
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
ActiverseEngine.World
- All Implemented Interfaces:
ActionListener
,KeyListener
,ImageObserver
,MenuContainer
,Serializable
,EventListener
,Accessible
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Component
Component.BaselineResizeBehavior
-
Field Summary
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Updates the world and repaints itvoid
Adds an actor to the world at the specified locationvoid
addSound
(ActiverseSound sound) Adds a sound to the worldfloat
calculateDistance
(int x1, int y1, int x2, int y2) Calculates the distance between two points, based on the Euclidean distance formula.static void
Sets default FPS value for Activerse (60)Returns the list of actors in the worldstatic int
getFPS()
Returns targeting FPSReturns the list of loaded images in the worldstatic int
Gets ticks done in the enginevoid
Handles key pressesvoid
Handles key releasesvoid
Handles key typingvoid
pause()
Pauses the world timervoid
removeObject
(Actor actor) Removes an actor from the worldvoid
resume()
Resumes the world timervoid
setBackgroundImage
(String imagePath) Sets background image of world subclassesstatic void
setFPS
(int fpsValue) void
Shows text on the world at the specified locationvoid
start()
Starts the world timervoid
stop()
Stops the world timervoid
update()
Updates the world by calling the act method of each actor at a tick interval Updates memory trackerMethods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
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
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
Adds an actor to the world at the specified location- Parameters:
actor
- The actor to add to the worldx
- The x-coordinate of the actory
- The y-coordinate of the actor- See Also:
-
removeObject
Removes an actor from the world- Parameters:
actor
- The actor to remove from the world- See Also:
-
addSound
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
Shows text on the world at the specified location- Parameters:
x
- The x-coordinate of the texty
- The y-coordinate of the texttext
- 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
Updates the world and repaints it- Specified by:
actionPerformed
in interfaceActionListener
-
keyPressed
Handles key presses- Specified by:
keyPressed
in interfaceKeyListener
-
keyReleased
Handles key releases- Specified by:
keyReleased
in interfaceKeyListener
-
keyTyped
-
getActors
-
getPreferredSize
Returns the list of loaded images in the world- Overrides:
getPreferredSize
in classJComponent
- Returns:
- The list of loaded images in the world
-