Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
- handling network error while login
- added different frames for the bird (bird actually flaps now :>)
  • Loading branch information
sarthakpranesh committed May 31, 2020
1 parent 6c46813 commit 542831e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 5 deletions.
Binary file added assets/bird2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/bird3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 17 additions & 2 deletions src/components/Bird.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* eslint-disable react-native/no-inline-styles */
import React, {Component} from 'react';
import {Image} from 'react-native';
import birdImage from '../../assets/bird.png';
import birdImage1 from '../../assets/bird.png';
import birdImage2 from '../../assets/bird2.png';
import birdImage3 from '../../assets/bird3.png';

import Constants from '../Constant.js';

Expand All @@ -13,9 +15,22 @@ export default class Bird extends Component {
this.height = Constants.BIRD_HEIGHT;
}

birdFrameSelector = () => {
if (this.props.pose === 0) {
return birdImage1;
} else if (this.props.pose === 1) {
return birdImage2;
} else if (this.props.pose === 2) {
return birdImage3;
} else {
return birdImage1;
}
};

render() {
const x = this.props.position[0] - this.width / 2;
const y = this.props.position[1] - this.height / 2;

return (
<Image
style={{
Expand All @@ -26,7 +41,7 @@ export default class Bird extends Component {
height: this.height,
}}
resizeMode="contain"
source={birdImage}
source={this.birdFrameSelector()}
/>
);
}
Expand Down
9 changes: 7 additions & 2 deletions src/components/Physics.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Constants from '../Constant';
let pause = false;
let birdJump = 0;
let gravity = 0;
let prevTime = 0;
let scored = false;

export const stopGame = () => {
Expand All @@ -26,7 +27,7 @@ export const randomBetween = () => {
return Math.floor(Math.random() * (max - min + 1) + min);
};

export const GameControl = (entities, {touches, dispatch}) => {
export const GameControl = (entities, {time, touches, dispatch}) => {
if (!pause) {
Object.keys(entities).forEach(key => {
const bird = entities['1'];
Expand Down Expand Up @@ -77,8 +78,12 @@ export const GameControl = (entities, {touches, dispatch}) => {
body.position[0] -= 1;
return;
} else {
// if bird, apply gravity
// if bird, apply gravity and change pose
body.position[1] += gravity - birdJump;
if (time.current - prevTime >= 500) {
prevTime = time.current;
body.pose = (body.pose + 1) % 3;
}
if (birdJump > 0) {
birdJump--;
}
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Play.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default class Play extends PureComponent {
];

return {
1: {position: bird, renderer: <Bird />, name: 'bird'},
1: {position: bird, renderer: <Bird />, name: 'bird', pose: 0},
2: {position: floor1, renderer: <Floor />, name: 'floor'},
3: {position: floor2, renderer: <Floor />, name: 'floor'},
4: {position: pipe1, renderer: <Pipe />, name: 'pipe'},
Expand Down
5 changes: 5 additions & 0 deletions src/screens/UserStarting.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export default class UserStarting extends Component {
'Please install Google Play Services!',
ToastAndroid.SHORT,
);
} else if (error.message === 'NETWORK_ERROR') {
ToastAndroid.show(
'We are having Network issues :<',
ToastAndroid.SHORT,
);
} else {
console.log(error.message);
}
Expand Down

0 comments on commit 542831e

Please sign in to comment.