| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- import Armature from "./Armature";
- import Role from "./Role";
- const {ccclass, property} = cc._decorator;
- /**玩家类 */
- @ccclass
- export default class Player extends Role {
- public onLoad():void{
- //初始化骨骼
- this.armature = new Armature('armature/player',this.node);
- //初始动画
- this.armature.playAnimation(Role.AnimationName_Idle,0);
- //玩家死亡惨叫
- this.node.on(Role.EventType_Die,()=>{
- cc.audioEngine.playEffect(cc.loader.getRes('audio/die',cc.AudioClip),false);
- },this);
- super.onLoad();
- }
-
- public leftDodge():boolean{
- if(super.leftDodge()){
- //躲避加入视觉上的物理位移
- this.node.runAction(cc.sequence(cc.moveTo(0.3,cc.v2(-250,this.node.y)),cc.moveTo(0.3,cc.v2(0,this.node.y))));
- return true;
- }
- return false;
- }
- public rightDodge():boolean{
- if(super.rightDodge()){
- //躲避加入视觉上的物理位移
- this.node.runAction(cc.sequence(cc.moveTo(0.3,cc.v2(250,this.node.y)),cc.moveTo(0.3,cc.v2(0,this.node.y))));
- return true;
- }
- return false;
- }
-
- public hurt(damage:number):boolean{
- if(super.hurt(damage)){
- //受伤闷声
- cc.audioEngine.playEffect(cc.loader.getRes('audio/hurt',cc.AudioClip),false);
- //震动屏幕
- window.gameMgr.background.runAction(cc.sequence(
- cc.shake(0.3,15,15),
- cc.callFunc(()=>{
- window.gameMgr.background.setPosition(0,0);
- },this)
- ));
- return true;
- }
- return false;
- }
- /**相机浮动方向 */
- private cameraActionDirection:number = 1;
- /**相机y方向偏移量 */
- private cameraOffsetY:number = 0;
- private redScreen:cc.Node;
- private tip_hpLow:cc.Node;
- private tip_enduranceLow:cc.Node;
- public update(dt:number):void{
- super.update(dt);
- ////耐力不足
- if(this.property_endurance<25&&!this.pausing){
- //添加耐力不足警告标志
- if(!this.tip_enduranceLow){
- this.tip_enduranceLow = new cc.Node();
- this.tip_enduranceLow.addComponent(cc.Sprite).spriteFrame = cc.loader.getRes('texture/font_tip1',cc.SpriteFrame);
- this.tip_enduranceLow.setPosition(0,-350);
- window.gameMgr.background.addChild(this.tip_enduranceLow);
- this.tip_enduranceLow.runAction(cc.repeatForever(cc.sequence(
- cc.scaleTo(0.3,1.2).easing(cc.easeBackInOut()),
- cc.scaleTo(0.3,1).easing(cc.easeBackInOut())
- )));
- }
- //相机浮动规律
- if(this.cameraOffsetY>10){
- this.cameraActionDirection = -1;
- }else if(this.cameraOffsetY<-10){
- this.cameraActionDirection = 1;
- }
- this.cameraOffsetY += this.cameraActionDirection*dt*300;
- window.gameMgr.camera.y = this.cameraOffsetY;
- }else{
- //取消相机浮动和耐力警告标志
- window.gameMgr.camera.y = 0
- if(this.tip_enduranceLow){
- this.tip_enduranceLow.destroy();
- this.tip_enduranceLow = null;
- }
- }
- //血量不足
- if(this.property_hp<25&&!this.pausing){
- //添加红屏
- if(!this.redScreen){
- this.redScreen = new cc.Node();
- let child = new cc.Node();
- child.addComponent(cc.Sprite).spriteFrame = cc.loader.getRes('texture/white',cc.SpriteFrame);
- child.color = cc.Color.RED;
- child.opacity = 100;
- child.setContentSize(window.gameMgr.gameViewSize);
- this.redScreen.addChild(child);
- window.gameMgr.background.addChild(this.redScreen);
- this.redScreen.runAction(cc.repeatForever(cc.sequence(
- cc.fadeOut(0.3).easing(cc.easeBackInOut()),
- cc.fadeIn(0.3).easing(cc.easeBackInOut())
- )));
- }
- //添加血量不足警告标志
- if(!this.tip_hpLow){
- this.tip_hpLow = new cc.Node();
- this.tip_hpLow.addComponent(cc.Sprite).spriteFrame = cc.loader.getRes('texture/font_tip2',cc.SpriteFrame);
- this.tip_hpLow.setPosition(0,-430);
- window.gameMgr.background.addChild(this.tip_hpLow);
- this.tip_hpLow.runAction(cc.repeatForever(cc.sequence(
- cc.scaleTo(0.3,1.2).easing(cc.easeBackInOut()),
- cc.scaleTo(0.3,1).easing(cc.easeBackInOut())
- )));
- }
- }else{
- //取消红屏和血量不足警告标志
- if(this.redScreen){
- this.redScreen.destroy();
- this.redScreen = null;
- }
- if(this.tip_hpLow){
- this.tip_hpLow.destroy();
- this.tip_hpLow = null;
- }
- }
- }
- }
|