This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // App.js | |
| const GOAL_SIZE = Math.floor(width * .04); | |
| const goalPoint = GetRandomPoint(GRID_X, GRID_Y); | |
| const goal = Matter.Bodies.rectangle(goalPoint.x, goalPoint.y, GOAL_SIZE, GOAL_SIZE, { | |
| isStatic: true, | |
| isSensor: true, | |
| label: 'goal' | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // App.js | |
| setUpdateIntervalForType(SensorTypes.accelerometer, 100); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // App.js | |
| export default class App extends Component { | |
| state = { | |
| ballX: theBall.position.x, | |
| ballY: theBall.position.y, | |
| } | |
| // next: add componentDidMount | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // App.js | |
| componentDidMount() { | |
| const { engine, world } = this._addObjectsToWorld(maze, theBall, goal); | |
| this.entities = this._getEntities(engine, world, maze, theBall, goal); | |
| this._setupCollisionHandler(engine); | |
| // next: subscribe to accelerometer | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // App.js | |
| accelerometer.subscribe(({ x, y }) => { | |
| Matter.Body.setPosition(theBall, { | |
| x: this.state.ballX + x, | |
| y: this.state.ballY + y | |
| }); | |
| this.setState({ | |
| ballX: x + this.state.ballX, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // App.js | |
| _addObjectsToWorld = (maze, ball, goal) => { | |
| const engine = Matter.Engine.create({ enableSleeping: false }); | |
| const world = engine.world; | |
| Matter.World.add(world, [ | |
| maze, | |
| ball, | |
| goal | |
| ]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // App.js | |
| _getEntities = (engine, world, maze, ball, goal) => { | |
| const entities = { | |
| physics: { | |
| engine, | |
| world | |
| }, | |
| playerBall: { | |
| body: ball, | |
| bgColor: '#FF5877', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // App.js | |
| render() { | |
| if (this.entities) { | |
| return ( | |
| <View style={styles.container}> | |
| <GameEngine | |
| systems={[this.physics]} | |
| entities={this.entities} | |
| > | |
| </GameEngine> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // App.js | |
| physics = (entities, { time }) => { | |
| let engine = entities["physics"].engine; | |
| engine.world.gravity = { | |
| x: 0, | |
| y: 0 | |
| }; | |
| Matter.Engine.update(engine, time.delta); | |
| return entities; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // src/components/Circle.js | |
| import React, { Component } from "react"; | |
| import { View, Dimensions } from "react-native"; | |
| const { height, width } = Dimensions.get('window'); | |
| const BODY_DIAMETER = Math.trunc(Math.max(width, height) * 0.02); | |
| const BORDER_WIDTH = Math.trunc(BODY_DIAMETER * 0.1); | |
| const Circle = ({ body, bgColor, borderColor }) => { |