56 lines
1.8 KiB
TypeScript
56 lines
1.8 KiB
TypeScript
import { _decorator, Component, Node, tween ,Vec3,v3,Collider2D,Contact2DType} from 'cc';
|
|
import { BoxSet } from '../common/config/BoxSet';
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass('baseCom')
|
|
export class baseCom extends Component {
|
|
speed:number = 600;
|
|
range:number = 80;
|
|
scale:number = 1;
|
|
start() {
|
|
let collider = this.getComponent(Collider2D);
|
|
|
|
if (collider) {
|
|
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
|
}
|
|
}
|
|
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D) {
|
|
|
|
switch (selfCollider.group) {
|
|
case BoxSet.HERO_SKILL:
|
|
switch (otherCollider.group){
|
|
case BoxSet.MONSTER:
|
|
// this.reset()
|
|
console.log('hero skill',selfCollider,otherCollider);
|
|
// this.speed = 0;
|
|
// this.timer = 1;
|
|
// console.log("speed:"+this.speed+" | timer:"+this.timer);
|
|
break;
|
|
}
|
|
break;
|
|
case BoxSet.MONSTER_SKILL:
|
|
switch (otherCollider.group){
|
|
case BoxSet.HERO:
|
|
// console.log('monster skill',selfCollider,otherCollider);
|
|
// this.reset()
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
|
|
update(deltaTime: number) {
|
|
this.node.setScale(v3(this.scale,this.node.scale.y,this.node.scale.z))
|
|
this.node.setPosition(v3(this.node.position.x+deltaTime*this.speed*this.scale,this.node.position.y,this.node.position.z))
|
|
if(Math.abs(this.node.position.x) > this.range)
|
|
{
|
|
this.node.destroy()
|
|
}
|
|
}
|
|
}
|
|
|
|
|