import GameData from "./GameData"; import GameManager from "./GameManager"; import { Notification } from './tool/Notification'; const {ccclass, property} = cc._decorator; @ccclass export default class NewClass extends cc.Component { @property(cc.Label) label: cc.Label = null; @property text: string = 'hello'; tween: cc.Tween; speed: number; //移动速度,时间参数,位移个固定 move: boolean; //是否在移动状态。 num: number; difficulty: number; // LIFE-CYCLE CALLBACKS: onLoad () { this.node.getComponent(cc.PolygonCollider).enabled = true; this.speed = 10; this.num = 0; this.move = false; if(this.node.name.length > 6){ this.num = parseInt(this.node.name.substring(5,7)) }else this.num = parseInt(this.node.name.substring(5,6)) this.speed = GameData._instance.BLOCK_INFO[this.num-1].speed; this.init(); } start () { } init(){ this.getSpeed(); if(this.num > GameData._instance.GM_INFO.blockScale){ if(this.speed < GameData._instance.LEVEL_INFO.slowSpeed)this.speed = GameData._instance.LEVEL_INFO.slowSpeed; } else { if(this.speed < GameData._instance.LEVEL_INFO.fastSpeed)this.speed = GameData._instance.LEVEL_INFO.fastSpeed; } if(this.num != 13 && !GameData._instance.GM_INFO.probation){ GameData._instance.CLICK_DATA.block = this.num; GameData._instance.CLICK_DATA.speed = this.speed; this.getDifficulty(); } else{ this.node.getComponent(cc.PolygonCollider).enabled = false; this.node.getComponent(cc.BoxCollider).enabled = false; GameData._instance.CLICK_DATA.fakeSpeed = this.speed; } this.move = true; this.tween = cc.tween(this.node) .to(this.speed,{x:-this.node.x}) .call(() =>{ this.move = false; }) .start(); } getSpeed(){ //先加范围 厚的 let reduceSpeed = GameData._instance.LEVEL_INFO.reduceSpeed; reduceSpeed = parseInt(Math.random()*reduceSpeed + ""); this.speed = this.speed - reduceSpeed/10; //最后乘以系数 this.speed = this.speed/GameData._instance.LEVEL_INFO.speed; this.speed = parseInt(this.speed*10 + "")/10; } getDifficulty(){ var difficulty1 = 0; var sudu = Math.abs(this.speed - GameManager._instance.oldSpeed); difficulty1 = (sudu/10+1)*(11-this.speed); if(difficulty1 <= 1) difficulty1 = 1; else if(difficulty1 >= 7) difficulty1 = 7; var difficulty2 = 0; if(this.node.width < 180) difficulty2 = 0; else if(this.node.width < 199) difficulty2 = 0.5; else difficulty2 = 1; var difficulty3 = 0; if(GameManager._instance.interfere == true){ difficulty3 = 1; } var difficulty4 = 0; if(this.num > 6){ difficulty4 = 1; } GameManager._instance.oldSpeed = this.speed; this.difficulty = 0; this.difficulty = difficulty1 + difficulty2 + difficulty3 + difficulty4; this.difficulty = parseInt(this.difficulty *10 + ""); GameData._instance.CLICK_DATA.difficulty = this.difficulty/10; if(GameData._instance.CLICK_DATA.difficulty > GameData._instance.GM_INFO.difficultyMax) GameData._instance.GM_INFO.difficultyMax = GameData._instance.CLICK_DATA.difficulty; } setScore(fen){ let score = 0; let difficulty = this.difficulty / 10; let layer = GameData._instance.LEVEL_INFO.layer; let doubleHit = GameData._instance.LEVEL_INFO.doubleHit; score = parseInt(fen * difficulty * layer * doubleHit + ""); Notification.emit("addScore",score); } hide(){ cc.tween(this.node) .to(0.2,{opacity:0}) .call(() =>{ this.node.active = false; this.node.removeFromParent(); this.node = null; }) .start(); } onCollisionEnter(other: cc.Collider, self: cc.Collider) { if(GameManager._instance){ if(GameManager._instance.over == true){ return; } } if(other.node.name == "Player"){ let max = self.name.length; let ColliderName = other.name.substring(6,max); if(this.move == true){ if(this.tween){ this.tween.stop(); } } } } update (dt) { } }