@@ -5,10 +5,9 @@ import { PreRenderTiledMapSystem } from "@serbanghita-gamedev/renderer";
5
5
import { IsTiledMap , Renderable } from "@serbanghita-gamedev/component" ;
6
6
import { loadSprites } from "./assets" ;
7
7
import { Point , Rectangle } from "@serbanghita-gamedev/geometry" ;
8
- import { randomInt } from "./helpers" ;
9
8
import IsMatrix from "./IsMatrix" ;
10
9
import { TiledMap } from "@serbanghita-gamedev/tiled" ;
11
- import { getTileCoordinates } from "@serbanghita-gamedev/matrix" ;
10
+ import { getTileCoordinates , getTileFromCoordinates } from "@serbanghita-gamedev/matrix" ;
12
11
import { QuadTree } from "@serbanghita-gamedev/quadtree" ;
13
12
import QuadTreeSystem from "./QuadTreeSystem" ;
14
13
import IsCollisionTile from "./IsCollisionTile" ;
@@ -84,10 +83,22 @@ async function setup() {
84
83
const x = event . clientX | 0 ;
85
84
const y = event . clientY | 0 ;
86
85
86
+ const map = world . getEntity ( "map" ) ;
87
+ if ( ! map ) {
88
+ throw new Error ( `Map entity has not been defined yet.` ) ;
89
+ }
90
+ const mapMatrix = map . getComponent ( IsMatrix ) ;
91
+ const tile = getTileFromCoordinates ( x , y , mapMatrix . properties ) ;
92
+
93
+ if ( mapMatrix . properties . matrix [ tile ] !== 0 ) {
94
+ return ;
95
+ }
96
+
87
97
const playerId = `player-${ x } -${ y } ` ;
88
98
const player = world . createEntity ( playerId ) ;
89
99
const point = new Point ( x , y , playerId ) ;
90
- player . addComponent ( IsCollisionTile , { x, y, point } ) ;
100
+
101
+ player . addComponent ( IsCollisionTile , { x, y, point, tile } ) ;
91
102
player . addComponent ( IsRenderedInForeground ) ;
92
103
player . addComponent ( IsPlayer ) ;
93
104
quadtree . addPoint ( point ) ;
0 commit comments