Description
Instead of global variables you can group application state into abstractions like struct/object, classes, closures, functors:
let cvs = document . getElementById ( "canvas" ) ;
let ctx = cvs . getContext ( "2d" ) ;
let frog = new Image ( ) ;
let background = new Image ( ) ;
let foreground = new Image ( ) ;
let fly = new Image ( ) ;
let pipeBottom = new Image ( ) ;
Multiple magic numbers and global variables, terrible approach for application state:
function jump ( ) {
yPos -= 100 ;
}
let pipe = [ ] ;
pipe [ 0 ] = {
x : cvs . width ,
y : 300
}
let xPos = 10 ;
let yPos = 490 ;
let widthFrog = 90 ;
let heightFrog = 80 ;
let grav = 3 ;
let max = 100 ;
let gap = 90 ;
let score = 0 ;
Use intermediate variables and constants instead of hardcodes magic numbers:
ctx . drawImage ( fly , pipe [ i ] . x , pipe [ i ] . y - pipeBottom . height + gap , 50 , 50 ) ;
Decompose complex conditions/expressions:
if ( xPos + widthFrog >= pipe [ i ] . x && yPos + heightFrog >= pipe [ i ] . y ) {
Project is short and rude, no linting, not prettier, no tests, single commit (no work history)
Reactions are currently unavailable
You can’t perform that action at this time.
CourseworkGame/js/game.js
Lines 1 to 8 in 5603d25
CourseworkGame/js/game.js
Lines 19 to 41 in 5603d25
CourseworkGame/js/game.js
Line 48 in 5603d25
CourseworkGame/js/game.js
Line 61 in 5603d25