Members
auto_optimize :number
Auto otimization flag. 1:ON -1:OFF
Type:
- number
- Source:
camera_mode :number
Mode of camera - 1:2d -1:3d
Type:
- number
- Source:
(constant) CAMERA_SHAKE :Number
player camera shake constant
Type:
- Number
- Source:
(constant) canvas :object
Canvas object
Type:
- object
- Source:
controls :Array
Map to key track of dynamic keybinds
Map to keep track of dynamic keybinds. Links actual keys with "codes" to determine said key's behaviour. i.e. ArrowLeft will by default map to rotate_left which will cause left rotation behaviour.
Type:
- Array
- Source:
(constant) ctx :object
2d context of the canvas
Type:
- object
- Source:
current_screen :number
ID of current screen. 0:gameplay 1:Win 2:Lose 3:Start 4:Load 5:Highscores
Type:
- number
- Source:
current_stage :object
Reference to the currently loaded Stage
Reference to the current Stage. For multiple "levels" within a single load of the program, this variable will change to a new Stage object. This was supposed to be implimented kinda how I would in C using Stage Object pointers. i.e. Stage* current_stage -> draw();
Type:
- object
- Source:
current_stage_ID :number
Index of selected stage or -1 if random
Type:
- number
- Source:
(constant) G :Number
Gravitational constant
Type:
- Number
- Source:
high_score_initials :array
Array for storing highschool entry initials
Type:
- array
- Source:
interval_id :number
ID of mainloop interval
Type:
- number
- Source:
keyPressMap :number
Map of the current state of keys. i.e. whether they are pressed or not. This is to solve the problem of annoying key press latency.
Type:
- number
- Source:
last_tick_time :number
Time tracking variable for framerate display and optimization
Type:
- number
- Source:
- To Do:
-
- fully impliment
(constant) MAX_X :number
Maximum x coordinate of the canvas
Type:
- number
- Source:
(constant) MAX_Y :number
Maximum y coordinate of the canvas
Type:
- number
- Source:
(constant) MENU_COLOUR :string
Colour of start menu text
Type:
- string
- Source:
(constant) MENU_KEYPRESS_MAP :array
Map of keypress behaviour functions
Type:
- array
- Source:
menu_selection :number
Index of selected option in menu
Type:
- number
- Source:
(constant) MIN_X :number
Minimum x coordinate of the canvas
Type:
- number
- Source:
(constant) MIN_Y :number
Minimum y coordinate of the canvas
Type:
- number
- Source:
pause :number
Paused game flag. 1:paused -1:unpaused
Type:
- number
- Source:
rails_depth :number
Depth of physics calculations
Linear physics calculation depth is the amount of iterations used to predict the future position of the player. Greater numbers will mean the player position will be predicted and displayed further into the "future", but will add increased strain to the cpu
Type:
- number
- Source:
(constant) ROCKET_SPEED :Number
player acceleration constant
Type:
- Number
- Source:
(constant) soundManager :array
Sound manager object. soundManger["soundname"] will return an HTML Audio object
Type:
- array
- Source:
(constant) STAGES_DISPLAY_OPTIONS :array
Stages selection menu options
Type:
- array
- Source:
(constant) START_MENU_OPTIONS :array
Menu options
Type:
- array
- Source:
(constant) TICK_MAP :array
Map of tick behaviour functions
Type:
- array
- Source:
tickCount :number
Total ticks that have been called. Will cause undefined behaviour if the game is left running for longer than about 200 days. (i.e MAX_SAFE_INT is reached and tickCount overflows.)
Type:
- number
- Source:
total_tick_time :number
Time tracking variable for framerate display and optimization
Type:
- number
- Source:
- To Do:
-
- fully impliment
updateNextControl :object
Variable to detect key bind changes. Will change to non null and store the information needed for the next key bind change.
Type:
- object
- Source:
Methods
add_alpha(colour, alpha)
Inserts an alpha value into a canvas rgb colour
Parameters:
Name | Type | Description |
---|---|---|
colour |
string | colour before alpha |
alpha |
number | alpha value |
- Source:
Returns:
New colour with alpha value
calc_collision(object, physics_objs) → {boolean}
Calculates collisions between two objects
Parameters:
Name | Type | Description |
---|---|---|
object |
object | to calculate collisions on |
physics_objs |
array | array of objects to calculate collisions from |
- Source:
Returns:
collision happened
- Type
- boolean
calc_grav(object, physics_objs) → {number}
Calculates x/y accleration to apply to an object
Parameters:
Name | Type | Description |
---|---|---|
object |
object | to calculate physics on |
physics_objs |
array | array of objects to calculate physics from |
- Source:
Returns:
acceleration to apply in [x,y] form
- Type
- number
clear_screen(alpha)
Clears the screen by redrawing the background image
Parameters:
Name | Type | Description |
---|---|---|
alpha |
number | Alpha value for background |
- Source:
debug_stage()
Prints the relevent contents of a stage to the console for debug purposes
- Source:
draw()
Renders the screen
- Source:
draw_arc(size, arc_start, arc_length)
Draws an arc to the canvas
Parameters:
Name | Type | Description |
---|---|---|
size |
number | size to scale shape to in radians |
arc_start |
number | Radian to start drawing at |
arc_length |
number | Radian to end drawing at |
- Source:
draw_path()
Renders the physics prediction line
- Source:
- To Do:
-
- Maybe store this function somewhere better
draw_shape(shape, x, y, colour, size, rotation, md, arc_start, arc_length)
Draws a shape to the canvas
Parameters:
Name | Type | Description |
---|---|---|
shape |
string | Shape description |
x |
number | x coordinate to draw at |
y |
number | y coordinate to draw at |
colour |
string | Shape colour |
size |
number | size to scale shape to in radians |
rotation |
number | rotation to draw shape at |
md |
number | Outline flag 1:YES 0:NO |
arc_start |
number | if a circle, radian to start drawing at |
arc_length |
number | if a circle, radian to end drawing at |
- Source:
get_angle(a, b) → {number}
Calculates the angle between two objects
Parameters:
Name | Type | Description |
---|---|---|
a |
object | Object one |
b |
object | Object two |
- Source:
Returns:
angle between a and b
- Type
- number
get_distance(a, b) → {number}
Calculates the distance between two objects
Parameters:
Name | Type | Description |
---|---|---|
a |
object | Object one |
b |
object | Object two |
- Source:
Returns:
distance between a and b
- Type
- number
get_element(id) → {object}
gets an element from document
Parameters:
Name | Type | Description |
---|---|---|
id |
string | id of element |
- Source:
Returns:
element of document
- Type
- object
get_framerate() → {number}
Calculates the current framerate
- Source:
Returns:
Framerate
- Type
- number
get_HTML(id) → {object}
gets an HTML fragment from document
Parameters:
Name | Type | Description |
---|---|---|
id |
string | id of HTML |
- Source:
Returns:
HTML of document
- Type
- object
get_possible_keys() → {array}
Gets the adjustable keybinds
- Source:
Returns:
adjustable keybinds
- Type
- array
get_sounds()
gets all of the projects sound names
Sounds were aquired from soundbible.com and soundcloud.com/squirrel-murphy/maeistrom-sounds
- Source:
Returns:
array of sound names
get_val(id) → {object}
gets a value from document
Parameters:
Name | Type | Description |
---|---|---|
id |
string | id of element |
- Source:
Returns:
value of document
- Type
- object
inBounds(xmin, xmax, ymin, ymax) → {boolean}
Calculates if x,y is the bounding box formed by xmin,ymin xmax,ymax
Parameters:
Name | Type | Description |
---|---|---|
xmin |
number | x coordinate of the top left corner of the bounding box |
xmax |
number | x coordinate of the bottom right corner of the bounding box |
ymin |
number | y coordinate of the top left corner of the bounding box |
ymax |
number | y coordinate of the bottom right corner of the bounding box |
- Source:
Returns:
x,y is within xmin,ymin xmax,ymax
- Type
- boolean
key_down(event)
Detects key down events and updates the key tracker
Parameters:
Name | Type | Description |
---|---|---|
event |
object | event to pull keypress data from |
- Source:
key_press_game(event)
Runs keypress behaviour for gameplay screen
Parameters:
Name | Type | Description |
---|---|---|
event |
object | keypress event object |
- Source:
key_press_highscore_menu(event)
Runs keypress behaviour for highscore viewing menu
Parameters:
Name | Type | Description |
---|---|---|
event |
object | keypress event object |
- Source:
key_press_load_menu(event)
Runs keypress behaviour for load stage menu
Parameters:
Name | Type | Description |
---|---|---|
event |
object | keypress event object |
- Source:
key_press_lose(event)
Runs keypress behaviour for lose screen
Parameters:
Name | Type | Description |
---|---|---|
event |
object | keypress event object |
- Source:
key_press_start_menu(event)
Runs keypress behaviour for start menu
Parameters:
Name | Type | Description |
---|---|---|
event |
object | keypress event object |
- Source:
key_press_win(event)
Runs keypress behaviour for win screen
Parameters:
Name | Type | Description |
---|---|---|
event |
object | keypress event object |
- Source:
key_up(event)
Detects key up events and updates the key tracker
Parameters:
Name | Type | Description |
---|---|---|
event |
object | event to pull keypress data from |
- Source:
left_shift(arr)
Left shifts elements in an array
Parameters:
Name | Type | Description |
---|---|---|
arr |
array | array to shift |
- Source:
load_level(md, index)
Loads a new stage into the game
Parameters:
Name | Type | Description |
---|---|---|
md |
number | stage creation mode 0:Random gen, 1: Load level |
index |
number | if loading a level, index of level to load |
- Source:
loading_screen_display()
Draws the word loading to the screen
- Source:
menu(inputs, display)
Renders a menu
Parameters:
Name | Type | Description |
---|---|---|
inputs |
array | Menu options |
display |
string | Menu Title |
- Source:
mouse_click(event)
Detects mouse click events and updates the rail depth settings
Parameters:
Name | Type | Description |
---|---|---|
event |
object | event to pull mousepress data from |
- Source:
newtons_gravity(m, d) → {number}
Calculates the acceleration due to gravity applied to an object
Parameters:
Name | Type | Description |
---|---|---|
m |
number | Mass of object two |
d |
number | Distance between the two objects |
- Source:
Returns:
Acceleration due to gravity
- Type
- number
ran_b(min_b, max_b) → {number}
Generates a random integer between min_b and max_b inclusively
Parameters:
Name | Type | Description |
---|---|---|
min_b |
number | Minimum bound |
max_b |
number | Maximum bound |
- Source:
Returns:
Random integer min_b <= num <= max_b
- Type
- number
ran_colour() → {string}
Generates a random rgb colour
- Source:
Returns:
Random colour
- Type
- string
reset_keypress()
Resets all kepresses to off
- Source:
set_HTML(id, val)
sets an HTML fragment in a document
Parameters:
Name | Type | Description |
---|---|---|
id |
string | id of element |
val |
string | value of HTML to set to element |
- Source:
set_val(id, val)
sets a value in a document
Parameters:
Name | Type | Description |
---|---|---|
id |
string | id of element |
val |
string | value to set to element |
- Source:
setUp()
Runs on page load. Initializes global variables. Sets intial physics calculation depth to the settings field. Initializes default keybinds. Adds event listeners.
- Source:
- To Do:
-
- Move to settings file system
- Move to server side global highscores
sort_player_distance(a) → {number}
Calculates the distance between an object and the player. Used for sorting
Parameters:
Name | Type | Description |
---|---|---|
a |
object | Object one |
- Source:
Returns:
distance between a and player
- Type
- number
tick()
Main game tick function. Applies key inputs. Updates framerate display. Updates tickcounts. Runs subtick methods. Calculates collisions. Calculates endgame conditions. Draws the screen. Updates information displays
- Source:
tick_gameplay()
Runs tick behaviour for the gameplay screen
- Source:
tick_lose_menu()
Runs tick behaviour for the lose menu
- Source:
tick_win_menu()
Runs tick behaviour for the win menu
- Source:
toggle_auto_rails()
Toggles optimizations
- Source:
- To Do:
-
- fully implement better optimizations. For now, this isn't really worth turning on
update_rails(amt)
Resets the Rocket#rails array
Parameters:
Name | Type | Description |
---|---|---|
amt |
new depth value |
- Source:
update_selection(key, selector, options)
Moves a menu selector up or down with wrapping
Parameters:
Name | Type | Description |
---|---|---|
key |
number | code of key press |
selector |
number | current selection |
options |
array | menu options |
- Source:
Returns:
new selction
update_settings()
Gets new physics depth input, validates it, and applies it
- Source:
updateControls()
Pauses the game, and sets updateNextControl to the keybind being updated
- Source:
updateKey(val, event)
Updates a keybind
Parameters:
Name | Type | Description |
---|---|---|
val |
string | new keybind |
event |
object | event to pull keypress data from. If undefined, function is in force override mode |
- Source:
vector(magnitude, angle) → {array}
Generates x/y values from a vector in magnitude/angle form
Parameters:
Name | Type | Description |
---|---|---|
magnitude |
number | Magnitude value to apply to vector |
angle |
number | angle to multiply magnitude by |
- Source:
Returns:
Vector in [x,y] form
- Type
- array