-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathApp.js
56 lines (52 loc) · 1.79 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
import { StatusBar } from 'expo-status-bar';
import React, { useState, useEffect } from 'react';
import { Text, TouchableOpacity, View } from 'react-native';
import { GameEngine } from 'react-native-game-engine';
import entities from './entities';
import Physics from './physics';
export default function App() {
const [running, setRunning] = useState(false)
const [gameEngine, setGameEngine] = useState(null)
const [currentPoints, setCurrentPoints] = useState(0)
useEffect(() => {
setRunning(false)
}, [])
return (
<View style={{ flex: 1 }}>
<Text style={{ textAlign: 'center', fontSize: 40, fontWeight: 'bold', margin: 20 }}>{currentPoints}</Text>
<GameEngine
ref={(ref) => { setGameEngine(ref) }}
systems={[Physics]}
entities={entities()}
running={running}
onEvent={(e) => {
switch (e.type) {
case 'game_over':
setRunning(false)
gameEngine.stop()
break;
case 'new_point':
setCurrentPoints(currentPoints + 1)
break;
}
}}
style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }}
>
<StatusBar style="auto" hidden={true} />
</GameEngine>
{!running ?
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<TouchableOpacity style={{ backgroundColor: 'black', paddingHorizontal: 30, paddingVertical: 10 }}
onPress={() => {
setCurrentPoints(0)
setRunning(true)
gameEngine.swap(entities())
}}>
<Text style={{ fontWeight: 'bold', color: 'white', fontSize: 30 }}>
START GAME
</Text>
</TouchableOpacity>
</View> : null}
</View>
);
}