Created
November 16, 2019 18:02
-
-
Save garganurag893/a6e12e3b15e34754ff68442220212ea9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Matter from 'matter-js'; | |
import Constants from '../utils/constants'; | |
import {getRandom} from '../utils/random'; | |
import {width} from '../utils/styleSheet'; | |
const UpdateObstacle = (entities, {time, dispatch}) => { | |
for (let i = 1; i <= 2; i++) { | |
if ( | |
entities['Obstacle' + i].type === 'top' && | |
entities['Obstacle' + i].body.position.x <= | |
-1 * (Constants.TOP_PIPE_WIDTH / 2) | |
) { | |
entities['Obstacle' + i].scored = false; | |
Matter.Body.setPosition(entities['Obstacle' + i].body, { | |
x: width * 2 - Constants.TOP_PIPE_WIDTH / 2, | |
y: getRandom(100, 300), | |
}); | |
} else if ( | |
entities['Obstacle' + i].type === 'bottom' && | |
entities['Obstacle' + i].body.position.x <= | |
-1 * (Constants.BOTTOM_PIPE_WIDTH / 2) | |
) { | |
entities['Obstacle' + i].scored = false; | |
Matter.Body.setPosition(entities['Obstacle' + i].body, { | |
x: width * 2 - Constants.BOTTOM_PIPE_WIDTH / 2, | |
y: getRandom(300, 500), | |
}); | |
} else { | |
Matter.Body.translate(entities['Obstacle' + i].body, {x: -4, y: 0}); | |
} | |
} | |
return entities; | |
}; | |
export default UpdateObstacle; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment