Skip to content

Instantly share code, notes, and snippets.

@garganurag893
Created November 16, 2019 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garganurag893/7861851b5235c18e0b0bbee58e311912 to your computer and use it in GitHub Desktop.
Save garganurag893/7861851b5235c18e0b0bbee58e311912 to your computer and use it in GitHub Desktop.
import React from 'react';
import {View} from 'react-native';
import {array, object, string} from 'prop-types';
import Matter from 'matter-js';
const Obstacle = props => {
const width = props.size[0];
const height = props.size[1];
const x = props.body.position.x - width / 2;
const y = props.body.position.y - height / 2;
return (
<View
style={[
{
position: 'absolute',
left: x,
top: y,
width: width,
borderRadius: 20,
height: height,
},
]}
/>
);
};
export default (world, type, pos, size) => {
const initialObstacle = Matter.Bodies.rectangle(
pos.x,
pos.y,
size.width,
size.height,
{isStatic: true, friction: 1},
);
Matter.World.add(world, [initialObstacle]);
return {
body: initialObstacle,
size: [size.width, size.height],
type: type,
scored: false,
renderer: <Obstacle />,
};
};
Obstacle.propTypes = {
size: array,
body: object,
color: string,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment