Aatu / FieryVoid

A browser game based on AOGwars
8 stars 12 forks source link

revert hexCoToPixel() #1392

Open Zero1627 opened 2 years ago

Zero1627 commented 2 years ago

for some calculations hex-based location is used, for others pixel-based.

Mathlib::hexCoToPixel() function converts hex coordinates to pixel. However, Mathlib::pixelCoToHex() (expected to be the reverse) apparently does not work. It also isn't called anywhere in game (well, it is called in one function which is never called itself), so its errorneous behavior could easily have been missed.

Preparing correct implementation would allow some calculations to be done - for starters making Plasma Web rely on $pos parameter passed (which is pixel... or at least should be) rather than self-estimating where the fire is coming from!

Zero1627 commented 2 years ago

actually this SHOULD be similar to this code (this is javascript for similar task from the net):

public HexCell coordsToHexCell(float x, float y){ final float size = this.size; // cell size float q = (float) ((1f/3f Math.sqrt(3) x - 1f/3f y) / size); float r = 2f/3f y / size; return getHexCell((int) r, (int) q); }