super-hero/assets/cc-game/scripts/game_play/hero/ActiveSkill1.ts

52 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-04-19 03:49:41 -07:00
import { _decorator, Component, Node } from 'cc';
import { ActiveSkillBase } from './ActiveSkillBase';
import { Vec3 } from 'cc';
import { EACTIVE_SKILL_TYPE, GameDefine } from '../../config/GameDefine';
import { RigidBody2D } from 'cc';
import { Vec2 } from 'cc';
import { UmLog } from '../../../../cc-common/cc-util/UmLog';
import { UmUtil } from '../../../../cc-common/cc-util/UmUtil';
import { GameGlobalData } from '../../global/GameGlobalData';
const { ccclass, property } = _decorator;
@ccclass('ActiveSkill1')
export class ActiveSkill1 extends ActiveSkillBase {
euler: Vec3 = new Vec3();
body: RigidBody2D;
public enableActiveSkill(data, parent) {
super.enableActiveSkill(data, parent);
this.skillType = Number(EACTIVE_SKILL_TYPE.SKILL_1);
this.speed = this.speed / this.useTime;
this.node.setScaleY(this.range);
this.addForce(parent);
}
addForce(parent)
{
this.body = (parent as Node)?.getComponent(RigidBody2D);
if (!this.body) return;
this.body.linearDamping = this.range;
var velocity = UmUtil.scaleVector3(GameGlobalData.Instance.lastHeroMoveDirection.normalize(), 1700 / 6 * this.range);
this.body.applyLinearImpulseToCenter(new Vec2(velocity.x, velocity.y), false);
}
update(dt: number)
{
if (!this.body) return;
var volocity = this.body.linearVelocity;
if (Vec2.distance(Vec2.ZERO, volocity) < 0.1)
{
this.body = null;
this.destroyNode();
return;
}
}
}