两个矩形碰撞

时间:2019-02-25 18:43:24

标签: javascript p5.js

我正在做一个简单的游戏。我有一个固定的矩形,另一个仅在y轴上移动。看起来像this
正确的汽车正在向下行驶。这两辆车的宽度为40,高度为80。

当我像这样检查碰撞时,它无法正常工作。

export default class WebServiceUse extends Component {
    constructor(props) {
        super(props);
        this.state = ({
            print1: '0000',
        })
    }
    componentDidMount() {
        fetch('https://**********', {
            method: 'POST',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({ id: '1' })
        }).then((response) => response.json()).then((responseJson) => {
            let array = responseJson.ed5aaf3d933385698d872d0a0d5d4f36
            alert(array[0].date)
            this.setState = ({
                print1: array[0].date,
            })
        })
            .catch((error) => {
                console.error(error)
            });
    }
    render() {
        return (
            <View style={styles.container}>
                <Text>Test:</Text>
                <Text>{this.state.print1}</Text>
            </View>
        );
    }
}

如何使其更准确?

1 个答案:

答案 0 :(得分:1)

现在,您正在执行圆-圆碰撞检测。您想进行矩形-矩形碰撞检测。

无耻的自我促进:here是有关冲突检测的教程。它是为处理而编写的,但是所有想法也都适用于P5.js。

谷歌搜索“矩形-矩形碰撞检测”也将返回大量结果。祝你好运!

相关问题