-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.js
88 lines (79 loc) · 1.99 KB
/
App.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
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import {
Dimensions,
StyleSheet,
Text,
View
} from 'react-native';
// 添加游戏引擎1/2
import { GameEngine } from "react-native-game-engine";
// 添加Ball 1/3
import Ball from './Ball';
// 添加Walls 1/3
import Wall from './Wall';
import {
Physics,
physicsEntity,
createWall,
createBall,
CreateBalls,
useAccelerometer
} from './Physics';
// const createObject = (x, y) => ({ position: { x: x, y: y } });
// 添加Ball 2/3
const { width, height } = Dimensions.get("screen");
const ballSize = Math.trunc(Math.max(width, height) * 0.075);
const ball = createBall(width / 2, height / 2, ballSize / 2);
// 添加Walls 2/3
const wallColor = "#335"
const wallSize = ballSize * 0.5;
const floor = createWall(width / 2, height - wallSize / 2, width, wallSize);
const leftwall = createWall(wallSize / 2, height / 2, wallSize, height);
const rightwall = createWall(width - wallSize / 2, height / 2, wallSize, height);
export default function App() {
useAccelerometer()
// 添加游戏引擎2/2
return (
<GameEngine
style={styles.container}
systems={[Physics, CreateBalls(Ball)]}
entities={{
physics: physicsEntity,
// 添加Ball 3/3
ball: {
body: ball,
size: [ballSize, ballSize],
color: '#fff',
renderer: Ball
},
// 添加Walls 3/3
leftwall: {
body: leftwall,
size: [wallSize, height],
color: wallColor,
renderer: Wall
},
rightwall: {
body: rightwall,
size: [wallSize, height],
color: wallColor,
renderer: Wall
},
floor: {
body: floor,
size: [width, wallSize],
color: wallColor,
renderer: Wall
}
}} >
<StatusBar hidden={true} />
</ GameEngine>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#669',
},
});