@@ -22,7 +22,8 @@ pipeSouthImg.src = pipeSouthPng;
2222const verticalGap = 200 ;
2323const horizontalGap = 75 ;
2424const maxY = 20 ;
25- const initialY = 100 ;
25+ const initialY = 200 ;
26+ const floorHeight = 280 ;
2627let pipe = [ ] ;
2728let constant = undefined ;
2829let score = 0 ;
@@ -50,7 +51,7 @@ class Dino extends React.Component {
5051 const { bX, bY } = this . state ;
5152 const canvas = this . canvasRef . current ;
5253 this . rAF = requestAnimationFrame ( this . updateAnimationState ) ;
53- this . setState ( { bY : maxY + this . props . yVelocity * 10 } ) ;
54+ this . setState ( { bY : bY } ) ; // maxY + this.props.yVelocity * 10
5455 for ( let i = 0 ; i < pipe . length ; i += 1 ) {
5556 constant = pipeNorthImg . height + verticalGap ;
5657 pipe [ i ] . x -= 1 ;
@@ -68,7 +69,7 @@ class Dino extends React.Component {
6869 bX <= pipe [ i ] . x + pipeNorthImg . width &&
6970 ( bY <= pipe [ i ] . y + pipeNorthImg . height ||
7071 bY + brickImg . height >= pipe [ i ] . y + constant ) ) ||
71- bY + brickImg . height >= canvas . height // - fgImg.height
72+ bY + brickImg . height >= canvas . height // - fgImg.height
7273 ) {
7374 score = 0 ;
7475 pipe = [
@@ -87,14 +88,14 @@ class Dino extends React.Component {
8788 } ;
8889
8990 moveUp = ( ) => {
90- this . setState ( { bY : this . state . bY - 25 } ) ;
91+ this . setState ( { bY : this . state . bY } ) ; // - 25
9192 this . onFlap ( ) ;
9293 } ;
9394
9495 componentDidMount ( ) {
9596 const canvas = this . canvasRef . current ;
9697 const context = canvas . getContext ( '2d' ) ;
97- context . drawImage ( bgImg , 0 , 0 ) ;
98+ context . drawImage ( bgImg , 0 , floorHeight ) ;
9899 this . rAF = requestAnimationFrame ( this . updateAnimationState ) ;
99100 pipe [ 0 ] = {
100101 x : canvas . width ,
@@ -118,7 +119,7 @@ class Dino extends React.Component {
118119 const height = canvas . height ;
119120 ctx . save ( ) ;
120121 ctx . clearRect ( 0 , 0 , width , height ) ;
121- ctx . drawImage ( bgImg , 0 , 0 ) ;
122+ ctx . drawImage ( bgImg , 0 , floorHeight ) ;
122123 ctx . drawImage ( fgImg , 0 , height - fgImg . height ) ;
123124 for ( let i = 0 ; i < pipe . length ; i += 1 ) {
124125 ctx . drawImage ( pipeNorthImg , pipe [ i ] . x , pipe [ i ] . y ) ;
0 commit comments