Commit 4e6c7a50 authored by zjz1994's avatar zjz1994

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

# Conflicts:
#	dist/.DS_Store
代码暂存
parents 247d9195 e8cb5a37
No preview for this file type
This diff is collapsed.
...@@ -5102,6 +5102,7 @@ declare module engine { ...@@ -5102,6 +5102,7 @@ declare module engine {
} }
export class DisplayObject extends EventDispatcher { export class DisplayObject extends EventDispatcher {
parent;
/** /**
* 基础信息 * 基础信息
*/ */
...@@ -5121,7 +5122,7 @@ declare module engine { ...@@ -5121,7 +5122,7 @@ declare module engine {
* @member {Container} * @member {Container}
* @readonly * @readonly
*/ */
parent: any; wrapper: any;
/** /**
* 舞台 * 舞台
*/ */
......
...@@ -34,8 +34,8 @@ export default class GameView extends engine.Container { ...@@ -34,8 +34,8 @@ export default class GameView extends engine.Container {
if (this.pictures) { if (this.pictures) {
for (const pic of this.pictures) { for (const pic of this.pictures) {
if (pic && pic.parent) if (pic && pic.wrapper)
pic.parent.removeChild(pic); pic.wrapper.removeChild(pic);
} }
} }
......
/**
* Created by renjianfeng on 2020-03-13.
*/
const customId = 'recycling';
(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('recycling-start', { time: 1500, maxScore: 200, speed: 3, sound: 1 });
const d = engine.gameStage.sceneContainer.getChildAt(0);
}, 2000);
// setTimeout(() => {
// engine.globalEvent.dispatchEvent('recycling-sound-update', { sound: 1 });
// const d = engine.gameStage.sceneContainer.getChildAt(0);
// }, 10 * 100);
// setTimeout(() => {
// engine.globalEvent.dispatchEvent('recycling-start', { time: 8, maxScore: 2 });
// const d = engine.gameStage.sceneContainer.getChildAt(0);
// }, 1000 * 10);
});
engine.globalEvent.addEventListener('recycling-time-update', (e) => {
console.log(e.type, e.data);
});
engine.globalEvent.addEventListener('recycling-score-update', (e) => {
console.log(e.type, e.data);
});
engine.globalEvent.addEventListener('recycling-game-end', (e) => {
console.log(e.type, e.data);
});
engine.globalEvent.addEventListener('recycling-game-success', (e) => {
console.log(e.type, e.data);
});
}
function getAssetByUUID(uuid) {
return engine.resolveCustomAsset(customId, uuid);
}
function getProps() {
return engine.getProps(customId);
}
\ No newline at end of file
<!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="engine.1de84ff79dba19e949088de63aa75af51a515e5c.js"></script>
<script crossorigin="anonymous" src="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>
<audio style="display:none;
height: 0" id="wrongTips" preload="auto" src="https://yun.duiba.com.cn/db_games/activity/garbageSorting1.00/wrongTips.mp3">
</audio>
<audio style="display:none;
height: 0" id="go" preload="auto" src="https://yun.duiba.com.cn/db_games/activity/garbageSorting1.00/go.mp3">
</audio>
<audio style="display:none;
height: 0" id="gameOver" preload="auto" src="https://yun.duiba.com.cn/db_games/activity/garbageSorting1.00/gameOver.mp3">
</audio>
<script>
// localStorage.clear()
function playMusic(id = "bgMusic", isPlay = true) {
var media = document.getElementById(id);
if (isPlay && media.paused) {
media.play();
}
if (!isPlay && !media.paused) {
media.pause();
}
}
</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"
}];
function loadAssets(customModuleAssets, onProgress, onComplete) {
return engine.loadAssets(assets.concat(...customModuleAssets), onProgress, onComplete);
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
/**
* Created by rockyl on 2020-01-21.
*/
let customModuleProps = {
};
This diff is collapsed.
import { getTextureByName } from "./utils";
export default class Conveyor extends engine.Sprite {
idx0: engine.Sprite;
idx1: engine.Sprite;
idx2: engine.Sprite;
idx3: engine.Sprite;
idx4: engine.Sprite;
constructor() {
super();
this.y = 904.21;
const sp = new engine.Sprite(getTextureByName('conveyor'));
this.addChild(sp);
this.idx0 = this.createItem(75, 50);
this.idx1 = this.createItem(225, 50);
this.idx2 = this.createItem(375, 50);
this.idx3 = this.createItem(525, 50);
this.idx4 = this.createItem(675, 50);
}
clear() {
this.clearItem(this.idx0)
this.clearItem(this.idx1)
this.clearItem(this.idx2)
this.clearItem(this.idx3)
this.clearItem(this.idx4)
}
private clearItem(idx: engine.Sprite) {
if (idx.children.length > 0)
idx.removeChildAt(0)
}
private createItem(x, y) {
const sp = new engine.Sprite();
this.addChild(sp);
sp.x = x;
sp.y = y;
// const g = new engine.Graphics;
// g.beginFill(0xff0000);
// g.drawRect(0,0,100,100);
// g.endFill();
// sp.addChild(g);
return sp
}
}
\ No newline at end of file
This diff is collapsed.
/**
* Created by rockyl on 2018/8/16.
*/
import { getTextureByName, playSound } from "../../../recycling/src/game/utils";
import { props } from "../props";
import Conveyor from "./Conveyor";
import Conveyors from "./Conveyors";
import uiConfig from "./uiConfig";
import getGuideInfo, { setGuide } from "./utils/getGuideInfo";
import CountDownGroup from "./views/CountDownGroup";
import GuideView from "./views/guideView";
import WrongTips from "./views/WrongTips";
import RightTips from "./views/RightTips";
export default class GameView extends engine.Container {
private _timer;
private _timeCounter = 0;
uiMap: any;
wetWaste: engine.Rectangle;
harmfulWaste: engine.Rectangle;
dryWaste: engine.Rectangle;
recoverableWaste: engine.Rectangle;
countdown: CountDownGroup;
guide: GuideView;
conveyors: Conveyors;
wrongTips: WrongTips;
rightTips: RightTips;
constructor() {
super();
this.once(engine.Event.ADDED_TO_STAGE, this.setup, this);
}
configUI() {
const uiMap: any = {};
this.uiMap = uiMap;
const config = uiConfig();
for (const item of config) {
const { id, texture, pos, anchor } = item;
const sp = new engine.Sprite(getTextureByName(texture));
this.addChild(sp);
uiMap[id] = sp;
if (anchor) {
sp.anchorX = anchor[0];
sp.anchorY = anchor[1];
}
if (pos) {
sp.x = pos[0];
sp.y = pos[1];
if (anchor) {
sp.x = pos[0] - sp.anchorX;
sp.y = pos[1] - sp.anchorY;
}
}
}
this.configConveyors();
this.createRects();
this.countdown = new CountDownGroup();
this.addChild(this.countdown)
this.guide = new GuideView();
this.addChild(this.guide);
this.wrongTips = new WrongTips();
this.rightTips = new RightTips()
this.addChild(this.wrongTips)
this.addChild(this.rightTips)
}
private createRects() {
this.wetWaste = this.createRect(74, 552, 301, 293, 0xffffff);
this.harmfulWaste = this.createRect(75, 247, 300, 293, 0xff0000);
this.dryWaste = this.createRect(389, 249, 286, 291, 0x000000);
this.recoverableWaste = this.createRect(389, 551, 287, 292, 0x0000ff);
}
createRect(x, y, w, h, c) {
const rect = new engine.Rectangle(x, y, w, h);
const sp = new engine.Sprite();
this.addChild(sp);
sp.x = x;
sp.y = y;
const g = new engine.Graphics;
g.alpha = 0.0;
g.beginFill(c);
g.drawRect(0, 0, w, h);
g.endFill();
sp.addChild(g);
return rect;
}
private configConveyors() {
const conveyor0 = new Conveyor();
const conveyor1 = new Conveyor();
this.addChild(conveyor0);
this.addChild(conveyor1);
conveyor0.x = 0;
conveyor1.x = 764;
this.conveyors = new Conveyors(this);
this.conveyors.initData(conveyor0, conveyor1)
}
playAni() {
let idlerWheels = ['idler0', 'idler1', 'idler2', 'idler3', 'idler4', 'idler5', 'idler6'];
idlerWheels = idlerWheels.map(i => this.uiMap[i]);
idlerWheels.forEach(i => {
engine.Tween.get(i, { loop: true }).to({ rotation: -360 }, 1000);
})
}
stopAni() {
let idlerWheels = ['idler0', 'idler1', 'idler2', 'idler3', 'idler4', 'idler5', 'idler6'];
idlerWheels = idlerWheels.map(i => this.uiMap[i]);
idlerWheels.forEach(i => {
engine.Tween.removeTweens(i);
})
}
async start() {
console.log('on start')
this._timeCounter = 0;
if (!getGuideInfo()) {
await this.guide.startGuide();
setGuide();
}
this.conveyors.clear()
await this.countdown.startCountDown();
this.startGame();
engine.globalEvent.dispatchEvent('recycling-time-update', {
second: this.getSecond(),
});
this._timer = setInterval(() => {
this.onTimer();
}, 1000);
}
private startGame() {
this.playAni();
this.conveyors.startConveyors();
}
private stopGame() {
this.stopAni();
}
getSecond() {
return props.time - this._timeCounter
}
onTimer() {
this._timeCounter++;
engine.globalEvent.dispatchEvent('recycling-time-update', {
second: this.getSecond(),
});
if (this.getSecond() == 0) {
this.stop();
this.conveyors.timeout();
if (props.sound) playSound("gameOverMp3")
}
}
stop() {
clearInterval(this._timer);
this.stopGame();
}
setup() {
console.log('onSteup', props);
this.configUI();
}
onDown(e: engine.MouseEvent) {
}
stageOnUp(e) {
}
private onSuccess() {
}
onMove(e: engine.MouseEvent) {
}
}
/**
* Created by rockyl on 2020-01-09.
*/
import GameView from "./GameView";
import { injectProps } from "../props";
export class GameWrapper extends engine.Container {
updateSound(event: engine.Event) {
injectProps(event.data);
}
// private _status;
private _gameView: GameView;
constructor() {
super();
engine.globalEvent.addEventListener('recycling-start', this.start, this);
engine.globalEvent.addEventListener('recycling-sound-update', this.updateSound, this);
engine.globalEvent.addEventListener('recycling-stop', this.stop, this);
//创建实例
let gameView = this._gameView = new GameView();
this.addChild(gameView);
}
start(event: engine.Event) {
injectProps(event.data);
this._gameView.start();
}
stop(event: engine.Event) {
this._gameView.stop();
}
}
import { GarbageTypes } from './GarbageTypes';
export default class GarbageConfig {
public static config: any[] = [
{ name: "保鲜盒", source: "g00", type: GarbageTypes.recoverableWaste, width: 129, height: 111 },
{ name: "报纸", source: "g01", type: GarbageTypes.recoverableWaste, width: 138, height: 144 },
{ name: "贝壳", source: "g02", type: GarbageTypes.dryWaste, width: 79, height: 117 },
{ name: "冰箱", source: "g03", type: GarbageTypes.recoverableWaste, width: 63, height: 151 },
{ name: "菜梗菜叶", source: "g04", type: GarbageTypes.wetWaste, width: 144, height: 98 },
{ name: "残枝落叶", source: "g05", type: GarbageTypes.wetWaste, width: 120, height: 99 },
{ name: "茶叶渣", source: "g06", type: GarbageTypes.wetWaste, width: 86, height: 96 },
{ name: "尘土", source: "g07", type: GarbageTypes.dryWaste, width: 109, height: 114 },
{ name: "创口贴", source: "g08", type: GarbageTypes.dryWaste, width: 112, height: 90 },
{ name: "大骨头", source: "g09", type: GarbageTypes.dryWaste, width: 89, height: 101 },
{ name: "普通干电池", source: "g11", type: GarbageTypes.dryWaste, width: 89, height: 131 },
{ name: "方便面盒", source: "g12", type: GarbageTypes.dryWaste, width: 89, height: 168 },
{ name: "废弃食用油脂", source: "g13", type: GarbageTypes.wetWaste, width: 131, height: 164 },
{ name: "骨骼内脏", source: "g14", type: GarbageTypes.wetWaste, width: 104, height: 82 },
{ name: "锅具", source: "g15", type: GarbageTypes.recoverableWaste, width: 119, height: 149 },
{ name: "果核", source: "g16", type: GarbageTypes.wetWaste, width: 99, height: 95 },
{ name: "果皮", source: "g17", type: GarbageTypes.wetWaste, width: 115, height: 127 },
{ name: "化妆品", source: "g18", type: GarbageTypes.harmfulWaste, width: 67, height: 151 },
{ name: "鸡蛋壳", source: "g19", type: GarbageTypes.wetWaste, width: 99, height: 107 },
{ name: "剪刀", source: "g20", type: GarbageTypes.recoverableWaste, width: 96, height: 127 },
{ name: "胶带", source: "g21", type: GarbageTypes.dryWaste, width: 87, height: 113 },
{ name: "榴莲壳", source: "g22", type: GarbageTypes.dryWaste, width: 136, height: 116 },
{ name: "毛巾", source: "g23", type: GarbageTypes.recoverableWaste, width: 108, height: 96 },
{ name: "纽扣电池", source: "g24", type: GarbageTypes.harmfulWaste, width: 87, height: 89 },
{ name: "破旧陶瓷罐", source: "g25", type: GarbageTypes.dryWaste, width: 110, height: 125 },
{ name: "杀虫剂", source: "g26", type: GarbageTypes.harmfulWaste, width: 64, height: 160 },
{ name: "剩菜剩饭", source: "g27", type: GarbageTypes.wetWaste, width: 128, height: 96 },
{ name: "手机", source: "g28", type: GarbageTypes.recoverableWaste, width: 82, height: 142 },
{ name: "书本", source: "g29", type: GarbageTypes.recoverableWaste, width: 106, height: 132 },
{ name: "玻璃杯", source: "g30", type: GarbageTypes.recoverableWaste, width: 62, height: 119 },
{ name: "水银温度计", source: "g31", type: GarbageTypes.harmfulWaste, width: 109, height: 162 },
{ name: "水银血压计", source: "g32", type: GarbageTypes.harmfulWaste, width: 115, height: 147 },
{ name: "塑料桶", source: "g33", type: GarbageTypes.recoverableWaste, width: 92, height: 131 },
{ name: "卫生纸", source: "g34", type: GarbageTypes.dryWaste, width: 92, height: 132 },
{ name: "污染织物", source: "g35", type: GarbageTypes.dryWaste, width: 128, height: 139 },
{ name: "污染纸张", source: "g36", type: GarbageTypes.dryWaste, width: 96, height: 136 },
{ name: "洗衣机", source: "g37", type: GarbageTypes.recoverableWaste, width: 87, height: 157 },
{ name: "烟蒂", source: "g38", type: GarbageTypes.dryWaste, width: 87, height: 124 },
{ name: "药品", source: "g39", type: GarbageTypes.harmfulWaste, width: 109, height: 131 },
{ name: "药品包装", source: "g40", type: GarbageTypes.harmfulWaste, width: 108, height: 125 },
{ name: "椰子壳", source: "g41", type: GarbageTypes.dryWaste, width: 104, height: 119 },
{ name: "衣服", source: "g42", type: GarbageTypes.recoverableWaste, width: 83, height: 137 },
{ name: "衣架", source: "g43", type: GarbageTypes.recoverableWaste, width: 132, height: 125 },
{ name: "易拉罐", source: "g44", type: GarbageTypes.recoverableWaste, width: 65, height: 133 },
{ name: "荧光灯", source: "g45", type: GarbageTypes.harmfulWaste, width: 90, height: 118 },
{ name: "油漆桶", source: "g46", type: GarbageTypes.harmfulWaste, width: 65, height: 143 },
{ name: "一次性纸杯", source: "g47", type: GarbageTypes.dryWaste, width: 76, height: 116 },
{ name: "纸尿裤", source: "g48", type: GarbageTypes.dryWaste, width: 93, height: 138 },
{ name: "纸箱", source: "g49", type: GarbageTypes.recoverableWaste, width: 112, height: 118 },
{ name: "指甲油", source: "g50", type: GarbageTypes.harmfulWaste, width: 64, height: 138 },
];
}
export enum GarbageTypes {
recoverableWaste='recoverableWaste',
harmfulWaste='harmfulWaste',
wetWaste='wetWaste',
dryWaste='dryWaste'
}
import { GarbageTypes } from "./GarbageTypes"
export default (list: any[]) => {
let tmp = [];
const contains = (val) => {
for (const i of tmp) {
if (val.targetType == i.targetType && val.itemType == i.itemType && val.itemName == i.itemName)
return true;
}
return false;
}
list.forEach(i => {
if (!contains(i))
tmp.push(i)
})
list = tmp;
tmp = [];
const nameList = [];
const contains2 = (val) => {
for (const i of tmp) {
if (val.itemName == i.itemName) {
nameList.push(i.itemName);
return true;
}
}
return false;
}
list.forEach(i => {
if (!contains2(i))
tmp.push(i)
})
list = tmp;
list.forEach(i=>{
if(nameList.indexOf(i.itemName) !=-1) {
i.targetType=i.itemType
}
})
return list.map(i => {
return {
'targetName': getTargetName(i.targetType),
'isCorrect': i.targetType == i.itemType,
'itemName': i.itemName,
'itemTypeName':getTargetName(i.itemType)
}
})
}
const getTargetName = (type: GarbageTypes) => {
switch (type) {
case GarbageTypes.recoverableWaste:
return '可回收物'
break;
case GarbageTypes.harmfulWaste:
return '有害垃圾'
break;
case GarbageTypes.wetWaste:
return '湿垃圾'
break;
case GarbageTypes.dryWaste:
return '其他垃圾'
break;
default:
break;
}
}
\ No newline at end of file
/**
* Created by rockyl on 2020-02-03.
*/
import {Goods} from "./Goods";
import ObjectPool = engine.ObjectPool;
export const PoolName: string = 'goods';
ObjectPool.registerPool(PoolName, function () {
return new Goods();
}, function (item: Goods, data) {
item.reset();
});
import { props } from "../props";
const urls = [];
const picMap = {};
const posMap = {};
export default (parent, url, MAX_COL, MAX_ROW) => {
if (picMap[url]) {
const pics:any[] = picMap[url];
for (const pic of pics) {
parent.addChild(pic);
}
return [picMap[url], posMap[url]]
}
const W = props.W;
const H = props.H;
const GAP = props.GAP;
const spr = [];
const pos = []
for (let row = 0; row < MAX_ROW; row++) {
for (let col = 0; col < MAX_COL; col++) {
const child = engine.Sprite.fromImage(url);
spr.push(child);
child.scaleX = 1 / MAX_COL;
child.scaleY = 1 / MAX_ROW;
parent.addChild(child);
child.x = col * (W / MAX_COL + GAP);
child.y = row * (H / MAX_ROW + GAP);
pos.push([child.x, child.y]);
// child.texture.addEventListener('update', () => {
child.addEventListener(engine.Event.COMPLETE, () => {
const uvs = new Float32Array([
col / MAX_COL,
row / MAX_ROW,
(col + 1) / MAX_COL,
row / MAX_ROW,
(col + 1) / MAX_COL,
(row + 1) / MAX_ROW,
col / MAX_COL,
(row + 1) / MAX_ROW,
]);
child.uvs = uvs;
// spr.push(child);
});
}
}
picMap[url] = spr.concat([]);
posMap[url] = pos.concat([]);;
// console.log(spr);
return [spr, pos];
};
export default () => {
return [
{
id: 'playBg',
texture: 'playBg'
},
{
id: 'idler0',
texture: 'idlerWheel',
pos: [75, 1038],
anchor: [20, 21.5]
},
{
id: 'idler1',
texture: 'idlerWheel',
pos: [175, 1038],
anchor: [20, 21.5]
},
{
id: 'idler2',
texture: 'idlerWheel',
pos: [275, 1038],
anchor: [20, 21.5]
},
{
id: 'idler3',
texture: 'idlerWheel',
pos: [375, 1038],
anchor: [20, 21.5]
},
{
id: 'idler4',
texture: 'idlerWheel',
pos: [475, 1038],
anchor: [20, 21.5]
},
{
id: 'idler5',
texture: 'idlerWheel',
pos: [575, 1038],
anchor: [20, 21.5]
},
{
id: 'idler6',
texture: 'idlerWheel',
pos: [675, 1038],
anchor: [20, 21.5]
},
]
}
\ 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
export default (view, rect: engine.Rectangle) => {
const { x, y } = view;
const { width, height } = view.texture
if (x > rect.x && y > rect.y && (x + width) < (rect.x + rect.width) && (y + height) < (rect.y + rect.height)) {
return true
}
return false;
}
export default () => {
//0 未引导
if (!window.localStorage) {
return 0
}
return localStorage.getItem('recyclingGuide')
}
export const setGuide = () => {
if (window.localStorage)
localStorage.setItem('recyclingGuide', '1')
}
\ No newline at end of file
export default (d:engine.DisplayObject)=>{
if(d && d.parent) {
d.parent.removeChild(d)
}
}
\ No newline at end of file
export default (e, arr)=> {
let index = arr.indexOf(e);
if (index >= 0) {
arr.splice(index, 1)
}
}
\ No newline at end of file
export default (arr): any =>{
let i = arr.length;
while (i) {
let j = Math.floor(Math.random() * i--); //5555
[arr[j], arr[i]] = [arr[i], arr[j]];
}
return arr;
}
\ No newline at end of file
import createBg from "./createBg";
import createImg from "./createImg";
import { props } from "../../props";
import { playSound } from "../utils";
export default class CountDownGroup extends engine.Sprite {
num1: engine.Sprite;
num2: engine.Sprite;
num3: engine.Sprite;
go: engine.Sprite;
constructor() {
super();
this.addChild(createBg(.6))
this.num1 = createImg('num1')
this.num2 = createImg('num2')
this.num3 = createImg('num3')
this.go = createImg('go')
this.go.anchorX = 240
this.go.anchorY = 171.5
this.num1.anchorX = 125.5
this.num1.anchorY = 189
this.num2.anchorX = 149.5
this.num2.anchorY = 191.5
this.num3.anchorX = 148.5
this.num3.anchorY = 191.5
this.go.x = 750 / 2 - 240
this.go.y = 525 - 171.5
this.num1.x = 750 / 2 - 125.5
this.num1.y = 529 - 189
this.num2.x = 750 / 2 - 149.5
this.num2.y = 526 - 191.5
this.num3.x = 750 / 2 - 148.5
this.num3.y = 525 - 191.5
this.addChild(this.num1)
this.addChild(this.num2)
this.addChild(this.num3)
this.addChild(this.go)
this.visible = false;
this.reset();
}
private reset() {
this.go.alpha = this.num1.alpha = this.num2.alpha = this.num3.alpha = 0;
this.go.scaleX = this.num1.scaleX = this.num2.scaleX = this.num3.scaleX = 3;
this.go.scaleY = this.num1.scaleY = this.num2.scaleY = this.num3.scaleY = 3;
}
async startCountDown() {
return new Promise((r) => {
this.reset();
this.visible = true;
this.num3.alpha = 1;
let n3 = engine.Tween.get(this.num3);
if (props.sound) {
playSound("numCountDown");
}
n3.to({ scaleX: 0.8, scaleY: 0.8 }, 200).to({ scaleX: 1, scaleY: 1 }, 100).wait(500).to({ scaleX: 0, scaleY: 0 }, 200).call(() => {
this.num2.alpha = 1;
let n2 = engine.Tween.get(this.num2);
if (props.sound) {
playSound("numCountDown");
}
n2.to({ scaleX: 0.8, scaleY: 0.8 }, 200).to({ scaleX: 1, scaleY: 1 }, 100).wait(500).to({ scaleX: 0, scaleY: 0 }, 200).call(() => {
this.num1.alpha = 1;
let n1 = engine.Tween.get(this.num1);
if (props.sound) {
playSound("numCountDown");
}
n1.to({ scaleX: 0.8, scaleY: 0.8 }, 200).to({ scaleX: 1, scaleY: 1 }, 100).wait(500).to({ scaleX: 0, scaleY: 0 }, 200).call(() => {
this.go.alpha = 1;
let go = engine.Tween.get(this.go);
if (props.sound) {
if (props.sound) playSound("goMp3");
}
go.to({ scaleX: 0.8, scaleY: 0.8 }, 200).to({ scaleX: 1, scaleY: 1 }, 100).wait(500).call(() => {
this.visible = false;
r()
})
})
})
})
})
}
}
\ No newline at end of file
import { getTextureByName, playSound } from "../utils";
import { props } from "../../props";
export default class RightTips extends engine.Sprite {
img: engine.Image;
txt: engine.TextField;
private SCORE = props.onceScore || 2;
constructor() {
super();
this.img = new engine.Image();
this.img.texture = getTextureByName('rightTips')
this.addChild(this.img);
this.img.anchorX = 88 / 2;
this.img.anchorY = 85 / 2;
this.visible = false;
this.txt = new engine.TextField();
this.addChild(this.txt)
this.txt.text = '+' + this.SCORE
this.txt.size = 60;
this.txt.fillColor = '#437726'
// this.txt.bold = true
engine.playSound
}
play(rect: engine.Rectangle) {
if (props.sound) {
playSound("rightTipsSound");
}
this.visible = true;
this.txt.x = 100;
engine.Tween.get(this.txt).set({ y: 60, alpha: 1 })
.to({ y: -50 }, 500)
.to({ alpha: 0 })
const DUR = 70;
engine.Tween.get(this.img).set({ x: 0, y: 0, scaleX: 0, scaleY: 0, alpha: 1 })
.to({ scaleX: 1, scaleY: 1 }, 200, engine.Ease.getBackOut(1))
.wait(200)
.to({ alpha: 0 }, 300)
this.x = rect.x + 180;
this.y = rect.y;
}
}
\ No newline at end of file
import { getTextureByName, playSound } from "../utils";
import { GarbageTypes } from "../datas/GarbageTypes";
import GameView from "../GameView";
import { props } from "../../props";
export default class WrongTips extends engine.Sprite {
img: engine.Image;
constructor() {
super();
this.img = new engine.Image();
this.img.texture = getTextureByName('wrongTips')//wrongTips
this.addChild(this.img);
this.img.anchorX = 88 / 2;
this.img.anchorY = 85 / 2;
this.visible = false;
}
play(rect: engine.Rectangle) {
this.visible = true;
if (props.sound) {
playSound("wrongTipsMp3");
}
const dur = 70;
const stren = 20;
engine.Tween.get(this.img).set({ x: 0, y: 0, scaleX: 1, scaleY: 1, alpha: 1 })
.to({ x: stren }, dur)
.to({ x: 0 }, dur)
.to({ x: -stren }, dur)
.to({ x: 0 }, dur)
.wait(200)
.to({ alpha: 0 }, 300)
this.x = rect.x + 180;
this.y = rect.y;
}
}
export const getTargetRect = (targetType, gameview: GameView) => {
switch (targetType) {
case GarbageTypes.dryWaste:
return gameview.dryWaste
break;
case GarbageTypes.wetWaste:
return gameview.wetWaste
break;
case GarbageTypes.harmfulWaste:
return gameview.harmfulWaste
break;
case GarbageTypes.recoverableWaste:
return gameview.recoverableWaste
break;
default:
break;
}
}
\ No newline at end of file
export default (a=1)=>{
const rect = new engine.Graphics();
rect.beginFill(0)
rect.drawRect(0,0,750,1624)
rect.endFill();
rect.alpha=a
return rect
}
\ No newline at end of file
import { getTextureByName } from "../utils";
export default (texture)=>{
return new engine.Sprite(getTextureByName(texture));
}
\ No newline at end of file
import createBg from "./createBg";
import createImg from "./createImg";
import { createSvga } from "../utils";
export default class GuideView extends engine.Sprite {
guideBg: engine.Sprite;
guideEle: engine.Sprite;
svga: svga.Svga;
constructor() {
super();
this.initUI();
this.visible = false;
}
initUI() {
this.addChild(createBg(.6))
this.guideBg = createImg('guideBg')
this.addChild(this.guideBg)
this.guideEle = createImg('guideEle')
this.addChild(this.guideEle)
this.guideBg.x = 393;
this.guideBg.y = 552;
this.guideEle.x = 361;
this.guideEle.y = 877;
this.guideEle.anchorX=14;
this.guideEle.anchorY=88;
this.guideEle.mouseEnabled = this.guideEle.mouseChildren = true;
let svga = createSvga("guideTips");
this.svga = svga
this.addChild(svga);
svga.gotoAndStop(1);
svga.mouseEnabled = svga.mouseChildren = false;
}
checkHit(x, y, w, h) {
const rect = new engine.Rectangle(393, 552, 281, 320)
if (x > rect.x && y > rect.y && (x + w) < (rect.x + rect.width) && (y + h) < (rect.y + rect.height)) {
return true
}
return false;
}
async startGuide() {
return new Promise((r) => {
this.visible = true;
this.svga.gotoAndStop(1);
this.svga.play(false, true)
this.guideEle.scaleX = 1;
this.guideEle.scaleY = 1;
let offset = [0, 0]
const guideOver = () => {
this.guideEle.removeEventListener(engine.MouseEvent.MOUSE_DOWN, ondown, this)
this.guideEle.anchorX=14;
this.guideEle.anchorY=44;
engine.Tween.get(this.guideEle).to({scaleX:0,scaleY:0},300).call(()=>{
this.visible = false;
r();
});
}
const onUp = (e: engine.MouseEvent) => {
this.stage.removeEventListener(engine.MouseEvent.MOUSE_MOVE, onMove, this)
if (this.checkHit(this.guideEle.x, this.guideEle.y, this.guideEle.width, this.guideEle.height)) {
guideOver();
} else {
this.svga.visible = true;
this.guideEle.x = 361;
this.guideEle.y = 877;
engine.Tween.get(this.guideEle).set({scaleX:0,scaleY:0}).to({scaleX:1,scaleY:1},300)
}
}
const onMove = (e: engine.MouseEvent) => {
this.guideEle.x = e.stageX - offset[0];
this.guideEle.y = e.stageY - offset[1];
}
const ondown = (e: engine.MouseEvent) => {
offset = [e.localX, e.localY]
this.svga.visible = false;
this.stage.once(engine.MouseEvent.MOUSE_UP, onUp, this)
this.stage.addEventListener(engine.MouseEvent.MOUSE_MOVE, onMove, this)
}
this.guideEle.addEventListener(engine.MouseEvent.MOUSE_DOWN, ondown, this)
})
}
}
\ 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);
}
...@@ -46,7 +46,7 @@ class RedPack extends engine.Image { ...@@ -46,7 +46,7 @@ class RedPack extends engine.Image {
this.x = this._pos.x += speedX; this.x = this._pos.x += speedX;
this.y = this._pos.y += speedY; this.y = this._pos.y += speedY;
this.parent.localToGlobal(this._pos, this._globalPos); this.wrapper.localToGlobal(this._pos, this._globalPos);
const {_globalPos: {x, y}} = this; const {_globalPos: {x, y}} = this;
if (y < -height || y > this.stage.height) { if (y < -height || y > this.stage.height) {
return true; return true;
......
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