Skip to content

Commit 912e595

Browse files
authored
Merge pull request #2 from konjoinfinity/master
Hey thanks for reaching out! Yeah happy to accept this! And hope you release something soon :)
2 parents e593594 + 42606bd commit 912e595

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+6914
-1962
lines changed

.buckconfig

Lines changed: 0 additions & 6 deletions
This file was deleted.

.expo/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
> Why do I have a folder named ".expo" in my project?
2+
The ".expo" folder is created when an Expo project is started using "expo start" command.
3+
> What do the files contain?
4+
- "devices.json": contains information about devices that have recently opened this project. This is used to populate the "Development sessions" list in your development builds.
5+
- "settings.json": contains the server configuration that is used to serve the application manifest.
6+
> Should I commit the ".expo" folder?
7+
No, you should not share the ".expo" folder. It does not contain any information that is relevant for other developers working on the project, it is specific to your machine.
8+
Upon project creation, the ".expo" folder is already added to your ".gitignore" file.

.expo/devices.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"devices": []
3+
}

.flowconfig

Lines changed: 0 additions & 58 deletions
This file was deleted.

App.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
import useCachedResources from './useCachedResources';
3+
import React from 'react';
4+
import Soccer from './Soccer';
5+
6+
7+
export default function App() {
8+
const isLoadingComplete = useCachedResources();
9+
10+
if (!isLoadingComplete) {
11+
return null
12+
} else {
13+
return (
14+
<Soccer />
15+
);
16+
}
17+
}

Soccer.js

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import React, {Component} from 'react';
2-
import {View,
3-
Text,
4-
StyleSheet,
5-
Dimensions,
6-
Image} from 'react-native';
2+
import {View,Text, StyleSheet,Dimensions,Image,Modal,TouchableOpacity,TouchableWithoutFeedback} from 'react-native';
3+
import * as Haptics from 'expo-haptics';
74
import Score from './components/Score';
85
import Emoji from './components/Emoji';
6+
import * as All from './images';
97

108
const LC_IDLE = 0;
119
const LC_RUNNING = 1;
1210
const LC_TAPPED = 2;
13-
const GRAVITY = 0.8;
11+
const GRAVITY = 0.6;
1412
const TAPPED_VELOCITY = 20;
1513
const ROTATION_FACTOR = 7;
16-
1714
const SCREEN_HEIGHT = Dimensions.get('window').height;
1815
const SCREEN_WIDTH = Dimensions.get('window').width;
1916
const BALL_WIDTH = SCREEN_WIDTH * 0.33;
@@ -22,9 +19,17 @@ const FLOOR_Y = SCREEN_HEIGHT - BALL_HEIGHT;
2219
const FLOOR_X = SCREEN_WIDTH / 2;
2320
const SCORE_Y = SCREEN_HEIGHT / 6;
2421
const EMOJI_Y = SCREEN_HEIGHT / 3;
22+
const sports = ['soccer', 'baseball', 'basketball', 'football', 'golf', 'tennis', 'hockey']
23+
24+
function Sports({sport, set}) {
25+
return (
26+
<TouchableOpacity onPress={()=> set(sport)}>
27+
<Image style={{width: Dimensions.get('window').width * 0.3, height: Dimensions.get('window').width * 0.3, marginBottom: 15}} source={All[`${sport}`]}/>
28+
</TouchableOpacity>
29+
)
30+
}
2531

2632
class Soccer extends Component {
27-
2833
constructor(props) {
2934
super(props);
3035
this.interval = null;
@@ -38,6 +43,9 @@ class Soccer extends Component {
3843
scored: false,
3944
lost: false,
4045
rotate: 0,
46+
sport: All.soccer,
47+
visible: true,
48+
button: true
4149
};
4250
}
4351

@@ -52,6 +60,8 @@ class Soccer extends Component {
5260
}
5361

5462
onTap(event) {
63+
Haptics.selectionAsync()
64+
this.setState({button: false})
5565
if(this.state.lifeCycle === LC_TAPPED) {
5666
this.setState({
5767
lifeCycle: LC_RUNNING,
@@ -61,8 +71,7 @@ class Soccer extends Component {
6171
else {
6272
let centerX = BALL_WIDTH / 2;
6373
let centerY = BALL_HEIGHT / 2;
64-
let velocityX = ((centerX - event.locationX) / SCREEN_WIDTH)
65-
* TAPPED_VELOCITY;
74+
let velocityX = ((centerX - event.locationX) / SCREEN_WIDTH) * TAPPED_VELOCITY;
6675
let velocityY = -TAPPED_VELOCITY;
6776
this.setState({
6877
vx: velocityX,
@@ -82,18 +91,19 @@ class Soccer extends Component {
8291
nextState.rotate += ROTATION_FACTOR * nextState.vx;
8392
// Hit the left wall
8493
if(nextState.x < BALL_WIDTH / 2) {
94+
Haptics.selectionAsync()
8595
nextState.vx = -nextState.vx;
8696
nextState.x = BALL_WIDTH / 2;
8797
}
88-
8998
// Hit the right wall
9099
if(nextState.x > SCREEN_WIDTH - BALL_WIDTH / 2) {
100+
Haptics.selectionAsync()
91101
nextState.vx = -nextState.vx;
92102
nextState.x = SCREEN_WIDTH - BALL_WIDTH / 2;
93103
}
94-
95104
// Reset after falling down
96105
if(nextState.y > SCREEN_HEIGHT + BALL_HEIGHT) {
106+
Haptics.selectionAsync()
97107
nextState.y = FLOOR_Y;
98108
nextState.x = FLOOR_X;
99109
nextState.lifeCycle = LC_IDLE;
@@ -109,17 +119,20 @@ class Soccer extends Component {
109119

110120
update() {
111121
if(this.state.lifeCycle === LC_IDLE) {
122+
this.setState({button: true})
112123
return;
113124
}
114-
115125
let nextState = Object.assign({}, this.state);
116-
117126
this.updatePosition(nextState);
118127
this.updateVelocity(nextState);
119-
120128
this.setState(nextState);
121129
}
122130

131+
setSport(sport){
132+
Haptics.selectionAsync()
133+
this.setState({visible: false, sport: All[`${sport}`]})
134+
}
135+
123136
render() {
124137
var position = {
125138
left: this.state.x - (BALL_WIDTH / 2),
@@ -134,10 +147,32 @@ class Soccer extends Component {
134147
<View>
135148
<Score score={this.state.score} y={SCORE_Y} scored={this.state.scored}/>
136149
<Emoji scored={this.state.scored} y={EMOJI_Y} lost={this.state.lost}/>
137-
<Image source={require('./images/soccer.png')}
138-
style={[styles.ball, position, rotation]}
139-
onStartShouldSetResponder={(event) => this.onTap(event.nativeEvent)}
140-
/>
150+
<TouchableWithoutFeedback style={{padding: 20}}
151+
onPress={(event) => this.onTap(event.nativeEvent)}
152+
onPressIn={(event) => this.onTap(event.nativeEvent)}
153+
onPressOut={(event) => this.onTap(event.nativeEvent)}>
154+
<Image source={this.state.sport} style={[styles.ball, position, rotation]}/>
155+
</TouchableWithoutFeedback>
156+
<Modal animationType='slide' presentationStyle='formSheet' visible={this.state.visible}>
157+
<View style={{ alignItems: "center", marginTop: Dimensions.get('window').height * 0.2}}>
158+
<Text style={{fontSize: "40", fontWeight: "200", marginBottom: 20}}>
159+
Choose your sport
160+
</Text>
161+
<View style={{flexDirection: "row", flexWrap: "wrap", justifyContent:"space-evenly"}}>
162+
{sports.map(sport => {return <Sports key={sport} set={() => this.setSport(sport)} sport={sport} /> })}
163+
</View>
164+
</View>
165+
</Modal>
166+
{this.state.button == true && <TouchableOpacity onPressIn={()=> {this.setState({visible: true}), Haptics.selectionAsync()}}
167+
style={{padding: 10, height: 55, width: 55, position: 'absolute', bottom: 30, right: 30, borderColor: '#e7e7e6', borderWidth: 0.5, shadowColor: "#555a74",
168+
shadowOffset: { height: 0.5, width: 0.5 },
169+
shadowOpacity: 0.5,
170+
shadowRadius: 0.5,
171+
backgroundColor: "white",
172+
borderRadius: 5,
173+
elevation: 8,
174+
justifyContent: 'center',
175+
alignItems: 'center'}}><Image style={{height: 50, width: 50}} source={require('./images/sportballs.png')}/></TouchableOpacity>}
141176
</View>
142177
);
143178
}

android/app/BUCK

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)