zomBiebullet.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-09-20 15:38:03
  4. * @LastEditTime: 2021-09-20 22:43:24
  5. * @LastEditors: Please set LastEditors
  6. * @Description: In User Settings Edit
  7. * @FilePath: \zombiefood\assets\script\gameLogic\gameObject\bullet\zomBiebullet.ts
  8. */
  9. import { Log, LOG_TAG } from "../../../framework/log/Log";
  10. import Utils from "../../../framework/utils/utils";
  11. import { GAME_OBJECT_TYPE } from "../../utrl/gameEnum";
  12. import GameObject from "../gameObject";
  13. import PlayerObject from "../player/playerObject";
  14. const { ccclass, property } = cc._decorator;
  15. /**子弹实体类 */
  16. @ccclass
  17. export default class BulletObject extends GameObject {
  18. @property(cc.Node)
  19. view: cc.Node = null;
  20. private inited = false;
  21. private height = 250;
  22. private u_speed = 500;
  23. private dur = 0;
  24. private a = -1000;
  25. private v_speed: cc.Vec3 = null;
  26. damage: number;
  27. init(pos: cc.Vec3, target_pos: cc.Vec3, damage: number) {
  28. target_pos.x = target_pos.x + Utils.random(-100, 100);
  29. this.node.setPosition(pos);
  30. this.view.y = this.height;
  31. this.dur = Math.sqrt(Math.pow(this.u_speed / this.a, 2) - this.height / this.a * 2) - this.u_speed / this.a;
  32. this.v_speed = target_pos.sub(pos).div(this.dur);
  33. this.type = GAME_OBJECT_TYPE.zombieBullet;
  34. this.damage = damage;
  35. this.inited = true;
  36. }
  37. update(dt: number) {
  38. if (!this.inited) {
  39. return;
  40. }
  41. if (this.view.y > 0) {
  42. this.u_speed += dt * this.a;
  43. this.view.y += this.u_speed * dt;
  44. if (this.view.y < 0) {
  45. this.view.y = 0;
  46. // Log.log(LOG_TAG.DEBUG, 'booooooooooooooom');
  47. if (this.node && cc.isValid(this.node))
  48. this.node.destroy();
  49. }
  50. let pos = this.node.position.add(this.v_speed.mul(dt));
  51. this.node.setPosition(pos);
  52. }
  53. }
  54. }