forked from EvanBacon/react-flappy-bird
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
executable file
·72 lines (68 loc) · 1.92 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
import { GLView } from 'expo';
import * as React from 'react';
import { Text, TouchableWithoutFeedback, View } from 'react-native';
import DisableBodyScrollingView from './components/DisableBodyScrollingView';
import ExpoButton from './components/ExpoButton';
import GithubButton from './components/GithubButton';
import KeyboardControlsView from './components/KeyboardControlsView';
import logyo from './components/logyo';
import Game from './src/game';
logyo('https://twitter.com/baconbrix');
export default class App extends React.Component {
state = {
score: 0,
};
render() {
const { style, ...props } = this.props;
return (
<View
style={[{ width: '100vw', height: '100vh', overflow: 'hidden' }, style]}
>
<DisableBodyScrollingView>
<KeyboardControlsView
onKeyDown={({ code }) => {
if (this.game) {
if (code === 'Space') {
this.game.onPress();
}
}
}}
>
<TouchableWithoutFeedback
onPressIn={() => {
if (this.game) this.game.onPress();
}}
>
<GLView
style={{ flex: 1, backgroundColor: 'black' }}
onContextCreate={context => {
this.game = new Game(context);
this.game.onScore = score => this.setState({ score });
}}
/>
</TouchableWithoutFeedback>
<Score>{this.state.score}</Score>
</KeyboardControlsView>
</DisableBodyScrollingView>
<ExpoButton />
<GithubButton />
</View>
);
}
}
const Score = ({ children }) => (
<Text
style={{
position: 'absolute',
left: 0,
top: '10%',
right: 0,
textAlign: 'center',
color: 'white',
fontSize: 48,
userSelect: 'none',
}}
>
{children}
</Text>
);