1
只是想在p5.js中做一个简单的pong游戏。我最近刚刚加入JavaScript,无法找出球与球棒之间的碰撞检测。我已经尝试了几种方法,但它主要是阻止我的代码运行..等..会爱任何帮助!Colision detection p5.js
这里是我的源代码:
function setup() {
createCanvas(750, 750);
}
var x = 50;
var y = 50;
var direction = 5;
var arrow = 0;
var ball;
var bat;
function draw() {
background(220);
fill ('white');
ball = ellipse (x, y, 50, 50);
x = x + direction;
if (x > width - 25){
direction = -5;
}
if (x < 25) {
direction = 5;
}
x++;
y++;
if (keyIsDown(RIGHT_ARROW)){
arrow += 7;
}
if (keyIsDown(LEFT_ARROW)){
arrow += -7;
}
fill ('black');
bat = rect(arrow, 600, 150, 15);
}
“阻止我的代码运行”您的问题是什么?你有什么问题?你希望代码片段做什么? –