Commit 26380604 authored by lujinlei's avatar lujinlei

-a

parent 4db3d343
This diff is collapsed.
This diff is collapsed.
......@@ -47,37 +47,40 @@
var turnTableNode = this._turnTableNode = new engine.Container();
this.addChild(turnTableNode);
for (var index_Y = 0; index_Y < 3; index_Y++) {
var _loop_1 = function (index_X) {
for (var index_X = 0; index_X < 3; index_X++) {
if (index_X == 1 && index_Y == 1)
return "continue";
continue;
var tmpNode = new engine.Container();
var unchecked = this_1.getImage('unchecked', 1);
var checked = this_1.getImage('checked', 0);
var unchecked = this.getImage('unchecked', 1);
var checked = this.getImage('checked', 0);
tmpNode.width = Math.max(unchecked.width, checked.width);
this_1._singleNodeWidth = this_1._singleNodeWidth ? this_1._singleNodeWidth : tmpNode.width;
this._singleNodeWidth = this._singleNodeWidth ? this._singleNodeWidth : tmpNode.width;
tmpNode.height = Math.max(unchecked.height, checked.height);
tmpNode.x = index_X * (tmpNode.width + this_1._horizontal_X);
tmpNode.y = index_Y * (tmpNode.height + this_1._vertical_Y);
tmpNode.x = index_X * (tmpNode.width + this._horizontal_X);
tmpNode.y = index_Y * (tmpNode.height + this._vertical_Y);
checked.x = (tmpNode.width - checked.width) / 2;
checked.y = (tmpNode.height - checked.height) / 2;
unchecked.x = (tmpNode.width - unchecked.width) / 2;
unchecked.y = (tmpNode.height - unchecked.height) / 2;
if (props.layer) {
tmpNode.addChild(checked);
tmpNode.addChild(unchecked);
}
else {
tmpNode.addChild(unchecked);
tmpNode.addChild(checked);
}
turnTableNode.addChild(tmpNode);
var tmpTexture = engine.Texture.fromImage(res[this_1._prizeIndex].img, undefined);
var prizeID = res[this_1._prizeIndex].id;
tmpTexture.addEventListener('loaded', function () {
var prize = new engine.Sprite(tmpTexture);
var prize = new engine.Sprite(engine.Texture.fromImage(res[this._prizeIndex].img));
var prizeID = res[this._prizeIndex].id;
prize.width = props.icon_width;
prize.height = props.icon_height;
prize.x = (tmpNode.width - prize.width) / 2 + props.icon_X;
prize.y = (tmpNode.height - prize.height) / 2 + props.icon_Y;
tmpNode.prizeID = prizeID;
tmpNode.addChild(prize);
}, this_1);
this_1._prizeIndex++;
this_1._boxArray.push(tmpNode);
};
var this_1 = this;
for (var index_X = 0; index_X < 3; index_X++) {
_loop_1(index_X);
this._prizeIndex++;
this._boxArray.push(tmpNode);
}
}
turnTableNode.x = (750 - (this._singleNodeWidth * 3 + this._horizontal_X * 2)) / 2;
......@@ -188,7 +191,6 @@
};
return Turntable;
}(engine.Container));
//# sourceMappingURL=turntable.js.map
var GameView = (function (_super) {
tslib.__extends(GameView, _super);
......
......@@ -46,6 +46,11 @@
"alias": "奖品Y轴偏移量(底框背景有透明)",
"type": "number",
"default": -20
},
"layer": {
"alias": "中奖标志是否在最下层",
"type": "boolean",
"default": false
}
},
"assets": [
......
......@@ -43,24 +43,50 @@ export class Turntable extends engine.Container{
tmpNode.width = Math.max(unchecked.width,checked.width);
this._singleNodeWidth = this._singleNodeWidth ? this._singleNodeWidth : tmpNode.width;
tmpNode.height = Math.max(unchecked.height,checked.height);
tmpNode.x = index_X*(tmpNode.width + this._horizontal_X);
tmpNode.y = index_Y*(tmpNode.height + this._vertical_Y);
checked.x = (tmpNode.width -checked.width)/2
checked.y = (tmpNode.height -checked.height)/2
unchecked.x = (tmpNode.width -unchecked.width)/2
unchecked.y = (tmpNode.height -unchecked.height)/2
if(props.layer){
tmpNode.addChild(checked);
tmpNode.addChild(unchecked);
}else{
tmpNode.addChild(unchecked);
tmpNode.addChild(checked);
}
turnTableNode.addChild(tmpNode);
let tmpTexture:engine.Texture = engine.Texture.fromImage(res[this._prizeIndex].img,undefined);
// let tmpTexture:engine.Texture = engine.Texture.fromImage(res[this._prizeIndex].img,undefined);
// let prizeID = res[this._prizeIndex].id;
// tmpTexture.addEventListener('loaded',()=>{
// let prize = new engine.Sprite(tmpTexture);
// prize.width = props.icon_width;
// prize.height = props.icon_height;
// prize.x = (tmpNode.width - prize.width)/2 + props.icon_X;
// prize.y = (tmpNode.height - prize.height)/2 + props.icon_Y;
// tmpNode.prizeID = prizeID;
// tmpNode.addChild(prize);
// },this)
let prize =new engine.Sprite(engine.Texture.fromImage(res[this._prizeIndex].img)) ;
let prizeID = res[this._prizeIndex].id;
tmpTexture.addEventListener('loaded',()=>{
let prize = new engine.Sprite(tmpTexture);
prize.width = props.icon_width;
prize.height = props.icon_height;
prize.x = (tmpNode.width - prize.width)/2 + props.icon_X;
prize.y = (tmpNode.height - prize.height)/2 + props.icon_Y;
tmpNode.prizeID = prizeID;
tmpNode.addChild(prize);
},this)
this._prizeIndex ++ ;
this._boxArray.push(tmpNode);
}
......
/**
* Created by renjianfeng on 2020-03-13.
*/
const customId = 'seabed-game';
(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('seabed-game-start',{color:"0x000000"});
}, 150);
});
engine.globalEvent.addEventListener('seabed-game-time-update', (e) => {
// console.log(e.type, e.data);
});
engine.globalEvent.addEventListener('seabed-game-game-fail', (e) => {
console.log(e.type, e.data);
});
engine.globalEvent.addEventListener('seabed-game-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.
<!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 src="matter.min.js"></script>
<script src="matter_decomp.min.js"></script>
<div id="debugCanvas" style="position:absolute;opacity: .5;pointer-events: none"></div>
<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 source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
/**
* Created by rockyl on 2020-01-21.
*/
let customModuleProps = {
};
This diff is collapsed.
{
"name": "海底",
"desc": "海底模块",
"props": {
"level_1": {
"alias": "第一关数据(第一个是当前关卡通过所需积分,第二个是炸弹个数,第三个是道具个数,第四个是关卡时间)",
"type": "array<number>",
"default": "5,1,9,60"
},
"level_2": {
"alias": "第一关数据(第一个是当前关卡通过所需积分,第二个是炸弹个数,第三个是道具个数,第四个是关卡时间)",
"type": "array<number>",
"default": "10,2,14,80"
},
"level_3": {
"alias": "第一关数据(第一个是当前关卡通过所需积分,第二个是炸弹个数,第三个是道具个数,第四个是关卡时间)",
"type": "array<number>",
"default": "15,3,19,110"
}
},
"assets": [
{
"name": "灯",
"url": "//yun.duiba.com.cn/aurora/assets/c0f7c4b4d650da31d9b23a9006bd0e58aaca95ad.png",
"uuid": "55a9e50c-c7bc-4bb1-8624-fdd7edb66f93",
"ext": ".png"
},
{
"name": "机子",
"url": "//yun.duiba.com.cn/aurora/assets/e07baecf71ed8ecd9429fbbebb064b3cd50658df.png",
"uuid": "dee8564f-e17a-4a78-87f7-bebeb83fd235",
"ext": ".png"
},
{
"name": "篮筐",
"url": "//yun.duiba.com.cn/aurora/assets/b6977968fa3cdefbe181adbe2a381df9e8402af5.png",
"uuid": "8b49fe91-f6b7-414c-81d1-a9689e473b29",
"ext": ".png"
},
{
"name": "右按钮",
"url": "//yun.duiba.com.cn/aurora/assets/e3b4d4c0e557529b8c383639acce3d2ac01bf9b3.png",
"uuid": "1b1acf4a-a1fb-427e-a8cd-48214f89ac46",
"ext": ".png"
},
{
"name": "左按钮",
"url": "//yun.duiba.com.cn/aurora/assets/4bc49a4477adbfcda25d348473504d4384ad3dd2.png",
"uuid": "d828d269-68e7-4801-a3b2-e4bb1c38592b",
"ext": ".png"
},
{
"name": "basket_bottom",
"url": "//yun.duiba.com.cn/aurora/assets/8003d15eda09a24c38fdf32d2b774fe9a16fcd81.png",
"uuid": "1bccf897-d37e-4dc7-814f-6b8caf27a03b",
"ext": ".png"
},
{
"name": "basket_top",
"url": "//yun.duiba.com.cn/aurora/assets/55596516d4d44685fe07be1fef2105c8186edcd7.png",
"uuid": "826c7811-2767-469f-bf6b-908f3d404a1d",
"ext": ".png"
},
{
"name": "coin_json",
"url": "//yun.duiba.com.cn/aurora/assets/4170985efa5fea693a27734d14250e3b5a49962b.json",
"uuid": "9a0265ec-d9e7-4d47-83c7-d775115df38e",
"ext": ".json"
},
{
"name": "coin",
"url": "//yun.duiba.com.cn/aurora/assets/d6a361f27ebb81dd444ac40e428dffd06a0aa4e3.png",
"uuid": "abe242de-cf82-46ec-8a40-fcd51b0ca13d",
"ext": ".png"
},
{
"name": "boom_json",
"url": "//yun.duiba.com.cn/aurora/assets/4da36db75239d5c4f7b89d5805429ad64f7a05d5.json",
"uuid": "b0f0ae6d-b7c7-4a35-8c5a-7c4249f011db",
"ext": ".json"
},
{
"name": "boom",
"url": "//yun.duiba.com.cn/aurora/assets/b4579f262046e16245df9982ef31c57e433b0ba7.png",
"uuid": "129aa5f7-e308-40ce-ba9b-3fdc733d4ecb",
"ext": ".png"
},
{
"name": "candy_json",
"url": "//yun.duiba.com.cn/aurora/assets/2512911b42641f570be929e686a17fa91582f411.json",
"uuid": "0f21fae8-08cb-4c41-bab5-993d98fd7070",
"ext": ".json"
},
{
"name": "candy",
"url": "//yun.duiba.com.cn/aurora/assets/a91c39b45b0aa042b112ac477bc5ab80f00e8816.png",
"uuid": "67c0717c-9b89-4b56-a61a-91c8c7a99e4c",
"ext": ".png"
},
{
"name": "egg_json",
"url": "//yun.duiba.com.cn/aurora/assets/d789e4167a136e889729dd97d4f8728517226c8a.json",
"uuid": "75ac3c28-f8a8-4609-b908-bb386a6ace2c",
"ext": ".json"
},
{
"name": "egg",
"url": "//yun.duiba.com.cn/aurora/assets/a9156427b733d959c473dc0e37c929f103f77174.png",
"uuid": "e2f61593-e082-405a-bf19-79c78e2c067a",
"ext": ".png"
},
{
"name": "fail_json",
"url": "//yun.duiba.com.cn/aurora/assets/be22c261821766b019138176658ea3857f7dc5c8.json",
"uuid": "96f6c48f-f01e-4d13-a058-0c082edc38fa",
"ext": ".json"
},
{
"name": "fail",
"url": "//yun.duiba.com.cn/aurora/assets/d5fff67caae5a86bc29969d1676b76b253eda701.png",
"uuid": "9473b143-bd58-4450-b7b9-cb18911f3ba3",
"ext": ".png"
},
{
"name": "gift_json",
"url": "//yun.duiba.com.cn/aurora/assets/9165343ca17a457133d227956c217e0a821a0cf3.json",
"uuid": "48347b92-7c99-4bf5-a67a-d535b4785b20",
"ext": ".json"
},
{
"name": "gift",
"url": "//yun.duiba.com.cn/aurora/assets/e47e2ebdbb9cc8fe1f9f0e941af3cbe92b08162b.png",
"uuid": "a3667116-4218-4b5f-a6ec-c1529ddb71cf",
"ext": ".png"
},
{
"name": "success_json",
"url": "//yun.duiba.com.cn/aurora/assets/a010032b62ec260b6ad0844b1eff530847954e10.json",
"uuid": "3a70f25d-03c0-483c-847b-88b6e4ed5dcf",
"ext": ".json"
},
{
"name": "success",
"url": "//yun.duiba.com.cn/aurora/assets/e6c6b8fff68fcbb2e30cbb50f5690d52be4d8c99.png",
"uuid": "0ec792be-6fcc-4c5b-bf8a-0e8406a5c34b",
"ext": ".png"
},
{
"name": "玻璃",
"url": "//yun.duiba.com.cn/aurora/assets/90edb55a1c5fb4b7baf689144b7c1f3508ecb7ff.png",
"uuid": "92d1a3d4-256b-467b-a9a2-4820c2c2c718",
"ext": ".png"
},
{
"name": "contPng",
"url": "//yun.duiba.com.cn/aurora/assets/a19ba2de0b7f11830700ed8122585a95ebef1757.png",
"uuid": "84e4f5dc-149d-4ace-a02c-8b2aaf6819b1",
"ext": ".png"
},
{
"name": "bubble",
"url": "//yun.duiba.com.cn/aurora/assets/f30c3b92eac79cdae679c48436eb4ef92b97ff6c.png",
"uuid": "28c4a8e4-9ff8-4962-842a-dd90d04a958c",
"ext": ".png"
},
{
"name": "倒计时",
"url": "//yun.duiba.com.cn/aurora/assets/a9b9490cd7ef4974c6ca5c34b3b4e4a2fdd1f8ca.png",
"uuid": "893a1116-1ddb-49e5-89bd-8f523ad56f81",
"ext": ".png"
},
{
"name": "awesome",
"url": "//yun.duiba.com.cn/aurora/assets/89de7d7785bb70a95b139fe444b90fbe5e802c80.png",
"uuid": "b7f19c22-22ea-419e-99d0-3b6959b59f88",
"ext": ".png"
},
{
"name": "cool",
"url": "//yun.duiba.com.cn/aurora/assets/5e1ce8651de0f67cf98220238db00ef6d46b1aeb.png",
"uuid": "585b11a0-8d5d-4265-8871-96d98c0a65cf",
"ext": ".png"
},
{
"name": "good",
"url": "//yun.duiba.com.cn/aurora/assets/49a5633dc8429fac1d59c7a55ba15f3386cdddc7.png",
"uuid": "bdbc7ff6-5b64-4878-bcb2-9b83a498206b",
"ext": ".png"
},
{
"name": "great",
"url": "//yun.duiba.com.cn/aurora/assets/ad47ea03239e36e09806a74cb4bd475a42edb00a.png",
"uuid": "bd1da4bb-1dbf-4b80-a6ea-eb4e50cf65aa",
"ext": ".png"
},
{
"name": "perfect",
"url": "//yun.duiba.com.cn/aurora/assets/b560b07e694a95ef6b40b6702cdfc8853eb73ec3.png",
"uuid": "63ce23dc-be8b-4222-a0a6-0fd5a27c0af6",
"ext": ".png"
},
{
"name": "unbelievable",
"url": "//yun.duiba.com.cn/aurora/assets/a436eb46836e45d8043721107e5f49a58367ac3f.png",
"uuid": "6f352da0-0522-4530-b064-9132b591b341",
"ext": ".png"
},
{
"name": "进度",
"url": "//yun.duiba.com.cn/aurora/assets/0a7f33bba28a882ea1ec436b73ecafbaed4542d5.png",
"uuid": "647dc81b-443d-446b-bcf6-8b95b8511470",
"ext": ".png"
},
{
"name": "点亮",
"url": "//yun.duiba.com.cn/aurora/assets/3e8ca3a3f044df467c76a7a0d5ebbd75520bda8e.png",
"uuid": "9808f74f-a474-4c10-a8c6-bb51663d1a8e",
"ext": ".png"
},
{
"name": "lv1",
"url": "//yun.duiba.com.cn/aurora/assets/76db0c80d7b8051d7de44e87cac763ce607d2c7a.png",
"uuid": "a9a91d6c-06b0-4fdf-bcb8-77abe9bc7d83",
"ext": ".png"
},
{
"name": "lv2",
"url": "//yun.duiba.com.cn/aurora/assets/c5f1c83c683c5703432cc615b2c206aee1c675e0.png",
"uuid": "de8b2a81-fb38-4128-b536-9ef03eb013df",
"ext": ".png"
},
{
"name": "lv3",
"url": "//yun.duiba.com.cn/aurora/assets/beed55701a29bfa9b49dca1d5a059b34d7702496.png",
"uuid": "710eed46-f371-4d85-9858-ad048c86fc74",
"ext": ".png"
},
{
"name": "lv_common",
"url": "//yun.duiba.com.cn/aurora/assets/0afe14fc04beb3c66ce9080502c7c381f4b658ea.png",
"uuid": "e53e80fd-80a6-4385-b296-a3f097eeb51a",
"ext": ".png"
},
{
"name": "dot",
"url": "//yun.duiba.com.cn/aurora/assets/b39a88200f27f65e9d8d3f2a98a671de979f3027.png",
"uuid": "b8acc117-7d3c-4bcb-aff9-b5f42b901edf",
"ext": ".png"
}
],
"events": {
"in": {
"seabed-game-start": {
"alias": "开始",
"data": {
}
},
"seabed-game-startNextLevel": {
"alias": "开始下一关",
"data": {
"level":"关卡"
}
},
"seabed-game-revive": {
"alias": "复活",
"data": {
}
},
"seabed-game-themeChange": {
"alias": "更换主题",
"data": {
"gameCountdownImage": "游戏页倒计时",
"leftButtonImage": "左按钮",
"rightButtonImage": "右按钮"
}
}
},
"out": {
"seabed-game-fail": {
"alias": "游戏结束",
"data": {
"score":"当前分数",
"level": "当前关卡"
}
},
"seabed-game-success": {
"alias": "游戏成功",
"data": {
"score":"当前分数",
"level": "当前关卡"
}
}
}
}
}
\ No newline at end of file
/**
* Created by rockyl on 2018/8/16.
*/
import { props } from "../props";
import { getIndexFromRC, getRandomArray, getTexture, getTextureByName } from "./utils";
import ObjectPool = engine.ObjectPool;
import { Tool } from "./Tools";
import { getScore, getCurLevel, getlevelMax } from "./goldData";
export default class GameData extends engine.Container {
private _scoreCount:engine.Label;
private _scorelabel:engine.Label;
private _levelLabel:engine.Label;
private _parentNode;
private starList = [];
private _progressMask;
private _color;
constructor(parentNode,color) {
super();
this._parentNode = parentNode;
this._color = color;
this.init();
}
init(){
//分数
let scoreCount = this._scoreCount = Tool.getLabel('',36,"#ffffff",true)
scoreCount.y = 48;
this.addChild(scoreCount);
let scorelabel = this._scorelabel = Tool.getLabel('分',22,"#ffffff")
scorelabel.y = 56;
this.addChild(scorelabel);
let progress = new engine.Sprite(getTextureByName('进度'));
progress.x = 212;
progress.y = 8;
this.addChild(progress);
let progressMask = this._progressMask = new engine.Rect()
progressMask.fillColor = 0x000000
progressMask.width = 245;
progressMask.height = 100;
progressMask.x = 213;
progressMask.y = 5;
//0.35 0.75 1
progressMask.scaleX = 0;
this.addChild(progressMask);
progress.mask = progressMask;
let star1 = new engine.Sprite(getTextureByName('点亮'));
star1.x = 270;
star1.y = 6;
star1.visible = false;
this.addChild(star1);
this.starList.push(star1);
let star2 = new engine.Sprite(getTextureByName('点亮'));
star2.x = 365;
star2.y = 6;
star2.visible = false;
this.addChild(star2);
this.starList.push(star2);
let star3 = new engine.Sprite(getTextureByName('点亮'));
star3.x = 435;
star3.y = 50;
star3.visible = false;
this.addChild(star3);
this.starList.push(star3);
this.scorePosUpdate();
//当前关卡数
let levelLabel = this._levelLabel = Tool.getLabel('',28,this._color||"#28c1ec",false)
levelLabel.y = 98;
this.addChild(levelLabel);
this.levelUpdate();
this.updateProgressMask();
}
scorePosUpdate(){
this._scoreCount.text = getScore()
this._scoreCount.x = (this._parentNode.width - this._scoreCount.width - this._scorelabel.width - 5)/2
this._scorelabel.x = this._scoreCount.x + this._scoreCount.width + 5;
this.updateProgressMask();
}
levelUpdate(color?){
this._levelLabel.text = `第${getCurLevel()}/3关`
this._levelLabel.x = (this._parentNode.width-this._levelLabel.width)/2;
}
updateProgressMask(){
let ratio = getScore()/getlevelMax()
this._progressMask.scaleX = ratio;
//0.35 0.75 1
if(ratio >= 0.35){
this.starList[0].visible = true;
}
if(ratio >= 0.75){
this.starList[1].visible = true;
}
if(ratio >= 1){
this.starList[2].visible = true;
}
}
resetMask(){
this.starList.forEach(element => {
element.visible = false;
});
}
}
\ No newline at end of file
This diff is collapsed.
import { setTouchEnabled, setlevelData } from './GoldData';
/**
* Created by rockyl on 2020-01-09.
*/
import GameView from "./GameView";
import { injectProps } from "../props";
import { setScore, setCurLevel } from "./goldData";
import { getJsonAsset } from "./JsonTools";
export class GameWrapper extends engine.Container {
// private _status;
private _gameView: GameView;
constructor() {
super();
engine.globalEvent.addEventListener('seabed-game-start', this.start, this);
engine.globalEvent.addEventListener('seabed-game-revive', this.revive, this);
engine.globalEvent.addEventListener('seabed-game-startNextLevel', this.startNextLevel, this);
engine.globalEvent.addEventListener('seabed-game-themeChange', this.themeChange, this);
//创建实例
let gameView = this._gameView = new GameView();
this.addChild(gameView);
//this.start(null);
// setTimeout(() => {
// engine.globalEvent.dispatchEvent('seabed-game-startNextLevel',{level:2});
// }, 300);
}
start(event: engine.Event) {
setlevelData();
this.initData();
this._gameView.start(event.data.color);
['coin','boom','fail','success'].forEach(element => {
getJsonAsset(element);
});
}
startNextLevel(event: engine.Event){
setScore(0);
setCurLevel(parseInt(event.data.level));
this._gameView.startNextLevel();
}
initData(){
setScore(0);
setCurLevel(1);
}
//复活
revive(){
this._gameView.revive();
}
themeChange(event: engine.Event){
this._gameView.themeChange(event.data.resData);
}
}
import LabelType from "./LabelType";
import { props } from "../props";
let curScore;
export function getScore(){
return curScore;
}
export function addScore(addCount:number){
curScore += addCount;
return curScore;
}
export function setScore(scoreCount:number){
curScore = scoreCount;
}
let curLevel;
export function getCurLevel(){
return curLevel;
}
export function setCurLevel(level){
curLevel = level
return curLevel;
}
//time-当前关卡时长
let levels;
export const setlevelData = () => {
levels = {
'1': { max: props.level_1[0], items: [[LabelType.boom, props.level_1[1]],[LabelType.coin, props.level_1[2]]],time:props.level_1[3]},
'2': { max: props.level_2[0], items: [[LabelType.boom, props.level_2[1]], [LabelType.coin, props.level_2[2]]] ,time:props.level_2[3]},
'3': { max: props.level_3[0], items: [[LabelType.boom, props.level_3[1]], [LabelType.coin, props.level_3[2]]] ,time:props.level_3[3]},
}
}
export const getLevelData = () => {
if(!levels){
setlevelData();
}
return levels[getCurLevel()]
}
export const getCurrentItems = () => {
if(!levels){
setlevelData();
}
return getLevelData().items
}
export const getlevelTime = () => {
if(!levels){
setlevelData();
}
return getLevelData().time
}
//当前关卡需要的最大通关数
export const getlevelMax = () => {
if(!levels){
setlevelData();
}
return getLevelData().max
}
let touchEnabled = false;
export const getTouchEnabled = () => {
return touchEnabled
}
export const setTouchEnabled = (b) => {
touchEnabled = b
}
\ No newline at end of file
let josnData: {
[name: string]: any
} = {};
export function getJsonAsset(name: string) {
let config = engine.getAssetByName(name+'_json');
let tmpJosnData = engine.globalLoader.get(config.uuid);
if(tmpJosnData){
josnData[name] = convert(tmpJosnData);
}
}
export function convert(data){
let frames = data.frames;
let jsonName = data.file.split('.')[0]
var obj = {};
for (var key in frames) {
let f = frames[key];
obj[jsonName + key + ".png"] = {
"x": f.x,
"y": f.y,
"w": f.w,
"h": f.h,
"ox": f.offX,
"oy": f.offY,
"sw": f.sourceW,
"sh": f.sourceH,
"ro": false,
}
}
return obj||null;
}
export function getJosnData(jsonName:string) {
return josnData[jsonName] || null;
}
\ No newline at end of file
enum LabelType {
boom='boom',candy='candy',coin='coin',gift='gift',egg='egg'
}
export default LabelType
\ No newline at end of file
export class Tool{
/**
*
* @param txt
* @param size
* @param color
* @param textWidth
* @param align
* @param x
* @param y
*/
public static getLabel(
txt: string,
size: number,
color: string = "#ffffff",
bold:boolean = false,
align: engine.TEXT_ALIGN = engine.TEXT_ALIGN.LEFT,
x: number = 0,
y: number = 0
):engine.Label{
var label = new engine.Label();
label.fillColor = color;
label.bold = bold;
label.size = size;
label.textAlign = align;
label.x = x;
label.y = y;
label.text = txt;
return label;
}
}
\ No newline at end of file
import GameView from "./GameView";
import LabelType from "./LabelType";
import { award } from "./collisionConfig";
import vibrate from "./vibrate";
import { playBoom, playSuccess } from "./playMovieClip";
import { getScore, getLevelData } from "./goldData";
import { createNewBubble } from "./createItems";
import { playTextAni } from "./playTextAni";
export function check (_this:GameView) {
const egretRenderContainer = _this.egretRenderContainer;
const center = 375;
const paddingX = 50;
const ypos = 570;
const h = 40;
// _this._egretRender._root.graphics.beginFill(0xff0000, 1);
// _this._egretRender._root.graphics.drawRect(center - paddingX, ypos, paddingX * 2, h);
// _this._egretRender._root.graphics.endFill();
const bodies = Matter.Composite.allBodies(_this._engine.world);
const isAward = (i: Matter.Body) => { return i.collisionFilter.group == award }
bodies.forEach(i => {
if (!isAward(i)) return;
if (i['timer']) {
const t0 = Date.now() - i['timer'];
if (t0 > 3000)//3s之内不可再用
{
delete i['timer'];
// console.log('重新可用', Date.now() / 1000)
}
}
const { x, y } = i.position;
const xResult = x > (center - paddingX) && x < (center + paddingX);
const yResult = y > ypos && y < (ypos + h);
if (xResult && yResult && i.velocity.y > 0 && !i['timer']) {
i['timer'] = Date.now();
if (i.label == LabelType.boom) {
_this._egretRender.remove(i);
vibrate(_this, 2);
playBoom(egretRenderContainer);
_this.onBoom();
}
else if (i.label == LabelType.egg) {
_this._egretRender.remove(i);
//PanelCtrl.instance.show(ModuleTypes.SLOT_PANEL);
}
else if (i.label == LabelType.candy) {
_this._egretRender.remove(i);
//PanelCtrl.instance.show(ModuleTypes.ROTATE_PANEL);
}
else if (i.label == LabelType.gift) {
_this._egretRender.remove(i);
//PanelCtrl.instance.show(ModuleTypes.TREASURE_PANEL);
}
else {
// console.log('不是boom,重用', Date.now() / 1000);
// playScoreAni(_this.egretRenderContainer, 1)
playSuccess(_this.egretRenderContainer);
_this._egretRender.remove(i);
_this.addScore();
//checkAdd(_this);
playTextAni(_this)
}
}
})
}
const checkAdd = (that: GameView) => {
const oldscore = getScore();
const awards = getLevelData().awards;
for (const award of awards) {
if (award[0] == oldscore) {
const type = award[1];
createNewBubble(that, type);
break;
}
}
}
export default check
\ No newline at end of file
export const wall = 1;
export const basket = 2;
export const award = 4;
export const bubble = 8;
export const bubbleStandby = 16;
export const bubbleGroup = -1;
export const bubbleStandbyGroup = -2;
export const wallMask = award + bubble + bubbleStandby;
export const basketMask = award + bubble + bubbleStandby;
export const awardMask = wall + basket + bubble;
export const bubbleMask = wall + basket + award;
export const bubbleStandbyMask = wall + basket;
import { wall, wallMask, basket, basketMask } from "./collisionConfig";
import GameView from "./GameView";
const createBox = (_this:GameView) => {
//202
//385 168 640 201 695 528 644 866 392 907 109 868 57 546 118 206 0 206 0 1624 750 1624 750 0
//385 370 630 380 670 728 620 1080 370 1100 109 1090 57 728 108 370 0 370 0 1624 750 1624 750 0
const path1 = Matter.Vertices.fromPath('385 370 630 380 670 728 620 1080 370 1100 109 1090 57 728 108 370 0 370 0 1624 750 1624 750 0', null);
//430, 717
//430,920
const body = Matter.Bodies.fromVertices(400, 880, [path1], { isStatic: true, collisionFilter: { group: wall, category: wall, mask: wallMask } }, true);
Matter.World.add(_this._engine.world, body);
//118 206 385 168 385 100
//108 370 385 370 385 300
const path2 = Matter.Vertices.fromPath('108 370 385 370 385 300', null);
//425 - 10 - 100 - 10 - 10 + 1, 30 + 100 + 10 + 10 + 6
//296, 365
const body2 = Matter.Bodies.fromVertices(296, 365, [path2], { isStatic: true, collisionFilter: { group: wall, category: wall, mask: wallMask } }, true);
Matter.World.add(_this._engine.world, body2);
//290 432 324 476 326 476 313 432
//290 560 324 600 326 600 313 565
const basketpath1 = Matter.Vertices.fromPath('290 560 324 600 326 600 313 565', null);
//311 - 3 - 8 + 2+3, 452 - 5
//305, 575
const basketbody1 = Matter.Bodies.fromVertices(305, 575, [basketpath1], { isStatic: true, friction: 0, collisionFilter: { group: basket, category: basket, mask: basketMask } }, true);
Matter.World.add(_this._engine.world, basketbody1);
//479 435 443 481 441 481 456 435
//465 563 443 605 441 605 456 560
const basketpath2 = Matter.Vertices.fromPath('465 563 443 605 441 605 456 560', null);
//449 + 3 + 8 - 2 - 2-3, 452 - 5
//453, 570
const basketbody2 = Matter.Bodies.fromVertices(453, 570, [basketpath2], { isStatic: true, friction: 0, collisionFilter: { group: basket, category: basket, mask: basketMask } }, true);
Matter.World.add(_this._engine.world, basketbody2);
//311 - 3 - 8 + 2 - 5, 427
//285, 560
const basketLeft = Matter.Bodies.circle(285, 560 , 12, { isStatic: true, friction: 0, collisionFilter: { group: basket, category: basket, mask: basketMask } })
Matter.World.add(_this._engine.world, basketLeft);
//456 + 5, 427
//461, 560
const basketRight = Matter.Bodies.circle(461, 560, 12, { isStatic: true, friction: 0, collisionFilter: { group: basket, category: basket, mask: basketMask } })
Matter.World.add(_this._engine.world, basketRight);
const w = 100;
const h = 50;
//153 + w / 2, 833 + h / 2
//180 1080
const rect = _this._egretRender.rectangle(180, 1080, w, h, null, { isStatic: true, collisionFilter: { group: wall, category: wall, mask: wallMask } });
//553 - 10 - 30 - 5 + w / 2, 833 + h / 2
//560 1080
const rect2 = _this._egretRender.rectangle(560, 1080, w, h, null, { isStatic: true, collisionFilter: { group: wall, category: wall, mask: wallMask } });
const w2 = 300;
const h2 = 10;
//375, 873 + h2 / 2
//375 1100
const rect3 = _this._egretRender.rectangle(375, 1100, w2, h2, null, { isStatic: true, collisionFilter: { group: wall, category: wall, mask: wallMask } });
}
export default createBox
\ No newline at end of file
import GameView from "./GameView";
export default (that: GameView) => {
const createShape = () => {
const shape = new engine.Shape();
shape.beginFill(0, .6);
shape.drawCircle(0, 0, that._leftBtn.width / 2);
shape.endFill();
return shape
}
[that._leftBtn, that._rightBtn].forEach(btn => {
btn.addEventListener(engine.MouseEvent.MOUSE_DOWN, (e: engine.MouseEvent) => {
const btn = e.target;
engine.Tween.removeTweens(btn);
engine.Tween.get(btn)
.to({scaleY:0.9},200)
}, that);
});
[that._leftBtn, that._rightBtn].forEach(btn => {
btn.addEventListener(engine.MouseEvent.MOUSE_UP, (e: engine.MouseEvent) => {
const btn = e.target;
engine.Tween.removeTweens(btn);
engine.Tween.get(btn)
.to({scaleX:1,scaleY:1},200)
}, that);
});
[that._leftBtn, that._rightBtn].forEach(btn => {
btn.addEventListener(engine.MouseEvent.MOUSE_OUT, (e: engine.MouseEvent) => {
const btn = e.target;
engine.Tween.removeTweens(btn);
engine.Tween.get(btn)
.to({scaleX:1,scaleY:1},200)
}, that);
});
// this['rightBtn'];
const shapeLeft = createShape();
shapeLeft.x = that._leftBtn.width/2
shapeLeft.y = that._leftBtn.height/2
that._leftBtn.addChild(shapeLeft);
//shapeLeft.x = that._leftBtn.x;
//shapeLeft.y = that._leftBtn.y;
//that._leftBtn.mask = shapeLeft;
const shapeR = createShape();
shapeR.x = that._rightBtn.width/2
shapeR.y = that._rightBtn.height/2
that._rightBtn.addChild(shapeR);
// shapeR.x = that._rightBtn.x;
// shapeR.y = that._rightBtn.y;
// that._rightBtn.mask = shapeR;
shapeLeft.alpha = shapeR.alpha = 0;
}
import { getTextureByName } from "./utils";
const createBubblePic = (r: number) => {
const bubbleTexture: engine.Texture = getTextureByName('bubble');
const bubblePic = new engine.Sprite(bubbleTexture);
//bubblePic.anchorX = 76;
//bubblePic.anchorY = 78;
//bubblePic.anchorTexture.set(0.5,0.5)
//bubblePic.x = bubblePic.x-76
//bubblePic.y = bubblePic.y-78
bubblePic.scaleX = bubblePic.scaleY = r * 2 / 100; //默认球的尺寸100
return bubblePic;
}
export default createBubblePic
\ No newline at end of file
import LabelType from "./LabelType";
import createCoin from "./item/createCoin";
import createBoom from "./item/createBoom";
import createGift from "./item/createGift";
import createCandy from "./item/createCandy";
import createEgg from "./item/createEgg";
const createItem = (scale, type: LabelType) => {
const funcs = {
'boom': createBoom,
'gift': createGift,
'candy': createCandy,
'egg': createEgg,
'coin': createCoin
};
const func = funcs[type];
return func(scale);
}
export default createItem
\ No newline at end of file
import GameView from "./GameView";
import LabelType from "./LabelType";
import createItem from "./createItem";
import { award, awardMask } from "./collisionConfig";
import { getCurrentItems, getScore } from "./goldData";
export const createNewBubble = (_this: GameView, type: LabelType) => {
createBubble(_this, type, 750 / 2, 450, { x: 0, y: 0 },0.001*10);
}
const createBubble = (_this: GameView, type: LabelType, x: number, y: number, force = { x: 0, y: 0 }, density = 0.001) => {
let scale;
const size = random(85, 100);
const maxsize = 100;
scale = size / maxsize;
const baseItem = createItem(scale, type);
let angle;
angle = 0;
//气泡纹理种气泡的尺寸默认100(总体还包含气泡周围的阴影效果)
//刚体和贴图尺寸比为1:1.12
_this._egretRender.circle(x, y, (size - 17) / 2, baseItem,
{
frictionAir: 0,
collisionFilter: { group: award, category: award, mask: awardMask },
angle: angle,
label: baseItem.type,
friction: 0,
force: force,
density: density
});
}
const random = (start, end) => {
const n = end - start;
return Math.random() * n + start;
}
export const rollbackIcon = (nums: number, _this:GameView) => {
const startY = 370;
const startX = Math.random() > .5 ? 150 : 750 - 150;
createBubble(_this, LabelType.boom, startX, startY);
let count = 0;
const coinsFall = setInterval(() => {
if (count <= nums - 1) {
const startX = Math.random() > .5 ? 150 : 750 - 150;
createBubble(_this, LabelType.coin, startX, startY)
count++;
} else {
//结束
}
}, 100);
}
export default (_this: GameView) => {
const score = getScore();
const items = getCurrentItems();//[[LabelType.boom, 1], [LabelType.coin, 5]]
const list = [];
for (const item of items) {
const type = item[0];
let nums = item[1];
if (type == LabelType.coin)
nums = nums - score;
for (let i = 0; i < nums; i++) {
list.push(type);
}
}
let count = 0;
const countMax = 1;
const coinsFall = setInterval(() => {
if (count <= list.length - 1) {
const type = list[count];
createBubble(_this, type,375 + Math.random() * 200-100 , 400 + 200 +200)
count++;
} else {
//结束
}
}, 100);
}
\ No newline at end of file
interface dataTm {
x: number, //x,y,w,h为图集上的切图位置数据
y: number,
w: number,
h: number,
ox: number, //ox,oy为偏移数据,trim裁剪的数据,在orig上的偏移{x:0,y:0,width:200,height:200}
oy: number,
sw: number, //sw,sh为原始宽高
sh: number,
ro: boolean, //是否旋转
}
//简化后的格式
var expData = {
"actOverTitle.png": { "x": 1, "y": 1, "w": 474, "h": 172, "ox": 0, "oy": 0, "sw": 474, "sh": 172, "ro": false },
"hasActOverLotBtn.png": { "x": 1, "y": 175, "w": 259, "h": 85, "ox": 0, "oy": 0, "sw": 259, "sh": 85, "ro": false }
}
/**
*
* @param baseTexture
* @param altaData
* @return 返回贴图集。不常用
*/
export function createTextureSheet(baseTexture:engine.BaseTexture, altaData) {
var frames = altaData;
var frameKeys = Object.keys(frames);
let frameIndex = 0;
//要返回的贴图集合
var textures = {};
while (frameIndex < frameKeys.length) {
//名字
const i = frameKeys[frameIndex];
//数据
const data: dataTm = frames[i];
//切图上的数据
let frame: engine.Rectangle = null;
//裁切的数据
let trim: engine.Rectangle = null;
//贴图原始尺寸
const orig = new engine.Rectangle(
0,
0,
Math.floor(data.sw),
Math.floor(data.sh)
);
//如果旋转过
if (data.ro) {
frame = new engine.Rectangle(
Math.floor(data.x),
Math.floor(data.y),
Math.floor(data.h),
Math.floor(data.w)
);
} else {
frame = new engine.Rectangle(
Math.floor(data.x),
Math.floor(data.y),
Math.floor(data.w),
Math.floor(data.h)
);
}
//如果是被截掉过透明边界的
if (data.ox || data.oy) {
//其实就是在orig上切图,偏移
trim = new engine.Rectangle(
Math.floor(data.ox),
Math.floor(data.oy),
Math.floor(data.w),
Math.floor(data.h)
);
}
var texture = new engine.Texture(
baseTexture,
frame,
orig,
trim,
data.ro ? 2 : 0,
// data.anchor
);
//缓存下
engine.Texture.addToCache(texture, i);
textures[i] = texture;
frameIndex++;
}
return textures;
}
\ No newline at end of file
import BaseItem from "../../physics/BaseItem";
import { getJosnData, getJsonAsset } from "../JsonTools";
import { createTextureSheet } from "../createTextureSheet";
import { getTextureByName } from "../utils";
import LabelType from "../LabelType";
import MovieClip from "../../physics/MovieClip";
const createBoom = (scale) => {
//气泡纹理种气泡的尺寸默认100(总体还包含气泡周围的阴影效果)
let josnData = getJosnData('boom');
if(!josnData){
getJsonAsset('boom');
josnData = getJosnData('boom');
}
const boomTexture = createTextureSheet(getTextureByName('boom').baseTexture,josnData);
//炸弹纹理种炸弹的尺寸默认58,不进行缩放
//气泡和炸弹的比例为100/58
const animation = createMovieClip(boomTexture);
const baseItem = new BaseItem(animation, LabelType.boom);
baseItem.scaleX = baseItem.scaleY = scale;
return baseItem
}
const createMovieClip = (spritesheet, scale = 1) => {
const list = ['boom1.png', 'boom2.png', 'boom3.png', 'boom4.png', 'boom5.png', 'boom6.png', 'boom7.png', 'boom8.png', 'boom9.png', 'boom10.png'];
const movieclip = new MovieClip({
spritesheet: spritesheet,
frameInterval: 5,
frames: list,
position: [0, 0],
scale: scale,
anchor: [.5, .5]
});
return movieclip
}
export default createBoom
\ No newline at end of file
import BaseItem from "../../physics/BaseItem";
import { getJosnData, getJsonAsset } from "../JsonTools";
import { createTextureSheet } from "../createTextureSheet";
import { getTextureByName } from "../utils";
import LabelType from "../LabelType";
import MovieClip from "../../physics/MovieClip";
const createCandy = (scale) => {
//气泡纹理种气泡的尺寸默认100(总体还包含气泡周围的阴影效果)
let josnData = getJosnData('candy');
if(!josnData){
getJsonAsset('candy');
josnData = getJosnData('candy');
}
const boomTexture = createTextureSheet(getTextureByName('candy').baseTexture,josnData);
//炸弹纹理种炸弹的尺寸默认58,不进行缩放
//气泡和炸弹的比例为100/58
const animation = createMovieClip(boomTexture);
const baseItem = new BaseItem(animation, LabelType.candy);
baseItem.scaleX = baseItem.scaleY = scale;
return baseItem
}
const createMovieClip = (spritesheet, scale = 1) => {
const list = ['candy1.png', 'candy2.png', 'candy3.png', 'candy4.png', 'candy5.png', 'candy6.png', 'candy7.png', 'candy8.png'];
const movieclip = new MovieClip({
spritesheet: spritesheet,
frameInterval: 6,
frames: list,
position: [0, 0],
scale: scale,
anchor: [.5, .5]
});
return movieclip
}
export default createCandy
\ No newline at end of file
import BaseItem from "../../physics/BaseItem";
import LabelType from "../LabelType";
import MovieClip from "../../physics/MovieClip";
import { getTextureByName } from "../utils";
import { getJosnData, getJsonAsset } from "../JsonTools";
import { createTextureSheet } from "../createTextureSheet";
const createCoin = (scale) => {
//气泡纹理种气泡的尺寸默认100(总体还包含气泡周围的阴影效果)
let josnData = getJosnData('coin');
if(!josnData){
getJsonAsset('coin');
josnData = getJosnData('coin');
}
const texture = createTextureSheet(getTextureByName('coin').baseTexture,josnData);
const animation = createMovieClip(texture, 0.6);
const baseItem = new BaseItem(animation,LabelType.coin);
baseItem.scaleX = baseItem.scaleY = scale;
return baseItem
}
const createMovieClip = (spritesheet, scale = 1) => {
const list = ['coin1.png', 'coin2.png', 'coin3.png', 'coin4.png', 'coin5.png', 'coin6.png', 'coin7.png', 'coin8.png'];
const movieclip = new MovieClip({
spritesheet: spritesheet,
frameInterval: 6,
frames: list,
position: [0, 0],
scale: scale,
anchor: [.5, .5]
});
return movieclip
}
export default createCoin
\ No newline at end of file
import BaseItem from "../../physics/BaseItem";
import LabelType from "../LabelType";
import MovieClip from "../../physics/MovieClip";
import { getTextureByName } from "../utils";
import { getJosnData, getJsonAsset } from "../JsonTools";
import { createTextureSheet } from "../createTextureSheet";
const createEgg = (scale) => {
//气泡纹理种气泡的尺寸默认100(总体还包含气泡周围的阴影效果)
let josnData = getJosnData('egg');
if(!josnData){
getJsonAsset('gift');
josnData = getJosnData('egg');
}
const texture = createTextureSheet(getTextureByName('egg').baseTexture,josnData);
const animation = createMovieClip(texture, 0.6);
const baseItem = new BaseItem(animation,LabelType.egg);
baseItem.scaleX = baseItem.scaleY = scale;
return baseItem
}
const createMovieClip = (spritesheet, scale = 1) => {
const list = ['egg1.png', 'egg2.png', 'egg3.png', 'egg4.png', 'egg5.png', 'egg6.png', 'egg7.png', 'egg8.png', 'egg9.png'];
const movieclip = new MovieClip({
spritesheet: spritesheet,
frameInterval: 5,
frames: list,
position: [0, 0],
scale: scale,
anchor: [.5, .5]
});
return movieclip
}
export default createEgg
\ No newline at end of file
import BaseItem from "../../physics/BaseItem";
import LabelType from "../LabelType";
import MovieClip from "../../physics/MovieClip";
import { getTextureByName } from "../utils";
import { getJosnData, getJsonAsset } from "../JsonTools";
import { createTextureSheet } from "../createTextureSheet";
const createGift = (scale) => {
//气泡纹理种气泡的尺寸默认100(总体还包含气泡周围的阴影效果)
let josnData = getJosnData('gift');
if(!josnData){
getJsonAsset('gift');
josnData = getJosnData('gift');
}
const texture = createTextureSheet(getTextureByName('gift').baseTexture,josnData);
const animation = createMovieClip(texture, 0.6);
const baseItem = new BaseItem(animation,LabelType.gift);
baseItem.scaleX = baseItem.scaleY = scale;
return baseItem
}
const createMovieClip = (spritesheet, scale = 1) => {
const list = ['gift1.png', 'gift2.png', 'gift3.png', 'gift4.png', 'gift5.png', 'gift6.png', 'gift7.png', 'gift8.png', 'gift9.png', 'gift10.png'];
const movieclip = new MovieClip({
spritesheet: spritesheet,
frameInterval: 5,
frames: list,
position: [0, 0],
scale: scale,
anchor: [.5, .5]
});
return movieclip
}
export default createGift
\ No newline at end of file
/**
* Created by rockyl on 2020-02-03.
*/
// import ObjectPool = engine.ObjectPool;
// export const PoolName: string = 'goods';
// ObjectPool.registerPool(PoolName, function () {
// return new Goods();
// }, function (item: Goods, data) {
// item.reset();
// });
import MovieClip from "../physics/MovieClip";
import wait from "./wait";
import { getJosnData, getJsonAsset } from "./JsonTools";
import { createTextureSheet } from "./createTextureSheet";
import { getTextureByName } from "./utils";
export async function playMovieClip (parent: engine.Container, key, frames, frameInterval = 5){
return new Promise(async (r) => {
let josnData = getJosnData(key);
if(!josnData){
getJsonAsset(key);
josnData = getJosnData(key);
}
let texture = createTextureSheet(getTextureByName(key).baseTexture,josnData);
if (texture) {
await createMc(parent, texture, frames, frameInterval);
r(1);
}
else {
//RES.getResAsync(key);
wait(300).then(async () => {
let josnData = getJosnData(key);
if(!josnData){
getJsonAsset(key);
josnData = getJosnData(key);
}
texture = createTextureSheet(getTextureByName(key).baseTexture,josnData);
if (texture) {
await createMc(parent, texture, frames, frameInterval);
r(1);
} else
r(0);
})
}
});
}
export function createMc(parent: engine.Container, spritesheet, frames: any[], frameInterval = 5) {
return new Promise((r) => {
const movieclip = new MovieClip({
spritesheet: spritesheet,
frameInterval: frameInterval,
frames: frames,
position: [0, 150],
scale: 1,
anchor: [0, 0],
loop: false,
callBack:()=>{
setTimeout(() => {
parent.removeChild(movieclip);
r(1)
}, 100);
}
});
parent.addChild(movieclip);
// setTimeout(() => {
// parent.removeChild(movieclip);
// r(1)
// }, 1000);
// movieclip.once('boomOver', () => {
// parent.removeChild(movieclip);
// r(1)
// }, this,true)
})
}
export const playBoom = (parent) => {
return playMovieClip(parent, 'fail', ['fail1.png', 'fail2.png', 'fail3.png', 'fail4.png', 'fail5.png', 'fail6.png', 'fail7.png', 'fail8.png'], 5);
}
export const playSuccess = (parent) => {
return playMovieClip(parent, 'success', ['success1.png', 'success2.png', 'success3.png', 'success4.png', 'success5.png', 'success6.png', 'success7.png', 'success8.png', 'success9.png'], 5);
}
\ No newline at end of file
const clear = (that) => {
TextList.forEach(i => {
engine.Tween.removeTweens(that.gameHint[i]);
that.gameHint[i].alpha = 0;
})
}
const playgood = (image: engine.Image) => {
engine.Tween.get(image).set({ x: 750, alpha: 1 }).to({ x: 530.5 }, 100).wait(500).to({ alpha: 0 }, 200)
}
const playgreat = (image: engine.Image) => {
engine.Tween.get(image).set({ x: 750, alpha: 1, scaleX: .9, scaleY: .9, rotation: 20 }).to({ x: 540.5, scaleX: 1, scaleY: 1, rotation: 0 }, 200, engine.Ease.getBackOut(2)).wait(500).to({ alpha: 0 }, 200)
}
const playcool = (image: engine.Image) => {
engine.Tween.get(image).set({ x: 750, alpha: 1, scaleX: .9, scaleY: .9, rotation: 60 }).to({ x: 526.09, scaleX: 1, scaleY: 1, rotation: 0 }, 200, engine.Ease.getBackOut(7)).wait(500).to({ alpha: 0 }, 200)
}
const playperfect = (image: engine.Image) => {
engine.Tween.get(image).set({ scaleX: 0, scaleY: 0, alpha: 1, }).to({ scaleX: 1, scaleY: 1 }, 200, engine.Ease.getBackOut(10)).wait(500).to({ alpha: 0 }, 200)
// egret.Tween.get(image).set({ x: 750, alpha: 1 }).to({ x: 530.5 }, 100).wait(500).to({ alpha: 0 }, 200)
}
const playawesome = (image: engine.Image) => {
engine.Tween.get(image).set({ scaleX: 0, scaleY: 0, alpha: 1, rotation: -20 }).to({ scaleX: 1, scaleY: 1, rotation: 0 }, 200, engine.Ease.getBackOut(20)).wait(500).to({ alpha: 0 }, 200)
// egret.Tween.get(image).set({ x: 750, alpha: 1 }).to({ x: 527 }, 100).wait(500).to({ alpha: 0 }, 200)
}
const playunbelievable = (image: engine.Image) => {
// egret.Tween.get(image).set({ x: 750, alpha: 1 }).to({ x: 482.5 }, 100).wait(500).to({ alpha: 0 }, 200)
engine.Tween.get(image).set({ scaleX: 0, scaleY: 0, alpha: 1, rotation: -60 }).to({ scaleX: 1, scaleY: 1, rotation: 0 }, 200, engine.Ease.getBackOut(40)).wait(500).to({ alpha: 0 }, 200)
}
const funcs = [playgreat, playcool, playperfect, playawesome, playunbelievable];
// const funcs = [playgood, playgreat, playcool, playperfect, playawesome, playunbelievable];
let cdtimer;
// let timer = 0;
let count = 0;
export const playTextAni = async (that) => {
clear(that);
count++;
if (count >= TextList.length) count = TextList.length;
console.log(count);
const image = that.gameHint[TextList[count - 1]];
image.visible = true;
funcs[count - 1](image);
if (cdtimer > 0) clearTimeout(cdtimer);
cdtimer = setTimeout(() => {
count = 0;
console.log('clear')
}, 5000);
}
export const TextList = ['great', 'cool', 'perfect', 'awesome', 'unbelievable']
// export const TextList = ['good', 'great', 'cool', 'perfect', 'awesome', 'unbelievable']
\ No newline at end of file
import { bubbleStandbyGroup, bubbleStandby, bubbleStandbyMask } from "./collisionConfig";
import createBubblePic from "./createBubblePic";
import EgretRender from "../physics/EgretRender";
let timerLeft;
let timerRight;
export const startStandbyBubblesLeft = (egretRender: EgretRender) => {
timerLeft = setInterval(() => {
const scale = 0.2;
const p1 = { x: 180, y: 1050 };
const r = random(8, 10);
const bubblePic = createBubblePic(r);
const body = egretRender.circle(p1.x, p1.y, r, bubblePic, {
restitution: 0,
frictionAir: 0,
force: { x: random(-0.005, 0.005) * scale, y: -0.02 * scale },
collisionFilter: { group: bubbleStandbyGroup, category: bubbleStandby, mask: bubbleStandbyMask }
});
setTimeout(() => {
egretRender.remove(body);
}, 1000);
}, 700);
}
export const startStandbyBubblesRight = (egretRender: EgretRender) => {
timerRight = setInterval(() => {
const scale = 0.2;
const p2 = { x: 560, y: 1050 };
const r2 = random(8, 10);
const bubblePic2 = createBubblePic(r2);
const body2 = egretRender.circle(p2.x, p2.y, r2, bubblePic2, {
restitution: 0,
frictionAir: 0,
force: { x: random(-0.005, 0.005) * scale, y: -0.02 * scale },
collisionFilter: { group: bubbleStandbyGroup, category: bubbleStandby, mask: bubbleStandbyMask }
});
setTimeout(() => {
egretRender.remove(body2);
}, 1000);
}, 700);
}
export const stopStandbyBubblesLeft = () => {
clearInterval(timerLeft)
}
export const stopStandbyBubblesRight = () => {
clearInterval(timerRight)
}
const random = (start, end) => {
const n = end - start;
return Math.random() * n + start;
}
\ No newline at end of file
/**
* Created by rockyl on 2020-01-21.
*/
import {props} from '../props'
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 0.5 - Math.random();
});
}
export default (view: engine.DisplayObject,count=2,strength=10) => {
return new Promise((r) => {
const pos = [
{ x: strength, y: 0 },
{ x: 0, y: -strength },
{ x: -strength, y: 0 },
{ x: 0, y: strength },
{ x: 0, y: 0 },
];
let list = [];
for (let i = 0; i < count; i++) {
list = list.concat(pos);
}
const x0 = view.x;
const y0 = view.y;
let counter = list.length;
for (let i = 0; i < list.length; i++) {
const element = list[i];
setTimeout(() => {
view.x = element.x + x0;
view.y = element.y + y0;
counter--;
if (counter == 0) {
view.x = x0;
view.y = y0;
r();
};
}, 1000 / 60 * i);
}
});
}
const wait = async (duration: number) =>
new Promise(
resolve => setTimeout(resolve, duration)
);
export default wait
\ 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;
}
{
"coin1.png": {
"x": 111,
"y": 113,
"w": 109,
"h": 110,
"ox": 3,
"oy": 2,
"sw": 115,
"sh": 115,
"ro": false
},
"coin2.png": {
"x": 111,
"y": 0,
"w": 109,
"h": 111,
"ox": 3,
"oy": 2,
"sw": 115,
"sh": 115,
"ro": false
},
"coin3.png": {
"x": 96,
"y": 225,
"w": 94,
"h": 113,
"ox": 10,
"oy": 1,
"sw": 115,
"sh": 115,
"ro": false
},
"coin4.png": {
"x": 67,
"y": 340,
"w": 65,
"h": 113,
"ox": 25,
"oy": 1,
"sw": 115,
"sh": 115,
"ro": false
},
"coin5.png": {
"x": 222,
"y": 0,
"w": 24,
"h": 108,
"ox": 45,
"oy": 3,
"sw": 115,
"sh": 115,
"ro": false
},
"coin6.png": {
"x": 0,
"y": 229,
"w": 65,
"h": 114,
"ox": 25,
"oy": 0,
"sw": 115,
"sh": 115,
"ro": false
},
"coin7.png": {
"x": 0,
"y": 114,
"w": 94,
"h": 113,
"ox": 10,
"oy": 1,
"sw": 115,
"sh": 115,
"ro": false
},
"coin8.png": {
"x": 0,
"y": 0,
"w": 109,
"h": 112,
"ox": 3,
"oy": 1,
"sw": 115,
"sh": 115,
"ro": false
}
}
\ No newline at end of file
import { getTextureByName } from "../game/utils";
import LabelType from "../game/LabelType";
import MovieClip from "./MovieClip";
export default class BaseItem extends engine.Sprite {
_mc: MovieClip;
type: LabelType;
constructor(mc: MovieClip, type?: LabelType) {
super();
this.type = type;
this._mc = mc;
const bubble: engine.Texture = getTextureByName('bubble');
const bubblePic = new engine.Sprite(bubble);
bubblePic.anchorTexture.set(0.5,0.5);
//bubblePic.anchorX = 76;
//bubblePic.anchorY = 78;
//bubblePic.x = bubblePic.x-76
//bubblePic.y = bubblePic.y-78
this._mc.anchorTexture.set(0.5,0.5)
this._mc.x = bubblePic.x/4;
this._mc.y = bubblePic.y/4;
this.addChild(bubblePic);
this.addChild(this._mc);
}
get mc() { return this._mc; }
}
\ No newline at end of file
import BaseItem from "./BaseItem";
export default class EgretRender {
_root: engine.Sprite;
private _engine: Matter.Engine;
constructor(root: engine.Sprite, engine: Matter.Engine) {
this._root = root;
this._engine = engine;
}
addBody(body: Matter.Body, display: engine.DisplayObject, x, y) {
if (display) {
body['display'] = display;
this._root.addChildAt(display, 0);
display.x = x;
display.y = y;
}
return body;
}
remove(body: Matter.Body): any {
this.removeBody(body);
this.removeDisplay(body);
}
removeBody(body: Matter.Body): any {
Matter.World.remove(this._engine.world, body);
}
removeDisplay(body: Matter.Body): any {
const display: engine.DisplayObject = body['display'];
if (display && display.parent)
display.parent.removeChild(display);
}
run() {
const bodies = Matter.Composite.allBodies(this._engine.world);
// tslint:disable-next-line:prefer-for-of
for (let i = 0; i < bodies.length; i++) {
const body = bodies[i];
const display = body['display'] as engine.DisplayObject;
if (!display) continue;
// 贴图与刚体位置的小数点后几位有点不一样,需要降低精度
const x1 = Math.round(display.x)
const x2 = Math.round(body.position.x)
const y1 = Math.round(display.y)
const y2 = Math.round(body.position.y)
const distanceX = Math.abs(x1 - x2);
const distanceY = Math.abs(y1 - y2);
const precision = 1;//精度
if (distanceX > precision || distanceY > precision) {
if (display instanceof BaseItem) display.mc.resume();
} else {
if (display instanceof BaseItem) display.mc.pause();
}
display.x = body.position.x;
display.y = body.position.y;
display.rotation = this.getRotation(body.angle);
}
}
//快速方法
rectangle(x: number, y: number, width: number, height: number, display: engine.DisplayObject, options?: Matter.IChamferableBodyDefinition) {
const body = this.rectangleToRender(x, y, width, height, display, options);
this.addBodyToWorld(body);
return body;
}
circle(x: number, y: number, radius: number, display: engine.DisplayObject, options?: Matter.IChamferableBodyDefinition) {
const body = this.circleToRender(x, y, radius, display, options);
this.addBodyToWorld(body);
return body;
}
//工具方法
private addBodyToWorld(body: Matter.Body) {
Matter.World.add(this._engine.world, body);
return body;
}
private rectangleToRender(x: number, y: number, width: number, height: number, display: engine.DisplayObject, options?: Matter.IChamferableBodyDefinition) {
const body = Matter.Bodies.rectangle(x, y, width, height, options);
this.addBody(body, display, x, y);
return body;
}
private circleToRender(x: number, y: number, radius: number, display: engine.DisplayObject, options?: Matter.IChamferableBodyDefinition) {
const body = Matter.Bodies.circle(x, y, radius, options);
this.addBody(body, display, x, y);
return body;
}
private getRotation(angle: number) {
return angle / Math.PI / 2 * 360;
}
}
\ No newline at end of file
This diff is collapsed.
/**
* 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);
}
This diff is collapsed.
......@@ -15,7 +15,7 @@
},
"include": [
"libs",
"src"
"src", "src/custom/seabed-game/debug/matter.min.js"
],
"exclude": [
"node_modules"
......
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