Aman Swaroop, Kuzey Gok, Myles Dalton
UWB CSS 452 | Professor Kelvin Sung
03/11/2022
Projectile Systems SDK Documentation
Module Description
Our module supports the creation of and general implementation of projectile systems.Our projectile system will be an
extension of the Game.Object class found in the game_objects file of the engine. Our current game engine uses the
Game.Object class to create projectiles. While this is possible, it is a very lackluster and barebones implementation
of a projectile. The game objects class was created as a main class for any game object made in the game and cannot be
considered a specialized solution for projectile objects.
Application Programming Interface (API)
List of scripts:
projectile.js:
- Creates a projectile object which is extended from the game object class.
- Sets the path of the projectile and calculates next projectile location based on the set path type.
- Sets up the ability to get a new trail renderable set up and changes the location of the trail renderable such
that it spawns every (input) trail interval time
- Sets its own lifetime and is destroyed after that lifetime is complete
- Has behavior effects beyond the bounds of creation and deletion that include object collision (among other
things)
trail_renderable.js:
- Sets up the projectile's trail renderable based on the projectile's previously known location
- Sets itself to invalid after the lifetime of the renderable has been completed (or if the parent projectile
dies)
List of functions:
Projectile
A projectile object is a game object that has properties that allows it to move across the screen and has a path that
would be similar to a projectile.
- Projectile (renderable, _lifetime, _trailTexture, _trailLifetime, _trailInterval)
- Parameter 1: renderable
- Accepts a string value for a renderable which the Projectile class will turn into a new texture renderable
to send to the super class (Game Object)
- Parameter 2: _lifetime
- Defines the lifetime of the projectile such that after the lifetime has elapsed, the projectile will no
longer be valid
- Parameter 3: _trailTexture
- Accepts a string value for the trailTexture which the Projectile class will set as the projectile's
trails' texture renderable. This will further be called in a future method to be drawn at a specific
location.
- The value of the trail texture will be defaulted to null in the case that the user does not provide a
value for the trail's texture.
- Parameter 4: _trailLifetime
- Defines the amount of time a trail renderable will be alive as it follows a projectile. After the amount
of time has elapsed, the trail renderable will be set to invalid inside the TrailRenderable class.
- The value is defaulted to 0 in the case that no trail lifetime has been defined by the user.
- Parameter 5: _trailInterval
- Defines the amount of time it takes to spawn a new trail renderable. After the given amount of time has
elapsed a new trail renderable will be spawned in the projectile's previously known location.
- The value is defaulted to 1000 milliseconds in the case that the user has not defined a value for this
parameter.
- Parameter 6: _trailSize
- Defines the size of the trail that will follow the projectile.
- This constructor sets up the projectile object and defines the necessary functionality needed throughout the
entire class, which includes, but is not limited to the following:
- Projectile lifetime
- Projectile creation time
- Projectile acceleration
- Projectile maximum rotation
- Projectile target point (in the case that one is needed for tracking of an object)
- Projectile path type (because that changes the overall algorithm of projectile movement)
- Projectile trail interval
- Projectile trail lifetime
- Projectile trail renderable
- Projectile trail set
- Projectile trail timer
- Projectile validity
- Projectile trailSize
- setTrail(trailRenderable)
- Parameter 1: trailRenderable
- Accepts a string value for the trailRenderable which will override the previous trail renderable's value.
- Sets the current projectile's trail renderable to be the input parameter's value of trailRenderable.
- spawnTrail()
- No parameters needed
- Spawns a trail renderable if the projectile is valid, a trail renderable is defined, and the total amount of
time elapsed is greater than or equal to the trail timer
- setTrailSize(w, h)
- Parameter 1: w
- Accepts a numerical value for the w parameter which defines the total width of the trail renderable
- Parameter 2: h
- Accepts a numerical value for the h parameter which defines the total height of the trail renderable
- Sets the size of the trail renderable based on the input x and y variables. (x notates the width of the
renderable and y notates the height of the trail renderable)
- setAcceleration(acc)
- Parameter 1: acc
- Accepts a numerical value for the acc parameter which will override the previous projectile acceleration's
value.
- Sets the current projectile's acceleration value to be the input parameter's value of acc.
- setLifetime(lifetime)
- Parameter 1: lifetime
- Accepts a numerical value for the lifetime parameter which will override the previous projectile
lifetime's value.
- Sets the current projectile's lifetime value to be the input parameter's value of lifetime.
-
SetReflectingPrototypes(gameObjectPrototypes = [])
- Parameter 1: GameObjectPrototypes
- Accepts an array of types of game objects to bounce
- Sets the type of game objects that the projectile can bounce from
- reflect()
- Checks to see whether the game object types are of the correct type and bounces off the object if it is.
- setStraight(target, targetPoint, targetDirection, speed, acceleration)
- Parameter 1: target
- Accepts an input transform of an object as a parameter. Defaults to null if nothing is provided
- Parameter 2: targetPoint
- Accepts an input point as a parameter. Defaults to null if nothing is provided
- Parameter 3: targetDirection
- Accepts an input direction as a parameter. Defaults to null if nothing is provided
- Parameter 4: speed
- Accepts a numerical value of speed as a parameter. Defaults to 0 if nothing is provided.
- Parameter 5: acceleration
- Accepts a numerical value of acceleration as a parameter. Defaults to 0 if nothing is provided.
- Calculates the direction and speed of a projectile and sets the current projectile's speed and acceleration
to be the input speed and acceleration, respectively.
- calcNewRotate()
- Takes no parameters and is a helper function that is used to find the degrees of the rotation of the
projectile.
- setTracking(target, maxRotation, speed, acceleration)
- Parameter 1: target
- Accepts an input transform of an object as a parameter.
- Parameter 2: maxRotation
- Accepts a max rotation (in rad) as an input. Defaults to 2 * Math.PI if nothing is provided by the user.
- Parameter 3: speed
- Accepts a numerical value of speed as a parameter. Defaults to 0 if nothing is provided.
- Parameter 4: acceleration
- Accepts a numerical value of acceleration as a parameter. Defaults to 0 if nothing is provided.
- Calculates the direction and speed of the projectile and sets the current projectile's speed and
acceleration to be the input speed and acceleration, respectively. Sets the path type to be “tracking” for
further updating in the update function.
- setParabola(direction, speed, accDirection, accMagnitude)
- Parameter 1: direction
- Accepts a direction value as a parameter. Defaults to null if nothing is provided.
- Parameter 2: speed
- Accepts a numerical value of speed as a parameter. Defaults to 0 if nothing is provided.
- Parameter 3: accDirection
- Accepts a acceleration direction value as a parameter
- Parameter 4: accMagnitude
- Accepts a acceleration magnitude value as a parameter
- Uses physics to calculate the path trajectory and overall structure based on all the input parameters that
are provided by the users.
- onTermination()
- No parameters needed
- Defines the behavioral effects of the projectile once the projectile has been terminated. These differ from
path type and acceleration and speed and all.
- draw(camera)
- Parameter 1: camera
- Draws all the valid trail renderables and the projectile itself on the input camera.
- checkObjectLifespan()
- No parameters needed
- Checks to see if any of the trail renderables are valid. If they are invalid, they are deleted from the set
that holds all of the trail renderables within each projectile.
- update()
- No parameters needed
- Updates the location, direction, and speed of the projectile, and all of the trail renderables that are
associated with the individual projectile object.
- Static updateAllProjectiles()
-
Static function that will update all of the projectiles in the game object set.
- Static drawallProjectiles()
- Static function that will draw all of the projectiles in the game object set.
Trail Renderable
A Trail renderable is a texture renderable that shows the previous locations of a projectile object and will have its
own lifetime and renderable.
- TrailRenderable(renderable, _lifeTime, xform, size)
- Parameter 1: renderable
- Accepts a string value for a renderable which the Trail Renderable class will use in the future to get
further image processing.
- Parameter 2: _lifeTime
- Defines the lifetime of the trail renderable such that after the lifetime has elapsed, the trail
renderable will no longer be valid
- Parameter 3:xform
- Accepts the projectile's transform information so that the location and rotation can easily be set for the
trail renderable.
- Parameter 4: size
- Accepts a 2-element array for width and height of the trail renderable. Defaults to width 5 and height 3
if nothing is provided by the user.
- This constructor sets up the trail renderable object and defines the necessary functionality needed
throughout the entire class, which includes, but is not limited to the following:
- Trail renderable validity
- Trail renderable
- Trail lifetime
- Trail creation time
- update()
- No parameters needed
- Checks to see whether the current trail renderable's lifetime has elapsed and if it has, the trail
renderable is set to invalid.
- terminate()
- No parameters needed
- Sets the trail renderable to be invalid.
Edits to Current Engine API
Transform
NOTE: The client never needs to access this code. This content was included because it was not part of the original
game engine API.
- getCorners()
- No parameters needed
- Get the corners of the transform that you are trying to get. This makes our arithmetic slightly easier for
tracking projectile movement and other things.
GameObject
NOTE: The client never needs to access this code. This content was included because it was not part of the original game engine API.
- Added fields to update gameobject set to keep track of all elements in the game object set
Input
NOTE: The client never needs to access this code. This content was included because it was not part of the original game engine API.
- Added fields get previous key clicked and to get the shift key for accelerated movement
Conclusion
Strengths
- Quite easy to perform detailed functionality
- Movement is constant and non-jittery.
Weaknesses
- Takes in a lot of parameters to perform tasks
- Rotation can be altering a lot based on our calculations
Potential Future Improvements
- Make the overall structure of the project work better and more detailed for what we have in our game engine.