Commit 0a4fe5ff authored by 汪欢's avatar 汪欢

cloud

parent b5cf2632
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/**
* Created by renjianfeng on 2020-03-13.
*/
const customId = 'getAwayFromCloud';
(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', {
picUrl: "//yun.duiba.com.cn/aurora/assets/f57e4cbfe6bb27333c8d53ed1031624c4e0500aa.pnghttp://yun.duiba.com.cn/aurora/assets/e1593b97c27077b85b92f7eaaeae1ed64a1eb79a.png",
blockUrl: "c9ff7c30-2734-417d-a811-d88b6b7140b8",
});
// const d = engine.gameStage.sceneContainer.getChildAt(0);
// engine.gameStage.sceneContainer.getChildAt(0).x = (d.stage.width-props.W)/2;
// engine.gameStage.sceneContainer.getChildAt(0).y = (d.stage.height-props.H)/2;
}, 1000);
// 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('cloud-time-update', (e) => {
// console.log(e.type, e.data);
});
engine.globalEvent.addEventListener('cloud-game-fail', (e) => {
console.log(e.type, e.data);
});
engine.globalEvent.addEventListener('cloud-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/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);
}
This diff is collapsed.
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
},
"OFFSET_X": {
"alias": "OFFSET_X",
"type": "number",
"default": 0
},
"OFFSET_Y": {
"alias": "OFFSET_Y",
"type": "number",
"default": 0
},
"GAME_TIME": {
"alias": "游戏时间",
"type": "number",
"default": 30
},
"GAP": {
"alias": "图片间隙",
"type": "number",
"default": 0
}
},
"assets": [
{
"name": "被遮罩",
"url": "//yun.duiba.com.cn/aurora/assets/c9d66b3e2381fdc7503cdcef9b7173f067a0b96d.png",
"uuid": "8a8e79b6-2c6f-441b-81ae-c441465abfb0",
"ext": ".png"
},
{
"name": "遮罩",
"url": "//yun.duiba.com.cn/aurora/assets/70ade7c1efa699c8662379f406319188fb6aebc5.png",
"uuid": "024d67e9-ed7f-4481-94ca-a15bd5226cad",
"ext": ".png"
},
{
"name":"衣服湿润度",
"url":"//yun.duiba.com.cn/aurora/assets/f59b03b7441b4da17d8e7567b44c6fe92ce9eb50.png",
"uuid":"ed0e8931-2557-4527-bcfc-9071f90d5737",
"ext":".png"
},
{
"name":"背景",
"url":"//yun.duiba.com.cn/aurora/assets/d0e22ae58b6e8519b969ed207197a31820790349.png",
"uuid":"5ab43bdc-a6ce-46fb-99c2-a806f57f7484",
"ext":".png"
},
{
"name":"倒计时",
"url":"//yun.duiba.com.cn/aurora/assets/97e5c35fa0503b5d28168fe7d22fb179f1279e21.png",
"uuid":"b7d2a60a-9e60-4eca-be80-a991abea47c9",
"ext":".png"
},
{
"name":"云1",
"url":"//yun.duiba.com.cn/aurora/assets/429981638472e8f02ce2a780f3b05be72d13b943.png",
"uuid":"1e1a6993-9da0-4813-b1bd-00f2dbae2af2",
"ext":".png"
},
{
"name":"云2",
"url":"//yun.duiba.com.cn/aurora/assets/c900fe3536b2119b1a917540e1aac5380363d9d1.png",
"uuid":"6ed0e2e7-3ba3-4967-8fe0-39667792e343",
"ext":".png"
},
{
"name":"太阳",
"url":"//yun.duiba.com.cn/aurora/assets/f4ad009080bac141589b7f8eb88d6e66da732cd9.png",
"uuid":"0f05aaae-338a-439a-82b0-20efcee5cca4",
"ext":".png"
},
{
"name":"常态1",
"url":"//yun.duiba.com.cn/aurora/assets/3a1e9ec8247078fc92af538ea8ee29c73b532b93.png",
"uuid":"487c1ca7-dea5-4732-b4b6-acb5406ee3a4",
"ext":".png"
},
{
"name":"吃力1",
"url":"//yun.duiba.com.cn/aurora/assets/40f906478c4fe90f9b68392df0031d382502f8d9.png",
"uuid":"b876771a-a5d1-47f4-bd45-5978519c521a",
"ext":".png"
},
{
"name":"沮丧1",
"url":"//yun.duiba.com.cn/aurora/assets/f76eb798d2ccff84f53780c37d802830c5f6071c.png",
"uuid":"ff43517a-27bb-4f73-948c-d7a4fa7b4c69",
"ext":".png"
},
{
"name":"常态2",
"url":"//yun.duiba.com.cn/aurora/assets/875fd6ba38735682fe27d010338277238672f310.png",
"uuid":"4f8d0a7e-9db3-408e-81f2-fdd323ba6094",
"ext":".png"
},
{
"name":"吃力2",
"url":"//yun.duiba.com.cn/aurora/assets/753b58a25ee4b617afe0a14767036b63681f0809.png",
"uuid":"71e07cee-fd6d-40bb-ac0b-5bb28c87276e",
"ext":".png"
},
{
"name":"沮丧2",
"url":"//yun.duiba.com.cn/aurora/assets/17682be2c0e9f299315bf4e17598ea2e3c8e11ce.png",
"uuid":"2cd9f1bb-d0d8-42ea-941b-dcd0428e474d",
"ext":".png"
},
{
"name":"撑伞按钮",
"url":"//yun.duiba.com.cn/aurora/assets/2d15942ed213e1d0ae953925565d80f93cec4701.png",
"uuid":"9e347bef-6e91-4c92-ba5f-f9a52e656207",
"ext":".png"
},
{
"name":"伞",
"url":"//yun.duiba.com.cn/aurora/assets/a4c14c17dc144611164c70f905f1d35a2aa1812f.png",
"uuid":"c7129f77-92a6-479e-9994-7d4b39040a15",
"ext":".png"
},
{
"name":"雨滴",
"url":"//yun.duiba.com.cn/aurora/assets/a1bf1b1622759aabec29e857e325039c147bac54.png",
"uuid":"07f74bf6-416f-445e-98d5-021efe4c9fdc",
"ext":".png"
},
{
"name":"",
"url":"//yun.duiba.com.cn/aurora/assets/1cded0d917c44d22ddce058f239e1cfac1b506c2.png",
"uuid":"57d4067e-c32f-4b12-a8fc-185753726fc6",
"ext":".png"
},
{
"name":"击中",
"url":"//yun.duiba.com.cn/aurora/assets/251402a1991ef00a124ddd91f519a30147285e00.png",
"uuid":"38ec6627-efa8-4f7a-9bdc-3c73cea717f1",
"ext":".png"
},
{
"name":"关闭",
"url":"//yun.duiba.com.cn/aurora/assets/6900f3a3b592c1b9cd3925fb9b66b6ec673a8c43.png",
"uuid":"e4a82aee-4472-4b06-bd75-02fb64f1c8c8",
"ext":".png"
}
],
"events": {
"in": {
"pictures-start": {
"alias": "开始",
"data": {
"picUrl":"图片路径",
"blockUrl":"blockUrl",
"GAME_TIME":"每局的游戏时间",
"MAX_ROW":"行",
"MAX_COL":"列",
"W":"宽",
"H":"高",
"GAP":"图片间隙",
"OFFSET_X":"OFFSET_X",
"OFFSET_Y":"OFFSET_Y"
}
},
"pictures-stop": {
"alias": "停止"
}
},
"out": {
"cloud-time-update": {
"alias": "倒计时更新",
"data": {
"time":"剩余时间"
}
},
"cloud-game-fail": {
"alias": "游戏结束",
"data": {
"reason": "结束原因(1:时间到了)"
}
},
"cloud-game-success": {
"alias": "游戏成功",
"data": {
"time": "游戏消耗时间"
}
}
}
}
}
\ No newline at end of file
import {getTexture} from './utils'
export default class CloudRain extends engine.Container{
clound1:engine.Sprite = new engine.Sprite(getTexture('1e1a6993-9da0-4813-b1bd-00f2dbae2af2'))
clound2:engine.Sprite = new engine.Sprite(getTexture('6ed0e2e7-3ba3-4967-8fe0-39667792e343'))
sun = new engine.Sprite(getTexture("0f05aaae-338a-439a-82b0-20efcee5cca4"));
constructor(){
super()
this.sun.x = 90;
this.sun.y = 120;
this.addChild(this.sun)
this.addChild(this.clound1);
this.addChild(this.clound2);
this.clound1.x = 100;
this.clound1.y = 220;
this.clound2.x = 150;
this.clound2.y = 220;
}
succeed(){
// 380 580
let a = 0
let ld = Date.now();
this.addEventListener(engine.Event.ENTER_FRAME,()=>{
let dt = Date.now() - ld;
a += dt;
if(a>100){
this.clound1.x -= (800 * dt) / 1000;
this.clound2.x += (820*dt)/1000;
if(this.clound1.x <= -380){
this.clound1.x = -380;
}
if(this.clound2.x >= 750){
this.clound2.x = 750;
}
this.sun.y -= (150 * dt) / 1000;
if(this.sun.y <= 60){
this.sun.y = 60;
}
}
ld = Date.now();
})
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
import GameView from "./GameView";
import GameTest from "./GameTest";
import { injectProps } from "../props";
export class GameWrapper extends engine.Container {
// private _status;
private _gameView: GameView;
private _gameTest: GameTest;
constructor() {
super();
engine.globalEvent.addEventListener('pictures-start', this.start, this);
engine.globalEvent.addEventListener('pictures-stop', this.stop, this);
//创建实例
// let gameView = this._gameView = new GameView();
let gameTest = this._gameTest = new GameTest();
this.addChild(gameTest);
}
start(event: engine.Event) {
injectProps(event.data);
// this._status = 1;
// this._gameView.start();
this._gameTest.start();
}
stop(event: engine.Event) {
// this._gameView.stop();
this._gameTest.stop();
}
}
import {getTexture} from './utils'
export default class Human extends engine.Container{
//常态,吃力,沮丧
humanArray = [
'487c1ca7-dea5-4732-b4b6-acb5406ee3a4',
'71e07cee-fd6d-40bb-ac0b-5bb28c87276e',
'2cd9f1bb-d0d8-42ea-941b-dcd0428e474d'
]
//三张面部表情
human:engine.Sprite = new engine.Sprite(getTexture(this.humanArray[0]))
constructor(){
super();
this.addChild(this.human)
this.width = this.human.width;
this.height = this.human.height;
}
facialChange(num){
let face = new engine.Sprite(getTexture(this.humanArray[num]));
this.human.addChild(face);
return face;
}
removeFace(face){
this.human.removeChild(face);
}
}
\ No newline at end of file
import {getTexture} from './utils'
export default class Moist extends engine.Container{
percent:number
moistBg:engine.Sprite = new engine.Sprite(getTexture('8a8e79b6-2c6f-441b-81ae-c441465abfb0'))
moist:engine.Sprite = new engine.Sprite(getTexture('024d67e9-ed7f-4481-94ca-a15bd5226cad'))
moistCover:any = new engine.Sprite(getTexture('024d67e9-ed7f-4481-94ca-a15bd5226cad'))
txt = new engine.TextInput();
hintpic:engine.Sprite = new engine.Sprite(getTexture('ed0e8931-2557-4527-bcfc-9071f90d5737'))
constructor(){
super();
this.percent = 0;
this.addChild(this.moistBg)
this.moistBg.addChild(this.moist)
this.moist.mask = this.moistCover;
this.txt.text = this.percent*100+'%';
this.txt.size = 30;
this.txt.fillColor = '#7A83C5';
this.addChild(this.txt)
this.txt.x = 0;
this.txt.y = -50;
this.hintpic.x = -10;
this.hintpic.y = 440;
this.addChild(this.hintpic)
}
cover(percent){
this.moistCover.anchorY = 416;
this.moistBg.addChild(this.moistCover)
this.moistCover.scaleY = percent;
}
stopScale(){
this.moistCover.scaleY = 1;
this.txt.text = '100%';
}
updateText(percent){
let a = percent * 100;
if(a <=90){
this.txt.text = a.toPrecision(2)+'%';
}else{
this.txt.text = a.toPrecision(3)+'%';
}
}
}
\ No newline at end of file
import {getTexture} from './utils'
export default class TimeCounter extends engine.Container{
timeCounter:engine.Sprite = new engine.Sprite(getTexture('b7d2a60a-9e60-4eca-be80-a991abea47c9'));
timeText:any;
time:number
constructor(){
super()
this.time = 20
this.addChild(this.timeCounter)
this.timeCounter.x = 256;
this.timeCounter.y = 50;
// 计时文本
this.timeText = new engine.TextInput();
this.timeText.text = this.time +'s';
this.timeText.size = 48;
this.timeText.fillColor = '#7A83C5';
this.timeCounter.addChild(this.timeText);
this.timeText.x = 100;
this.timeText.y = 15;
}
updateTime(time){
this.time = time;
this.timeText.text = this.time + 's'
}
}
\ No newline at end of file
/**
* 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
import {GameWrapper} from "./game/GameWrapper";
import {injectProps, prepareProps} from "./props";
export default function (props) {
prepareProps();
injectProps(props);
let instance = new GameWrapper();
return instance;
}
export let props: any = {};
export function prepareProps() {
let metaProps = getProps();
engine.injectProp(props, metaProps);
}
export function injectProps(p) {
engine.injectProp(props, p);
}
const W = 600
const H = 600
const MAX_ROW = 3;
const MAX_COL = 3;
const GAP = 10;
const w = W / MAX_COL;
const h = H / MAX_ROW;
export default class GameView extends engine.Container{
constructor(){
super()
}
start(){
}
setup(){
}
cutPicture(parent, url, MAX_ROW, MAX_COL){
const sprite = []
for(let row = 0; row < MAX_ROW; row++) {
for(let col = 0; col < MAX_COL; col++) {
// 创建图片子节点
const child = new engine.Sprite.fromImage(url);
sprite.push(child)
child.scaleX =
}
}
}
}
\ No newline at end of file
import {props} from '../props'
import { getTexture } from "./utils";
const W = 600
const H = 600
const MAX_ROW = 3;
const MAX_COL = 3;
const GAP = 10;
const w = W / MAX_COL;
const h = H / MAX_ROW;
export default class GameView extends engine.Container{
constructor(){
super()
this.once(engine.Event.ADDED_TO_STAGE,this.setup,this);
}
start(){
}
pictures:engine.Sprite[]
private picturesWrapper: engine.Sprite;
setup(){
const getSprites = this.cutPicture(this.picturesWrapper,props.picUrl,MAX_ROW,MAX_COL)
this.pictures = getSprites[0];
const parent = new engine.Sprite();
this.picturesWrapper = parent;
this.addChild(parent);
}
// 切图
cutPicture(parent, url, MAX_ROW, MAX_COL){
const sprite = []
const spritePos = []
// 正确的图片顺序
for(let row = 0; row < MAX_ROW; row++) {
for(let col = 0; col < MAX_COL; col++) {
// 创建图片子节点
const child = engine.Sprite.fromImage(url);
sprite.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);
spritePos.push([child.x,child.y]);
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;
});
}
}
return [sprite,spritePos];
}
// 随机函数
getRandomArray(array){
array.sort(()=>{
return 0.5 - Math.random();
})
}
}
\ No newline at end of file
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;
}
\ No newline at end of file
{
"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": 50
}
},
"assets": [
{
"name": "遮罩",
"url": "//yun.duiba.com.cn/aurora/assets/5b3e30496b2d9fdafb0cf3835fd6704ce10e45b4.png",
"uuid": "888",
"ext": ".png"
}
],
"events": {
"in": {
"pictures-start": {
"alias": "开始",
"data": {
"picUrl":"图片路径",
"blockUrl":"blockUrl"
}
},
"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
export let props: any = {};
export function prepareProps() {
let metaProps = getProps();
engine.injectProp(props, metaProps);
}
export function injectProps(p) {
engine.injectProp(props, p);
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
......@@ -40,7 +40,7 @@
"GAME_TIME": {
"alias": "游戏时间",
"type": "number",
"default": 5
"default": 10
}
},
......
......@@ -24,6 +24,8 @@ export default class GameView extends engine.Container {
private _timer;
private _timeCounter = 0;
private date
start() {
if (!this.guideHole) {
......@@ -76,19 +78,30 @@ export default class GameView extends engine.Container {
this._timer = setInterval(() => {
this.onTimer();
}, 10)
this.date = new Date().getTime();
}
onTimer() {
let date = new Date().getTime();
let gap = ((date - this.date) / 1000);
this.date = date;
console.log(gap,"gap");
// 以GAME_TIME为标准
GAME_TIME -= 0.01
GAME_TIME -= gap;
if(GAME_TIME < 0){
GAME_TIME = 0;
}
GAME_TIME = this.afterPointTwo(GAME_TIME);
GAME_TIME = GAME_TIME.toFixed(2)
if (GAME_TIME < 10) {
GAME_TIME = '0' + GAME_TIME
}
// console.log(GAME_TIME);
console.log(GAME_TIME);
engine.globalEvent.dispatchEvent('pictures-time-update', {
......@@ -96,7 +109,6 @@ export default class GameView extends engine.Container {
});
if (this.getSecond() == 0) {
GAME_TIME = props.GAME_TIME
this.stop();
engine.globalEvent.dispatchEvent('pictures-game-fail', {
reason: 1
......@@ -110,11 +122,7 @@ export default class GameView extends engine.Container {
if (isNaN(floatN)) {
return;
}
floatN = Math.round(floatN * 100) / 100;
return floatN;
}
......@@ -125,7 +133,7 @@ export default class GameView extends engine.Container {
stop() {
// GAME_TIME = props.GAME_TIME
GAME_TIME = props.GAME_TIME
clearInterval(this._timer);
let len = this.pictures.length;
for(let i=0;i<len;i++){
......
/**
* Created by renjianfeng on 2020-03-13.
*/
const customId = 'playWithPlane';
(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', {
picUrl: "//yun.duiba.com.cn/aurora/assets/57725dcf8cb23905afb87f42d7aba2ffa4c8d2d1.png",
blockUrl: "308742a0-0ea2-4610-b34a-a230add82021",
});
// const d = engine.gameStage.sceneContainer.getChildAt(0);
// engine.gameStage.sceneContainer.getChildAt(0).x = (d.stage.width-props.W)/2;
// engine.gameStage.sceneContainer.getChildAt(0).y = (d.stage.height-props.H)/2;
}, 1000);
// 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/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);
}
This diff is collapsed.
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
},
"GAME_TIME": {
"alias": "游戏时间",
"type": "number",
"default": 30
},
"GAP": {
"alias": "图片间隙",
"type": "number",
"default": 0
}
},
"assets": [
{
"name": "遮罩",
"url": "//yun.duiba.com.cn/aurora/assets/5b3e30496b2d9fdafb0cf3835fd6704ce10e45b4.png",
"uuid": "888",
"ext": ".png"
},
{
"name":"背景",
"url":" //yun.duiba.com.cn/aurora/assets/57725dcf8cb23905afb87f42d7aba2ffa4c8d2d1.png",
"uuid":"308742a0-0ea2-4610-b34a-a230add82021",
"ext":".png"
},
{
"name":"飞机",
"url":"//yun.duiba.com.cn/aurora/assets/1d2ba15cb8baf3e5783a9f865673dcf9a2421f19.png",
"uuid":"32ec481a-3f75-4c36-95ed-ee97aa936517",
"ext":".png"
},
{
"name":"开始按钮",
"url":"//yun.duiba.com.cn/aurora/assets/2bed3a9e3cae15a6332397ca675c5d44849eaac2.png",
"uuid":"855e3d77-ffff-443d-b884-4f67a2ebe458",
"ext":".png"
},
{
"name":"游戏背景",
"url":"//yun.duiba.com.cn/aurora/assets/5f56d60285f0e3b253716bc938a3c28cbb288cdf.png",
"uuid":"76820072-df5a-4ab7-8cb7-10c8cd8605c8",
"ext":".png"
},
{
"name":"子弹",
"url":"//yun.duiba.com.cn/aurora/assets/06b3baba53973c01be8943b7a002e58de3bea7cf.png",
"uuid":"18852543-1f1d-498b-af64-88cd3b343758",
"ext":".png"
},
{
"name":"敌机",
"url":"//yun.duiba.com.cn/aurora/assets/fc3b2a4349b098183b2b20c8a754b8b182d73806.png",
"uuid":"780b6b63-3abd-4246-94ba-2a3fbdb3c5af",
"ext":".png"
},
{
"name":"small敌机",
"url":"//yun.duiba.com.cn/aurora/assets/1cded0d917c44d22ddce058f239e1cfac1b506c2.png",
"uuid":"57d4067e-c32f-4b12-a8fc-185753726fc6",
"ext":".png"
},
{
"name":"击中",
"url":"//yun.duiba.com.cn/aurora/assets/251402a1991ef00a124ddd91f519a30147285e00.png",
"uuid":"38ec6627-efa8-4f7a-9bdc-3c73cea717f1",
"ext":".png"
}
],
"events": {
"in": {
"pictures-start": {
"alias": "开始",
"data": {
"picUrl":"图片路径",
"blockUrl":"blockUrl",
"GAME_TIME":"每局的游戏时间",
"MAX_ROW":"行",
"MAX_COL":"列",
"W":"宽",
"H":"高",
"GAP":"图片间隙",
"OFFSET_X":"OFFSET_X",
"OFFSET_Y":"OFFSET_Y"
}
},
"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 {getTexture} from './utils'
export default class Ball extends engine.Container{
name:string
// 生命值
life:number;
plane:engine.Sprite = new engine.Sprite()
constructor(){
super();
this.addChild(this.plane)
}
setPosition(){};
died(){}
}
\ No newline at end of file
import { getTexture } from "./utils"
export class Bullets extends engine.Container{
harm:number
bulletPic = new engine.Sprite(getTexture('18852543-1f1d-498b-af64-88cd3b343758'))
constructor(_harm = 1){
super()
this.harm = _harm
this.addChild(this.bulletPic)
}
bullet:engine.Sprite
public bullets:engine.Sprite[] = []
addBullet(planeModel?){
let bullet = new engine.Sprite(getTexture('18852543-1f1d-498b-af64-88cd3b343758'))
bullet.x = planeModel ? planeModel.x + planeModel.width / 2 - bullet.width / 2 : 375 - bullet.width / 2 ;
bullet.y = 1150
// this.bullets.push(bullet)
return bullet
}
// 创建子弹
createBullet(planeModel){
this.x = planeModel.x + planeModel.width / 2 - this.bulletPic.width / 2;
this.y = 1150;
}
// 达到一定分数增加火力
addBulletNum(w){
}
}
\ No newline at end of file
import GameObject from "./GameObject";
export default abstract class GameComponent {
public get enabled(): boolean {
return this._enabled;
}
public set enabled(v: boolean) {
if (v == true && this._enabled == false) {
this.onEnabled();
this._enabled = v;
} else if (v == false && this._enabled == true) {
this.onDisabled();
this._enabled = v;
}
}
private _enabled: boolean = false;
public get owner(): GameObject {
return this._owner;
}
private _owner: GameObject = null;
constructor(owner: GameObject) {
this._owner = owner;
}
protected abstract onEnabled(): void;
protected abstract onDisabled(): void;
}
\ No newline at end of file
import GameComponent from "./GameComponent";
export default class GameObject extends engine.Container {
public name: string = "";
public addComponent<T extends GameComponent>(cls: any): T {
if (this.getComponent(cls) != null) {
console.error("component is existent");
return;
}
let ins = new cls(this);
ins.enabled = true;
this.componentList.push(ins);
return ins;
}
public getComponent<T extends GameComponent>(cls: any): T {
for (let i of this.componentList) {
if (i instanceof cls) {
return i as T;
}
}
return null;
}
public removeComponent(cls: any) {
for (let i of this.componentList) {
if (i instanceof cls) {
i.enabled = false;
this.componentList = this.componentList.filter(e => e != i);
return;
}
}
}
private _anchorOffsetX: number = 0;
public get anchorOffsetX(): number {
return this._anchorOffsetX;
}
public set anchorOffsetX(v: number) {
this._anchorOffsetX = v;
}
private _anchorOffsetY: number = 0;
public get anchorOffsetY(): number {
return this._anchorOffsetY;
}
public set anchorOffsetY(v: number) {
this._anchorOffsetY = v;
}
private componentList: GameComponent[] = [];
constructor() {
super();
// this.addEventListener(engine.Event.REMOVED_FROM_STAGE, this.disableAllComponents, this);
this.mouseEnabled = false;
this.mouseChildren = false;
}
/**销毁时禁用所有组件 */
dispose() {
this.destroy();
this.disableAllComponents();
}
protected disableAllComponents() {
Object.keys(this.componentList).forEach(e => this.componentList[e].enabled = false);
}
protected enableAllComponents() {
Object.keys(this.componentList).forEach(e => this.componentList[e].enabled = true);
}
}
\ No newline at end of file
This diff is collapsed.
import GameView from "./GameView";
import { injectProps } from "../props";
import TestView from './TestView'
export class GameWrapper extends engine.Container{
private _gameView:GameView
private _testView:TestView
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);
let testView = this._testView = new TestView();
this.addChild(testView);
}
// start(event: engine.Event) {
// injectProps(event.data);
// // this._status = 1;
// this._gameView.start();
// }
// stop(event: engine.Event) {
// this._gameView.stop();
// }
start(event: engine.Event) {
injectProps(event.data);
// this._status = 1;
this._testView.start();
}
stop(event: engine.Event) {
this._testView.stop();
}
}
\ No newline at end of file
import Ball from "./Ball";
import { getTexture } from "./utils";
export class SmallPlane extends Ball{
_life:number = 3;
smallPlane = new engine.Sprite(getTexture('57d4067e-c32f-4b12-a8fc-185753726fc6'))
constructor(){
super()
this.life = 3;
this.name = "smallBall"
this.addChild(this.smallPlane)
}
setPosition(){
this.x = Math.random() * (750 - this.width)
this.y = Math.random() * (this.height)
}
died(){
}
}
\ No newline at end of file
This diff is collapsed.
/**
* 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
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);
}
/**
* Created by renjianfeng on 2020-03-13.
*/
const customId = 'rounds-pic';
(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', {
picUrl: "http://yun.duiba.com.cn/aurora/assets/e1593b97c27077b85b92f7eaaeae1ed64a1eb79a.png",
blockUrl: "888",
GAME_TIME:30,
MAX_ROW:4,
MAX_COL:3,
W:618,
H:827,
GAP:0,
OFFSET_X:0,
OFFSET_Y:0
});
const d = engine.gameStage.sceneContainer.getChildAt(0);
engine.gameStage.sceneContainer.getChildAt(0).x = (d.stage.width-props.W)/2;
engine.gameStage.sceneContainer.getChildAt(0).y = (d.stage.height-props.H)/2;
}, 1000);
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);
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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