Commit 996b1a1d authored by 范雪寒's avatar 范雪寒

feat:

parent ecd65728
This diff is collapsed.
{
"ver": "1.0.1",
"uuid": "3fdeea1b-2b0d-47aa-93f5-2ef9fcbc2ae4",
"subMetas": {}
}
\ No newline at end of file
{"name":"mao","imagePath":"mao_tex.png","SubTexture":[{"name":"猫01/影子","x":1,"height":66,"y":343,"width":337},{"name":"猫01/尾巴","x":1,"height":109,"y":188,"width":175},{"name":"猫01/右腿","x":178,"height":117,"y":188,"width":104},{"name":"猫01/左腿","x":1,"height":115,"y":569,"width":64},{"name":"猫01/右手","x":427,"height":122,"y":590,"width":69},{"name":"猫01/左手","x":301,"height":74,"y":590,"width":124},{"name":"猫01伸/左手伸直","x":299,"height":169,"y":1,"width":168},{"name":"猫01伸/右手伸直","x":299,"height":169,"y":172,"width":168},{"name":"猫01/身体","x":340,"height":180,"y":343,"width":122},{"name":"猫01/领带","x":1,"height":156,"y":411,"width":120},{"name":"猫01/右耳","x":155,"height":76,"y":602,"width":90},{"name":"猫01/左耳","x":67,"height":85,"y":602,"width":86},{"name":"猫01/组_1","x":1,"height":185,"y":1,"width":296},{"name":"猫01/右眼","x":1,"height":60,"y":686,"width":59},{"name":"猫01/右眉毛","x":67,"height":5,"y":595,"width":33},{"name":"猫01/左眼","x":247,"height":60,"y":666,"width":59},{"name":"猫01/左眉毛","x":247,"height":12,"y":602,"width":31},{"name":"猫01/眼镜","x":301,"height":63,"y":525,"width":170},{"name":"猫01/胡子","x":123,"height":85,"y":515,"width":176},{"name":"猫01/鼻子","x":67,"height":24,"y":569,"width":28},{"name":"猫01/嘴","x":1,"height":30,"y":299,"width":65},{"name":"猫01/帽子","x":123,"height":102,"y":411,"width":158}],"height":1024,"width":512}
\ No newline at end of file
{
"ver": "1.0.1",
"uuid": "45272f38-1b21-49e6-9941-a9d0b08f0f0b",
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "10cccc1d-7177-49ca-8012-64e2205d04c5",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 512,
"height": 1024,
"platformSettings": {},
"subMetas": {
"mao_tex": {
"ver": "1.0.4",
"uuid": "34e252fc-26d1-4940-81c2-42bc7414ff0d",
"rawTextureUuid": "10cccc1d-7177-49ca-8012-64e2205d04c5",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": -7.5,
"offsetY": 138.5,
"trimX": 1,
"trimY": 1,
"width": 495,
"height": 745,
"rawWidth": 512,
"rawHeight": 1024,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
......@@ -758,7 +758,7 @@
}
],
"_armatureName": "Armature",
"_animationName": "normal",
"_animationName": "",
"_preCacheMode": 0,
"_cacheMode": 0,
"playTimes": 1,
......@@ -777,7 +777,7 @@
"__uuid__": "4d383739-c916-4c07-8eb0-933686886df6"
},
"_N$_defaultArmatureIndex": 0,
"_N$_animationIndex": 1,
"_N$_animationIndex": 0,
"_N$_defaultCacheMode": 0,
"_N$timeScale": 1,
"_N$debugBones": false,
......
This diff is collapsed.
This diff is collapsed.
import { NetworkHelper } from "./NetworkHelper";
import { asyncDelay } from "./util";
export class AI {
networkHelper: NetworkHelper;
playerData: any;
_status = {
Red: 0,
Blue: 0,
letter: '',
current: 'Blue'
};
constructor(networkHelper: NetworkHelper, playerData: any) {
this.networkHelper = networkHelper;
this.playerData = playerData;
}
async onFrameEvent(event) {
console.log('AI get event: ' + JSON.stringify(event));
if (event.type == 'SERVER_updateStatus') {
this._status = JSON.parse(JSON.stringify(event.status));
} else if (event.type == 'SERVER_playerRoll') {
this._status.letter = event.letter;
if (this.playerData.color == this._status.current) {
await asyncDelay(Math.random() * 3 + 11);
}
} else if (event.type == 'SERVER_playerRight') {
this._status.letter = '';
this._status[event.color] = event.idx;
this.changeSide();
} else if (event.type == 'SERVER_playerWrong') {
this._status.letter = '';
this.changeSide();
}
if (this.playerData.color == this._status.current) {
await asyncDelay(Math.random() * 3 + 2);
if (this._status.letter == '') {
this.networkHelper.sendFrame({
type: 'roll',
uuid: this.playerData.uuid
});
} else {
const idx = this.getNextRightIdx();
if (Math.random() > 0.5) {
this.networkHelper.sendFrame({
type: 'right',
idx: idx,
uuid: this.playerData.uuid,
color: this.playerData.color
});
} else {
this.networkHelper.sendFrame({
type: 'wrong',
uuid: this.playerData.uuid,
color: this.playerData.color
});
}
}
}
}
changeSide() {
if (this._status.current == 'Red') {
this._status.current = 'Blue';
} else {
this._status.current = 'Red';
}
}
getNextRightIdx() {
const board = cc.find('Canvas/bg/chessBoard/boardItems');
const startIdx = this._status[this._status.current];
for (let i = startIdx + 1; i < board.children.length; i++) {
const targetNode = board.children[i];
const itemData = targetNode.getComponent('ItemData');
if (itemData.letter.toLowerCase() == this._status.letter.toLowerCase()) {
return i;
}
}
return -1;
}
}
\ No newline at end of file
{
"ver": "1.0.8",
"uuid": "8a141335-ae7b-4b46-91f0-06b28cf11902",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
import { asyncPlayDragonBoneAnimation } from "./util";
const { ccclass, property } = cc._decorator;
@ccclass
......@@ -93,6 +95,8 @@ export default class SceneComponent extends cc.Component {
cc.find('left', this.node).addChild(headNode);
} else {
cc.find('right', this.node).addChild(headNode);
const vs = cc.find('vs', this.node);
asyncPlayDragonBoneAnimation(vs, 'normal', 1);
}
const rate = Math.min(1, this._playerList.length / this._maxPlayerNum);
......
......@@ -124,7 +124,7 @@ export class NetworkHelper {
};
this.room.matchRoom(matchRoomPara, event => {
console.log(JSON.stringify(event))
// console.log(JSON.stringify(event))
if (event.code === 0) {
cc.log("匹配成功: " + event.data.roomInfo.id);
const player = event.data.roomInfo.playerList.find(player => player.name == playerName);
......
import { RandomInt } from "../script/util";
import { asyncDelay, RandomInt } from "../script/util";
import { AI } from "./AI";
import { NetworkHelper } from "./NetworkHelper";
export class GameServer {
......@@ -31,28 +32,28 @@ export class GameServer {
this.networkHelper.startFrameSync();
}
addPlayer(player) {
async addPlayer(player) {
console.log('addPlayer');
this.playerList.push({
name: this.nameList.splice(0, 1)[0],
uuid: player.uuid,
color: player.uuid == this.networkHelper.room.roomInfo.owner ? 'Blue' : 'Red',
isAI: player.isAI,
headUrl: this.headUrls.splice(0, 1)[0],
complete: false,
duration: null
headUrl: this.headUrls.splice(0, 1)[0]
});
await asyncDelay(1);
this.networkHelper.sendFrame({
type: 'SERVER_allPlayerInfo',
playerData: this.playerList
});
if (this.playerList.length == this.playerMaxNumber) {
this.networkHelper.closeRoom();
await asyncDelay(0.5);
this.startGame();
this.startAI();
}
this.networkHelper.sendFrame({
type: 'SERVER_allPlayerInfo',
playerData: this.playerList
});
}
gameStatus = {
......@@ -75,15 +76,19 @@ export class GameServer {
});
}
_aiPlayerList = [];
startMatch() {
for (let i = 0; i < this.playerMaxNumber; i++) {
this._timeoutIds.push(setTimeout(() => {
const count = this.playerMaxNumber - this.playerList.length;
if (count > 0) {
this.addPlayer({
const playerInfo = {
uuid: 'ai_' + i,
isAI: true
});
isAI: true,
color: 'Red'
}
this._aiPlayerList.push(new AI(this.networkHelper, playerInfo));
this.addPlayer(playerInfo);
}
}, RandomInt(10000, 15000)));
}
......@@ -91,13 +96,66 @@ export class GameServer {
onFrameEvent(data) {
if (data.type == 'roll') {
const player = this.playerList.find(player => player.uuid == data.uuid);
const letter = ['A', 'B', 'C', 'D', 'E', 'F'][RandomInt(6)];
const letterList = this.getLetterList();
if (letterList.length > 0) {
const letter = letterList[RandomInt(letterList.length)];
this.gameStatus.letter = letter;
this.networkHelper.sendFrame({
type: 'SERVER_playerRoll',
letter: letter
});
} else {
this.networkHelper.sendFrame({
type: 'SERVER_playerWin',
color: this.gameStatus.current
});
}
} else if (data.type == 'right') {
this.gameStatus[data.color] = data.idx;
this.changeSide();
this.networkHelper.sendFrame({
type: 'SERVER_playerRight',
idx: data.idx,
uuid: data.uuid,
color: data.color
});
} else if (data.type == 'wrong') {
this.gameStatus[data.color] = data.idx;
this.changeSide();
this.networkHelper.sendFrame({
type: 'SERVER_playerWrong',
uuid: data.uuid,
color: data.color
});
} else {
this._aiPlayerList.forEach((ai: AI) => {
ai.onFrameEvent(data);
});
}
}
getLetterList() {
const board = cc.find('Canvas/bg/chessBoard/boardItems');
const color = this.gameStatus.current;
const startIdx = this.gameStatus[color];
const letterList = [];
for (let i = startIdx + 1; i < board.children.length; i++) {
const targetNode = board.children[i];
const itemData = targetNode.getComponent('ItemData');
const nodeLetter = itemData.letter.toUpperCase();
if (!letterList.find(letter => letter == nodeLetter)) {
letterList.push(nodeLetter);
}
}
return letterList;
}
changeSide() {
if (this.gameStatus.current == 'Red') {
this.gameStatus.current = 'Blue';
} else {
this.gameStatus.current = 'Red';
}
}
......
......@@ -94,13 +94,13 @@ export function getScaleRateBy2Node(baseNode, targetNode, maxFlag = true) {
}
}
export function getDistance (start, end){
export function getDistance(start, end) {
var pos = cc.v2(start.x - end.x, start.y - end.y);
var dis = Math.sqrt(pos.x*pos.x + pos.y*pos.y);
var dis = Math.sqrt(pos.x * pos.x + pos.y * pos.y);
return dis;
}
export function playAudioByUrl(audio_url, cb=null) {
export function playAudioByUrl(audio_url, cb = null) {
if (audio_url) {
cc.assetManager.loadRemote(audio_url, (err, audioClip) => {
const audioId = cc.audioEngine.play(audioClip, false, 0.8);
......@@ -114,21 +114,21 @@ export function playAudioByUrl(audio_url, cb=null) {
}
export function btnClickAnima(btn, time=0.15, rate=1.05) {
export function btnClickAnima(btn, time = 0.15, rate = 1.05) {
btn.tmpScale = btn.scale;
btn.on(cc.Node.EventType.TOUCH_START, () => {
cc.tween(btn)
.to(time / 2, {scale: btn.scale * rate})
.to(time / 2, { scale: btn.scale * rate })
.start()
})
btn.on(cc.Node.EventType.TOUCH_CANCEL, () => {
cc.tween(btn)
.to(time / 2, {scale: btn.tmpScale})
.to(time / 2, { scale: btn.tmpScale })
.start()
})
btn.on(cc.Node.EventType.TOUCH_END, () => {
cc.tween(btn)
.to(time / 2, {scale: btn.tmpScale})
.to(time / 2, { scale: btn.tmpScale })
.start()
})
}
......@@ -177,13 +177,17 @@ export function playAudio(audioClip, cb = null) {
export async function asyncDelay(time) {
return new Promise((resolve, reject) => {
try {
setTimeout(() => {
const canvas = cc.find('Canvas');
cc.tween(canvas)
.delay(time)
.call(() => {
resolve(null);
}, time * 1000);
})
.start();
} catch (e) {
reject(e);
}
})
});
}
export class FireworkSettings {
......@@ -352,3 +356,22 @@ export function onHomeworkFinish() {
console.log('onHomeworkFinish');
}
}
export async function asyncPlayDragonBoneAnimation(node, animationName, time = 1, onFrameEvent = null) {
return new Promise((resolve, reject) => {
node.getComponent(dragonBones.ArmatureDisplay)
.once(dragonBones.EventObject.COMPLETE, () => {
resolve(null);
});
node.getComponent(dragonBones.ArmatureDisplay)
.on(dragonBones.EventObject.FRAME_EVENT, ({ name }) => {
if (onFrameEvent && typeof (onFrameEvent) == 'function') {
onFrameEvent(name);
}
});
node.getComponent(dragonBones.ArmatureDisplay)
.playAnimation(animationName, time);
});
}
......@@ -11,7 +11,7 @@
"height": 485,
"platformSettings": {},
"subMetas": {
"胜利失败背景": {
"bg": {
"ver": "1.0.4",
"uuid": "c5823412-a5f8-4ec4-8828-d41608b90e8c",
"rawTextureUuid": "be46f91b-9dfa-4f4a-b026-2d491d8cc6e0",
......
......@@ -11,7 +11,7 @@
"height": 319,
"platformSettings": {},
"subMetas": {
"蓝色边框": {
"frameBlue": {
"ver": "1.0.4",
"uuid": "961b4c40-b93f-4af5-af66-e3683eb2b5b6",
"rawTextureUuid": "a943b9ca-061f-42d2-bcc3-9eac9ddd09ab",
......
......@@ -11,7 +11,7 @@
"height": 319,
"platformSettings": {},
"subMetas": {
"红色边框": {
"frameRed": {
"ver": "1.0.4",
"uuid": "ad273e18-b723-4e1d-9092-71a4de3aa643",
"rawTextureUuid": "7fd24a72-0dcf-410e-a5a0-50eb2c6dd22a",
......
......@@ -11,7 +11,7 @@
"height": 451,
"platformSettings": {},
"subMetas": {
"失败": {
"labelLoss": {
"ver": "1.0.4",
"uuid": "88509eaa-1979-4b1b-8467-1213107d8d9b",
"rawTextureUuid": "30968867-0801-40ad-af1c-7e693a374b19",
......
......@@ -11,7 +11,7 @@
"height": 451,
"platformSettings": {},
"subMetas": {
"胜利文字": {
"labelWin": {
"ver": "1.0.4",
"uuid": "f41aec72-d848-49d4-b123-5685b65f97b4",
"rawTextureUuid": "346354b4-b49e-4822-b4d9-b4788f6d04eb",
......
{
"ver": "2.3.5",
"uuid": "44348d3b-ad2f-4ba4-906c-abefa6e9f51e",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 591,
"height": 298,
"platformSettings": {},
"subMetas": {
"tree": {
"ver": "1.0.4",
"uuid": "933d5888-8fc0-4967-a884-d0afeb6a2cbc",
"rawTextureUuid": "44348d3b-ad2f-4ba4-906c-abefa6e9f51e",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 591,
"height": 298,
"rawWidth": 591,
"rawHeight": 298,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
......@@ -128,5 +128,8 @@
}
}
},
"defaultProject": "ng-template-generator"
"defaultProject": "ng-template-generator",
"cli": {
"analytics": false
}
}
\ No newline at end of file
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>NgOne</title>
<!-- <base href="/"> -->
<!-- <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">-->
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="//staging-teach.cdn.ireadabc.com/h5template/h5-static-lib/js/air.js"></script>
<style>
.border {
border-radius: 20px;
border-style: dashed;
padding: 20px;
margin: 20px;
width: 800px;
border-radius: 20px;
border-width: 2px;
border-color: #000000;
}
.error {
border-color: red;
}
.right {
border-color: rgb(50, 255, 50);
}
.normal {
border-color: black;
}
</style>
<script>
let saveDataStr = '';
function loadData() {
window.courseware.getData((data, aspect) => {
const textarea = document.getElementById('saveDataTextarea');
textarea.value = JSON.stringify(data);
saveDataStr = textarea.value.trim();
});
}
function saveData() {
const textarea = document.getElementById('saveDataTextarea');
const textareaStr = textarea.value;
if (textareaStr.trim() == saveDataStr.trim()) {
textarea.className = "normal";
return;
}
try {
const data = JSON.parse(textareaStr);
window.courseware.setData(data);
saveDataStr = textarea.value.trim();
textarea.className = "right";
} catch (e) {
textarea.className = "error";
console.error(e);
}
}
</script>
</head>
<body onload="loadData();" style="background-color: white;">
<div class="border">
保存的数据:
<textarea class="normal" style="width: 100%; height: 300px;" id="saveDataTextarea" onBlur="saveData();"></textarea>
</div>
</body>
</html>
\ No newline at end of file
......@@ -20,10 +20,10 @@
border-style: dashed;
padding: 20px;
margin: 20px;
/*width: 500px; */
/*//border-radius: 20px;*/
/*//border-width: 2px;*/
/*//border-color: #000000;*/
width: 500px;
border-radius: 20px;
border-width: 2px;
border-color: #000000;
}
......
<div class="model-content">
<div class="border" style="padding: 50px;">
<div style="margin-bottom: 20px;">
<span style="font-size: 20px;">开始音频: </span>
<app-audio-recorder [audioUrl]="item.gameStartAudio"
(audioUploaded)="onAudioUploadSuccess($event, 'gameStartAudio')">
</app-audio-recorder>
</div>
<div style="margin-bottom: 20px;">
<span style="font-size: 20px;">加载音频: </span>
<app-audio-recorder [audioUrl]="item.gameLoadingAudio"
(audioUploaded)="onAudioUploadSuccess($event, 'gameLoadingAudio')">
</app-audio-recorder>
</div>
<div style="margin-bottom: 20px;">
<span style="font-size: 20px;">猫咪<b>转盘</b>待机音频: </span>
<app-audio-recorder [audioUrl]="item.waitingWheel" (audioUploaded)="onAudioUploadSuccess($event, 'waitingWheel')">
</app-audio-recorder>
</div>
<div style="margin-bottom: 20px;">
<span style="font-size: 20px;">猫咪<b>走棋</b>待机音频: </span>
<app-audio-recorder [audioUrl]="item.waitingPiece" (audioUploaded)="onAudioUploadSuccess($event, 'waitingPiece')">
</app-audio-recorder>
</div>
<div style="margin-bottom: 20px;">
<span style="font-size: 20px;">猫咪<b>对方轮次</b>待机音频: </span>
<app-audio-recorder [audioUrl]="item.waitingTurn" (audioUploaded)="onAudioUploadSuccess($event, 'waitingTurn')">
</app-audio-recorder>
</div>
</div>
</div>
\ No newline at end of file
......@@ -18,24 +18,15 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
}
createShell() {
this.item.wordList.push({
word: '',
audio: '',
backWord: '',
backWordAudio: '',
});
this.save();
}
removeShell(idx) {
this.item.wordList.splice(idx, 1);
this.save();
}
ngOnInit() {
this.item = {};
this.item = {
gameStartAudio: '',
gameLoadingAudio: '',
waitingWheel: '',
waitingPiece: '',
waitingTurn: '',
};
// 获取存储的数据
(<any>window).courseware.getData((data) => {
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment