//setCollider
//setCollider ("circle",offsetX,offsetY,radius)
//setCollider ("rectangle",offsetX,offsetY,width,height)
// Either "rectangle" or "circle"
//"circle"場合は半径
//"rectangle"場合は長方形の幅
///////////////////////
var gr;
var boxes;
function setup() {
var myCanvas = createCanvas(300, 300);
myCanvas.parent('myContainer');
gr = new Group();
for(var i=0; i<8; i++) {
var circle=createSprite(random(0,width),
random(0,height),60, 60);
circle.draw = function() {
fill(237,205,0);
ellipse(0,0, 60, 60);
}
circle.setCollider("circle", 0,0,30);
circle.setSpeed(random(2,5), random(0, 360));
circle.scale = 0.5;
circle.mass = circle.scale;
gr.add(circle);
}
boxes = new Group();
for(var i=0; i<4; i++) {
var box = createSprite(random(0,width-50),random(0,height-50));
box.addAnimation("normal", "img/b1.png", "img/b3.png");
box.scale = 0.4;
box.immovable = true;
if(i%2==0)
box.rotation = 90;
boxes.add(box);
}
}
function draw() {
background(240,240,235);
gr.bounce(gr);
gr.bounce(boxes);
for(var i=0; i<allSprites.length; i++) {
var s = allSprites[i];
if(s.position.x<0+15) {
// s.position.x = 1;
s.velocity.x = abs(s.velocity.x);
}
if(s.position.x>width-15) {
// s.position.x = width-1;
s.velocity.x = -abs(s.velocity.x);
}
if(s.position.y<0+15) {
// s.position.y = 1;
s.velocity.y = abs(s.velocity.y);
}
if(s.position.y>height-15) {
// s.position.y = height-1;
s.velocity.y = -abs(s.velocity.y);
}
}
drawSprites();
}
preview
コメントを残す