This Is (NOT!) A Car Club - BIBLE
how the game's code works
Files: game.php - loadfirst.js - ascend.js - functions.js - basic.js - input.js - main.jsFunctions that run every frame (or at least regularly and repeating)
ascend_main()
- runs every frame and updates the 3D terrain etc
cars_control()
- controls both the player's and AI characters' car movement
cars_physics()
- handles both the player's and AI characters' physics, for example friction, collision, gravity, etc
cars_sound()
- plays sounds depending on what you or AI characters do with the cars
layout_set()
- updates all layout
camera_set()
- updates the camera
light_set()
- updates daylight and all other lights (mostly daylight)
fog_set()
- updates fog
chunk_set()
- everything related to the current chunk
gameplay_fps()
- first person shooter gameplay code
cut_set()
- everything related to cut value. one big part of it is a list of where all characters should be placed and move towards at certain events, and one big part is the full list of story dialogue. there's also a bit other stuff.
Dialogue & story functions
dialog_set_metadata(at_object)
- sets character name & image and plays character sound at dialogue
cc(at_object, fdialog, from_x, from_z)
- shows dialogue in cutscene
cc2(at_object, fdialog, fdialog2, from_x, from_z)
- copy of cc() with different dialog depending on player's last answer
ccS(fdialog, fdialog2)
- copy of cc() for player's answer
ccS3(fdialog, fdialog2, fdialog3)
- copy of cc() for player's answer (3 answers!)
bet_pers(at_object, fdialog)
- LOCKED 231102 - shows dialogue BETween cutscenes. dialogue changes by timer
rolling_dialog()
- LOCKED 231007 - rolling text in dialog
rolling_dialog2()
- copy of rolling_dialog() for player's answer
rolling_dialog3()
- copy of rolling_dialog() for player's answer (3d answer!)
room_set(wall_texture, floor_texture)
- LOCKED 231007 - creates a room with a specific wall and floor texture, for dialogue "cutscenes"
place_cz_in_room(fobject, direction, height, distance)
- LOCKED 231007 - places characters/objects close to the player, in a specific direction (n,s,e,w,ne,nw,se,sw). good for quickly making a dialogue scene that looks OK
place_cz_in_room_ground(fobject, direction, height, distance)
- place_cz_in_room() but characters/objects get placed right above ground automatically
World functions
x_to_chunk_no(x)
- LOCKED 231007 - convert x or z position to chunk number
x_to_x_in_chunk(x)
- LOCKED 231007 - convert x or z position to x or z position relative to chunk
x_in_chunk_to_x(fi1, fi)
- LOCKED 231007 - convert chunk-relative x or z position to "real" x or z position
distance_get_xz(fx1, fz1, fx2, fz2)
- LOCKED 231007 - get distance between two points
distance_get(fobject1, fobject2)
- LOCKED 231007 - get distance between two czs/objects
height_get_xz(x, z)
- LOCKED 231012 - get height at position, not exact height but heightgrid height
height_get_xz_exact(x, z)
- get exact height at position (interpolates between four points (height values) to find out the exact value - https://codeplea.com/triangular-interpolation)
height_get(fobject)
- get exact height at a cz's/object's position
object_get(object)
- get object value (another thing than cz/object. this is part of the terrain: trees, houses, etc) at cz's/object's position
place_sprite(fobject, fx, fz)
- Makes sure characters and/or objects get the correct height (just above ground)
place_sprite_noidle(fobject, fx, fz)
- LOCKED 231012 - same as place_sprite() but with no idle stuff
talk_char(fsprite, fpos_x, fpos_z, fcut, fdistance, fradius)
- abstraction for talk characters in chunk_set()
talk_char_still(fsprite, fpos_x, fpos_z, fcut, fdistance)
- talk_char() but for characters that stand still
talk_char_flag(fsprite, fpos_x, fpos_z, fcut, fdistance)
- talk_char() but for characters that stand still, with longer click distance. and flag functionality (race).
talk_char_where(fsprite, fpos_x, fpos_z, fcut, fcz1, fcz2, fcz3, fcut2)
- variant of talk_char() for going to different cuts depending on where certain characters are
talk_char_when_still(fsprite, fpos_x, fpos_z, fcut, fcut_after, fcut_last)
- variant of talk_char() for going to different cuts depending on which cut you are at (=where in the game's story)
Terrain generation functions
distance_get_oval_xz(fx1, fz1, fx2, fz2, factorx, factorz)
- LOCKED 231012 - distance functions turn out to be useful for creating circles, or in this case ovals, in the terrain.
grelf()
- LOCKED 231007 - From Graham Relf's game The Forest. All terrain creation in the game is based on this
grelf3()
- LOCKED 231007 - variation on grelf()
grelf_detail()
- LOCKED 231007 - a more "high-res" version of grelf()
grelf_detail2()
- LOCKED 231007 - variation on grelf_detail()
grelf_objects()
- LOCKED 231007 - just a bit different grelf(), i think
grelf_objects_detail()
- LOCKED 231007 - a more "high-res" version of grelf_objects(), i think
grelf_houses()
- LOCKED 231007 - just a bit different grelf(), i think
grelf_weird()
- LOCKED 231007 - a high-res version of grelf()
set_wideness_highness(fi1, fj1)
- LOCKED 231007 - here i set values that decide how the weights in set_weights() will turn out (= how the terrain will look)
set_weights(fi1, fj1, fi, fj)
- LOCKED 231007 - here weights get set that decide how the hm and object generation will turn out. everything here should come originally from the seed variable
calculate_chunklevel(fi1, fj1, fi, fj)
- LOCKED 231102 - tilts a whole chunk. complicated to explain but it's cool and effective
terrain_amplify(fi1, fj1, fi, fj, depth)
- LOCKED - creating a lake/hole in ONE chunk. or mountain
terrain_amplify_4chunks(fi1_start, fj1_start, fi1, fj1, fi, fj, depth, fpower)
- LOCKED - creating a lake/hole in 4 chunks. or mountain
terrain_make_plains(fi1, fj1, fi, fj, base)
- LOCKED 231007 - make plains in terrain
calculate_height(fi1, fj1, fi, fj)
- generate heightvalues to the hm[][][][] array
calculate_height_after(fi1, fj1)
- heightvalues generated by the in-game "minecraft" editor. this runs only one time per chunk, otherwise it's very slow. these should get added after everything else (if everything is set up right).
generate_objects_array(fi1, fj1, fi, fj)
- generate object values to the om[][][][] array
generate_objects_array_after(fi1, fj1)
- objects generated by the in-game "minecraft" editor. this runs only one time per chunk, otherwise it's very slow. these should get added after everything else (if everything is set up right).
Terrain handling/creating functions
create_terrain_3d_vertices(fi1, fj1, fi, fj)
- LOCKED 231007 - create terrain vertices from hm
create_objects_3d_ver_houses(fi1, fj1, fi, fj, ver_array, hght, roofheight)
- LOCKED 231007 - create house vertices
create_objects_3d_vertices(fi1, fj1, fi, fj, number)
- LOCKED 231012 - create vertices for object mesh/sprites/etc
create_3d_meshes(fi1, fj1)
- dynamic function for creating meshes (and pointsprites, etc) from vertices
create_one(fi1, fj1)
- function to create ONE chunk before all the others. preferably the one you get "spawned" (created) in, so you don't have to wait for the ground under you to get created
show_and_hide_terrain_chunks()
- LOCKED 231012 - show and hide terrain chunks
hide_bushes_grass_etc_outside_current_chunk()
- LOCKED 231102 - hide some things that should only be seen in the current chunk (to save draw calls so the game is faster)
ascend_intro(master_seed)
- creates the terrain. runs at the start. also, a lot of code that just lies outside of functions in ascend.js also runs at start, before this.
create_too_large_arrays(fi1, fj1)
- LOCKED 231012 - function for creating a few time-consuming laaarge arrays. this is made into a function so we can create only the arrays we need, when we need them. creating all of them at the same time will take too long time.
dynload_hm()
- LOCKED 231007 - dynamic heightmap generation
dynload_objects()
- LOCKED 231007 - dynamic objects generation
create_terrain_chunks_before_showing_them()
- LOCKED 231012 - add and remove chunks when moving into a new place
Music/sound functions
pause_all_cz_sounds()
- pauses all character sounds (obvious from name)
sound_play(fsound)
- LOCKED 231012 - play a sound from the START!
sequencer_play()
- plays music based on samples and pre-created note sequences (like MIDI, but my own simpler and better format - just write the notes as a string ("A A C C F F C G ")
music_play(file, fvolume, floop, fspeed)
- plays mp3 file with Web Audio API
Race/road functions (most race functionality actually runs in cut_set()!)
add_road_block(fx, fz)
- LOCKED 231102 - abstraction for race_create()
race_create(x_array, z_array, number)
- LOCKED 231007 - creates a road, from an array of coordinates, that can be used for race. it also adds a bit of randomization in between the coordinates. unlike most other world generation that is automatic from simple seed values etc, this is semi-manual.
Misc. functions
hexcol(fobject, hex)
- function without the three.js stuff
pseudorandom(number)
- LOCKED 231007 - get pseudorandom value. always returns the same value if number is the same
get_time_by_minutes_resolution(minutes_resolution)
- LOCKED 231007 - get current in-game time. you set minutes_resolution to 15 you get the current quarter, 60 you get the current hour, and so on. the game's time comes from frame_counter which increases with 1 every frame, so it's good to be able to get less exact time
lookat_datass(fobject1, fobject2)
- LOCKED 231007 - my own version of lookAt() that only works in x and z dimensions (=you can't look upwards). for characters/objects. because rotations and quaternions suck
lookat_datass_xz(fx1, fz1, fx2, fz2)
- LOCKED 231007 - my own version of lookAt() that only works in x and z dimensions (=you can't look upwards). for xz positions. because rotations and quaternions suck
rotation_real_get(angle)
- LOCKED 231007 - get the actual rotation in radians. my own function because the standard functions don't work (because rotations and quaternions suck).
ts_start()
- LOCKED 231102 - timescene abstraction
ts_end(fcut)
- timescene abstraction
ts_end_from_talk(fcut)
- timescene abstraction
ts_during()
- LOCKED 231012 - timescene abstraction
fog_area(fred,fgreen,fblue, from_i1, to_i1, from_j1, to_j1)
- abstraction for fog_set()
hide_cut_sprites()
- hides all characters that then can be shown in cut_set()
talk_char_when(fsprite, fpos_x, fpos_z, fcut, fcut_after, fcut_last, fdistance, fradius) - NOT DOCUMENTED!
tex(file, r1, r2, mirrored)
- LOCKED 231007 - create texture material
snd(file, fvolume, floop)
- LOCKED 231007 - create sound
xhtmlsound(url)
- load sound file via XHTML
spr(file, size, width)
- LOCKED 231007 - create sprite
psp(file, fsize)
- LOCKED 231007 - create pointsprites material
load_audio()
- NOT DOCUMENTED!
load_audio_lead()
- NOT DOCUMENTED!
load_audio_padd()
- NOT DOCUMENTED!
load_audio_kick()
- NOT DOCUMENTED!
load_audio_snar()
- NOT DOCUMENTED!
load_audio_hiha()
- NOT DOCUMENTED!
(background image by sachikomiliart)