Skip to content

Instantly share code, notes, and snippets.

@naosim
Created September 28, 2024 08:48
Show Gist options
  • Save naosim/46e320b125987f0e5c78ae85d3906acf to your computer and use it in GitHub Desktop.
Save naosim/46e320b125987f0e5c78ae85d3906acf to your computer and use it in GitHub Desktop.
【microStudio】javascript + matter.js
// https://microstudio.dev/documentation/Matter/
var engine;
var ground;
var box;
init = function() {
engine = Matter.Engine.create();
engine.world.gravity.y = -1;
ground = Matter.Bodies.rectangle(0, -50, 200, 10, {isStatic: true});
Matter.Composite.add(engine.world, ground);
box = Matter.Bodies.rectangle(0, 50, 20, 20);
Matter.Composite.add(engine.world, box);
}
update = function() {
Matter.Engine.update(engine,1000/60);
}
draw = function() {
screen.clear();
screen.drawRect(ground.position.x, ground.position.y, 200, 10, "rgb(255,0,0)");
screen.setDrawRotation(box.angle/Math.PI*180); // PIをMath.PIに変更
screen.drawRect(box.position.x, box.position.y, 20, 20, "#FF0");
screen.setDrawRotation(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment