sketch.js
1/*function handle(event) { 2 event.preventDefault(); 3} 4 5window.onload = function () { 6 document.addEventListener("touchmove", handle, { passive: false }); 7 document.addEventListener("mousewheel", handle, { passive: false }); 8};*/ 9 10var Engine = Matter.Engine, 11 Render = Matter.Render, 12 World = Matter.World, 13 Bodies = Matter.Bodies, 14 Composite = Matter.Composite, 15 Composites = Matter.Composites, 16 Vector = Matter.Vector, 17 Constraint = Matter.Constraint, 18 Events = Matter.Events; 19 20var engine; 21var world; 22var boxes = []; 23var ground; 24var 足場; 25var line; 26const ballComposite = Composite.create(); 27 28let emojis = []; 29 30function preload() { 31 emojis[0] = loadImage( 32 `https://cdn.glitch.global/(略)` 33 ); 34 emojis[1] = loadImage( 35 `https://cdn.glitch.global/(略)` 36 ); 37 emojis[2] = loadImage( 38 `https://cdn.glitch.global/(略)` 39 ); 40 emojis[3] = loadImage( 41 `https://cdn.glitch.global/(略)` 42 ); 43 emojis[4] = loadImage( 44 `https://cdn.glitch.global/(略)` 45 ); 46 emojis[5] = loadImage( 47 `https://cdn.glitch.global/(略)` 48 ); 49 emojis[6] = loadImage( 50 `https://cdn.glitch.global/(略)` 51 ); 52 emojis[7] = loadImage( 53 `https://cdn.glitch.global/(略)` 54 ); 55 emojis[8] = loadImage( 56 `https://cdn.glitch.global/(略)` 57 ); 58 emojis[9] = loadImage( 59 `https://cdn.glitch.global/(略)` 60 ); 61} 62 63function setup() { 64 createCanvas(window.innerWidth, window.innerHeight - 280); 65 engine = Engine.create(); 66 world = engine.world; 67 Engine.run(engine); 68 var options = { 69 isStatic: true, //固定する 70 label: "pit", 71 }; 72 for (let i = 0; i < 10; i++) { 73 r = random(200, 200); 74 var posx = random(width - 1000, width - 500); 75 let posy = 0; 76 boxes.push(new Box(posx, posy, r, r)); 77 } 78 ground = Bodies.rectangle(0, height - 200, 1800, 20, options); 79 足場 = Bodies.rectangle(400, height - 600, 500, 20, { 80 isStatic: true, 81 sprite: { 82 texture: "./images/7BDAEFF1-5750-45DF-954A-9219062295FC.png", 83 }, 84 }); 85 World.add(world, [ground,足場]); 86} 87 88function 出す() { 89 let test = boxes.push(new Box(500, 50, 200, 200)); 90} 91 92function draw() { 93 background(51); 94 for (var i = 0; i < boxes.length; i++) { 95 boxes[i].show(); 96 } 97 document.getElementById("カウント").innerHTML = 98 `<p id = "カウント">今の数:` + boxes.length + `人</p>`; 99} 100 101function Box(x, y, w, h, img) { 102 this.body = Bodies.rectangle(x, y, w, h); 103 this.w = w; 104 this.h = h; 105 this.emoji = random(emojis); 106 World.add(world, this.body); 107 108 this.show = function () { 109 var pos = this.body.position; 110 var angle = this.body.angle; 111 112 push(); 113 translate(pos.x, pos.y); 114 image(this.emoji, 0, 0, this.w, this.h); 115 pop(); 116 }; 117} 118
0 コメント