2024-05-27 02:19:31 -07:00
|
|
|
import { _decorator, Animation, AudioClip, Collider2D, Component, Contact2DType, Node, RigidBody2D } from 'cc';
|
|
|
|
import AudioManager from '../Manager/AudioManager';
|
2024-03-28 20:35:44 -07:00
|
|
|
import { CameraController } from './CameraController';
|
2024-03-21 01:59:08 -07:00
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
|
|
@ccclass('SlingShot')
|
|
|
|
export default class SlingShot extends Component {
|
|
|
|
@property({ type: Animation, visible: true })
|
|
|
|
private _animation: Animation;
|
|
|
|
@property({ type: Collider2D, visible: true })
|
|
|
|
private _collider: Collider2D;
|
|
|
|
|
2024-04-03 02:43:18 -07:00
|
|
|
@property({ type: AudioClip, visible: true })
|
|
|
|
private _soundFx: AudioClip;
|
|
|
|
|
2024-03-21 01:59:08 -07:00
|
|
|
protected onLoad(): void {
|
|
|
|
this._collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
onBeginContact(self: Collider2D, other: Collider2D) {
|
|
|
|
this._animation.play();
|
2024-03-28 20:35:44 -07:00
|
|
|
const velocity = other.getComponent(RigidBody2D).linearVelocity.length();
|
2024-05-27 02:19:31 -07:00
|
|
|
AudioManager.playSfx(this._soundFx);
|
2024-04-03 02:43:18 -07:00
|
|
|
if (velocity >= 40) {
|
|
|
|
CameraController.instance.shake(0.08);
|
|
|
|
}
|
2024-03-21 01:59:08 -07:00
|
|
|
}
|
|
|
|
}
|