flamingo-ui
Version:
火烈鸟UI组件库
167 lines (166 loc) • 7.06 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var stdin_exports = {};
__export(stdin_exports, {
default: () => stdin_default
});
module.exports = __toCommonJS(stdin_exports);
var import_matter_js = __toESM(require("matter-js"));
var import_vue = require("vue");
var import_vue2 = require("vue");
const __default__ = {
name: "AngryBird"
};
const __vue_sfc__ = /* @__PURE__ */ Object.assign(__default__, {
props: {
ejectDistance: {
type: Number,
default: 3
},
WIDTH: {
type: Number,
default: 1022
}
},
setup(__props, { expose }) {
expose();
const props = __props;
const HEIGHT = (0, import_vue.ref)(props.WIDTH / 2.2914);
const dom = (0, import_vue.ref)(null);
const slingshot = () => {
var Engine = import_matter_js.default.Engine, Render = import_matter_js.default.Render, Runner = import_matter_js.default.Runner, Events = import_matter_js.default.Events, Constraint = import_matter_js.default.Constraint, MouseConstraint = import_matter_js.default.MouseConstraint, Mouse = import_matter_js.default.Mouse, World = import_matter_js.default.World, Bodies = import_matter_js.default.Bodies;
var engine = Engine.create(), world = engine.world;
var render = Render.create({
element: dom.value,
engine,
options: {
width: props.WIDTH,
height: HEIGHT.value,
background: "#fff",
wireframeBackground: "#fff",
wireframes: false,
showVelocity: true,
showCollitions: true
}
});
Render.run(render);
var runner = Runner.create();
Runner.run(runner, engine);
var ground = Bodies.rectangle(511, 446, 1022, 10, { isStatic: true }), birdOptions = { mass: 20, restitution: 0.6 }, bird = Bodies.circle(200, 350, 16, birdOptions), anchor = { x: 200, y: 350 }, elastic = Constraint.create({
pointA: anchor,
bodyB: bird,
length: 0.01,
stiffness: 0.25,
render: {
strokeStyle: "black"
}
});
var woodOptions = { mass: 2, isStatic: false, restitution: 0, friction: 0.4 };
var rockOptions = { mass: 4, isStatic: false, restitution: 0, friction: 0.5 };
var ironOptions = { mass: 6, isStatic: false, restitution: 0, friction: 0.2 };
var stacks = [];
stacks[0] = Bodies.rectangle(450, 404, 30, 70, rockOptions);
stacks[1] = Bodies.rectangle(485, 358, 80, 20, rockOptions);
stacks[2] = Bodies.rectangle(520, 404, 30, 70, rockOptions);
stacks[3] = Bodies.rectangle(620, 388, 28, 100, rockOptions);
stacks[4] = Bodies.rectangle(650, 327, 80, 20, rockOptions);
stacks[5] = Bodies.rectangle(680, 388, 28, 100, rockOptions);
stacks[6] = Bodies.rectangle(780, 364, 20, 150, rockOptions);
stacks[7] = Bodies.rectangle(800, 364, 20, 150, rockOptions);
stacks[8] = Bodies.rectangle(850, 278, 150, 20, rockOptions);
stacks[9] = Bodies.rectangle(900, 364, 20, 150, rockOptions);
stacks[10] = Bodies.rectangle(920, 364, 20, 150, rockOptions);
stacks[11] = Bodies.rectangle(570, 418, 20, 40, woodOptions);
stacks[12] = Bodies.rectangle(570, 388, 60, 20, woodOptions);
stacks[13] = Bodies.rectangle(730, 418, 20, 40, woodOptions);
stacks[14] = Bodies.rectangle(730, 388, 60, 20, woodOptions);
stacks[15] = Bodies.rectangle(900, 252, 30, 30, woodOptions);
stacks[16] = Bodies.rectangle(840, 226, 120, 10, woodOptions);
stacks[17] = Bodies.rectangle(485, 308, 30, 80, ironOptions);
stacks[18] = Bodies.rectangle(485, 252, 30, 30, ironOptions);
stacks[19] = Bodies.rectangle(650, 276, 30, 80, ironOptions);
stacks[20] = Bodies.rectangle(570, 226, 220, 20, ironOptions);
stacks[21] = Bodies.circle(570, 358, 20, ironOptions);
stacks[22] = Bodies.circle(730, 362, 16, ironOptions);
stacks[23] = Bodies.circle(570, 196, 20, ironOptions);
World.add(engine.world, [ground, bird, ...stacks, elastic]);
Events.on(engine, "afterUpdate", function() {
if (mouseConstraint.mouse.button === -1 && (bird.position.x > 200 + props.ejectDistance || bird.position.y < 350 - props.ejectDistance)) {
bird = Bodies.circle(200, 350, 16, birdOptions);
World.add(engine.world, bird);
elastic.bodyB = bird;
}
});
var mouse = Mouse.create(render.canvas), mouseConstraint = MouseConstraint.create(engine, {
mouse,
constraint: {
stiffness: 0.2,
render: {
visible: false
}
}
});
World.add(world, mouseConstraint);
render.mouse = mouse;
Render.lookAt(render, {
min: { x: 0, y: 0 },
max: { x: 1022, y: 446 }
});
return {
engine,
runner,
render,
canvas: render.canvas,
stop: function() {
import_matter_js.default.Render.stop(render);
import_matter_js.default.Runner.stop(runner);
}
};
};
(0, import_vue.onMounted)(() => {
slingshot();
});
const __returned__ = { props, HEIGHT, dom, slingshot, get Matter() {
return import_matter_js.default;
}, ref: import_vue.ref, onMounted: import_vue.onMounted };
Object.defineProperty(__returned__, "__isScriptSetup", { enumerable: false, value: true });
return __returned__;
}
});
const _hoisted_1 = { ref: "dom" };
function __vue_render__(_ctx, _cache, $props, $setup, $data, $options) {
return (0, import_vue2.openBlock)(), (0, import_vue2.createElementBlock)(
"div",
_hoisted_1,
null,
512
/* NEED_PATCH */
);
}
__vue_sfc__.render = __vue_render__;
var stdin_default = __vue_sfc__;