Browse code

debug collisiion

devnewton authored on 13/10/2016 at 14:10:55
Showing 6 changed files
... ...
@@ -18,7 +18,8 @@ export class Bullet extends Phaser.Sprite implements Vulnerable {
18 18
     }
19 19
 
20 20
     getVulnerableRectangles(): Array<Phaser.Rectangle> {
21
-        return [new Phaser.Rectangle(this.x, this.y, this.width, this.height)];
21
+        let b = this.getBounds();
22
+        return [new Phaser.Rectangle(b.x, b.y, b.width, b.height)];
22 23
     }
23 24
 
24 25
     fire(fromX: number, fromY: number, angle: number, speed: number, gravityX: number, gravityY: number) {
... ...
@@ -28,7 +28,8 @@ export class Grobelin extends Phaser.Sprite implements Vulnerable {
28 28
     }
29 29
 
30 30
     getVulnerableRectangles(): Array<Phaser.Rectangle> {
31
-        return [new Phaser.Rectangle(this.x, this.y, this.width, this.height)];
31
+        let b = this.getBounds();
32
+        return [new Phaser.Rectangle(b.x, b.y, b.width, b.height)];
32 33
     }
33 34
 
34 35
     appears(fromX: number, fromY: number, target: Phaser.Sprite) {
... ...
@@ -29,7 +29,8 @@ export class Hero extends Phaser.Sprite implements Vulnerable {
29 29
     }
30 30
 
31 31
     getVulnerableRectangles(): Array<Phaser.Rectangle> {
32
-        return [new Phaser.Rectangle(this.x, this.y, this.width, this.height)];
32
+        let b = this.getBounds();
33
+        return [new Phaser.Rectangle(b.x, b.y, b.width, b.height)];
33 34
     }
34 35
 
35 36
     static preload(game: Phaser.Game) {
... ...
@@ -31,7 +31,8 @@ export class Spider extends Phaser.Sprite implements Vulnerable {
31 31
     }
32 32
 
33 33
     getVulnerableRectangles(): Array<Phaser.Rectangle> {
34
-        return [new Phaser.Rectangle(this.x, this.y, this.width, this.height)];
34
+        let b = this.getBounds();
35
+        return [new Phaser.Rectangle(b.x, b.y, b.width, b.height)];
35 36
     }
36 37
 
37 38
     appears(fromX: number, fromY: number, target: Phaser.Sprite) {
... ...
@@ -6,6 +6,9 @@ import {GrobelinHorde} from "../entities/GrobelinHorde.ts";
6 6
 import {SpiderHorde} from "../entities/SpiderHorde.ts";
7 7
 import {Spider} from "../entities/Spider.ts";
8 8
 
9
+import {Vulnerable} from "../entities/features/Vulnerable.ts";
10
+
11
+
9 12
 import {Pathfinder} from "../ia/services/Pathfinder.ts";
10 13
 import {DamageResolver} from "../utils/DamageResolver.ts";
11 14
 
... ...
@@ -81,9 +84,12 @@ export class Level extends AbstractState {
81 81
         this.spiderHorde = new SpiderHorde(this.hero, this.pathfinder, 0);
82 82
         this.game.add.existing(this.spiderHorde);
83 83
 
84
+ this.game.time.events.add(1000, () => this.birdFlock.reset(this.hero, 10));
85
+        /*
84 86
         this.game.time.events.add(1000, () => this.grobelinHorde.reset(this.hero, 3));
85 87
         this.game.time.events.add(60000, () => this.spiderHorde.reset(this.hero, 4));
86 88
         this.game.time.events.add(12000, () => this.birdFlock.reset(this.hero, 10));
89
+        */
87 90
     }
88 91
 
89 92
     update() {
... ...
@@ -104,5 +110,11 @@ export class Level extends AbstractState {
104 104
     }
105 105
 
106 106
     render() {
107
+        for(let b of this.birdFlock.children) {
108
+            let vulnerable = <Vulnerable><any>b;
109
+            for(let v of vulnerable.getVulnerableRectangles()) {
110
+                this.game.debug.rectangle(v);
111
+            }
112
+         }
107 113
     }
108 114
 }
... ...
@@ -46,7 +46,7 @@ export class DamageResolver {
46 46
     static checkIfRectanglesIntersect(rectanglesA: Array<Phaser.Rectangle>, rectanglesB: Array<Phaser.Rectangle>): boolean {
47 47
         for (let a of rectanglesA) {
48 48
             for (let b of rectanglesB) {
49
-                if (a.intersects(b, 1)) {
49
+                if (a.intersects(b, 0)) {
50 50
                     return true;
51 51
                 }
52 52
             }