-
Notifications
You must be signed in to change notification settings - Fork 0
/
systems.js
59 lines (46 loc) · 1.48 KB
/
systems.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
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
import { Dimensions } from 'react-native';
const MoveFinger = (entities, props) => {
const { height: screenHeight, width: screenWidth } = Dimensions.get('window');
let arrow = entities[2];
let square = entities[3];
let direction = arrow.direction;
props.touches.filter(t => t.type === "move").forEach(t => {
const { pageX, pageY } = t.delta;
if (Math.abs(pageX) > Math.abs(pageY)) {
if (pageX > 0) { direction = 'right' }
else { direction = 'left' }
} else {
if (pageY > 0) { direction = 'down' }
else { direction = 'up'; }
}
});
const movements = {
up: -10,
right: 10,
down: 10,
left: -10,
};
const newPosition = [...square.position]
if (square && square.position) {
const delta = props.time.delta/16
const movements = {
up: square.position[1] - delta,
right: square.position[0] + delta,
left: square.position[0] - delta,
down: square.position[1] + delta,
};
console.log('tick', direction);
if (direction === 'left' || direction === 'right') {
newValue = movements[direction];
newPosition[0] = newValue >= screenWidth || newValue < 0 ? screenWidth/2 : newValue
}
if (direction === 'up' || direction === 'down') {
newValue = movements[direction];
newPosition[1] = newValue >= screenHeight || newValue < 0 ? screenHeight/2 : newValue
}
}
square.position = newPosition
arrow.direction = direction;
return entities;
};
export { MoveFinger };