[READ-ONLY] Mirror of https://github.com/andrioid/silly-experiment1. Workshop tasks turned into a silly poop game. That's how mature I am.
0

Configure Feed

Select the types of activity you want to include in your feed.

so its a working game now

+45 -23
+40 -16
App.js
··· 1 1 import React from "react"; 2 - import { StyleSheet, Text, View, Animated, Easing } from "react-native"; 2 + import { StyleSheet, Text, View, Animated, Easing, Button } from "react-native"; 3 3 import { Flag } from "./Flag"; 4 4 import { FrenchBox } from "./FrenchBox"; 5 5 import { Blob } from "./Blob"; ··· 8 8 anim = new Animated.Value(0); 9 9 10 10 state = { 11 - blobs: [{ id: 1 }, { id: 2 }], 12 - counter: 0 11 + blobs: [{ id: 1 }, { id: 2 }, { id: 3 }], 12 + counter: 0, 13 + score: 0, 14 + baseSpeed: 1, 15 + running: true 13 16 }; 14 17 15 18 addBlob = () => { ··· 27 30 28 31 handleDead = id => { 29 32 this.addBlob(); 30 - // delete the dead one, add two more 33 + // delete the dead one, add one more and increase speed 31 34 const idx = this.state.blobs.findIndex(v => v.id === id); 32 35 if (idx !== -1) { 33 36 // delete the old one from array 34 37 this.setState(state => { 35 38 state.blobs.splice(idx, 1); // I'm not happy with this 36 39 return { 37 - ...state 40 + score: state.score + 1, 41 + baseSpeed: state.baseSpeed + 0.1, 42 + blobs: state.blobs 38 43 }; 39 44 }); 40 45 } 41 46 }; 42 47 43 48 handleGameOver = () => { 44 - alert("Game over"); 49 + this.setState({ running: false, baseSpeed: 1 }); 45 50 }; 46 51 47 52 render() { 48 53 return ( 49 54 <View style={styles.container}> 50 - {this.state.blobs.map(b => ( 51 - <Blob 52 - key={b.id} 53 - onDead={() => this.handleDead(b.id)} 54 - onGameOver={this.handleGameOver} 55 - /> 56 - ))} 55 + {this.state.running ? ( 56 + <View style={{ flex: 1, backgroundColor: "#ffffff" }}> 57 + {this.state.blobs.map(b => ( 58 + <Blob 59 + key={b.id} 60 + onDead={() => this.handleDead(b.id)} 61 + baseSpeed={this.state.baseSpeed} 62 + onGameOver={this.handleGameOver} 63 + /> 64 + ))} 65 + </View> 66 + ) : ( 67 + <View 68 + style={{ flex: 1, justifyContent: "center", alignItems: "center" }} 69 + > 70 + <Text style={{ fontSize: 20 }}>Game Over</Text> 71 + <Text>Your score: {this.state.score}</Text> 72 + <Button 73 + title="Restart" 74 + onPress={() => { 75 + this.setState({ running: true, score: 0 }); 76 + }} 77 + /> 78 + </View> 79 + )} 80 + <View> 81 + <Text style={{ fontSize: 24 }}>{this.state.score}</Text> 82 + </View> 57 83 </View> 58 84 ); 59 85 } ··· 62 88 const styles = StyleSheet.create({ 63 89 container: { 64 90 flex: 1, 65 - backgroundColor: "#d3d3d3", 66 - alignItems: "center", 67 - justifyContent: "space-around" 91 + backgroundColor: "#d3d3d3" 68 92 } 69 93 });
+1 -1
Blob.js
··· 36 36 const initialPosition = Animated.timing(this.anim, { 37 37 toValue: 1, 38 38 easing: Easing.linear, 39 - duration: 8000, 39 + duration: 8000 / this.props.baseSpeed, 40 40 useNativeDriver: true 41 41 }).start(({ finished }) => { 42 42 if (finished) {
+4 -6
app.json
··· 1 1 { 2 2 "expo": { 3 - "name": "day1-1", 4 - "description": "This project is really great.", 5 - "slug": "day1-1", 3 + "name": "Poo Falls", 4 + "description": "Some silly game I made", 5 + "slug": "poo-falls", 6 6 "privacy": "public", 7 7 "sdkVersion": "27.0.0", 8 8 "platforms": ["ios", "android"], ··· 17 17 "updates": { 18 18 "fallbackToCacheTimeout": 0 19 19 }, 20 - "assetBundlePatterns": [ 21 - "**/*" 22 - ], 20 + "assetBundlePatterns": ["**/*"], 23 21 "ios": { 24 22 "supportsTablet": true 25 23 }