1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- /*
- * @Author: your name
- * @Date: 2021-09-20 15:38:03
- * @LastEditTime: 2021-09-20 22:43:24
- * @LastEditors: Please set LastEditors
- * @Description: In User Settings Edit
- * @FilePath: \zombiefood\assets\script\gameLogic\gameObject\bullet\zomBiebullet.ts
- */
- import { Log, LOG_TAG } from "../../../framework/log/Log";
- import Utils from "../../../framework/utils/utils";
- import { GAME_OBJECT_TYPE } from "../../utrl/gameEnum";
- import GameObject from "../gameObject";
- import PlayerObject from "../player/playerObject";
- const { ccclass, property } = cc._decorator;
- /**子弹实体类 */
- @ccclass
- export default class BulletObject extends GameObject {
- @property(cc.Node)
- view: cc.Node = null;
- private inited = false;
- private height = 250;
- private u_speed = 500;
- private dur = 0;
- private a = -1000;
- private v_speed: cc.Vec3 = null;
- damage: number;
- init(pos: cc.Vec3, target_pos: cc.Vec3, damage: number) {
- target_pos.x = target_pos.x + Utils.random(-100, 100);
- this.node.setPosition(pos);
- this.view.y = this.height;
- this.dur = Math.sqrt(Math.pow(this.u_speed / this.a, 2) - this.height / this.a * 2) - this.u_speed / this.a;
- this.v_speed = target_pos.sub(pos).div(this.dur);
- this.type = GAME_OBJECT_TYPE.zombieBullet;
- this.damage = damage;
- this.inited = true;
- }
- update(dt: number) {
- if (!this.inited) {
- return;
- }
- if (this.view.y > 0) {
- this.u_speed += dt * this.a;
- this.view.y += this.u_speed * dt;
- if (this.view.y < 0) {
- this.view.y = 0;
- // Log.log(LOG_TAG.DEBUG, 'booooooooooooooom');
- if (this.node && cc.isValid(this.node))
- this.node.destroy();
- }
- let pos = this.node.position.add(this.v_speed.mul(dt));
- this.node.setPosition(pos);
- }
- }
- }
|