-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhysics.js
28 lines (22 loc) · 942 Bytes
/
Physics.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import Matter from 'matter-js'
import { Dimensions } from 'react-native'
const Physics = (entities, {touches, time}) => {
let engine = entities.physics.engine
let butterfly = entities.butterfly.body
const PIPE_WIDTH = 100
const MAX_WIDTH = Dimensions.get("screen").width
const MAX_HEIGHT= Dimensions.get("screen").height
touches.filter(t => t.type === "press").forEach(t => {
Matter.Body.applyForce(butterfly, butterfly.position , {x : 0.0 , y : -0.1})
})
for(let i = 1; i<=4 ; i++){
if(entities["pipe" + i].body.position.x <= -1 * PIPE_WIDTH/2){
Matter.Body.setPosition(entities["pipe" + i].body , {x : MAX_WIDTH * 2 - PIPE_WIDTH/2, y : entities["pipe" + i].body.position.y })
}else{
Matter.Body.translate(entities["pipe" + i].body, {x : -1, y : 0})
}
}
Matter.Engine.update(engine, time.delta)
return entities
}
export default Physics