-
Notifications
You must be signed in to change notification settings - Fork 0
/
entities.js
89 lines (77 loc) · 2.22 KB
/
entities.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import Matter from "matter-js";
import Platform from "./components/Platform";
import Peter from "./components/Peter";
import { Dimensions } from "react-native";
const { width, height } = Dimensions.get("window");
function importAll(r) {
return r.keys().map(r);
}
export const platformWidth = 110;
export const platformHeight = 40;
export default (restart) => {
let engine = Matter.Engine.create({ enableSleeping: false });
let world = engine.world;
engine.gravity.y = 0.4;
const images = importAll(
require.context("./assets/game-screen/food", false, /\.(png)$/)
);
const invImages = importAll(
require.context("./assets/game-screen/food/inverses", false, /\.(png)$/)
);
const wrongImages = importAll(
require.context("./assets/game-screen/animals", false, /\.(png)$/)
);
const invWrongImages = importAll(
require.context("./assets/game-screen/animals/inverses", false, /\.(png)$/)
);
let platforms = {};
let spacing = 200;
let startHeight = 200;
console.log(wrongImages)
correct_array = Array.from({ length: 6 }, () => Math.floor(Math.random() * 2))
for (let i = 0; i < 6; i++) {
label = "platform" + i;
x = 100;
y = startHeight - i * spacing;
correct = correct_array[i]
platforms[label] = Platform(
world,
label,
{ x: x, y: y },
{ height: platformHeight, width: platformWidth },
correct ? images[i] : wrongImages[i],
correct ? invImages[i] : invWrongImages[i],
correct,
);
}
for (let i = 0; i < 6; i++) {
label = "platform2" + i;
x = 300;
y = startHeight - i * spacing;
correct = 1 - correct_array[i]
platforms[label] = Platform(
world,
label,
{ x: x, y: y },
{ height: platformHeight, width: platformWidth },
correct ? images[i + 6] : wrongImages[i + 6],
correct ? invImages[i + 6] : invWrongImages[i + 6],
correct,
);
}
console.log(images);
return {
physics: { engine, world },
Peter: Peter(world, { x: 200, y: 0 }, { height: 30, width: 50 }),
...platforms,
platformfloor: Platform(
world,
"platformfloor",
{ x: 200, y: startHeight + 200 },
{ height: 50, width: 600 },
null,
null,
true
),
};
};