Commit 21a3813f authored by 汪欢's avatar 汪欢

Merge branch 'dev' of http://gitlab2.dui88.com/laoqifeng/zeroing-libs into dev

parents 2a1e1b52 33823dbd
This diff is collapsed.
This diff is collapsed.
/**
* Created by renjianfeng on 2020-03-13.
*/
const customId = 'p2demo';
(async function () {
let customModule = await fetch(`../meta.json`);
customModule = await customModule.json();
console.log(customModule);
await loadAssets(customModule.assets);
launchWithCustomModule(customModule);
})();
function launchWithCustomModule(customModule) {
//engine.registerCustomCodeModule(customModule);
engine.registerCustomModule(customId, window[customId]);
const { props: propsOption, assets } = customModule;
let props = engine.computeProps(customModuleProps, propsOption);
const customModuleIns = {
id: customId,
props,
assets,
};
engine.registerCustomModules([customModuleIns]);
engine.launchWithConfig({
options: {
entrySceneView: 'entry',
},
assets: [],
views: [{
name: 'entry',
type: 'node',
properties: {
x: 0,
y: 0,
}
}],
customs: [],
}, null, function () {
setTimeout(() => {
engine.addCustomModule(customId, engine.gameStage.sceneContainer.getChildAt(0));
}, 100);
setTimeout(() => {
engine.globalEvent.dispatchEvent('pictures-start', { });
const d = engine.gameStage.sceneContainer.getChildAt(0);
}, 100);
// setTimeout(() => {
// engine.globalEvent.dispatchEvent('pictures-start', {
// picUrl: "http://yun.duiba.com.cn/aurora/assets/e1593b97c27077b85b92f7eaaeae1ed64a1eb79a.png",
// // picUrl: "http://yun.duiba.com.cn/aurora/assets/d23e73d37ec01931e48cbd0a4095367044c5675c.png"
// blockUrl: "888"
// });
// }, 30*1000);
});
engine.globalEvent.addEventListener('pictures-time-update', (e) => {
// console.log(e.type, e.data);
});
engine.globalEvent.addEventListener('pictures-game-fail', (e) => {
console.log(e.type, e.data);
});
engine.globalEvent.addEventListener('pictures-game-success', (e) => {
console.log(e.type, e.data);
});
}
function getAssetByUUID(uuid) {
return engine.resolveCustomAsset(customId, uuid);
}
function getProps() {
return engine.getProps(customId);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>美食从天而降</title>
<meta name="viewport"
content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="full-screen" content="true"/>
<meta name="screen-orientation" content="portrait"/>
<meta name="x5-fullscreen" content="true"/>
<meta name="360-fullscreen" content="true"/>
<style>
html,
body {
padding: 0;
margin: 0;
border: 0;
width: 100%;
height: 100%;
overflow: hidden;
position: absolute;
background-color: gray;
}
.game-container{
width: 100%;
height: 100%;
line-height:0;
font-size:0;
}
</style>
</head>
<body>
<div id="game-container" class="game-container"></div>
<script crossorigin="anonymous" src="//yun.duiba.com.cn/editor/zeroing/libs/engine.1de84ff79dba19e949088de63aa75af51a515e5c.js"></script>
<script crossorigin="anonymous" src="//yun.duiba.com.cn/editor/zeroing/libs/svga.fd3923ae6e664251ca7981801a65809cc5f36bc3.js"></script>
<script src="//yun.duiba.com.cn/js-libs/p2.js/0.7.1/p2.min.js"></script>
<!-- <script src="//yun.duiba.com.cn/editor/zeroing/libs/engine.ebc906f6b50b8da0a669f77027981d5f3cb560ce.js"></script> -->
<!-- <script src="http://localhost:4002/debug/engine.js"></script>
<script src="http://localhost:4003/debug/engine-svga.js"></script> -->
<!--<script src="//yun.duiba.com.cn/editor/zeroing/libs/engine.9a9dbfda4cb2dd5508ecddfe3d95dfd88063f7b5.js"></script>-->
<script src="app.js"></script>
<script src="props.js"></script>
<script src="load-assets.js"></script>
<script src="main.js"></script>
<script>
</script>
</body>
\ No newline at end of file
/**
* Created by rockyl on 2020-01-21.
*/
const assets = [
{
"name": "玩家icon",
"url": "//yun.duiba.com.cn/aurora/assets/5b3e30496b2d9fdafb0cf3835fd6704ce10e45b4.png",
"uuid": "888",
"ext": ".png"
},
{
"name": "雨滴",
"url": "//yun.duiba.com.cn/aurora/assets/8564c8c9be3aead71b05a0bab8d7d07ac3f778a1.png",
"uuid": "264a6192-d7bf-45e8-8f15-6ba2c439a532",
"ext": ".png"
},
{
"name": "炸弹",
"url": "//yun.duiba.com.cn/aurora/assets/171e92283cd13c013ee1b76d28d252ff08815d47.png",
"uuid": "eb88b42d-e151-4c1b-94b9-7c16f7bfac29",
"ext": ".png"
},
{
"name": "石块",
"url": "//yun.duiba.com.cn/aurora/assets/99b0af0c59fe79a415a3f032149cfacc27e3ac2c.png",
"uuid": "ab1bdabc-21ba-46bf-9299-6c638f766c88",
"ext": ".png"
},
{
"name": "水花",
"url": "//yun.duiba.com.cn/aurora/assets/93d37b4a0e367e80e375308a6b4414d72d7666fc.svga",
"uuid": "b521bf94-20e1-44dd-8eca-d24996cbaeae",
"ext": ".svga"
},
{
"name": "炸弹",
"url": "//yun.duiba.com.cn/aurora/assets/4dd18f0689c663bbcf710a7afc4d929084d97d36.svga",
"uuid": "322edf39-805b-4e84-9d07-5573dfeebc0e",
"ext": ".svga"
},
{
"name": "玩家",
"url": "//yun.duiba.com.cn/aurora/assets/b66300c5d4f27134b0aac3dc90a3220e8ae572eb.svga",
"uuid": "71d8dcbc-3931-471a-b585-b3ae01b25aa6",
"ext": ".svga"
}
];
function loadAssets(customModuleAssets, onProgress, onComplete){
return engine.loadAssets(assets.concat(...customModuleAssets), onProgress, onComplete);
}
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('tslib')) :
typeof define === 'function' && define.amd ? define(['tslib'], factory) :
(global = global || self, global.p2demo = factory(global.tslib));
}(this, (function (tslib) { 'use strict';
function getTexture(uuid) {
return engine.Texture.from(getAssetByUUID(uuid).uuid);
}
function getTextureByName(name) {
return getTexture(engine.getAssetByName(name).uuid);
}
var OptionState;
(function (OptionState) {
OptionState[OptionState["CHOICE_RIGHT"] = 0] = "CHOICE_RIGHT";
OptionState[OptionState["CHOICE_WRONG"] = 1] = "CHOICE_WRONG";
OptionState[OptionState["CHOICE_SELECT"] = 2] = "CHOICE_SELECT";
})(OptionState || (OptionState = {}));
var GameState;
(function (GameState) {
GameState[GameState["STATE_START"] = 0] = "STATE_START";
GameState[GameState["STATE_END"] = 1] = "STATE_END";
})(GameState || (GameState = {}));
//# sourceMappingURL=utils.js.map
var GameView = (function (_super) {
tslib.__extends(GameView, _super);
function GameView() {
var _this = _super.call(this) || this;
_this.factor = 10;
_this.isDebug = 0;
_this.once(engine.Event.ADDED_TO_STAGE, _this.setup, _this);
return _this;
}
GameView.prototype.createBall = function (r) {
var shape = new engine.Shape();
shape.beginFill(0xfff000);
shape.drawCircle(0, 0, r);
shape.endFill();
return shape;
};
GameView.prototype.start = function () {
console.log('start');
this.stage.addEventListener(engine.MouseEvent.CLICK, this.onClick, this);
};
GameView.prototype.createBitmapByName = function (name) {
var imgContainer = new engine.Sprite();
var img = new engine.Sprite(getTextureByName(name));
img.anchorX = img.width / 2;
img.anchorY = img.height / 2;
img.x = -img.width / 2;
img.y = -img.height / 2;
imgContainer.addChild(img);
return imgContainer;
};
GameView.prototype.createBox = function (width, height) {
var shape = new engine.Shape();
shape.beginFill(0xfff000);
shape.drawRect(-width / 2, -height / 2, width, height);
shape.endFill();
return shape;
};
GameView.prototype.onClick = function (e) {
var _a = this, world = _a.world, factor = _a.factor;
var positionX = (e.stageX / factor);
var positionY = ((engine.gameStage.stage.height - e.stageY) / factor);
var display;
if (Math.random() > .5) {
var boxShape = new p2.Box({ width: 306 / factor, height: 172 / factor });
var boxBody = new p2.Body({ mass: 1, position: [positionX, positionY], angularVelocity: 1 });
boxBody.addShape(boxShape);
world.addBody(boxBody);
if (this.isDebug) {
display = this.createBox(boxShape.width * factor, boxShape.height * factor);
}
else {
display = this.createBitmapByName("block");
}
}
else {
var boxShape = new p2.Circle({ radius: 120 / 2 / factor });
var boxBody = new p2.Body({ mass: 1, position: [positionX, positionY] });
boxBody.addShape(boxShape);
world.addBody(boxBody);
if (this.isDebug) {
display = this.createBall(boxShape.radius * factor);
}
else {
display = this.createBitmapByName("ball");
}
}
boxBody.displays = [display];
this.addChild(display);
};
GameView.prototype.setup = function () {
console.log('setup');
var world = new p2.World({
gravity: [0, -10],
});
world.sleepMode = p2.World.BODY_SLEEPING;
var planeShape = new p2.Plane();
var planeBody = new p2.Body();
planeBody.addShape(planeShape);
planeBody.displays = [];
world.addBody(planeBody);
this.world = world;
this.stage.addEventListener(engine.Event.ENTER_FRAME, this.onEnterFrame, this);
};
GameView.prototype.onEnterFrame = function () {
var _a = this, world = _a.world, factor = _a.factor;
world.step(60 / 1000);
var stageHeight = engine.gameStage.stage.height;
var l = world.bodies.length;
for (var i = 0; i < l; i++) {
var boxBody = world.bodies[i];
var box = boxBody.displays[0];
if (box) {
box.x = boxBody.position[0] * factor;
box.y = stageHeight - boxBody.position[1] * factor;
box.rotation = 360 - (boxBody.angle + boxBody.shapes[0].angle) * 180 / Math.PI;
if (boxBody.sleepState == p2.Body.SLEEPING) {
box.alpha = 0.5;
}
else {
box.alpha = 1;
}
}
}
};
return GameView;
}(engine.Container));
var props = {};
function prepareProps() {
var metaProps = getProps();
engine.injectProp(props, metaProps);
}
function injectProps(p) {
engine.injectProp(props, p);
}
//# sourceMappingURL=props.js.map
var GameWrapper = (function (_super) {
tslib.__extends(GameWrapper, _super);
function GameWrapper() {
var _this = _super.call(this) || this;
engine.globalEvent.addEventListener('pictures-start', _this.start, _this);
engine.globalEvent.addEventListener('pictures-stop', _this.stop, _this);
var gameView = _this._gameView = new GameView();
_this.addChild(gameView);
return _this;
}
GameWrapper.prototype.start = function (event) {
injectProps(event.data);
this._gameView.start();
};
GameWrapper.prototype.stop = function (event) {
};
return GameWrapper;
}(engine.Container));
//# sourceMappingURL=GameWrapper.js.map
function index (props) {
prepareProps();
injectProps(props);
var instance = new GameWrapper();
return instance;
}
//# sourceMappingURL=index.js.map
return index;
})));
//# sourceMappingURL=main.js.map
\ No newline at end of file
This diff is collapsed.
/**
* Created by rockyl on 2020-01-21.
*/
let customModuleProps = {
};
{
"name": "拼图",
"desc": "拼图模块1.0",
"props": {
"MAX_COL": {
"alias": "图片分成几列",
"type": "number",
"default": 3
},
"MAX_ROW": {
"alias": "图片分成几行",
"type": "number",
"default": 4
},
"W": {
"alias": "图片的宽度",
"type": "number",
"default": 618
},
"H": {
"alias": "图片的高度",
"type": "number",
"default": 827
},
"OFFSET_X": {
"alias": "OFFSET_X",
"type": "number",
"default": 0
},
"OFFSET_Y": {
"alias": "OFFSET_Y",
"type": "number",
"default": 0
},
"GAP": {
"alias": "图片间隙",
"type": "number",
"default": 0
},
"GAME_TIME": {
"alias": "游戏时间",
"type": "number",
"default": 10
}
},
"assets": [
{
"name": "block",
"url": "//yun.duiba.com.cn/aurora/assets/f91184b338ef9540b167eebe7d58e71402e8d9d9.png",
"uuid": "888",
"ext": ".png"
},
{
"name": "ball",
"url": "//yun.duiba.com.cn/aurora/assets/3dc11f2d91659b7e7e1d06a9853cbc9f818e1ea2.png",
"uuid": "999",
"ext": ".png"
}
],
"events": {
"in": {
"pictures-start": {
"alias": "开始",
"data": {
"picUrl":"图片路径",
"blockUrl":"blockUrl",
"row":"行",
"column":"列",
"gameTime":"游戏时间"
}
},
"pictures-stop": {
"alias": "停止"
}
},
"out": {
"pictures-time-update": {
"alias": "倒计时更新",
"data": {
"time":"剩余时间"
}
},
"pictures-game-fail": {
"alias": "游戏结束",
"data": {
"reason": "结束原因(1:时间到了)"
}
},
"pictures-game-success": {
"alias": "游戏成功",
"data": {
"time": "游戏消耗时间"
}
}
}
}
}
\ No newline at end of file
import { Tool } from "../../../seabed-game/src/game/Tools";
import { getTextureByName } from "../../../answer-game/src/game/utils";
export default class GameView extends engine.Container {
world: p2.World;
factor: number = 10;
isDebug = 0;
constructor() {
super();
this.once(engine.Event.ADDED_TO_STAGE, this.setup, this);
}
private createBall(r: number) {
var shape = new engine.Shape();
shape.beginFill(0xfff000);
shape.drawCircle(0, 0, r);
shape.endFill();
return shape;
}
start() {
console.log('start');
this.stage.addEventListener(engine.MouseEvent.CLICK, this.onClick, this);
}
createBitmapByName(name) {
const imgContainer = new engine.Sprite();
const img = new engine.Sprite(getTextureByName(name));
img.anchorX = img.width / 2;
img.anchorY = img.height / 2;
img.x = -img.width / 2;
img.y = -img.height / 2;
imgContainer.addChild(img);
return imgContainer
}
private createBox(width: number, height: number): engine.Shape {
var shape = new engine.Shape();
shape.beginFill(0xfff000);
shape.drawRect(-width / 2, -height / 2, width, height);
shape.endFill();
return shape;
}
onClick(e: engine.MouseEvent) {
// const ball = this.createBitmapByName('ball');
// this.addChild(ball);
// engine.Tween.get(ball, { loop: true }).to({ rotation: 360 }, 1000);
// return;
// const box = this.createBitmapByName('block');
// this.addChild(box);
// engine.Tween.get(box, { loop: true }).to({ rotation: 360 }, 1000);
// return;
// const box = this.createBox(750, 100)
// this.addChild(box);
// box.x = 750/2;
// box.y = 1624/2;
// engine.Tween.get(box, { loop: true }).to({ rotation: 360 }, 1000)
// return;
// const ball = this.createBall(750/2);
// this.addChild(ball);
// ball.x = e.stageX;
// ball.y = e.stageY;
// return;
const { world, factor } = this;
var positionX: number = (e.stageX / factor);
var positionY: number = ((engine.gameStage.stage.height - e.stageY) / factor);
var display: engine.DisplayObject;
if (Math.random() > .5) {
//添加方形刚体
var boxShape: p2.Shape = new p2.Box({ width: 306 / factor, height: 172 / factor });
var boxBody: p2.Body = new p2.Body({ mass: 1, position: [positionX, positionY], angularVelocity: 1 });
boxBody.addShape(boxShape);
world.addBody(boxBody);
if (this.isDebug) {
display = this.createBox((<p2.Box>boxShape).width * factor, (<p2.Box>boxShape).height * factor);
} else {
display = this.createBitmapByName("block");
}
}
else {
//添加圆形刚体
var boxShape: p2.Shape = new p2.Circle({ radius: 120 / 2 / factor });
var boxBody: p2.Body = new p2.Body({ mass: 1, position: [positionX, positionY] });
boxBody.addShape(boxShape);
world.addBody(boxBody);
if (this.isDebug) {
display = this.createBall((<p2.Circle>boxShape).radius * factor);
} else {
display = this.createBitmapByName("ball");
}
// display.width = (<p2.Circle>boxShape).radius * 2 * factor;
// display.height = (<p2.Circle>boxShape).radius * 2 * factor;
}
// display.anchorX = display.width / 2;
// display.anchorY = display.height / 2;
boxBody.displays = [display];
this.addChild(display);
}
setup() {
console.log('setup');
//创建world
var world: p2.World = new p2.World({
gravity: [0, -10],
});
world.sleepMode = p2.World.BODY_SLEEPING;
//创建plane
var planeShape: p2.Plane = new p2.Plane();
var planeBody: p2.Body = new p2.Body();
planeBody.addShape(planeShape);
planeBody.displays = [];
world.addBody(planeBody);
this.world = world;
this.stage.addEventListener(engine.Event.ENTER_FRAME, this.onEnterFrame, this)
}
onEnterFrame() {
const { world, factor } = this;
world.step(60 / 1000);
const stageHeight = engine.gameStage.stage.height;
var l = world.bodies.length;
for (var i: number = 0; i < l; i++) {
var boxBody: p2.Body = world.bodies[i];
var box = boxBody.displays[0];
if (box) {
box.x = boxBody.position[0] * factor;
box.y = stageHeight - boxBody.position[1] * factor;
box.rotation = 360 - (boxBody.angle + boxBody.shapes[0].angle) * 180 / Math.PI;
if (boxBody.sleepState == p2.Body.SLEEPING) {
box.alpha = 0.5;
}
else {
box.alpha = 1;
}
}
}
}
}
/**
* Created by rockyl on 2020-01-09.
*/
import GameView from "./GameView";
import { injectProps } from "../props";
export class GameWrapper extends engine.Container {
// private _status;
private _gameView: GameView;
constructor() {
super();
engine.globalEvent.addEventListener('pictures-start', this.start, this);
engine.globalEvent.addEventListener('pictures-stop', this.stop, this);
//创建实例
let gameView = this._gameView = new GameView();
this.addChild(gameView);
}
start(event: engine.Event) {
injectProps(event.data);
// this._status = 1;
this._gameView.start();
}
stop(event: engine.Event) {
}
}
/**
* Created by rockyl on 2020-02-03.
*/
import {Goods} from "./Goods";
import ObjectPool = engine.ObjectPool;
export const PoolName: string = 'goods';
ObjectPool.registerPool(PoolName, function () {
return new Goods();
}, function (item: Goods, data) {
item.reset();
});
import { props } from "../props";
const urls = [];
const picMap = {};
const posMap = {};
export default (parent, url, MAX_COL, MAX_ROW) => {
if (picMap[url]) {
const pics:any[] = picMap[url];
for (const pic of pics) {
parent.addChild(pic);
}
return [picMap[url], posMap[url]]
}
const W = props.W;
const H = props.H;
const GAP = props.GAP;
const spr = [];
const pos = []
for (let row = 0; row < MAX_ROW; row++) {
for (let col = 0; col < MAX_COL; col++) {
const child = engine.Sprite.fromImage(url);
spr.push(child);
child.scaleX = 1 / MAX_COL;
child.scaleY = 1 / MAX_ROW;
parent.addChild(child);
child.x = col * (W / MAX_COL + GAP);
child.y = row * (H / MAX_ROW + GAP);
pos.push([child.x, child.y]);
// child.texture.addEventListener('update', () => {
child.addEventListener(engine.Event.COMPLETE, () => {
const uvs = new Float32Array([
col / MAX_COL,
row / MAX_ROW,
(col + 1) / MAX_COL,
row / MAX_ROW,
(col + 1) / MAX_COL,
(row + 1) / MAX_ROW,
col / MAX_COL,
(row + 1) / MAX_ROW,
]);
child.uvs = uvs;
// spr.push(child);
});
}
}
picMap[url] = spr.concat([]);
posMap[url] = pos.concat([]);;
// console.log(spr);
return [spr, pos];
};
/**
* Created by rockyl on 2020-01-21.
*/
export function getTexture(uuid) {
return engine.Texture.from(getAssetByUUID(uuid).uuid);
}
export function getTextureByName(name) {
return getTexture(engine.getAssetByName(name).uuid);
}
export function playSound(name) {
engine.playSound(engine.getAssetByName(name).uuid, {keep: true});
}
export function createSvga(name, anchorName?) {
let inst = new svga.Svga();
inst.source = 'asset://' + engine.getAssetByName(name).uuid;
return inst;
}
export function getIndexFromRC(row,col,maxCol){
let index;
index = row * maxCol + col ;
return index
}
export function getRandomArray(array){
array.sort(function() {
return .5 - Math.random();
});
}
\ No newline at end of file
/**
* Created by rockyl on 2019-11-20.
*/
import {GameWrapper} from "./game/GameWrapper";
import {injectProps, prepareProps} from "./props";
export default function (props) {
prepareProps();
injectProps(props);
let instance = new GameWrapper();
return instance;
}
/**
* Created by rockyl on 2020-01-21.
*/
export let props: any = {};
export function prepareProps() {
let metaProps = getProps();
engine.injectProp(props, metaProps);
}
export function injectProps(p) {
engine.injectProp(props, p);
}
......@@ -52,9 +52,15 @@ function launchWithCustomModule(customModule) {
engine.globalEvent.dispatchEvent('pictures-start', {
picUrl: "http://yun.duiba.com.cn/aurora/assets/e1593b97c27077b85b92f7eaaeae1ed64a1eb79a.png",
blockUrl: "888",
<<<<<<< HEAD
row: 3,
column: 3,
gameTime: 50
=======
column:"2",
row:"2",
gameTime:"50"
>>>>>>> 33823dbdb9c3b079aa71a545ab5472146df6429b
});
const d = engine.gameStage.sceneContainer.getChildAt(0);
......
......@@ -187,7 +187,10 @@
MAX_COL = props.MAX_COL;
MAX_ROW = props.MAX_ROW;
GAME_TIME = props.GAME_TIME;
<<<<<<< HEAD
console.log(GAME_TIME, 'setuptime');
=======
>>>>>>> 33823dbdb9c3b079aa71a545ab5472146df6429b
W = props.W;
H = props.H;
GAP = props.GAP;
......
This diff is collapsed.
......@@ -28,18 +28,26 @@ export default class GameView extends engine.Container {
start() {
<<<<<<< HEAD
<<<<<<< HEAD
=======
//优先获取start事件接收到的参数
>>>>>>> 2533efe07c13d1586974175c8874bc3dad71643a
=======
//优先获取start事件接收到的参数
>>>>>>> 33823dbdb9c3b079aa71a545ab5472146df6429b
MAX_COL = props.column || props.MAX_COL;
MAX_ROW = props.row || props.MAX_ROW;
GAME_TIME = props.gameTime || props.GAME_TIME;
console.log('start',props.column,props.row,props.gameTime)
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> 2533efe07c13d1586974175c8874bc3dad71643a
=======
>>>>>>> 33823dbdb9c3b079aa71a545ab5472146df6429b
if (!this.guideHole) {
this.guideHole = new engine.Image();
this.guideHole.source = 'asset://' + props.blockUrl;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment