Advertisement
Guest User

Untitled

a guest
Dec 14th, 2024
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. # update method from the game scene
  2. update(time: number, delta: number) {
  3. const pointer = this.input.activePointer;
  4.  
  5. if (pointer.isDown) {
  6. if (!this.isDrawing) {
  7. const line = new MyLine(this, pointer.x, pointer.y);
  8. this.add.existing(line);
  9. this.lines[line.getId()] = line;
  10. this.isDrawing = true;
  11. this.currentLineId = newCon.getId();
  12. } else if (this.isDrawing) {
  13. const curLine = this.lines[this.currentLineId];
  14. curLine.setTo(
  15. curLine.getPointA().x, curLine.getPointA().y,
  16. pointer.x, pointer.y
  17. )
  18. curLine.draw();
  19. }
  20. } else if (this.isDrawing) {
  21. this.isDrawing = false;
  22. }
  23.  
  24. if (this.sKey && this.sKey.isDown && !this.curServer) {
  25. const pointer = this.input.activePointer;
  26. const circle = new MyCircle(this, pointer.x, pointer.y);
  27. this.add.existing(circle);
  28. this.circles.push(circle);
  29. this.curCircle = circle.getId();
  30. } else if (this.sKey && this.sKey.isUp && this.curCircle) {
  31. this.curCircle = undefined;
  32. }
  33. }
  34.  
  35.  
  36. export class Resource extends GameObjects.Graphics {
  37. protected id: string;
  38.  
  39. constructor(scene: Scene) {
  40. super(scene)
  41. this.id = uuid();
  42. }
  43.  
  44. getId() {
  45. return this.id;
  46. };
  47. }
  48.  
  49. export class MyCircle extends Resource {
  50.  
  51. constructor(scene: Scene, x: number, y: number) {
  52. super(scene);
  53. this.setX(x);
  54. this.setY(y);
  55. this.clear();
  56. this.lineStyle(5, 0x1E90FF, 1.0);
  57. this.fillCircle(0, 0, 20);
  58. }
  59.  
  60. }
  61.  
  62. export class MyLine extends Resource {
  63. line: Geom.Line;
  64.  
  65. constructor(scene: Scene, x1?: number, y1?: number, x2?: number, y2?: number) {
  66. super(scene);
  67.  
  68. this.line = new Geom.Line(x1, y1, x2, y2);
  69. }
  70.  
  71. getPointA() {
  72. return this.line.getPointA();
  73. }
  74.  
  75. draw() {
  76. this.clear();
  77. this.lineStyle(5, 0xFF00FF, 1.0);
  78. this.strokeLineShape(this.line);
  79.  
  80. return this;
  81. }
  82.  
  83. setTo(x1: number, y1: number, x2: number, y2:number) {
  84. this.line.setTo(x1, y1, x2, y2);
  85. }
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement