1 decade ago by unstoppableCarl
I'm working on a turn based wargame that uses a hex grid. I have a lot of the js code and test cases needed for pathfinding, line of sight, and movement already. I've starting to develop the game in impact and I could use some input on organizing things.
I have each hex as an entity. My existing code stores them in a multi-dimensional array so they can be looked up quickly hexes[x][y]. With impact all entities are stored in the game.entities array.
Question 1) Can I simply store my hex entities in a multi-dimensional array on the game object with out any adverse effects. Should I handle my hex data in a different way?
I am planning to have each unit be an entity with a reference to the hex it is currently on for lookups and movement etc. I am currently using getEntityByName('hex_1_2') for the lookups instead of the multi-dimensional array I want. When using this lookup in the UnitEntity.update() method you have to check to make sure that hex entity exists first wich can be tricky.
I tried making a simple helper method on my game object
but when trying to call it from my UnitEntity.update() method it gave an error that the method was undefined. I don't have this problem if I set a property on my game object and try to reference it from the same UnitEntity.update() method.
Question 2) How do I call custom methods on my game object from my entities?
I have already extended the map and map tile objects to handle and render my hexgrid. So the hex entities don't HAVE to manage the background image data. I don't know if this matters or not I assumed that having the background map rendering graphics was more efficient than each hex entity rendering its own.
Question 3) Should I even bother with the background map?
I have each hex as an entity. My existing code stores them in a multi-dimensional array so they can be looked up quickly hexes[x][y]. With impact all entities are stored in the game.entities array.
Question 1) Can I simply store my hex entities in a multi-dimensional array on the game object with out any adverse effects. Should I handle my hex data in a different way?
I am planning to have each unit be an entity with a reference to the hex it is currently on for lookups and movement etc. I am currently using getEntityByName('hex_1_2') for the lookups instead of the multi-dimensional array I want. When using this lookup in the UnitEntity.update() method you have to check to make sure that hex entity exists first wich can be tricky.
I tried making a simple helper method on my game object
getHex(x,y) { return this.getEntitiyByName('hex_'+x+'_'+y); }
but when trying to call it from my UnitEntity.update() method it gave an error that the method was undefined. I don't have this problem if I set a property on my game object and try to reference it from the same UnitEntity.update() method.
Question 2) How do I call custom methods on my game object from my entities?
I have already extended the map and map tile objects to handle and render my hexgrid. So the hex entities don't HAVE to manage the background image data. I don't know if this matters or not I assumed that having the background map rendering graphics was more efficient than each hex entity rendering its own.
Question 3) Should I even bother with the background map?