Commit e29e32b9 authored by zjz1994's avatar zjz1994

人保财险消消乐暂存

parent 76315174
This diff is collapsed.
/**
* Created by renjianfeng on 2020-03-13.
*/
const customId = 'rbcxiaoxiaole';
(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,
}
}],
}, null, function () {
setTimeout(() => {
engine.addCustomModule(customId, engine.gameStage.sceneContainer.getChildAt(0));
}, 100);
setTimeout(() => {
engine.globalEvent.dispatchEvent('game-init',{
time:100000,
level:1,
mode:"day"
});
}, 500);
setTimeout(() => {
engine.globalEvent.dispatchEvent('game-start');
}, 700);
});
}
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: red; */
}
</style>
</head>
<body>
<div id="game-container" style="line-height:0;font-size:0"></div>
<script crossorigin="anonymous" src="//yun.duiba.com.cn/editor/zeroing/libs/engine.50cdcef6ebe4e8c0fbc624f9d4fbf225102c5750.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 = [
];
function loadAssets(customModuleAssets, onProgress, onComplete){
return engine.loadAssets(assets.concat(...customModuleAssets), onProgress, onComplete);
}
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
/**
* Created by rockyl on 2020-01-21.
*/
let customModuleProps = {
};
{
"name": "消消乐",
"desc": "消消乐模块",
"props": {
"threeEscore":{
"alias":"三消加分",
"type":"number",
"default":1
},
"fourEscore":{
"alias":"四消加分",
"type":"number",
"default":2
},
"moreEscore":{
"alias":"多消加分",
"type":"number",
"default":3
}
},
"assets": [
{
"name": "底图",
"url": "//yun.duiba.com.cn/aurora/assets/d2b599cece087d5ab315cd1392f94139941280bb.png",
"uuid": "map",
"ext": ".png"
},
{
"name": "狗",
"url": "//yun.duiba.com.cn/aurora/assets/26780d2fb48d047e111857da9e82fe49b0d310a8.png",
"uuid": "gdog",
"ext": ".png"
},
{
"name": "鸟",
"url": "//yun.duiba.com.cn/aurora/assets/39a1a8865ca101d6fa29325bf1fc37c26190e382.png",
"uuid": "pbird",
"ext": ".png"
},
{
"name": "牛",
"url": "//yun.duiba.com.cn/aurora/assets/2e74dd7faab031f71e644dad340b4c83791b8bf0.png",
"uuid": "hniu",
"ext": ".png"
},
{
"name": "兔子",
"url": "//yun.duiba.com.cn/aurora/assets/6c4033a865bc6c73b680bc31d29de55ac347d397.png",
"uuid": "bribbit",
"ext": ".png"
},
{
"name": "猪",
"url": "//yun.duiba.com.cn/aurora/assets/c14e003bb3847bd7ab30eb6ba0915124f207bc31.png",
"uuid": "rpig",
"ext": ".png"
},
{
"name": "选中框",
"url": "//yun.duiba.com.cn/aurora/assets/c6ed5f3f94958e74fcbfc1da56e99795056fd75a.png",
"uuid": "selected",
"ext": ".png"
},
{
"name": "交换箭头",
"url": "//yun.duiba.com.cn/aurora/assets/438ca6e721eab32728aceaca5df0095e1387f340.png",
"uuid": "jiantou",
"ext": ".png"
},
{
"name": "房子动画",
"url": "//yun.duiba.com.cn/aurora/assets/10d6c3c657e4f26eee2e6f1edca36ec468d57353.svga",
"uuid": "homeani",
"ext": ".svga"
},
{
"name": "夜晚房子",
"url": "//yun.duiba.com.cn/aurora/assets/aa9261273423b4b9343b4526b7e5f71a6a35a345.svga",
"uuid": "homenight",
"ext": ".svga"
}
],
"events": {
"in": {
"game-init":{
"alias": "初始化第一关",
"data": {
}
},
"game-reset": {
"alias": "关卡通过重玩之类的重置关卡",
"data": {
}
},
"game-start": {
"alias": "开始"
},
"game-pause": {
"alias": "暂停"
},
"game-resume": {
"alias": "继续"
},
"game-recordcomp": {
"alias": "记录完毕"
}
},
"out": {
"game-score-update": {
"alias": "分数更新",
"data": {
"score":"分数"
}
},
"game-time-update": {
"alias": "倒计时更新",
"data": {
"time":"剩余时间"
}
},
"game-over": {
"alias": "游戏结束",
"data": {
"score":"分数",
"reason": "结束原因(1:时间到了,2:过关)"
}
},
"game-record": {
"alias": "游戏记录",
"data": {
"score":"操作得分",
"seq": "操作步骤号",
"sptime":"操纵开始时间",
"eptime":"操作结束时间"
}
}
}
}
}
\ No newline at end of file
This diff is collapsed.
/**
* Created by rockyl on 2020-01-09.
*/
import GameView from "./GameView";
import {injectProps} from "../props";
export class GameWrapper extends engine.Container {
private _gameView: GameView;
constructor() {
super();
this._gameView = new GameView();
this.addChild(this._gameView);
engine.globalEvent.addEventListener('game-init',this.init,this);
engine.globalEvent.addEventListener('game-reset',this.reset,this);
engine.globalEvent.addEventListener('game-start',this.start,this);
engine.globalEvent.addEventListener('game-pause',this.pause,this);
engine.globalEvent.addEventListener('game-resume',this.resume,this);
engine.globalEvent.addEventListener('game-recordcomp',this.recordcomp,this);
}
init(event:engine.Event){
// console.log("gamewrapper-init",event);
let time = event.data.time;
let level = event.data.level;
let mode = event.data.mode;
this._gameView.init(time,level,mode);
}
reset(event:engine.Event){
// console.log("gamewrapper-reset",event);
let time = event.data.time;
let level = event.data.level;
let mode = event.data.mode;
this._gameView.reset(time,level,mode);;
}
start(){
this._gameView.start();
}
pause(){
this._gameView.pause();
}
resume(){
this._gameView.resume();
}
recordcomp(){
this._gameView.recordcomp();
}
}
import Element from "./ele/Element";
import { getTextureByName } from "./utils";
export enum ElementType{
gdog = 1,
pbird,
hniu,
bribbit,
rpig
}
export enum GameEvent{
SelectEle = "SelectEle",
}
export default class MapData{
//单格大小
static itemsize = 116;
//
static paddingw = 7;
static paddingh = 7;
static paddingwi = 4;
static paddinghi = 2;
//
static row = 5;
static col = 5;
//行-列,对应位置
static posData = {
};
static eleidx = 1;
static elePool = {};
static anispeed = 1000;
static gdotTex:engine.Texture;
static pbirdTex:engine.Texture;
static hniuTex:engine.Texture;
static bribbitTex:engine.Texture;
static rpigTex:engine.Texture;
static levelData:Array<Array<Array<number>>> = [
[
[1,2,5,3,4],
[3,1,2,4,5],
[2,5,3,4,1],
[5,4,1,2,3],
[4,1,3,5,2],
],
[
[5,2,1,2,1],
[3,1,4,5,4],
[2,5,3,5,1],
[5,4,1,2,3],
[4,1,3,1,2],
],
[
[2,4,1,5,2],
[2,3,4,1,3],
[4,1,3,2,3],
[3,2,1,1,4],
[1,1,3,5,4],
],
[
[3,2,1,4,5],
[2,4,1,2,3],
[2,3,2,3,3],
[4,4,5,5,4],
[3,3,1,2,4],
],
[
[4,5,1,2,4],
[3,2,3,4,2],
[1,5,2,3,5],
[4,5,5,1,3],
[1,2,3,2,4],
]
]
static getRy(r){
return this.paddingh+r*(this.itemsize+this.paddinghi);
}
static getCx(c){
return this.paddingw+c*(this.itemsize+this.paddingwi);
}
static getRCPos(r,c){
let x = this.getCx(c);
let y = this.getRy(r);
return [x,y];
}
static adaptElePos(pos,wid,hei){
let x = pos[0]+(this.itemsize-wid)/2;
let y = pos[1]+(this.itemsize-hei)/2;
return [x,y];
}
static getEtypeImgName(type:ElementType){
let ename:string;
switch(type){
case ElementType.gdog:
ename = "狗";
break;
case ElementType.pbird:
ename = "鸟";
break;
case ElementType.hniu:
ename = "牛";
break;
case ElementType.bribbit:
ename = "兔子";
break;
case ElementType.rpig:
ename = "猪";
break;
default:
console.error("未定义元素类型");
break;
}
return ename;
}
static getEtypeImgTex(type:ElementType){
let etex:engine.Texture;
switch(type){
case ElementType.gdog:
if(!this.gdotTex){
this.gdotTex = getTextureByName("狗");
console.log("新素材加载---狗");
}
etex = this.gdotTex;
break;
case ElementType.pbird:
if(!this.pbirdTex){
this.pbirdTex = getTextureByName("鸟");
console.log("新素材加载---鸟");
}
etex = this.pbirdTex;
break;
case ElementType.hniu:
if(!this.hniuTex){
this.hniuTex = getTextureByName("牛");
console.log("新素材加载---牛");
}
etex = this.hniuTex;
break;
case ElementType.bribbit:
if(!this.bribbitTex){
this.bribbitTex = getTextureByName("兔子");
console.log("新素材加载---兔子");
}
etex = this.bribbitTex;
break;
case ElementType.rpig:
if(!this.rpigTex){
this.rpigTex = getTextureByName("猪");
console.log("新素材加载---猪");
}
etex = this.rpigTex;
break;
default:
console.error("未定义元素类型");
break;
}
return etex;
}
static getRandEtype(){
let eletypeArr = [ElementType.gdog,ElementType.pbird,ElementType.hniu,ElementType.bribbit,ElementType.rpig];
let etype = eletypeArr[Math.floor(Math.random()*eletypeArr.length)];
return etype;
}
static initPoolEle(){
// console.error("初始化元素池");
this.gdotTex = getTextureByName("狗");
this.pbirdTex = getTextureByName("鸟");
this.hniuTex = getTextureByName("牛");
this.bribbitTex = getTextureByName("兔子");
this.rpigTex = getTextureByName("猪");
let eletypes = [ElementType.gdog,ElementType.pbird,ElementType.hniu,ElementType.bribbit,ElementType.rpig];
this.elePool["ele"] = new Array();
//初始5*5个元素备用;
for(let i=0;i<eletypes.length;i++){
let itype = eletypes[i];
// this.elePool[itype] = new Array();
for(let a=0;a<5;a++){
let iele = new Element();
// iele.eimage.texture = this.getEtypeImgTex(itype);
this.elePool["ele"].push(iele);
}
}
//得分得txt
this.elePool["score"] = new Array();
for(let t=0;t<8;t++){
let itxt = new engine.Label();
itxt.size = 66;
itxt.width = 200;
itxt.height = 70;
itxt.textAlign = engine.TEXT_ALIGN.CENTER;
itxt.verticalAlign = engine.VERTICAL_ALIGN.MIDDLE;
itxt.anchorY = 35;
itxt.anchorX = 100;
itxt.bold = true;
this.elePool["score"].push(itxt);
}
}
static getOneEle(type:ElementType):Element{
let ele:Element;
if(this.elePool["ele"]){
if(this.elePool["ele"].length>0){
ele = this.elePool["ele"].shift();
}
}else{
this.elePool["ele"] = new Array();
}
if(!ele){
console.error("创建了新的了ele");
ele = new Element();
// ele.eimage.texture = getTextureByName(this.getEtypeImgName(type));
}
ele.name = "ele_"+this.eleidx;
this.eleidx += 1;
ele.init(type)
return ele;
}
static getOneTxt():engine.Label{
let itxt:engine.Label;
if(this.elePool["score"]){
if(this.elePool["score"].length>0){
itxt = this.elePool["score"].shift();
}
}else{
this.elePool["score"] = new Array();
}
if(!itxt){
itxt = new engine.Label();
itxt.size = 66;
itxt.width = 200;
itxt.height = 70;
itxt.textAlign = engine.TEXT_ALIGN.CENTER;
itxt.verticalAlign = engine.VERTICAL_ALIGN.MIDDLE;
itxt.anchorY = 35;
itxt.anchorX = 100;
itxt.bold = true;
// console.log("创建了新的txt");
}
itxt.mouseEnabled = false;
return itxt;
}
static recoverEle(ele:Element,type:ElementType){
if(ele.eimage){
ele.eimage.texture = null;
}
this.elePool["ele"].push(ele);
}
static recoverTxt(txt:engine.Label){
this.elePool["score"].push(txt);
}
static getDistance(p1,p2){
let p1x = p1[0];
let p1y = p1[1];
let p2x = p2[0];
let p2y = p2[1];
let dis = Math.sqrt(Math.pow(p1x-p2x,2)+Math.pow(p1y-p2y,2));
return dis;
}
}
\ No newline at end of file
import MapData, { ElementType, GameEvent } from "../MapData";
import { getTextureByName } from "../utils";
export default class Element extends engine.Container{
type:ElementType;
eimage:engine.Image;
inrow;
incol;
set touch(touch){
this.mouseEnabled = touch;
this.mouseChildren = touch;
}
constructor(){
super();
this.width = MapData.itemsize;
this.height = MapData.itemsize;
this.anchorX = MapData.itemsize/2;
this.eimage = new engine.Image();
this.addChild(this.eimage);
this.touch = true;
// this.addEventListener(engine.MouseEvent.CLICK,this.selectele,this);
this.addEventListener(engine.MouseEvent.MOUSE_DOWN,this.selectele,this);
this.addEventListener(engine.MouseEvent.MOUSE_MOVE,this.changemove,this);
}
init(type:ElementType){
this.anchorY = MapData.itemsize;
this.scaleX = 1;
this.scaleY = 1;
this.alpha = 1;
this.type = type;
let ename = MapData.getEtypeImgName(type);
this.eimage.texture = MapData.getEtypeImgTex(type);
let imgwid = this.eimage.texture.width;
let imghei = this.eimage.texture.height;
// console.log("大小",imgwid,imghei);
this.eimage.x = (this.width - imgwid)/2;
this.eimage.y = (this.height-imghei)/2;
}
setrc(r,c){
this.inrow = r;
this.incol = c;
}
selectele(e:engine.MouseEvent){
engine.globalEvent.dispatchEvent(GameEvent.SelectEle,{
r:this.inrow,
c:this.incol,
type:"mouse_down"
})
}
changemove(e:engine.MouseEvent){
// console.log(this.inrow+":"+this.incol);
engine.globalEvent.dispatchEvent(GameEvent.SelectEle,{
r:this.inrow,
c:this.incol,
type:"mouse_move"
})
}
public get factor():number {
return 0;
}
public set factor(value:number) {
this.x = (1 - value) * (1 - value) * this.p1x + 2 * value * (1 - value) * this.c1x + value * value * this.p2x;
this.y = (1 - value) * (1 - value) * this.p1y + 2 * value * (1 - value) * this.c1y + value * value * this.p2y;
var mscale = (1 - value) * (1 - value) * 1 + 2 * value * (1 - value) * 0.6 + value * value * 0.35;
this.scaleX = mscale;
this.scaleY = mscale;
}
p1x;
p1y;
c1x;
c1y;
p2x;
p2y;
//飞到小屋
flyToHome(tx,ty,time){
this.p1x = this.x;
this.p1y = this.y+20;
this.c1x = (this.p1x-tx)/4+tx;
this.c1y = ty;
this.p2x = tx;
this.p2y = ty;
engine.Tween.removeTweens(this);
engine.Tween.get(this).to({
scaleX:1.1,
scaleY:1.1
},200)
.to({
scaleX:1.1,
scaleY:0.88
},100)
.to({
scaleX:0.98,
scaleY:0.98,
y:this.y+20
},100)
.call(()=>{
this.factor = 0;
engine.Tween.get(this).to({
factor:1
},450)
.call(()=>{
let nodeparent:engine.Container = this.parent;
nodeparent&&nodeparent.removeChild(this);
MapData.recoverEle(this,this.type);
})
})
}
changePos(tpos:Array<number>){
let nx = this.x;
let ny = this.y;
let tx = tpos[0];
let ty = tpos[1];
let dis = MapData.getDistance([nx,ny],tpos);
let time = Math.ceil(dis/MapData.anispeed*1000);
engine.Tween.removeTweens(this);
let pro = new Promise(res=>{
engine.Tween.get(this,{loop:false}).to({
x:tx,
y:ty
},time)
.call(()=>{
// console.log("单个移动完毕");
res();
})
})
return pro;
}
}
\ 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;
}
\ 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);
}
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