From a777e9cb5ba5269a1add2ba8886209a3ba3e54a2 Mon Sep 17 00:00:00 2001 From: lucasstarsz Date: Sun, 23 May 2021 00:00:37 -0400 Subject: [PATCH 1/9] (#11) Removed all uses of Scene from InputManager, Keyboard, Mouse --- .../fastj/systems/control/SceneManager.java | 2 +- .../fastj/systems/input/InputManager.java | 25 +++++--------- .../systems/input/keyboard/Keyboard.java | 26 +++++++------- .../fastj/systems/input/mouse/Mouse.java | 34 +++++++++---------- 4 files changed, 39 insertions(+), 48 deletions(-) diff --git a/src/main/java/io/github/lucasstarsz/fastj/systems/control/SceneManager.java b/src/main/java/io/github/lucasstarsz/fastj/systems/control/SceneManager.java index 8e0bf57f..e2c51e9c 100644 --- a/src/main/java/io/github/lucasstarsz/fastj/systems/control/SceneManager.java +++ b/src/main/java/io/github/lucasstarsz/fastj/systems/control/SceneManager.java @@ -26,7 +26,7 @@ public abstract class SceneManager implements LogicManager { /** Processes all pending input events. */ public void processInputEvents() { - currentScene.inputManager.processEvents(currentScene); + currentScene.inputManager.processEvents(); } @Override diff --git a/src/main/java/io/github/lucasstarsz/fastj/systems/input/InputManager.java b/src/main/java/io/github/lucasstarsz/fastj/systems/input/InputManager.java index ecb5a6be..d090633a 100644 --- a/src/main/java/io/github/lucasstarsz/fastj/systems/input/InputManager.java +++ b/src/main/java/io/github/lucasstarsz/fastj/systems/input/InputManager.java @@ -1,6 +1,5 @@ package io.github.lucasstarsz.fastj.systems.input; -import io.github.lucasstarsz.fastj.systems.control.Scene; import io.github.lucasstarsz.fastj.systems.input.keyboard.Keyboard; import io.github.lucasstarsz.fastj.systems.input.keyboard.KeyboardActionListener; import io.github.lucasstarsz.fastj.systems.input.mouse.Mouse; @@ -149,13 +148,7 @@ public void fireKeyEvent(KeyEvent keyEvent) { KeyboardActionProcessor.get(keyEvent.getID()).accept(keyEvent, keyActionListeners); } - /** - * Fires a {@code keys down} event to all listening {@code KeyboardActionListeners}. - *

- * - * NOTE: When used by a FastJ {@code Scene}, this event gets fired every engine update - * call, if there are any keys pressed. - */ + /** Fires a {@code keys down} event to all listening {@code KeyboardActionListeners}. */ public void fireKeysDown() { if (Keyboard.areKeysDown()) { for (KeyboardActionListener listener : keyActionListeners) { @@ -206,7 +199,7 @@ public void fireMouseEvent(MouseEvent mouseEvent) { * backlog gets emptied into the main event list after all the events in that main list have been processed. * * @param event The event to be stored for processing later. - * @see #processEvents(Scene) + * @see #processEvents() */ public void receivedInputEvent(InputEvent event) { if (isProcessingEvents) { @@ -221,17 +214,15 @@ public void receivedInputEvent(InputEvent event) { *

* This method also empties the event backlog into the main event set after all the current events have been * processed and removed. - * - * @param current The scene to process events for. */ - public void processEvents(Scene current) { + public void processEvents() { isProcessingEvents = true; - for (InputEvent event : receivedInputEvents) { - if (event instanceof MouseEvent) { - Mouse.processEvent(current, (MouseEvent) event); - } else if (event instanceof KeyEvent) { - Keyboard.processEvent(current, (KeyEvent) event); + for (InputEvent inputEvent : receivedInputEvents) { + if (inputEvent instanceof MouseEvent) { + Mouse.processEvent(this, (MouseEvent) inputEvent); + } else if (inputEvent instanceof KeyEvent) { + Keyboard.processEvent(this, (KeyEvent) inputEvent); } } receivedInputEvents.clear(); diff --git a/src/main/java/io/github/lucasstarsz/fastj/systems/input/keyboard/Keyboard.java b/src/main/java/io/github/lucasstarsz/fastj/systems/input/keyboard/Keyboard.java index 82ef735a..55636060 100644 --- a/src/main/java/io/github/lucasstarsz/fastj/systems/input/keyboard/Keyboard.java +++ b/src/main/java/io/github/lucasstarsz/fastj/systems/input/keyboard/Keyboard.java @@ -2,7 +2,7 @@ import io.github.lucasstarsz.fastj.engine.FastJEngine; -import io.github.lucasstarsz.fastj.systems.control.Scene; +import io.github.lucasstarsz.fastj.systems.input.InputManager; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; @@ -25,8 +25,8 @@ public class Keyboard implements KeyListener { private static String lastKeyPressed = ""; private static ScheduledExecutorService keyChecker; - private static final Map> KeyEventProcessor = Map.of( - KeyEvent.KEY_PRESSED, (scene, keyEvent) -> { + private static final Map> KeyEventProcessor = Map.of( + KeyEvent.KEY_PRESSED, (inputManager, keyEvent) -> { KeyDescription keyDescription = KeyDescription.get(keyEvent.getKeyCode(), keyEvent.getKeyLocation()); Key key = null; @@ -42,12 +42,12 @@ public class Keyboard implements KeyListener { if (!key.currentlyPressed) { key.setRecentPress(true); - scene.inputManager.fireKeyEvent(keyEvent); + inputManager.fireKeyEvent(keyEvent); } key.setCurrentPress(true); }, - KeyEvent.KEY_RELEASED, (scene, keyEvent) -> { + KeyEvent.KEY_RELEASED, (inputManager, keyEvent) -> { KeyDescription keyDescription = KeyDescription.get(keyEvent.getKeyCode(), keyEvent.getKeyLocation()); Key key = Keys.get(keyDescription); @@ -57,11 +57,11 @@ public class Keyboard implements KeyListener { key.setRecentRelease(true); } - scene.inputManager.fireKeyEvent(keyEvent); + inputManager.fireKeyEvent(keyEvent); }, - KeyEvent.KEY_TYPED, (scene, keyEvent) -> { + KeyEvent.KEY_TYPED, (inputManager, keyEvent) -> { lastKeyPressed = KeyEvent.getKeyText(keyEvent.getKeyCode()); - scene.inputManager.fireKeyEvent(keyEvent); + inputManager.fireKeyEvent(keyEvent); } ); @@ -245,13 +245,13 @@ public void keyTyped(KeyEvent e) { } /** - * Processes the specified key event for the specified scene, based on its event type. + * Processes the specified key event for the specified input manager, based on its event type. * - * @param scene The scene to fire the event to. - * @param event The key event to process. + * @param inputManager The input manager to fire the event to. + * @param event The key event to process. */ - public static void processEvent(Scene scene, KeyEvent event) { - KeyEventProcessor.get(event.getID()).accept(scene, event); + public static void processEvent(InputManager inputManager, KeyEvent event) { + KeyEventProcessor.get(event.getID()).accept(inputManager, event); /* Don't call the fireKeyEvent here! * KeyEvent.KEY_PRESSED only gets called under certain * conditions, so it cannot be abstracted to work here without some serious effort. */ diff --git a/src/main/java/io/github/lucasstarsz/fastj/systems/input/mouse/Mouse.java b/src/main/java/io/github/lucasstarsz/fastj/systems/input/mouse/Mouse.java index 2a18091a..553973a2 100644 --- a/src/main/java/io/github/lucasstarsz/fastj/systems/input/mouse/Mouse.java +++ b/src/main/java/io/github/lucasstarsz/fastj/systems/input/mouse/Mouse.java @@ -5,7 +5,7 @@ import io.github.lucasstarsz.fastj.graphics.Display; import io.github.lucasstarsz.fastj.graphics.Drawable; -import io.github.lucasstarsz.fastj.systems.control.Scene; +import io.github.lucasstarsz.fastj.systems.input.InputManager; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; @@ -19,7 +19,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; -import java.util.function.BiConsumer; +import java.util.function.Consumer; /** * Mouse class that takes mouse input from the {@code Display}, and uses it to store variables about the mouse's current @@ -44,8 +44,8 @@ public class Mouse implements MouseListener, MouseMotionListener, MouseWheelList private static boolean currentlyOnScreen; private static Pointf mouseLocation = new Pointf(); - private static final Map> MouseEventProcessor = Map.of( - MouseEvent.MOUSE_PRESSED, (scene, mouseEvent) -> { + private static final Map> MouseEventProcessor = Map.of( + MouseEvent.MOUSE_PRESSED, mouseEvent -> { if (!MouseAction.Press.recentAction) { createSleeperThread(MouseAction.Press); } @@ -58,7 +58,7 @@ public class Mouse implements MouseListener, MouseMotionListener, MouseWheelList buttonLastPressed = mouseEvent.getButton(); MouseButtons.get(mouseEvent.getButton()).currentlyPressed = true; }, - MouseEvent.MOUSE_RELEASED, (scene, mouseEvent) -> { + MouseEvent.MOUSE_RELEASED, mouseEvent -> { if (!MouseAction.Release.recentAction) { createSleeperThread(MouseAction.Release); } @@ -69,14 +69,14 @@ public class Mouse implements MouseListener, MouseMotionListener, MouseWheelList buttonLastReleased = mouseEvent.getButton(); }, - MouseEvent.MOUSE_CLICKED, (scene, mouseEvent) -> { + MouseEvent.MOUSE_CLICKED, mouseEvent -> { if (!MouseAction.Click.recentAction) { createSleeperThread(MouseAction.Click); } buttonLastClicked = mouseEvent.getButton(); }, - MouseEvent.MOUSE_MOVED, (scene, mouseEvent) -> { + MouseEvent.MOUSE_MOVED, mouseEvent -> { if (!MouseAction.Move.recentAction) { createSleeperThread(MouseAction.Move); } @@ -86,7 +86,7 @@ public class Mouse implements MouseListener, MouseMotionListener, MouseWheelList FastJEngine.getDisplay().getResolutionScale() ); }, - MouseEvent.MOUSE_DRAGGED, (scene, mouseEvent) -> { + MouseEvent.MOUSE_DRAGGED, mouseEvent -> { if (!MouseAction.Drag.recentAction) { createSleeperThread(MouseAction.Drag); } @@ -96,21 +96,21 @@ public class Mouse implements MouseListener, MouseMotionListener, MouseWheelList FastJEngine.getDisplay().getResolutionScale() ); }, - MouseEvent.MOUSE_ENTERED, (scene, mouseEvent) -> { + MouseEvent.MOUSE_ENTERED, mouseEvent -> { if (MouseAction.Enter.recentAction) { createSleeperThread(MouseAction.Enter); } currentlyOnScreen = true; }, - MouseEvent.MOUSE_EXITED, (scene, mouseEvent) -> { + MouseEvent.MOUSE_EXITED, mouseEvent -> { if (MouseAction.Enter.recentAction) { createSleeperThread(MouseAction.Exit); } currentlyOnScreen = false; }, - MouseEvent.MOUSE_WHEEL, (scene, mouseEvent) -> { + MouseEvent.MOUSE_WHEEL, mouseEvent -> { if (!MouseAction.WheelScroll.recentAction) { createSleeperThread(MouseAction.WheelScroll); } @@ -300,14 +300,14 @@ public void mouseExited(MouseEvent e) { } /** - * Processes the specified mouse event for the specified scene, based on its event type. + * Processes the specified mouse event for the specified input manager, based on its event type. * - * @param scene The scene to fire the event to. - * @param event The mouse event to process. + * @param inputManager The input manager to fire the event to. + * @param event The mouse event to process. */ - public static void processEvent(Scene scene, MouseEvent event) { - MouseEventProcessor.get(event.getID()).accept(scene, event); - scene.inputManager.fireMouseEvent(event); + public static void processEvent(InputManager inputManager, MouseEvent event) { + MouseEventProcessor.get(event.getID()).accept(event); + inputManager.fireMouseEvent(event); } /** Private class to store the value of a mouse button, and whether it is currently pressed. */ From 01448fd6e76702932f80edd5934e01264ac4edaf Mon Sep 17 00:00:00 2001 From: lucasstarsz Date: Sun, 23 May 2021 00:39:39 -0400 Subject: [PATCH 2/9] (#11) Removed all uses of Scene from BehaviorManager, TagManager --- .../systems/behaviors/BehaviorHandler.java | 56 +++++++++++ .../systems/behaviors/BehaviorManager.java | 79 ++++++++------- .../fastj/systems/control/Scene.java | 99 +------------------ .../fastj/systems/tags/TagHandler.java | 59 +++++++++++ .../fastj/systems/tags/TagManager.java | 75 +++++++------- 5 files changed, 195 insertions(+), 173 deletions(-) create mode 100644 src/main/java/io/github/lucasstarsz/fastj/systems/behaviors/BehaviorHandler.java create mode 100644 src/main/java/io/github/lucasstarsz/fastj/systems/tags/TagHandler.java diff --git a/src/main/java/io/github/lucasstarsz/fastj/systems/behaviors/BehaviorHandler.java b/src/main/java/io/github/lucasstarsz/fastj/systems/behaviors/BehaviorHandler.java new file mode 100644 index 00000000..1a59497e --- /dev/null +++ b/src/main/java/io/github/lucasstarsz/fastj/systems/behaviors/BehaviorHandler.java @@ -0,0 +1,56 @@ +package io.github.lucasstarsz.fastj.systems.behaviors; + +import io.github.lucasstarsz.fastj.graphics.game.GameObject; + +import java.util.List; + +/** + * Interface denoting that the implementing classes directly interface with the {@link BehaviorManager} class. + * + * FOR IMPLEMENTORS: In order for these methods to work you need to call {@link + * BehaviorManager#addListenerList(BehaviorHandler)} upon construction. + */ +public interface BehaviorHandler { + + /** + * Gets the behavior listeners assigned to the behavior handler. + * + * @return The behavior listeners of the behavior handler. + */ + default List getBehaviorListeners() { + return BehaviorManager.getList(this); + } + + /** + * Adds the specified behavior listener to the behavior handler. + * + * @param listener The behavior listener to add. + */ + default void addBehaviorListener(GameObject listener) { + BehaviorManager.addListener(this, listener); + } + + /** + * Removes the specified behavior listener from the behavior handler. + * + * @param listener The behavior listener to remove. + */ + default void removeBehaviorListener(GameObject listener) { + BehaviorManager.removeListener(this, listener); + } + + /** Initializes all behavior listeners in the behavior handler. */ + default void initBehaviorListeners() { + BehaviorManager.initBehaviorListeners(this); + } + + /** Updates all behavior listeners in the behavior handler. */ + default void updateBehaviorListeners() { + BehaviorManager.updateBehaviorListeners(this); + } + + /** Removes all behavior listeners in the behavior handler. */ + default void clearBehaviorListeners() { + BehaviorManager.clearListenerList(this); + } +} diff --git a/src/main/java/io/github/lucasstarsz/fastj/systems/behaviors/BehaviorManager.java b/src/main/java/io/github/lucasstarsz/fastj/systems/behaviors/BehaviorManager.java index ace71846..c2592ecf 100644 --- a/src/main/java/io/github/lucasstarsz/fastj/systems/behaviors/BehaviorManager.java +++ b/src/main/java/io/github/lucasstarsz/fastj/systems/behaviors/BehaviorManager.java @@ -2,106 +2,105 @@ import io.github.lucasstarsz.fastj.graphics.game.GameObject; -import io.github.lucasstarsz.fastj.systems.control.Scene; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** - * Class to manage behavior listeners for all scenes. + * Class to manage behavior listeners for all {@link BehaviorHandler}s. * * @author Andrew Dey * @version 1.0.0 */ public class BehaviorManager { - private static final Map> BehaviorListenerLists = new HashMap<>(); + private static final Map> BehaviorListenerLists = new HashMap<>(); private BehaviorManager() { throw new java.lang.IllegalStateException(); } /** - * Gets the specified list of behavior listeners aliased to the specified {@code Scene}. + * Gets the specified list of behavior listeners aliased to the specified {@link BehaviorHandler}. * - * @param scene The {@code Scene} to get the list of behavior listeners for. + * @param behaviorHandler The {@code BehaviorHandler} to get the list of behavior listeners for. * @return The list of behavior listeners. */ - public static List getList(Scene scene) { - return BehaviorListenerLists.get(scene); + public static List getList(BehaviorHandler behaviorHandler) { + return BehaviorListenerLists.get(behaviorHandler); } /** - * Adds the specified behavior listener to the list aliased to the specified {@code Scene}. + * Adds the specified behavior listener to the list aliased to the specified {@link BehaviorHandler}. * - * @param scene The {@code Scene} used as the alias to add the specified behavior listener to. - * @param listener The behavior listener to add. + * @param behaviorHandler The {@code BehaviorHandler} used as the alias to add the specified behavior listener to. + * @param listener The behavior listener to add. */ - public static void addListener(Scene scene, GameObject listener) { - if (!BehaviorListenerLists.get(scene).contains(listener)) { - BehaviorListenerLists.get(scene).add(listener); + public static void addListener(BehaviorHandler behaviorHandler, GameObject listener) { + if (!BehaviorListenerLists.get(behaviorHandler).contains(listener)) { + BehaviorListenerLists.get(behaviorHandler).add(listener); } } /** - * Removes the specified behavior from the list aliased to the specified {@code Scene}. + * Removes the specified behavior from the list aliased to the specified {@link BehaviorHandler}. * - * @param scene The {@code Scene} used as the alias to remove the specified behavior listener from. - * @param listener The behavior listener to remove. + * @param behaviorHandler The {@code BehaviorHandler} used as the alias to remove the specified behavior listener + * from. + * @param listener The behavior listener to remove. */ - public static void removeListener(Scene scene, GameObject listener) { - BehaviorListenerLists.get(scene).remove(listener); + public static void removeListener(BehaviorHandler behaviorHandler, GameObject listener) { + BehaviorListenerLists.get(behaviorHandler).remove(listener); } /** - * Adds an alias for the specified {@code Scene}, if one does not already exist. + * Adds an alias for the specified {@link BehaviorHandler}, if one does not already exist. * - * @param scene The {@code Scene} to add a new alias for. + * @param behaviorHandler The {@code BehaviorHandler} to add a new alias for. */ - public static void addListenerList(Scene scene) { - if (!BehaviorListenerLists.containsKey(scene)) { - BehaviorListenerLists.put(scene, new ArrayList<>()); + public static void addListenerList(BehaviorHandler behaviorHandler) { + if (!BehaviorListenerLists.containsKey(behaviorHandler)) { + BehaviorListenerLists.put(behaviorHandler, new ArrayList<>()); } } /** - * Removes the list aliased to the specified {@code Scene}, and all elements inside. + * Removes the list aliased to the specified {@link BehaviorHandler}, and all elements inside. * - * @param scene The {@code Scene} to remove the alias for. + * @param behaviorHandler The {@code BehaviorHandler} to remove the alias for. */ - public static void removeListenerList(Scene scene) { - BehaviorListenerLists.remove(scene); + public static void removeListenerList(BehaviorHandler behaviorHandler) { + BehaviorListenerLists.remove(behaviorHandler); } /** - * Removes all elements from the list aliased to the specified {@code Scene}. + * Removes all elements from the list aliased to the specified {@link BehaviorHandler}. * - * @param scene The {@code Scene} used as the alias to remove all behavior listeners. + * @param behaviorHandler The {@code BehaviorHandler} used as the alias to remove all behavior listeners. */ - public static void clearListenerList(Scene scene) { - BehaviorListenerLists.get(scene).clear(); + public static void clearListenerList(BehaviorHandler behaviorHandler) { + BehaviorListenerLists.get(behaviorHandler).clear(); } /** - * Initializes the behavior listeners aliased to the specified {@code Scene}. + * Initializes the behavior listeners aliased to the specified {@link BehaviorHandler}. * - * @param scene The {@code Scene} used as the alias to initialize the behavior listeners for. + * @param behaviorHandler The {@code BehaviorHandler} used as the alias to initialize the behavior listeners for. */ - public static void initBehaviorListeners(Scene scene) { - for (GameObject listener : BehaviorListenerLists.get(scene)) { + public static void initBehaviorListeners(BehaviorHandler behaviorHandler) { + for (GameObject listener : BehaviorListenerLists.get(behaviorHandler)) { listener.initBehaviors(); } } /** - * Updates the behavior listeners aliased to the specified {@code Scene}. + * Updates the behavior listeners aliased to the specified {@link BehaviorHandler}. * - * @param scene The {@code Scene} used as the alias to update the behavior listeners for. + * @param behaviorHandler The {@code BehaviorHandler} used as the alias to update the behavior listeners for. */ - public static void updateBehaviorListeners(Scene scene) { - for (GameObject listener : BehaviorListenerLists.get(scene)) { + public static void updateBehaviorListeners(BehaviorHandler behaviorHandler) { + for (GameObject listener : BehaviorListenerLists.get(behaviorHandler)) { listener.updateBehaviors(); } } diff --git a/src/main/java/io/github/lucasstarsz/fastj/systems/control/Scene.java b/src/main/java/io/github/lucasstarsz/fastj/systems/control/Scene.java index ad485b1c..d1d51139 100644 --- a/src/main/java/io/github/lucasstarsz/fastj/systems/control/Scene.java +++ b/src/main/java/io/github/lucasstarsz/fastj/systems/control/Scene.java @@ -2,25 +2,23 @@ import io.github.lucasstarsz.fastj.graphics.Camera; import io.github.lucasstarsz.fastj.graphics.Display; -import io.github.lucasstarsz.fastj.graphics.Drawable; -import io.github.lucasstarsz.fastj.graphics.game.GameObject; +import io.github.lucasstarsz.fastj.systems.behaviors.BehaviorHandler; import io.github.lucasstarsz.fastj.systems.behaviors.BehaviorManager; import io.github.lucasstarsz.fastj.systems.input.InputManager; +import io.github.lucasstarsz.fastj.systems.tags.TagHandler; import io.github.lucasstarsz.fastj.systems.tags.TagManager; -import java.util.List; - /** * Class containing the logic for a specific section, or scene, of a game. *

- * The {@code LogicManager} of any game made with FastJ can store many scenes. Through this, the user can divide their + * A {@code SceneManager} of any game made with FastJ can store many scenes. Through this, the user can divide their * game into different sections. * * @author Andrew Dey * @version 1.0.0 */ -public abstract class Scene { +public abstract class Scene implements BehaviorHandler, TagHandler { private final String sceneName; private final Camera camera; @@ -84,24 +82,6 @@ public String getSceneName() { return sceneName; } - /** - * Gets the behavior listeners assigned to the scene. - * - * @return The behavior listeners of the scene. - */ - public List getBehaviorListeners() { - return BehaviorManager.getList(this); - } - - /** - * Gets the taggable entities assigned to the scene. - * - * @return The taggable entities of the scene. - */ - public List getTaggableEntities() { - return TagManager.getEntityList(this); - } - /** * Gets the camera of the scene. * @@ -129,77 +109,6 @@ public void setInitialized(boolean initialized) { isInitialized = initialized; } - /** - * Gets all taggable entities with the specified tag. - * - * @param tag The tag to check for. - * @return A list of all taggable entities with the specified tag. - */ - public List getAllWithTag(String tag) { - return TagManager.getAllInListWithTag(this, tag); - } - - /* Behavior Listeners */ - - /** - * Adds the specified behavior listener to the scene. - * - * @param listener The behavior listener to add. - */ - public void addBehaviorListener(GameObject listener) { - BehaviorManager.addListener(this, listener); - } - - /** - * Removes the specified behavior listener from the scene. - * - * @param listener The behavior listener to remove. - */ - public void removeBehaviorListener(GameObject listener) { - BehaviorManager.removeListener(this, listener); - } - - /** Initializes all behavior listeners in the scene. */ - public void initBehaviorListeners() { - BehaviorManager.initBehaviorListeners(this); - } - - /** Updates all behavior listeners in the scene. */ - public void updateBehaviorListeners() { - BehaviorManager.updateBehaviorListeners(this); - } - - /** Removes all behavior listeners in the scene. */ - public void clearBehaviorListeners() { - BehaviorManager.clearListenerList(this); - } - - /* Taggable Entities */ - - /** - * Adds the specified taggable entity, only if it extends the {@code Drawable} class. - * - * @param entity The taggable entity to add. - * @param The type of the taggable entity, which must extend the {@code Drawable} class. - */ - public void addTaggableEntity(T entity) { - TagManager.addTaggableEntity(this, entity); - } - - /** - * Removes the specified taggable entity. - * - * @param entity The taggable entity to remove. - */ - public void removeTaggableEntity(Drawable entity) { - TagManager.removeTaggableEntity(this, entity); - } - - /** Removes all taggable from the scene. */ - public void clearTaggableEntities() { - TagManager.clearEntityList(this); - } - /* Reset */ /** Removes all elements from the scene. */ diff --git a/src/main/java/io/github/lucasstarsz/fastj/systems/tags/TagHandler.java b/src/main/java/io/github/lucasstarsz/fastj/systems/tags/TagHandler.java new file mode 100644 index 00000000..5382917e --- /dev/null +++ b/src/main/java/io/github/lucasstarsz/fastj/systems/tags/TagHandler.java @@ -0,0 +1,59 @@ +package io.github.lucasstarsz.fastj.systems.tags; + +import io.github.lucasstarsz.fastj.graphics.Drawable; + +import io.github.lucasstarsz.fastj.systems.behaviors.BehaviorManager; + +import java.util.List; + +/** + * Interface denoting that the implementing classes directly interface with the {@link BehaviorManager} class. + * + * FOR IMPLEMENTORS: In order for these methods to work you need to call {@link + * TagManager#addTaggableEntityList(TagHandler)} upon construction. + */ +public interface TagHandler { + + /** + * Gets the taggable entities assigned to the tag handler. + * + * @return The taggable entities of the tag handler. + */ + default List getTaggableEntities() { + return TagManager.getEntityList(this); + } + + /** + * Gets all taggable entities with the specified tag. + * + * @param tag The tag to check for. + * @return A list of all taggable entities with the specified tag. + */ + default List getAllWithTag(String tag) { + return TagManager.getAllInListWithTag(this, tag); + } + + /** + * Adds the specified taggable entity, only if it extends the {@code Drawable} class. + * + * @param entity The taggable entity to add. + * @param The type of the taggable entity, which must extend the {@code Drawable} class. + */ + default void addTaggableEntity(T entity) { + TagManager.addTaggableEntity(this, entity); + } + + /** + * Removes the specified taggable entity. + * + * @param entity The taggable entity to remove. + */ + default void removeTaggableEntity(Drawable entity) { + TagManager.removeTaggableEntity(this, entity); + } + + /** Removes all taggable entities from the tag handler. */ + default void clearTaggableEntities() { + TagManager.clearEntityList(this); + } +} diff --git a/src/main/java/io/github/lucasstarsz/fastj/systems/tags/TagManager.java b/src/main/java/io/github/lucasstarsz/fastj/systems/tags/TagManager.java index 3547a7b0..d0dde3f5 100644 --- a/src/main/java/io/github/lucasstarsz/fastj/systems/tags/TagManager.java +++ b/src/main/java/io/github/lucasstarsz/fastj/systems/tags/TagManager.java @@ -2,8 +2,6 @@ import io.github.lucasstarsz.fastj.graphics.Drawable; -import io.github.lucasstarsz.fastj.systems.control.Scene; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -11,7 +9,7 @@ import java.util.stream.Collectors; /** - * Class to manage tags and taggable entities for all game scenes. + * Class to manage tags and taggable entities for all {@link TagHandler}s. * * @author Andrew Dey * @version 1.0.0 @@ -19,20 +17,20 @@ public class TagManager { private static final List MasterTagList = new ArrayList<>(); - private static final Map> EntityLists = new HashMap<>(); + private static final Map> EntityLists = new HashMap<>(); private TagManager() { throw new java.lang.IllegalStateException(); } /** - * Gets the list of taggable entities at the specified {@code Scene}. + * Gets the list of taggable entities at the specified {@link TagHandler}. * - * @param scene The scene to get the list of taggable entities from. + * @param tagHandler The tag handler to get the list of taggable entities from. * @return The list of taggable entities, as a {@code List}. */ - public static List getEntityList(Scene scene) { - return EntityLists.get(scene); + public static List getEntityList(TagHandler tagHandler) { + return EntityLists.get(tagHandler); } /** @@ -60,66 +58,67 @@ public static boolean doesTagExist(String tag) { } /** - * Adds the specified taggable entity to the list of taggable entities for the specified scene. + * Adds the specified taggable entity to the list of taggable entities for the specified tag handler. *

- * The taggable entity is only added if the specified scene does not already contain the specified taggable entity. + * The taggable entity is only added if the specified tag handler does not already contain the specified taggable + * entity. * - * @param scene The {@code Scene} which the taggable entity will be aliased with. + * @param tagHandler The {@link TagHandler} which the taggable entity will be aliased with. * @param taggableEntity The {@code Drawable} to add. */ - public static void addTaggableEntity(Scene scene, Drawable taggableEntity) { - if (!EntityLists.get(scene).contains(taggableEntity)) { - EntityLists.get(scene).add(taggableEntity); + public static void addTaggableEntity(TagHandler tagHandler, Drawable taggableEntity) { + if (!EntityLists.get(tagHandler).contains(taggableEntity)) { + EntityLists.get(tagHandler).add(taggableEntity); } } /** - * Removes the specified taggable entity from the list of taggable entities for the specified scene. + * Removes the specified taggable entity from the list of taggable entities for the specified tag handler. * - * @param scene The {@code Scene} that the taggable entity is aliased with. + * @param tagHandler The {@link TagHandler} that the taggable entity is aliased with. * @param taggableEntity The {@code Drawable} to remove. */ - public static void removeTaggableEntity(Scene scene, Drawable taggableEntity) { - EntityLists.get(scene).remove(taggableEntity); + public static void removeTaggableEntity(TagHandler tagHandler, Drawable taggableEntity) { + EntityLists.get(tagHandler).remove(taggableEntity); } /** - * Adds the specified {@code Scene} as an alias to store a list of taggable entities for. + * Adds the specified {@link TagHandler} as an alias to store a list of taggable entities for. *

- * The specified {@code Scene} is only added if it is not already in the tag manager. + * The specified {@link TagHandler} is only added if it is not already in the tag manager. * - * @param scene The scene to add. + * @param tagHandler The tag handler to add. */ - public static void addTaggableEntityList(Scene scene) { - if (!EntityLists.containsKey(scene)) { - EntityLists.put(scene, new ArrayList<>()); + public static void addTaggableEntityList(TagHandler tagHandler) { + if (!EntityLists.containsKey(tagHandler)) { + EntityLists.put(tagHandler, new ArrayList<>()); } } /** - * Removes the list of taggable entities aliased to the specified {@code Scene}. + * Removes the list of taggable entities aliased to the specified {@link TagHandler}. * - * @param scene The scene to remove. + * @param tagHandler The tag handler to remove. */ - public static void removeTaggableEntityList(Scene scene) { - EntityLists.remove(scene); + public static void removeTaggableEntityList(TagHandler tagHandler) { + EntityLists.remove(tagHandler); } /** - * Gets all taggable entities in the specified {@code Scene} with the specified tag. + * Gets all taggable entities in the specified {@link TagHandler} with the specified tag. * - * @param scene The scene to search through. - * @param tag The tag to search for. + * @param tagHandler The tag handler to search through. + * @param tag The tag to search for. * @return A list of taggable entities that have the specified tag. */ - public static List getAllInListWithTag(Scene scene, String tag) { - return EntityLists.get(scene).stream() + public static List getAllInListWithTag(TagHandler tagHandler, String tag) { + return EntityLists.get(tagHandler).stream() .filter(obj -> obj.hasTag(tag)) .collect(Collectors.toList()); } /** - * Gets all taggable entities from all {@code Scene}s with the specified tag. + * Gets all taggable entities from all {@link TagHandler}s with the specified tag. * * @param tag The tag to search for. * @return A list of taggable entities that have the specified tag. @@ -132,12 +131,12 @@ public static List getAllWithTag(String tag) { } /** - * Clears the taggable entity list aliased to the specified scene. + * Clears the taggable entity list aliased to the specified tag handler. * - * @param scene The scene to clear the list of taggable entities for. + * @param tagHandler The tag handler to clear the list of taggable entities for. */ - public static void clearEntityList(Scene scene) { - EntityLists.get(scene).clear(); + public static void clearEntityList(TagHandler tagHandler) { + EntityLists.get(tagHandler).clear(); } /** Wipes the {@code TagManager} of all aliases and tags. */ From 3fd54c13d4306511f8430d7357fb0756400b71e3 Mon Sep 17 00:00:00 2001 From: lucasstarsz Date: Sun, 23 May 2021 01:55:20 -0400 Subject: [PATCH 3/9] added missing @Override annotations --- .../fastj/systems/control/SceneManager.java | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/github/lucasstarsz/fastj/systems/control/SceneManager.java b/src/main/java/io/github/lucasstarsz/fastj/systems/control/SceneManager.java index e2c51e9c..1aa210b1 100644 --- a/src/main/java/io/github/lucasstarsz/fastj/systems/control/SceneManager.java +++ b/src/main/java/io/github/lucasstarsz/fastj/systems/control/SceneManager.java @@ -24,21 +24,12 @@ public abstract class SceneManager implements LogicManager { private Scene currentScene; private boolean switchingScenes; - /** Processes all pending input events. */ - public void processInputEvents() { - currentScene.inputManager.processEvents(); - } - - @Override - public void receivedInputEvent(InputEvent inputEvent) { - currentScene.inputManager.receivedInputEvent(inputEvent); - } - /** * Updates the current scene, its behaviors, and listeners. * * @param display The {@code Display} that the game renders to. */ + @Override public void update(Display display) { updateCurrentScene(display); } @@ -48,11 +39,24 @@ public void update(Display display) { * * @param display The {@code Display} that the game renders to. */ + @Override public void render(Display display) { renderCurrentScene(display); } + /** Processes all pending input events. */ + @Override + public void processInputEvents() { + currentScene.inputManager.processEvents(); + } + + @Override + public void receivedInputEvent(InputEvent inputEvent) { + currentScene.inputManager.receivedInputEvent(inputEvent); + } + /** Resets the logic manager. */ + @Override public void reset() { for (Scene s : scenes.values()) { if (s.isInitialized()) { @@ -228,7 +232,7 @@ private void updateCurrentScene(Display display) { } /** - * Safely renders the current scene to the Display. + * Safely renders the current scene to the {@code Display}. * * @param display The {@code Display} that the game renders to. */ From 730e795958670a05e40cafddbeb0076f4a1fbf5f Mon Sep 17 00:00:00 2001 From: lucasstarsz Date: Sun, 23 May 2021 01:55:47 -0400 Subject: [PATCH 4/9] (#11) Added LogicManager implementation without scenes --- .../fastj/systems/control/SimpleManager.java | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/main/java/io/github/lucasstarsz/fastj/systems/control/SimpleManager.java diff --git a/src/main/java/io/github/lucasstarsz/fastj/systems/control/SimpleManager.java b/src/main/java/io/github/lucasstarsz/fastj/systems/control/SimpleManager.java new file mode 100644 index 00000000..675dd13b --- /dev/null +++ b/src/main/java/io/github/lucasstarsz/fastj/systems/control/SimpleManager.java @@ -0,0 +1,74 @@ +package io.github.lucasstarsz.fastj.systems.control; + +import io.github.lucasstarsz.fastj.graphics.Camera; +import io.github.lucasstarsz.fastj.graphics.Display; + +import io.github.lucasstarsz.fastj.systems.behaviors.BehaviorHandler; +import io.github.lucasstarsz.fastj.systems.behaviors.BehaviorManager; +import io.github.lucasstarsz.fastj.systems.input.InputManager; +import io.github.lucasstarsz.fastj.systems.tags.TagHandler; +import io.github.lucasstarsz.fastj.systems.tags.TagManager; + +import java.awt.event.InputEvent; + +public abstract class SimpleManager implements LogicManager, BehaviorHandler, TagHandler { + + private final Camera camera; + public final InputManager inputManager; + public final DrawableManager drawableManager; + + /** + * Initializes the contents of the {@code SimpleManager}. + */ + public SimpleManager() { + camera = new Camera(); + + inputManager = new InputManager(); + drawableManager = new DrawableManager(); + + TagManager.addTaggableEntityList(this); + BehaviorManager.addListenerList(this); + } + + /** + * Renders the contents of the manager's {@code DrawableManager} to the {@code Display}. + * + * @param display The {@code Display} that the game renders to. + */ + @Override + public void render(Display display) { + display.render( + drawableManager.getGameObjects(), + drawableManager.getUIElements(), + camera + ); + } + + @Override + public void processInputEvents() { + inputManager.processEvents(); + } + + @Override + public void receivedInputEvent(InputEvent inputEvent) { + inputManager.receivedInputEvent(inputEvent); + } + + /** + * Gets the {@code Camera} of the manager. + * + * @return The manager's camera. + */ + public Camera getCamera() { + return camera; + } + + @Override + public void reset() { + camera.reset(); + inputManager.clearAllLists(); + drawableManager.clearAllLists(); + this.clearTaggableEntities(); + this.clearBehaviorListeners(); + } +} From 6d496c455a1c261677563bc05f8791b7a3694540 Mon Sep 17 00:00:00 2001 From: lucasstarsz Date: Sun, 23 May 2021 02:20:15 -0400 Subject: [PATCH 5/9] changed example names to better fit their content --- .../example/bullethell/{Main.java => BulletHellGame.java} | 4 ++-- .../example/helloworld/{Main.java => OldHelloWorld.java} | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename src/example/java/io/github/lucasstarsz/fastj/example/bullethell/{Main.java => BulletHellGame.java} (88%) rename src/example/java/io/github/lucasstarsz/fastj/example/helloworld/{Main.java => OldHelloWorld.java} (92%) diff --git a/src/example/java/io/github/lucasstarsz/fastj/example/bullethell/Main.java b/src/example/java/io/github/lucasstarsz/fastj/example/bullethell/BulletHellGame.java similarity index 88% rename from src/example/java/io/github/lucasstarsz/fastj/example/bullethell/Main.java rename to src/example/java/io/github/lucasstarsz/fastj/example/bullethell/BulletHellGame.java index 7de58627..7fa27e80 100644 --- a/src/example/java/io/github/lucasstarsz/fastj/example/bullethell/Main.java +++ b/src/example/java/io/github/lucasstarsz/fastj/example/bullethell/BulletHellGame.java @@ -10,7 +10,7 @@ import io.github.lucasstarsz.fastj.example.bullethell.scenes.GameScene; import io.github.lucasstarsz.fastj.example.bullethell.scenes.LoseScene; -public class Main extends SceneManager { +public class BulletHellGame extends SceneManager { @Override public void init(Display display) { @@ -28,7 +28,7 @@ public void init(Display display) { } public static void main(String[] args) { - FastJEngine.init("Simple Bullet Hell", new Main()); + FastJEngine.init("Simple Bullet Hell", new BulletHellGame()); FastJEngine.run(); } } diff --git a/src/example/java/io/github/lucasstarsz/fastj/example/helloworld/Main.java b/src/example/java/io/github/lucasstarsz/fastj/example/helloworld/OldHelloWorld.java similarity index 92% rename from src/example/java/io/github/lucasstarsz/fastj/example/helloworld/Main.java rename to src/example/java/io/github/lucasstarsz/fastj/example/helloworld/OldHelloWorld.java index af780e63..69e69040 100644 --- a/src/example/java/io/github/lucasstarsz/fastj/example/helloworld/Main.java +++ b/src/example/java/io/github/lucasstarsz/fastj/example/helloworld/OldHelloWorld.java @@ -2,7 +2,7 @@ import io.github.lucasstarsz.fastj.engine.FastJEngine; -public class Main { +public class OldHelloWorld { public static void main(String[] args) { /* Initializes the game engine, with an instance of our game manager. */ FastJEngine.init("Example Game", new GameManager()); From 17438a6723928c0bb7c8e2a5605c1a48843eb9c4 Mon Sep 17 00:00:00 2001 From: lucasstarsz Date: Sun, 23 May 2021 02:20:32 -0400 Subject: [PATCH 6/9] add hello-fastj example --- .../fastj/example/hellofastj/HelloFastJ.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/example/java/io/github/lucasstarsz/fastj/example/hellofastj/HelloFastJ.java diff --git a/src/example/java/io/github/lucasstarsz/fastj/example/hellofastj/HelloFastJ.java b/src/example/java/io/github/lucasstarsz/fastj/example/hellofastj/HelloFastJ.java new file mode 100644 index 00000000..0e2d45af --- /dev/null +++ b/src/example/java/io/github/lucasstarsz/fastj/example/hellofastj/HelloFastJ.java @@ -0,0 +1,22 @@ +package io.github.lucasstarsz.fastj.example.hellofastj; + +import io.github.lucasstarsz.fastj.engine.FastJEngine; +import io.github.lucasstarsz.fastj.graphics.Display; + +import io.github.lucasstarsz.fastj.systems.control.SimpleManager; + +public class HelloFastJ extends SimpleManager { + + @Override + public void init(Display display) { + } + + @Override + public void update(Display display) { + } + + public static void main(String[] args) { + FastJEngine.init("Hello, FastJ!", new HelloFastJ()); + FastJEngine.run(); + } +} From 88d937945cf1dd4ca4c00774c6628b555dd832ed Mon Sep 17 00:00:00 2001 From: lucasstarsz Date: Sun, 23 May 2021 02:28:04 -0400 Subject: [PATCH 7/9] rename original helloworld to oldhelloworld --- .../example/{helloworld => oldhelloworld}/GameManager.java | 4 ++-- .../example/{helloworld => oldhelloworld}/OldHelloWorld.java | 2 +- .../customscripts/PlayerScript.java | 4 ++-- .../{helloworld => oldhelloworld}/scenes/GameScene.java | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) rename src/example/java/io/github/lucasstarsz/fastj/example/{helloworld => oldhelloworld}/GameManager.java (89%) rename src/example/java/io/github/lucasstarsz/fastj/example/{helloworld => oldhelloworld}/OldHelloWorld.java (85%) rename src/example/java/io/github/lucasstarsz/fastj/example/{helloworld => oldhelloworld}/customscripts/PlayerScript.java (94%) rename src/example/java/io/github/lucasstarsz/fastj/example/{helloworld => oldhelloworld}/scenes/GameScene.java (97%) diff --git a/src/example/java/io/github/lucasstarsz/fastj/example/helloworld/GameManager.java b/src/example/java/io/github/lucasstarsz/fastj/example/oldhelloworld/GameManager.java similarity index 89% rename from src/example/java/io/github/lucasstarsz/fastj/example/helloworld/GameManager.java rename to src/example/java/io/github/lucasstarsz/fastj/example/oldhelloworld/GameManager.java index d6e64aed..21d8dee7 100644 --- a/src/example/java/io/github/lucasstarsz/fastj/example/helloworld/GameManager.java +++ b/src/example/java/io/github/lucasstarsz/fastj/example/oldhelloworld/GameManager.java @@ -1,4 +1,4 @@ -package io.github.lucasstarsz.fastj.example.helloworld; +package io.github.lucasstarsz.fastj.example.oldhelloworld; import io.github.lucasstarsz.fastj.graphics.Display; @@ -6,7 +6,7 @@ import java.awt.RenderingHints; -import io.github.lucasstarsz.fastj.example.helloworld.scenes.GameScene; +import io.github.lucasstarsz.fastj.example.oldhelloworld.scenes.GameScene; /** * Manages the game's overall state (in the background). diff --git a/src/example/java/io/github/lucasstarsz/fastj/example/helloworld/OldHelloWorld.java b/src/example/java/io/github/lucasstarsz/fastj/example/oldhelloworld/OldHelloWorld.java similarity index 85% rename from src/example/java/io/github/lucasstarsz/fastj/example/helloworld/OldHelloWorld.java rename to src/example/java/io/github/lucasstarsz/fastj/example/oldhelloworld/OldHelloWorld.java index 69e69040..8f528ea6 100644 --- a/src/example/java/io/github/lucasstarsz/fastj/example/helloworld/OldHelloWorld.java +++ b/src/example/java/io/github/lucasstarsz/fastj/example/oldhelloworld/OldHelloWorld.java @@ -1,4 +1,4 @@ -package io.github.lucasstarsz.fastj.example.helloworld; +package io.github.lucasstarsz.fastj.example.oldhelloworld; import io.github.lucasstarsz.fastj.engine.FastJEngine; diff --git a/src/example/java/io/github/lucasstarsz/fastj/example/helloworld/customscripts/PlayerScript.java b/src/example/java/io/github/lucasstarsz/fastj/example/oldhelloworld/customscripts/PlayerScript.java similarity index 94% rename from src/example/java/io/github/lucasstarsz/fastj/example/helloworld/customscripts/PlayerScript.java rename to src/example/java/io/github/lucasstarsz/fastj/example/oldhelloworld/customscripts/PlayerScript.java index 7c15af03..03ce0163 100644 --- a/src/example/java/io/github/lucasstarsz/fastj/example/helloworld/customscripts/PlayerScript.java +++ b/src/example/java/io/github/lucasstarsz/fastj/example/oldhelloworld/customscripts/PlayerScript.java @@ -1,4 +1,4 @@ -package io.github.lucasstarsz.fastj.example.helloworld.customscripts; +package io.github.lucasstarsz.fastj.example.oldhelloworld.customscripts; import io.github.lucasstarsz.fastj.math.Pointf; import io.github.lucasstarsz.fastj.graphics.game.GameObject; @@ -7,7 +7,7 @@ import io.github.lucasstarsz.fastj.systems.input.keyboard.Keyboard; import io.github.lucasstarsz.fastj.systems.input.keyboard.Keys; -import io.github.lucasstarsz.fastj.example.helloworld.scenes.GameScene; +import io.github.lucasstarsz.fastj.example.oldhelloworld.scenes.GameScene; /** A custom script that moves the received game object using the WASD keys. */ public class PlayerScript implements Behavior { diff --git a/src/example/java/io/github/lucasstarsz/fastj/example/helloworld/scenes/GameScene.java b/src/example/java/io/github/lucasstarsz/fastj/example/oldhelloworld/scenes/GameScene.java similarity index 97% rename from src/example/java/io/github/lucasstarsz/fastj/example/helloworld/scenes/GameScene.java rename to src/example/java/io/github/lucasstarsz/fastj/example/oldhelloworld/scenes/GameScene.java index c3cf373f..094559b5 100644 --- a/src/example/java/io/github/lucasstarsz/fastj/example/helloworld/scenes/GameScene.java +++ b/src/example/java/io/github/lucasstarsz/fastj/example/oldhelloworld/scenes/GameScene.java @@ -1,4 +1,4 @@ -package io.github.lucasstarsz.fastj.example.helloworld.scenes; +package io.github.lucasstarsz.fastj.example.oldhelloworld.scenes; import io.github.lucasstarsz.fastj.engine.FastJEngine; import io.github.lucasstarsz.fastj.math.Pointf; @@ -15,7 +15,7 @@ import java.awt.Color; import java.awt.Font; -import io.github.lucasstarsz.fastj.example.helloworld.customscripts.PlayerScript; +import io.github.lucasstarsz.fastj.example.oldhelloworld.customscripts.PlayerScript; /** The game scene, where all the action happens! */ public class GameScene extends Scene { From 839b9bca7b68bb9070d4014b7e7ea4da94937bab Mon Sep 17 00:00:00 2001 From: lucasstarsz Date: Sun, 23 May 2021 11:51:43 -0400 Subject: [PATCH 8/9] Renamed examples to be consistent with example task --- build.gradle | 4 ++-- .../example/bullethell/{BulletHellGame.java => Main.java} | 4 ++-- .../fastj/example/hellofastj/{HelloFastJ.java => Main.java} | 4 ++-- .../example/oldhelloworld/{OldHelloWorld.java => Main.java} | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) rename src/example/java/io/github/lucasstarsz/fastj/example/bullethell/{BulletHellGame.java => Main.java} (88%) rename src/example/java/io/github/lucasstarsz/fastj/example/hellofastj/{HelloFastJ.java => Main.java} (80%) rename src/example/java/io/github/lucasstarsz/fastj/example/oldhelloworld/{OldHelloWorld.java => Main.java} (92%) diff --git a/build.gradle b/build.gradle index 89630e0f..e649b6ba 100644 --- a/build.gradle +++ b/build.gradle @@ -24,11 +24,11 @@ sourceSets { if (!project.hasProperty("example")) { throw new IllegalStateException(""" You need to specify which example using the "example" property! -E.G. \"./gradlew example -Pexample=helloworld\"""") +E.G. \"./gradlew example -Pexample=hellofastj\"""") } } - description('An example game using FastJ.') + description('Runs a FastJ example program.') classpath = files(sourceSets.main.output, sourceSets.example.runtimeClasspath) main = "io.github.lucasstarsz.fastj.example.${project.hasProperty("example") ? project.getProperty("example") : ""}.Main" } diff --git a/src/example/java/io/github/lucasstarsz/fastj/example/bullethell/BulletHellGame.java b/src/example/java/io/github/lucasstarsz/fastj/example/bullethell/Main.java similarity index 88% rename from src/example/java/io/github/lucasstarsz/fastj/example/bullethell/BulletHellGame.java rename to src/example/java/io/github/lucasstarsz/fastj/example/bullethell/Main.java index 7fa27e80..7de58627 100644 --- a/src/example/java/io/github/lucasstarsz/fastj/example/bullethell/BulletHellGame.java +++ b/src/example/java/io/github/lucasstarsz/fastj/example/bullethell/Main.java @@ -10,7 +10,7 @@ import io.github.lucasstarsz.fastj.example.bullethell.scenes.GameScene; import io.github.lucasstarsz.fastj.example.bullethell.scenes.LoseScene; -public class BulletHellGame extends SceneManager { +public class Main extends SceneManager { @Override public void init(Display display) { @@ -28,7 +28,7 @@ public void init(Display display) { } public static void main(String[] args) { - FastJEngine.init("Simple Bullet Hell", new BulletHellGame()); + FastJEngine.init("Simple Bullet Hell", new Main()); FastJEngine.run(); } } diff --git a/src/example/java/io/github/lucasstarsz/fastj/example/hellofastj/HelloFastJ.java b/src/example/java/io/github/lucasstarsz/fastj/example/hellofastj/Main.java similarity index 80% rename from src/example/java/io/github/lucasstarsz/fastj/example/hellofastj/HelloFastJ.java rename to src/example/java/io/github/lucasstarsz/fastj/example/hellofastj/Main.java index 0e2d45af..f6ba3242 100644 --- a/src/example/java/io/github/lucasstarsz/fastj/example/hellofastj/HelloFastJ.java +++ b/src/example/java/io/github/lucasstarsz/fastj/example/hellofastj/Main.java @@ -5,7 +5,7 @@ import io.github.lucasstarsz.fastj.systems.control.SimpleManager; -public class HelloFastJ extends SimpleManager { +public class Main extends SimpleManager { @Override public void init(Display display) { @@ -16,7 +16,7 @@ public void update(Display display) { } public static void main(String[] args) { - FastJEngine.init("Hello, FastJ!", new HelloFastJ()); + FastJEngine.init("Hello, FastJ!", new Main()); FastJEngine.run(); } } diff --git a/src/example/java/io/github/lucasstarsz/fastj/example/oldhelloworld/OldHelloWorld.java b/src/example/java/io/github/lucasstarsz/fastj/example/oldhelloworld/Main.java similarity index 92% rename from src/example/java/io/github/lucasstarsz/fastj/example/oldhelloworld/OldHelloWorld.java rename to src/example/java/io/github/lucasstarsz/fastj/example/oldhelloworld/Main.java index 8f528ea6..249ce8e7 100644 --- a/src/example/java/io/github/lucasstarsz/fastj/example/oldhelloworld/OldHelloWorld.java +++ b/src/example/java/io/github/lucasstarsz/fastj/example/oldhelloworld/Main.java @@ -2,7 +2,7 @@ import io.github.lucasstarsz.fastj.engine.FastJEngine; -public class OldHelloWorld { +public class Main { public static void main(String[] args) { /* Initializes the game engine, with an instance of our game manager. */ FastJEngine.init("Example Game", new GameManager()); From 5c2bf51c706d28e79bc6fb9c077298efbab448ae Mon Sep 17 00:00:00 2001 From: lucasstarsz Date: Sun, 23 May 2021 12:00:13 -0400 Subject: [PATCH 9/9] update example readme with changes to examples --- src/example/README.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/example/README.md b/src/example/README.md index 795e39d6..d05e50ac 100644 --- a/src/example/README.md +++ b/src/example/README.md @@ -12,9 +12,14 @@ Then, run the gradle task `example`. When you do this, you'll need to specify wh ``` _Having trouble using `gradlew`? Read [this][Terminals Are Different]._ -## Example Projects +## Example Programs -### Hello, World! +### Hello, FastJ! +This program is a remarkably simple introduction to starting work with FastJ. It initializes the engine and runs the engine, which results in an empty window. This also can serve as a project template for working with FastJ. + +Command to run: `./gradlew example -Pexample=hellofastj` + +### (Old) Hello, World! This project is an introduction to working with FastJ, and covers many of the essential topics: - Engine Initialization/Running - Window Creation @@ -22,7 +27,7 @@ This project is an introduction to working with FastJ, and covers many of the es - Drawing game objects and UI - Applying Behaviors to Game Objects -Command to run: `./gradlew example -Pexample=helloworld` +Command to run: `./gradlew example -Pexample=oldhelloworld` ### Bullet Hell This project takes the concepts we've learned so far and meshes them together into a game!