matter实现拖动弹簧发射小球物理碰撞模拟交互游戏代码
代码语言:html
所属分类:游戏
代码描述:matter实现拖动弹簧发射小球物理碰撞模拟交互游戏代码
代码标签: matter 拖动 弹簧 发射 小球 物理 碰撞 模拟 交互 游戏 代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> * { box-sizing: border-box; } body { margin: 0; padding: 0; } </style> </head> <body > <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/matter.0.18.0.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/matter-tools.js"></script> <script> var Example = Example || {}; Example.slingshot = function () { var Engine = Matter.Engine, Render = Matter.Render, Runner = Matter.Runner, Composites = Matter.Composites, Events = Matter.Events, Constraint = Matter.Constraint, MouseConstraint = Matter.MouseConstraint, Mouse = Matter.Mouse, World = Matter.World, Bodies = Matter.Bodies; // create engine var engine = Engine.create(), world = engine.world; // create renderer var render = Render.create({ element: document.body, engine: engine, options: { width: 800, height: 600, wireframes: false } }); Render.run(render); // create runner var runner = Runner.create(); Runner.run(runner, engine); // add bodies var ground = Bodies.rectangle(395, 600, 815, 50, { isStatic: true }), rockOptions = { density: 0.004 }, rock = Bodies.polygon(170, 450, 8, 20, rockOptions), anchor = { x: 170, y: 450 }, elastic = Constraint.create({ pointA: anchor, bodyB: rock, stiffness: 0.05 }); var pyramid = Composites.pyramid(500, 300, 9, 10, 0, 0, function (x, y) { return Bodies.rectangle(x, y, 25, 40); }); var ground2 = Bodies.rectangle(610, 250, 200, 20, { isStatic: true }); .........完整代码请登录后点击上方下载按钮下载查看
网友评论0