OBJECT REFERENCE
game object
The game object is responsible for instantiating all the objects in the program, creates and runs the main loop.
For a reference of all the internal variables, open game.js - there's comments for every relevant variable at the beginning of the file - you shouldn't change any of them directly, see functions for the appropiate way of changing a variable
Functions:
Cgame
creates the object
usage: var game=new Cgame(gameDivId);
parameters:
-gameDivId:id for the container html element
Load
makes instances for most of the child objects; called automatically by the constructor; can be used to force a restart of the game.
usage: game.Load(forceResize)
parameters:
-forceResize: if set to true, will compute the size of the game, otherwise that part will be skipped.
Resize
resizes the game to fit in a specified rectangle size
usage: game.Resize(Pwidth,Pheight);
parameters:
-Pwidth: max width for the game
-Pheight: max height for the game
preStartLoad
loads the game configuration, starts the loading of the main assets (images for the menus) and initializes the GSP object
called by the Load function, do not call this manually.
usage: game.preStartLoad();
startLoad
loads the main assets (images for the menus) and starts the google add. called automatically when the config has been loaded, do not call manually.
usage: game.startLoad();
MainLoadComplete
called when the main assets of the game have been loaded, do not call manually.
usage: game.MainLoadComplete();
broadcastReadyStatus
resets ready status for this player
usage: game.broadcastReadyStatus(player);
parameters:
-player:player object as sent by the sdk
setCurrentSentence
sets the currently displayed sentence (game.currentSentence) to the chosen index from the array of picked sentences (game.sentences)
usage: game.setCurrentSentence(index);
parameters:
-index:index in the game.sentences array
getHtmlSentence
generates the html code of the current sentence to display in the game (show the current character in red and underlined)
usage: var code=game.getHtmlSentence();
startGame
loads the elements file and starts the new game queue
usage: game.startGame();
LoadedGameElements
called when the elements file has been loaded (startGame function); creates the car(s) for the race and continues in the new game queue with LoadGameData();
usage: game.LoadedGameElements();
LoadGameData
loads race assets (images and sounds) unless they're already loaded
usage: game.LoadGameData();
LoadedGameData
calculates which elements to be used during the race and starts loading the sounds for spelling mode;
called when the race assets have been loaded, do not call manually.
usage: game.LoadedGameData();
LoadedGameSentence
called when all the sentences (if any) sounds are loaded; sets the game into lobby mode; do not call manually
usage: game.LoadedGameSentence();
lobby
function called in the main loop to handle the lobby game mode
usage: game.lobby();
addMplayer
adds a new multiplayer car to the game.cars array
usage: game.addMplayer(player, players);
parameters:
-player:player object to be added
-players:player array with all the players
onMultiplayerReady
called when a player reports ready status
usage: game.onMultiplayerReady(player,carType);
parameters:
-player:player that reported being ready
-carType:car type for the player
onMultiplayerType
called when a player types a character
usage:onMultiplayerType(player,position,wpm,time);
parameters:
-player:player that triggered the event
-position:at which charater the player is currently (from 0 to the sum of the lengths of all the sentences in the current game)
-wpm:current wpm for the player
-time:number of miliseconds from the start of the race
onMultiplayerERR
called when a player makes an error
usage: game.onMultiplayerERR(player,errCount,time);
parameters:
-player:player that triggered the event
-errCount:current error count
-time:number of miliseconds since the start of the race
onMultiplayerHighScore
called at the end of the race, when a player sends their current status
usage: game.onMultiplayerHighScore(player,points,rank,highScore);
parameters:
-player:player that triggered the event
-points:points for the player
-rank:rank of the player
-highScore:highest wpm for the player
crashPlayer
called when a player needs to be eliminated from the race
usage: game.crashPlayer(player);
parameters:
-player:player to be eliminated
gameOver
called to end the current game
usage: game.gameOver(newStatus);
parameters:
-newStatus:the new screen to set for the game
onLeaveGame
called by gameOver() once the game's over; do not call manually
usage: game.onLeaveGame();
playing
function called in the main loop to handle the in race game mode
usage: game.playing();
getScore
returns the current wpm for the player
usage: var score=game.getScore();
calculateLevel
returns the level for the car
usage: var level=game.calculateLevel(car);
parameters:
-car:car for which to calculate the level
getPoints
returns the number of points for the car
usage: game.getPoints(car);
parameters:
-car:car for which to calculate points
getPosition
returns the position in the race for the car
usage: game.getPosition(car);
parameters:
-car:car for which to calculate position
getRaceTime
returns the in-race time for the current player in the format mm:ss
usage: var time=game.getRaceTime();
getErrors
returns the number of errors for the current player
usage: var errorCount=game.getErrors();
keyPressed
called when the player presses a key
usage: game.keyPressed();
LoadGarrage
loads the images for the garrage screen
usage: game.LoadGarrage();
LoadedGarrageData
called when all the images in the garrage screen have been loaded; sets the game to garrage mode
usage: game.LoadedGarrageData();
Run
main loop for the game
sets the game.time value (milisecond counter)
calls the appropiate functions depending on game.status
calls the main loop functions for the game.UI and game.assets objects
usage: game.Run();
UI object
The game object is responsible for drawing all the page elements and game elements (cars, dials, etc..).
For a reference of all the internal variables, open ui.js - there's comments for every relevant variable at the beginning of the file - you shouldn't change any of them directly, see functions for the appropiate way of changing a variable
Unless mentioned otherwise, all the functions scale position and size parameters (so if the game has a with of 480, a width of 100 will be considered to be 50)
For the functions that look like functionName(set) set is true if the interface already created the elements needed for this page, and false if those elements need to be created
Functions:
CUI
creates the object
usage: var UI=new CUI(game);
parameters:
-game:the game object
Load
creates the containing div element, the HTML elements for the loading screen, the adds div element and the canvas used to measure text width
usage: UI.load();
show
shows or hides the interface elements; if the interface is hidden, the loading screen is shown.
usage: UI.show(display);
parameters:
-display:if set to true, the interface is shown; if set to true, the inrerface is hidden and the loading screen is shown.
Run
main loop function for the object
usage: UI.Run(gameStatus);
parameters:
-gameStatus: the current page
drawLoading
shows the loading screen
usage: UI.drawLoading(count, total);
parameters:
-count:how many elements have been loaded so far
-total:total number of elements to load
getButtonCode
returns the html code to form a button interface element
usage: var htmlCode=UI.getButtonCode(id,src,srcH,width,height,callFunc,hoverOn,hoverOff);
parameters:
-id:id for the main element
-src:asset id for the button image
-srcH:asset id for the button image when the mouse hovers over it
-width:width of the button(if 0, the image's width will be used)
-height:height of the button(if 0, the image's height will be used)
-callFunc:name of the function to call when the button's pressed; must be a function of the UI object
-hoverOn:function to call when the mouse gets on top of the button
-hoverOff:function to call when the mouse gets off the button
getPanelCode
returns the html code to draw a multi-row select panel
usage: var htmlCode=UI.getPanelCode(id,src,srcH,width,height,left,top,fontFamily,fontSize,txt,callFunc,resizeFont);
parameters:
-id:id for the panel
-src:asset id for the button image
-srcH:asset id for the button image when the mouse hovers over it
-width:width of the button(if 0, the image's width will be used)
-height:height of the button(if 0, the image's height will be used)
-left:position for the text(if 0, the text will be centered)
-top:position for the text(if 0, the text will be centered)
-fontFamily:family for the font
-fontSize:size for the font
-txt:array with all the lines of text; a line is in the format [text,height,function] where text is the actual text to show in this line and height is the height of the line(if 0, the height of the element will be used), function is the function to call when the line is clicked
-callFunc:function to be called when the element is clicked
-resizeFont:set to true if the font is to be scaled to fit inside the width paramater
getTextWidth
returns the width of a text (not scaled)
usage: var width=UI.getTextWidth(txt,fontFamily,fontSize);
parameters:
-txt:the text to measure
-fontFamily:family for the font
-fontSize:size for the font (will not be scaled by scaleVal)
getTextButtonCode
returns the html code for a button with text
usage: var htmlCode=UI.getTextButtonCode(text,classN,width,height,font_size,textX,textY,callFunc,idN,skipValign,textWPercent);
parameters:
-text:text for the button
-classN:id for the css class for the button (the actual class names are: 'button_'+classN and 'button_'+classN+'On' - when the button is hovered over);
-width,height:size for the button
-font_size:size for the font (font will be specified in the css)
-textX,textY:position for the text from the center(examle: set textX to -10 to move the text to the left of the center by 10 pixels)
-callFunc:function to be called when the button is pressed
-idN:id for the button
-skipValign:if set to true, the text will not be aligned to the middle of the button
-textWPercent:maximum percentage of the button's width in which to fit the text(default:0.8, which means 80%)
showPopup
displays a popup
usage: UI.showPopup(code,BG,width,height,Dx,Dy);
parameters:
-code:the html code to show within the popup
-BG:asset id for the background image for the popup
-width,height:size of the popup (if set to 0, the background image's width/height will be used)
-Dx,Dy:position for the popup from the middle of the game screen (exampe, set Dy to -10 to move the popup 10 pixels higher than the middle)
hidePopup
hides a popup if one is currently shown
usage: UI.hidePopup();
focusInput
gives focus to the hidden input object that captures user key presses during the race
usage: UI.focusInput();
loginScreen1
handles the first login screen (GUEST / LOGIN buttons)
usage: UI.loginScreen1(set);
loginScreen2
handles the second login screen (shows the social providers for login)
usage: UI.handles the first login screen();
providerOn
called when the mouse hovers over one of the provider buttons in the second login page
usage: UI.providerOn(id);
parameters:
-id:the provider hovered over (example: facebook)
providerOff
called when the mouse moves off one of the provider buttons in the second login page
usage: UI.providerOff(id);
parameters:
-id:the provider hovered over (example: facebook)
Login
logs in with the picked provider
usage: UI.Login(provider);
parameters:
-provider:the provider to use for login
loginButtonPress
called when the login button is pressed in the first login screen or the main menu, moves to the second login screen
usage: UI.loginButtonPress();
guestButtonPress
called when the guest button is pressed, moves to the main menu as a guest user
usage: UI.guestButtonPress();
mainMenu
handles the main menu screen
usage: UI.mainMenu();
showLogMenu
shows the expanded select control when the logged in user clicks their name
usage: UI.showLogMenu();
logOut
called when the user clicks log out, moves to the first login screen
usage: UI.logOut();
soundButtonPress
turns the sound effects on and off
usage: UI.soundButtonPress(ignoreButton,stopSentence);
parameters:
-ignoreButton:if set to true, the control is disabled
-stopSentence:set to true if the button is also to stop a sentence being played during a spelling race
languageSelect
shows the language select popup
usage: UI.languageSelect();
languageChange
called when the user clicks on one of the flags to change the language; the UI.language variable is already set to the value to be used
usage: UI.languageChange();
highScoresButtonPress
shows the high scores screen
usage: UI.highScoresButtonPress();
garrageButtonPress
shows the garrage screen
usage: UI.garrageButtonPress();
difficultySelect
shows the difficulty selection popup
usage: UI.difficultySelect();
startEasy
starts a solo race in easy difficulty
usage: UI.startEasy();
startMedium
starts a solo race in medium difficulty
usage: UI.startMedium();
startHard
starts a solo race in hard difficulty
usage: UI.startHard();
soloButtonPress
called when the user clicks on the solo race button; calls the difficultySelect function
usage: UI.soloButtonPress();
multiButtonPress
called when the user clicks on the multiplayer button; starts a multiplayer game
usage: UI.multiButtonPress();
race
handles the in-race screen
usage: UI.race(set);
hintButtonPress
called when the player presses on the hint button; makes preparations for and calls showHints()
usage: UI.hintButtonPress();
showHints
shows the hints during the race
usage: UI.showHints();
replayButtonPress
replays the sentence during a spelling race
usage: UI.replayButtonPress();
setSentence
shows the sentence during the race; different functionality depending if the game is typing or spelling, and wether the hints are currently being shown or not in a spelling race.
usage: UI.setSentence(fontFamily,fontSize);
parameters:
-fontFamily,fontSize:settings for the font
raceReport
handles the race results screen
usage: UI.raceReport(set);
mainMenuButtPress
returns to the main menu from other screens
usage: UI.mainMenuButtPress();
raceAgainButtPress
starts a new race with the same settings as the one that just ended
usage: UI.raceAgainButtPress();
loginNow
handles the 'login to save' function
usage: UI.loginNow();
getEndCarReport
returns the html code for one of the cars in the end race screen
usage: var htmlCode=UI.getEndCarReport(index,place);
parameters:
-index:index in the game.cars array, pointing at the car to get the code for
-place:which place the car came in at the end of the race
getPlayerCarReport
returns the html code with the end game car statistics for the player
usage: var htmlCode=UI.getPlayerCarReport();
getGarrage
handles the garrage screen
usage: UI.getGarrage(set);
useCarButtonPress
sets the currently selected and available car as the active car for the player
usage: UI.useCarButtonPress();
buyCarButtonPress
makes the current car available to the player, sets it as the active car and removes it's coins cost from the player's total
usage: UI.buyCarButtonPress();
garrageChange
changes the currently selected car
usage: UI.garrageChange(direction);
parameters:
-direction:selects the car on the left on a negative value, or the one on the right on a positive value (0 will result in a never ending loop)
carUpgradeButtonPress
opens the garage door to show the cars
usage: UI.carUpgradeButtonPress();
globalRankButtonPress
switches to the global rank screen
usage: UI.globalRankButtonPress();
raceHistoryButtonPress
switches to the race history screen
usage: UI.raceHistoryButtonPress();
shareButtonPress
called when the share button is pressed - currently it's empty, the popup is being called where the button is being initialized (getGarrage function)
getHighScores
retrieves the high score data from the server, and calls for the highScores function to show it
usage: UI.getHighScores(period,sort_order);
parameters:
-period,sort_order:parameters for the GSP.getHighscores function
highScores
handles the high scores screen
usage: UI.highScores(set);
highScores ButtonPress functions
call the getHighScores function with different parameters
getGlobalRank
handles the global rank screen
usage: UI.getGlobalRank(set);
getRaceHistory
handles the race history screen
usage: UI.getRaceHistory(set);
resourcesManager object
Object responsible for loading images / sounds / files and making them available.
It's also responsible for using the UI.drawLoading and UI.show functions to switch to and from the loading screen
Usage: first make an arbitrary number of LoadFile / LoadImage / LoadSound calls, filling up the queue with files to load, then call the Start function; this will show the loading screen, hiding the rest of the interface; once all the assets enqued have downloaded (the queueEmpty function returns true) the loading screen will be hidden and the rest of the interface shown again.
Variables:
-funcCall: function to be called when the loading process is finished
-objCall: parameter for the funcCall function
-show: if true, it's loading something, so the loading screen needs to be drawn
-Data: object containing the Images, Sounds and Files arrays
-queue and queueStart: objects used in the loading process
-fileCount and filesLoaded: number of files being loaded and number of files that finished loading
Functions:
resourcesManager
creates the object
usage: var assets=new resourcesManager(game);
parameters:
-game:the game object
queueEmpty
returns true if there's nothing left to load or false if at least an asset is downloading
usage: var ok=assets.queueEmpty(src);
parameters:
-src:optional parameter, set to a specific file url to see if the file can be queued for loading at that time (if the queue is not empty, it will throw a message in the console)
LoadFile
loads a file as text
usage: assets.LoadFile(id,src);
parameters:
-id:the id for the resource in the Data.Files array
-src: the url for the file
LoadSound
loads a sound asset
usage: assets.LoadSound(id,src_mp3,src_ogg);
parameters:
-id:the id for the resource in the Data.Sounds array
-src_mp3 and src_ogg: url for the sound file (only one will be used, depending on the browser)
LoadImage
loads an image asset
usage: assets.LoadImage(id,src);
parameters:
-id:the id for the resource in the Data.Images array
-src: the url for the image
Start
starts downloading the previously enqueued assets
usage: assets.Start(functionCall,obj)
parameters:
-functionCall:function to be called when all the assets have finished downloading
-obj:optional parameter to be passed as s parameter to the functionCall function
Run
main loop function
usage: assets.Run();
car object
Object responsible for drawing a player's car in the race screen, and the garrage screen.
Variables:
-drawPosition: current position on screen, it follows the position value according to the configuration car speeds values
-position: virtual position of the car
-ready: wether the car is on the ready line or not
-carType: index for the appearance of the config.cars array
-lane: in which lane the car is to be drawn
-animIndex: handles the animation (for the wheels)
Functions:
Ccar
creates the object
usage: var car=new Ccar(game,carType,lane);
parameters:
-game:the game object
-carType:index for the appearance of the config.cars array
-lane:in which lane the car is to be drawn
goToStart
moves the car to the start line (position goes from -1 to 0 when ready is set to true)
usage: car.goToStart();
Run
main loop function
usage: car.Run();
Draw
draws the car in the race screen
usage: car.Draw();
DrawGarrage
draws the car in the garrage screen
usage: car.DrawGarrage(position);
parameters:
-position: where to draw the car (0 is in the middle of the garrage, negative values are to the left of that and positive to the right)
pcPlayer object
Object handling the player's car.
file:game.js
Variables:
-type: set to PC, indicates a player car
-car: Ccar object responsible for the drawing
-position: virtual position of the car
-ERR: number of errors
-WPM: current speed for this player
-crash: set to true if the car got crashed or the player was disqualified
-finished: set to true if the player finished the race
Functions:
CpcPlayer
creates the object
usage: var player=new CpcPlayer(game,type,lane);
parameters:
-game:the game object
-type:index for the appearance of the config.cars array
-lane:in which lane the car is to be drawn
ready
returns true if the player is ready to race
usage: var ok=player.ready();
Run
main loop function
usage: player.Run();
Draw
draws the car
usage: player.Draw();
ai object
Object handling a computer oponent's car.
Functionality is similar to that of the pcPlayer object
mplayer object
Object handling a multiplayer oponent's car.
Functionality is similar to that of the pcPlayer object
Functions:
setPosition
sets the position for the car on an GSP onPlayerUpdate event
usage: car.setPosition(pos,wpm,time);
parameters:
-pos:current car position
-wpm:current score of the car
-time:number of miliseconds since the start of the race
error
sets a new error for the car on an GSP onPlayerUpdate event
usage: car.error(time);
parameters:
-time:number of miliseconds since the start of the race
configuration file
{
"gameSettings":{
"settings":{
"readyCarSpeed":0.02, :the speed the car has when it moves to the start line (animation only)
"moveCarSpeed":2.0, :the speed the car has in game (animation only)
"animCarSpeed":0.2, :the speed at which the wheels spin when the car is moving (how fast the frames change for that animation)
"lightTimer":1000, :how long the switchlight stays on one color (miliseconds)
"letterTrackSize":5, :how many pixels each letter counts towards total track size (the higher the number, the more the cars will move when a word is completed)
"hintDuration":3000, :how many miliseconds the hints are to stay on screen
"hushVolume":0.2, :volume for the sound effects while a sentence is being heared in a spelling race
"backgroundSpeed":5.0, :speed at which the background moves during a race
"maxIdleTime":30000, :how many miliseconds before the player is disqualified for not typing
"warningIdleTime":15000,:how many miliseconds before a hint will be displayed when the player is not typing
"adsWidth":532, :width for the ads container
"adsHeight":300, :height for the ads container
"showAdd":true, :set to false if you don't want the ads to be shown
"adsTagUrl":"http://.." :set to the ads tag url (default can be found in gsp.js, search for 'defaultTag')
},
"language":{ :language settings
"text":"ENG", :current language text button
"skipFlag":false, :set to true if you don't want the flag to be shown on the button for the current language
"rtl":false, :set to true if you want the text to be shown from right to left during the race
"list":[ :array with all the languages in the choose language popup
{
"text":"FRA", :text for this language's button
"folder":"fr", :folder name and get parameter value for this language
"skipFlag":false:set to true if you don't want the flag to be shown for this language
},
{
}.....
]
},
"difficulty":[ :array with the difficulty settings, in order easy/medium/hard/multiplayer
{
"AI":[0,1], :what AI oponents to use this difficulty (indexes from the AIOponents array below)
"elementsUrl": "elements.json" : url for the elements file for this difficulty
"hintCount":4, :number of hints for this difficulty
"sentenceCount":1, :number of sentences in a race for this difficulty
"errorsToSmoke":20, :how many errors before the car starts to smoke
"errorsToFire":25, :how many errors before the car is on fire
"errorsToCrash":30 :how many errors before the player crashes
},
{
}...
],
"AIOponents":[ :AI drivers for single-player mode
{
"name":"SlowTyper", :the name of the driver
"fastest":20, :minimum ammount of miliseconds between two letters
"slowest":1000, :maximum ammount of miliseconds between two letters
"ErrorPercent":3 :how many errors this player makes (this is the chance it has to mistype every letter, it affects how quickly and how likely it is for the player to overheat
},
{
"name":"AverageTyper",
"fastest":10,
"slowest":500,
"ErrorPercent":2
},
{
"name":"FastTyper",
"fastest":5,
"slowest":200,
"ErrorPercent":1
}
],
"cars":[ :those are settings for the graphics of the cars, please don't change unless you're changing the images or if you're adding more cars (make sure that the truck is always last)
{
"images":["race/Car-02.png","race/Car-03.png","race/Car-04.png"], :the images of the car in the spinning wheels animation
"behindEff":[10,1], :position adjustment for the effects coming from the back of the car (afterburner, smoke)
"tireEff":[0,0], :position adjustment for the rubber burn effect
"hoodEff":[20,-30], :position adjustment for the effects coming from the hood (flames and smoke on overheat)
"cost":120 :how many coins to unlock this car
},
{
}...
]
},
"sound_Effects":{ :contains all the sounds in the game
"RaceMusic":{"audio_mp3":"raceBackSound.mp3","audio_ogg":"raceBackSound.ogg"},
"RedLight":{"audio_mp3":"ReadySetGo.mp3","audio_ogg":"ReadySetGo.ogg"},
"YellowLight":false,
"GreenLight":false,
"typo":{"audio_mp3":"typo.mp3","audio_ogg":"typo.ogg"},
"engine1":{"audio_mp3":"engine1.mp3","audio_ogg":"engine1.ogg"},
"engine2":{"audio_mp3":"engine2.mp3","audio_ogg":"engine2.ogg"},
"crash":{"audio_mp3":"carBrakeCrash.mp3","audio_ogg":"carBrakeCrash.ogg"},
"cheer":{"audio_mp3":"crowdCheer.mp3","audio_ogg":"crowdCheer.ogg"}
},
"menuTexts": { :contains all the texts in the game
"Login":"Login",
"Guest":"Guest",
.....
}
}
release notes
2014-09-09 :
-added "adsTagUrl" to config file (gameSettings.settings.adsTagUrl)
2014-12-21 :
-changes and fixes for V2.
-config changes:
-added gameSettings.boosters:
"boosters":[ //contains all the boosters
{
"title":"nitro", :name of the booster
"target":false, :whether or not activating this booster will trigger a target prompt
"modifier":"ALT", :what(if any) modifier key needs to be pressed; accepted values: "ALT","CTRL","SHIFT",false
"keyCode":73, :key code for the key to be pressed to trigger the booster
"hint":"you have nitro, use it to get ahead!", :hint to be shown in the starting screen if this booster is available
"buttonText":"ALT
I", :text for the button; should contain a line break (
) to align the html
"icon":"garrage/BigNitro.png",:icon for this booster in the garage screen
"cost":5, :how many coins it costs to purchase this
"effect":10 :only applies to the rocket booster, specifies how many errors should be added on the target when the rocket hits
},
...
]
-added gameSettings.cars[].boosters:
"boosters":["fog","nitro"] :array with all the boosters available when driving this car
-added in menuTexts:
"targettingText":"Choose who you want to use #POWERNAME on", :#POWERNAME will be replaced by the name of the booster
"boosters":"boosters",
"getMore":"get more",
"gameNo":"game #game",
"Join":"join",
"noGames":"No games to join",
"topRacers":"top racers"
2015-01-25 :
-added in gameSettings.settings:
"cheatCoinsMin":1000 - players will always have that many coins; set to 0 or false to disable
-changes in gameSettings.boosters:
-added: "type":"nitro" :this should be left alone; title can be translated, but not type !
-added: "iconSmall":"race/nitro.png": :the icon to be used on the small button in-race
-added: "maxPerRace":2 :maximum of that booster that would be available per race
-oil now has "effect":1, it defines the number of words that the target will be sent back
-modifier and keyCode are not used anymore