This commit is contained in:
Blocky 2024-05-06 18:49:45 -06:00 committed by GitHub
parent 5dfb73ce98
commit 229e357c07
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -43,6 +43,7 @@ public ExampleEntity(Position pos, Dimension coll){
``` ```
could be used to make the editor pass through a Dimension with the `construct(Position pos, Dimension collision, int[] data)` method. could be used to make the editor pass through a Dimension with the `construct(Position pos, Dimension collision, int[] data)` method.
> `ExampleEntity()` or "registry constructor" > `ExampleEntity()` or "registry constructor"
Register the entity in the entity registry. Register the entity in the entity registry.
@ -52,6 +53,7 @@ Important note: the `hasColl` variable means the editor can set the collision, i
Keep in mind that choices in code will not affect the editor, so you have to keep things consistent. For example, if you make an entity with the registry arguments `("gunpickup", false, 1)` , you will have to name a custom entity "gunpickup" (yes, it's case-sensitive), click `no` when prompted if it should have collision, and type '1' for the amount of data it has (as well as whatever you want on that 1 data in the next popup). Keep in mind that choices in code will not affect the editor, so you have to keep things consistent. For example, if you make an entity with the registry arguments `("gunpickup", false, 1)` , you will have to name a custom entity "gunpickup" (yes, it's case-sensitive), click `no` when prompted if it should have collision, and type '1' for the amount of data it has (as well as whatever you want on that 1 data in the next popup).
> `TridEntity construct(Position pos, Dimension collision, int[] data)` > `TridEntity construct(Position pos, Dimension collision, int[] data)`
Used to place the entity in the world from the editor. Used to place the entity in the world from the editor.
@ -59,6 +61,7 @@ Depending on the arguments passed through in the registry constructor, `collisio
`collision` is null if `hasColl` was set to `false` in the registry constructor, but will have a value if set to `true`. `collision` is null if `hasColl` was set to `false` in the registry constructor, but will have a value if set to `true`.
> `void render(Graphics g, JPanel panel, int x, int y)` > `void render(Graphics g, JPanel panel, int x, int y)`
Renders the entity. Renders the entity.
@ -66,15 +69,18 @@ g = Graphics object for rendering
panel = the panel panel = the panel
x, y = the screen location the entity should render at x, y = the screen location the entity should render at
> `void update(long elapsedTime)` > `void update(long elapsedTime)`
Runs every 'tick'. Use this for things like game logic. Runs every 'tick'. Use this for things like game logic.
> `void sceneStart(String scene)` > `void sceneStart(String scene)`
Runs when the scene is loaded. Runs when the scene is loaded.
## trident/ ## trident/
Main Trident classes. Don't edit these unless you know what you're doing. Main Trident classes. Don't edit these unless you know what you're doing.
@ -104,30 +110,37 @@ Main interface with the engine.
Toggles drawing the player's position in the top left Toggles drawing the player's position in the top left
> `boolean drawCollision = false;` > `boolean drawCollision = false;`
Toggles rendering the collision Toggles rendering the collision
> `boolean noclip = false;` > `boolean noclip = false;`
Toggles noclip Toggles noclip
> `boolean engineDraw = false;` > `boolean engineDraw = false;`
Toggles drawing entities as seen in the engine Toggles drawing entities as seen in the engine
> `Color debugColor = Color.red;` > `Color debugColor = Color.red;`
Changes the font color for drawPos and drawFrames Changes the font color for drawPos and drawFrames
> `boolean intro = true;` > `boolean intro = true;`
Toggles the intro splash screen at startup Toggles the intro splash screen at startup
> `ImageIcon splash = null;` > `ImageIcon splash = null;`
Image drawn below the engine splash screen at startup Image drawn below the engine splash screen at startup
> `boolean drawFrames = false;` > `boolean drawFrames = false;`
Toggles drawing the framerate and tickrate. Toggles drawing the framerate and tickrate.
@ -137,165 +150,203 @@ TPS: -- (--ms)
FPS: -- (--ms) FPS: -- (--ms)
``` ```
> `boolean consoleEnabled = true;` > `boolean consoleEnabled = true;`
Enables or disables the developer console accessible with the tilde key Enables or disables the developer console accessible with the tilde key
> `boolean fullbright = false;` > `boolean fullbright = false;`
Toggles fullbright Toggles fullbright
***Public Variables*** ***Public Variables***
> `Point mousePos;` > `Point mousePos;`
Current mouse position Current mouse position
> `Point mouseDelta;` > `Point mouseDelta;`
How much the mouse moved How much the mouse moved
> `boolean drawPlayer = true;` > `boolean drawPlayer = true;`
Toggles whether or not the player is rendered with the default rendering Toggles whether or not the player is rendered with the default rendering
> `Position mouseWorldPos = new Position();` > `Position mouseWorldPos = new Position();`
Mouse position translated into the world Mouse position translated into the world
> `boolean enableBloom = true, enableExposure = true;` > `boolean enableBloom = true, enableExposure = true;`
Toggles bloom and exposure (experimental, kills performance) Toggles bloom and exposure (experimental, kills performance)
***Methods*** ***Methods***
> `void setPlrSpeed(double speed)` > `void setPlrSpeed(double speed)`
Sets the player speed Sets the player speed
> `void setPlrPos(Position pos)` > `void setPlrPos(Position pos)`
Sets the player position Sets the player position
> `void setShortCollision(boolean b)` > `void setShortCollision(boolean b)`
Toggles whether or not the player has short collision Toggles whether or not the player has short collision
true = half of sprite height true = half of sprite height
false = exact sprite height false = exact sprite height
> `void setWindowTitle(String title)` > `void setWindowTitle(String title)`
Sets the title of the window Sets the title of the window
> `void setupScenes()` > `void setupScenes()`
Reads and mounts the scenes from the files in data/scenes/ Reads and mounts the scenes from the files in data/scenes/
> `void loadScene(String name)` > `void loadScene(String name)`
Load a scene (must be mounted first with setupScenes()) Load a scene (must be mounted first with setupScenes())
> `void addCustomEntity(TridEntity e)` > `void addCustomEntity(TridEntity e)`
Registers a custom entity. Registers a custom entity.
Must use the registry constructor (e.g. `Trident.addCustomEntity(new ExampleEntity());`) Must use the registry constructor (e.g. `Trident.addCustomEntity(new ExampleEntity());`)
> `void spawnEntity(TridEntity e)` > `void spawnEntity(TridEntity e)`
Spawn an entity in the current scene. Spawn an entity in the current scene.
> `void setDefaultScene(String s)` > `void setDefaultScene(String s)`
Sets the default scene when starting the game. Keep in mind this doesn't do anything during runtime, and is only useful during setup Sets the default scene when starting the game. Keep in mind this doesn't do anything during runtime, and is only useful during setup
> `void destroy(TridEntity object)` > `void destroy(TridEntity object)`
Removes an object from the current scene. Keep in mind that if the object is referenced elsewhere, it will technically still be alive, but won't render or update. Removes an object from the current scene. Keep in mind that if the object is referenced elsewhere, it will technically still be alive, but won't render or update.
> `void shakeCam(double intensity)` > `void shakeCam(double intensity)`
Add 'trauma' to the camera shake system. 0 is minimum, 1 is maximum. Add 'trauma' to the camera shake system. 0 is minimum, 1 is maximum.
> `void removeShake()` > `void removeShake()`
Set the camera shake's 'trauma' to 0, stopping any current shaking. Set the camera shake's 'trauma' to 0, stopping any current shaking.
> `void setShakeStrength(int str)` > `void setShakeStrength(int str)`
Sets the strength of the camera shake system. `str` is in pixels, as in if the current 'trauma' is 1, or max, the camera can move `str` pixels away from it's actual position. Sets the strength of the camera shake system. `str` is in pixels, as in if the current 'trauma' is 1, or max, the camera can move `str` pixels away from it's actual position.
> `void setShakeLoss(double loss)` > `void setShakeLoss(double loss)`
Sets how fast the camera shake loses 'trauma' per millisecond. Sets how fast the camera shake loses 'trauma' per millisecond.
For example, if `loss` is 0.0003 (the default setting), and 16 milliseconds pass in a tick, the camera shake system's 'trauma' will lose 0.0048 'trauma' or 0.48% 'trauma' in one tick. This may sound like very little, but remember the game is often running around 60 ticks per second. In one second, the camera shake would lose 30% 'trauma', meaning it would take just over 3 seconds to go from 100% 'trauma' to 0%. For example, if `loss` is 0.0003 (the default setting), and 16 milliseconds pass in a tick, the camera shake system's 'trauma' will lose 0.0048 'trauma' or 0.48% 'trauma' in one tick. This may sound like very little, but remember the game is often running around 60 ticks per second. In one second, the camera shake would lose 30% 'trauma', meaning it would take just over 3 seconds to go from 100% 'trauma' to 0%.
> `void setBloom(double amount)` > `void setBloom(double amount)`
Sets the amount of bloom to use in post-processing. This feature is experimental and causes significant performance issues. Sets the amount of bloom to use in post-processing. This feature is experimental and causes significant performance issues.
> `void setExposure(double exp)` > `void setExposure(double exp)`
Sets the amount of exposure to use in post-processing. This feature is experimental and causes strange rendering. Sets the amount of exposure to use in post-processing. This feature is experimental and causes strange rendering.
> `void setLightBlur(int level)` > `void setLightBlur(int level)`
Sets the lighting system to blur the lighting `level` times. It's recommended to leave it at 1, the default, since it has a good balance between performance and quality. Sets the lighting system to blur the lighting `level` times. It's recommended to leave it at 1, the default, since it has a good balance between performance and quality.
> `void addLight(Light l)` > `void addLight(Light l)`
Adds a light to the light list. If you want an entity to spawn during runtime, and have a light with it, you have to use this method. Make sure you also remove the light before the entity is deleted, otherwise you could end up with a rogue light. Adds a light to the light list. If you want an entity to spawn during runtime, and have a light with it, you have to use this method. Make sure you also remove the light before the entity is deleted, otherwise you could end up with a rogue light.
> `void resetKeys()` > `void resetKeys()`
You can run this method and it will reset all keys to be not pressed, as well as all mouse buttons to not be pressed. You can run this method and it will reset all keys to be not pressed, as well as all mouse buttons to not be pressed.
> `void setPlrSprite(String path)` > `void setPlrSprite(String path)`
Sets a new filepath to be where the player looks for its spritesheets. Sets a new filepath to be where the player looks for its spritesheets.
> `void removeLight(Light l)` > `void removeLight(Light l)`
Removes a light from the light list. Removes a light from the light list.
> `void setDefaultLight(int level)` > `void setDefaultLight(int level)`
Sets the default light level for the scene. 0 is completely dark, 255 is completely bright. You can use this during runtime to make something like a day-night cycle, or dynamically change the lighting when entering a dark area. Sets the default light level for the scene. 0 is completely dark, 255 is completely bright. You can use this during runtime to make something like a day-night cycle, or dynamically change the lighting when entering a dark area.
> `double getPlrSpeed()` > `double getPlrSpeed()`
Returns the player's current speed. Returns the player's current speed.
> `Position getPlrPos()` > `Position getPlrPos()`
Returns a copy of the player's position. Editing this `Position` object will not change the player's location. Returns a copy of the player's position. Editing this `Position` object will not change the player's location.
> `Scene getCurrentScene()` > `Scene getCurrentScene()`
Returns the current scene as a `Scene` object. If you want to get the scene's name, you can use `Trident.getCurrentScene().name`. Returns the current scene as a `Scene` object. If you want to get the scene's name, you can use `Trident.getCurrentScene().name`.
> `boolean getFullscreen()` > `boolean getFullscreen()`
Returns a `boolean` to say if the game is in fullscreen. `true` means it's in fullscreen, `false` means it's in windowed. Returns a `boolean` to say if the game is in fullscreen. `true` means it's in fullscreen, `false` means it's in windowed.
> `ArrayList<Entity> tridArrToEntArr(ArrayList<TridEntity> entities)` > `ArrayList<Entity> tridArrToEntArr(ArrayList<TridEntity> entities)`
Translates a `TridEntity` list into an `Entity` list. Since `TridEntity` is an engine-specific class, and `Entity` is a library-specific class, this could be used to make an engine's entity list compatible with some library methods that take `Entity` lists. Translates a `TridEntity` list into an `Entity` list. Since `TridEntity` is an engine-specific class, and `Entity` is a library-specific class, this could be used to make an engine's entity list compatible with some library methods that take `Entity` lists.
> `ArrayList<TridEntity> entArrToTridArr(ArrayList<Entity> entities)` > `ArrayList<TridEntity> entArrToTridArr(ArrayList<Entity> entities)`
Translates an `Entity` list into a `TridEntity` list. Similarly to the previous method, it could be used to make library methods that return `Entity` lists compatible with the engine. Translates an `Entity` list into a `TridEntity` list. Similarly to the previous method, it could be used to make library methods that return `Entity` lists compatible with the engine.
> `ArrayList<TridEntity> getEntities()` > `ArrayList<TridEntity> getEntities()`
Gets the `TridEntity` list of the current scene. This is useful when looking for other entities. Gets the `TridEntity` list of the current scene. This is useful when looking for other entities.
> `ArrayList<Rectangle> getCollision()` > `ArrayList<Rectangle> getCollision()`
Gets the collision from all entities in the scene, expressed as `Rectangle` objects Gets the collision from all entities in the scene, expressed as `Rectangle` objects
> `boolean getMouseDown(int mb)` > `boolean getMouseDown(int mb)`
Returns if the mouse button `mb` is pressed, from 1 to 5. Returns if the mouse button `mb` is pressed, from 1 to 5.
@ -306,19 +357,23 @@ Returns if the mouse button `mb` is pressed, from 1 to 5.
4, 5 = mouse button 4, 5 (side buttons on specific mice) 4, 5 = mouse button 4, 5 (side buttons on specific mice)
``` ```
> `boolean getKeyDown(int key)` > `boolean getKeyDown(int key)`
Returns if the key `key` is pressed, using the `java.awt.event.KeyEvent` keycodes. For example, if you import `java.awt.event.*` or `java.awt.event.KeyEvent`, you can use `KeyEvent.VK_W` to represent the 'W' key. Like this: `Trident.getKeyDown(KeyEvent.VK_W);` Returns if the key `key` is pressed, using the `java.awt.event.KeyEvent` keycodes. For example, if you import `java.awt.event.*` or `java.awt.event.KeyEvent`, you can use `KeyEvent.VK_W` to represent the 'W' key. Like this: `Trident.getKeyDown(KeyEvent.VK_W);`
> `Player getPlr()` > `Player getPlr()`
Gets the `Player` object. Gets the `Player` object.
> `int getFrameWidth()` and `int getFrameHeight()` > `int getFrameWidth()` and `int getFrameHeight()`
Gets the set frame width and height, respectively. Gets the set frame width and height, respectively.
### TridEntity.java ### TridEntity.java
Meant to be a superclass for all custom entities Meant to be a superclass for all custom entities
@ -326,39 +381,48 @@ Meant to be a superclass for all custom entities
It's in the name. `true` if it has collision, `false` if it doesn't. It's in the name. `true` if it has collision, `false` if it doesn't.
> `TridEntity(Position pos)` > `TridEntity(Position pos)`
Constructor that makes an entity with no collision. Constructor that makes an entity with no collision.
> `TridEntity(Position pos, Dimension collision)` > `TridEntity(Position pos, Dimension collision)`
Constructor that makes an entity with collision as defined in `collision`. Constructor that makes an entity with collision as defined in `collision`.
> `TridEntity construct(Position pos, Dimension collision, int[] data)` > `TridEntity construct(Position pos, Dimension collision, int[] data)`
Prints "Error: tried to create an empty entity" and returns `null`. Prints "Error: tried to create an empty entity" and returns `null`.
> `Rectangle getCollision()` > `Rectangle getCollision()`
Gets the collision of the entity. Can be overridden, for example if you want a door that returns a `Rectangle(0, 0, 0, 0)` collision when open, and the default collision when closed. Gets the collision of the entity. Can be overridden, for example if you want a door that returns a `Rectangle(0, 0, 0, 0)` collision when open, and the default collision when closed.
> `void render(Graphics g, JPanel panel, int x, int y)` > `void render(Graphics g, JPanel panel, int x, int y)`
Refer to ExampleEntity.java. Refer to ExampleEntity.java.
> `void engineRender(Graphics g, JPanel panel, int x, int y)` > `void engineRender(Graphics g, JPanel panel, int x, int y)`
Renders the entity as it would be in the engine. Can be overridden, for example if the game would be too difficult to navigate without it rendering properly. Renders the entity as it would be in the engine. Can be overridden, for example if the game would be too difficult to navigate without it rendering properly.
> `void update(long elapsedTime)` > `void update(long elapsedTime)`
Refer to ExampleEntity.java. Refer to ExampleEntity.java.
> `void sceneStart(String scene)` > `void sceneStart(String scene)`
Refer to ExampleEntity.java. Refer to ExampleEntity.java.
### ent/ ### ent/
Contains the default engine entities. Not typically used during runtime. Contains the default engine entities. Not typically used during runtime.
@ -371,6 +435,7 @@ Colored box that has collision.
`size` = size of the box. `size` = size of the box.
`c` = color of the box. `c` = color of the box.
#### BoxNoColl.java #### BoxNoColl.java
Colored box with no collision. Colored box with no collision.
@ -380,6 +445,7 @@ Colored box with no collision.
`c` = color of the box. `c` = color of the box.
`w`, `h` = width and height of the box. `w`, `h` = width and height of the box.
#### InvisColl.java #### InvisColl.java
Invisible collision. Invisible collision.
@ -388,6 +454,7 @@ Invisible collision.
`pos` = position of the collision. `pos` = position of the collision.
`size` = size of the collision. `size` = size of the collision.
#### PlrStart.java #### PlrStart.java
Where the player starts in a scene. Note that the engine will only take the first one it finds, or the oldest. Where the player starts in a scene. Note that the engine will only take the first one it finds, or the oldest.
@ -395,6 +462,7 @@ Where the player starts in a scene. Note that the engine will only take the firs
I mean do I really need to tell you what `pos` means at this point? I mean do I really need to tell you what `pos` means at this point?
#### TridLight.java #### TridLight.java
Spawns a light, only really useful in engine. Spawns a light, only really useful in engine.
@ -403,6 +471,7 @@ Spawns a light, only really useful in engine.
`pos` = you guessed it, position of the light. `pos` = you guessed it, position of the light.
`r` = radius of the light. `r` = radius of the light.
#### Trigger.java #### Trigger.java
Runs code in the `Update` class every tick that the player is inside the bounds. Runs code in the `Update` class every tick that the player is inside the bounds.
@ -412,6 +481,7 @@ Runs code in the `Update` class every tick that the player is inside the bounds.
`size` = size of the trigger. `size` = size of the trigger.
`i` = ID of the trigger. This is sent through when running the `Update.trigger(int id)` method. `i` = ID of the trigger. This is sent through when running the `Update.trigger(int id)` method.
## update/ ## update/
Contains the main ways you, as the developer, will interact with the game, other than entities. Contains the main ways you, as the developer, will interact with the game, other than entities.
@ -423,6 +493,7 @@ Runs code whenever an input is detected.
Runs when a key is pressed. `key` uses the `java.awt.event.KeyEvent` keycodes. See trident/Trident.java, method `getKeyDown(int key)`. Runs when a key is pressed. `key` uses the `java.awt.event.KeyEvent` keycodes. See trident/Trident.java, method `getKeyDown(int key)`.
> `void mousePressed(int mb, Point mousePos, Position worldPos)` > `void mousePressed(int mb, Point mousePos, Position worldPos)`
Runs when a mouse button is pressed. Runs when a mouse button is pressed.
@ -430,10 +501,12 @@ Runs when a mouse button is pressed.
`mousePos` = mouse position on the screen. `mousePos` = mouse position on the screen.
`worldPos` = mouse position in the game world (useful for clicking on entities). `worldPos` = mouse position in the game world (useful for clicking on entities).
> `void onScroll(int scroll)` > `void onScroll(int scroll)`
Runs when the mouse wheel is scrolled. `scroll` is the scroll direction, where `-1` is up/forward and `1` is down/backward. Runs when the mouse wheel is scrolled. `scroll` is the scroll direction, where `-1` is up/forward and `1` is down/backward.
### Update.java ### Update.java
Contains things like setup, update, and trigger. Used to interface with the engine. Contains things like setup, update, and trigger. Used to interface with the engine.
@ -441,18 +514,22 @@ Contains things like setup, update, and trigger. Used to interface with the engi
Runs before the game starts to set things up. Such as adding custom entities to the registry, setting the settings, and setting the splash screen image. Runs before the game starts to set things up. Such as adding custom entities to the registry, setting the settings, and setting the splash screen image.
> `void sceneStart(String scene)` > `void sceneStart(String scene)`
Runs when a new scene is loaded. `scene` is the name of the scene. Runs when a new scene is loaded. `scene` is the name of the scene.
> `void update(long elapsedTime)` > `void update(long elapsedTime)`
Runs once every 'tick'. `elapsedTime` is the milliseconds since the last tick. Runs once every 'tick'. `elapsedTime` is the milliseconds since the last tick.
> `void trigger(int id)` > `void trigger(int id)`
Run when the player is in a `Trigger` object. `id` is the ID of the `Trigger` object. Run when the player is in a `Trigger` object. `id` is the ID of the `Trigger` object.
> `void tridentEvent(int id)` > `void tridentEvent(int id)`
Run when Trident does various things. Current events: Run when Trident does various things. Current events:
@ -461,6 +538,7 @@ Run when Trident does various things. Current events:
Runs when the player takes a screenshot Runs when the player takes a screenshot
``` ```
> `int command(ArrayList<String> cmdParts)` > `int command(ArrayList<String> cmdParts)`
Lets you add more commands to the developer console accessible through the tilde key. Return 0 if the command is recognized, 1 if it is not. Lets you add more commands to the developer console accessible through the tilde key. Return 0 if the command is recognized, 1 if it is not.