-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhysics.js
More file actions
60 lines (45 loc) · 1.63 KB
/
Copy pathPhysics.js
File metadata and controls
60 lines (45 loc) · 1.63 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import Matter from 'matter-js';
import { getRandomPosRocket } from "./utils/random";
import { Dimensions } from 'react-native';
const windowWidth = Dimensions.get('window').width;
const windowHeight = Dimensions.get('window').height;
const Physics = (entities, { touches, events, time, dispatch }) => {
let engine = entities.physics.engine;
events.forEach((e) => {
if (e.type === 'move_up') {
Matter.Body.setVelocity(entities.Drone.body, {
x: 0,
y: -5,
});
} else if (e.type === 'move_down') {
Matter.Body.setVelocity(entities.Drone.body, {
x: 0,
y: 5,
});
}
});
for (let index = 1; index <= 2; index++) {
// if(entities[`Rocket${index}`].body.bounds.max.x <= 50 && !entities[`Rocket${index}`].point){
// entities[`Rocket${index}`].point = true;
// dispatch({type: 'new_point'})
// }
if(entities[`Rocket${index}`].body.bounds.max.x <= 0){
const pipeSizePos = getRandomPosRocket(windowWidth * 0.9);
Matter.Body.setPosition(entities[`Rocket${index}`].body, pipeSizePos)
}
Matter.Body.translate(entities[`Rocket${index}`].body, {x: -6, y:0})
}
// Matter.Body.translate(entities[`Rocket`].body, { x: -8, y: 0 });
Matter.Engine.update(engine, time.delta);
// Remove the obstacle-related code
// Collision logic remains unchanged
Matter.Events.on(engine, 'collisionStart', (event) => {
event.pairs.forEach((collision) => {
if (collision.bodyA.label === 'Drone' || collision.bodyB.label === 'Drone') {
dispatch({ type: 'game_over' });
}
});
});
return entities;
};
export default Physics;