Commit 8d39557c authored by Thomas Dupriez's avatar Thomas Dupriez

Moved most of the conversions between Core and Graphics coordinate systems...

Moved most of the conversions between Core and Graphics coordinate systems into GraphicalBridgeConfiguration
parent 3db9e6e4
package graphics.graphical_utility;
import core.zone.Point;
import graphics.guiSkeleton.mapManagement.GraphicsMapPoint;
/**
* Created by etouss on 20/12/2015.
*/
......@@ -12,4 +15,29 @@ public final class GraphicalBridgeConfiguration {
public static final int TILE_SCALE=32;
public static final int TILE_SIZE=16;
/**
* Converts a distance expressed in the Core coordinate system to the same distance, expressed in the Graphics coordinate system
* @param distanceInCoreSystem
* @return
*/
public static final int core2Graphics(int distanceInCoreSystem) {
return ( (int) ((float) distanceInCoreSystem * (float) TILE_SCALE / (float) (Point.TileScale)));
}
//For checking the core2Graphics method
public static void main(String[] args){
System.out.println("DistanceConverterCheck: Input="+50+", Output="+ core2Graphics(50));
}
/**
* Convert the coordinates of a Point instance (defined in the core) to an instance of GraphicsMapPoint (with coordinates in the Swing system)
* @param x: the x coordinate of an instance of Point (IN THE CORE COORDINATE SYSTEM !)
* @param y: the y coordinate of the same instance of Point (IN THE CORE COORDINATE SYSTEM !)
* @return
*/
public static GraphicsMapPoint makeMapPointFromCoreCoordinates(int x, int y)
{
return new GraphicsMapPoint(core2Graphics(y), core2Graphics(x));
}
}
package graphics.guiSkeleton.entityDisplayer;
import core.gamestate.Being;
import graphics.graphical_utility.GraphicalBridgeConfiguration;
import graphics.guiSkeleton.mapManagement.GraphicsMap;
import graphics.guiSkeleton.mapManagement.GraphicsMapPoint;
import graphics.guiSkeleton.mapManagement.PositionedSprite;
......@@ -37,7 +38,7 @@ public class HealthBarDisplayer {
int hp = being.getHP();
int maxHP = being.getMaxHP();
float healthRatio = ((float)hp)/maxHP;
GraphicsMapPoint beingPosition = graphicsMap.makeMapPointFromCoreCoordinates(being.getX(), being.getY());
GraphicsMapPoint beingPosition = GraphicalBridgeConfiguration.makeMapPointFromCoreCoordinates(being.getX(), being.getY());
//applying translation
GraphicsMapPoint healthBarContainerTopLeft = beingPosition.translate(- assumedSpriteWidth/2, assumedSpriteHeight + yOffsetForHealthBarContainer);
......
......@@ -2,6 +2,7 @@ package graphics.guiSkeleton.entityDisplayer.entityDisplayerBank;
import core.gamestate.Action;
import core.gamestate.Entity;
import graphics.graphical_utility.GraphicalBridgeConfiguration;
import graphics.guiSkeleton.mapManagement.GraphicsMap;
import graphics.guiSkeleton.entityDisplayer.EntityDisplayer;
import graphics.guiSkeleton.mapManagement.GraphicsMapPoint;
......@@ -44,7 +45,7 @@ public class ChatRoseEntityDisplayer extends EntityDisplayer {
Sprite sprite = SpriteStorage.getInstance().getChatRose();
Entity entity = getAssociatedEntity();
GraphicsMapPoint entityPositionGraphicsMapPoint = graphicsMap.makeMapPointFromCoreCoordinates(entity.getX(), entity.getY());
GraphicsMapPoint entityPositionGraphicsMapPoint = GraphicalBridgeConfiguration.makeMapPointFromCoreCoordinates(entity.getX(), entity.getY());
//applying translation
GraphicsMapPoint spriteTopLeftGraphicsMapPoint = entityPositionGraphicsMapPoint.translate(- sprite_width/2, - sprite_height/2);
int direction = entity.getDirection().ordinal();
......
package graphics.guiSkeleton.entityDisplayer.entityDisplayerBank;
import core.gamestate.Entity;
import graphics.graphical_utility.GraphicalBridgeConfiguration;
import graphics.guiSkeleton.mapManagement.GraphicsMap;
import graphics.guiSkeleton.entityDisplayer.EntityDisplayer;
import graphics.guiSkeleton.mapManagement.GraphicsMapPoint;
......@@ -26,7 +27,7 @@ public class InvisibleEntityDisplayer extends EntityDisplayer {
public PositionedSprite getPositionedSprite(GraphicsMap graphicsMap) {
Sprite sprite = SpriteStorage.getInstance().getInvisible();
Entity entity = getAssociatedEntity();
GraphicsMapPoint entityPositionGraphicsMapPoint = graphicsMap.makeMapPointFromCoreCoordinates(entity.getX(), entity.getY());
GraphicsMapPoint entityPositionGraphicsMapPoint = GraphicalBridgeConfiguration.makeMapPointFromCoreCoordinates(entity.getX(), entity.getY());
return PositionedSprite.PositionSprite(sprite, entityPositionGraphicsMapPoint);
}
}
......@@ -2,6 +2,7 @@ package graphics.guiSkeleton.entityDisplayer.entityDisplayerBank;
import core.gamestate.Entity;
import core.gamestate.Action;
import graphics.graphical_utility.GraphicalBridgeConfiguration;
import graphics.guiSkeleton.mapManagement.GraphicsMap;
import graphics.guiSkeleton.entityDisplayer.EntityDisplayer;
import graphics.guiSkeleton.mapManagement.GraphicsMapPoint;
......@@ -41,7 +42,7 @@ public class RonflexEntityDisplayer extends EntityDisplayer {
Sprite sprite = SpriteStorage.getInstance().getRonflex();
Entity entity = getAssociatedEntity();
GraphicsMapPoint entityPositionGraphicsMapPoint = graphicsMap.makeMapPointFromCoreCoordinates(entity.getX(), entity.getY());
GraphicsMapPoint entityPositionGraphicsMapPoint = GraphicalBridgeConfiguration.makeMapPointFromCoreCoordinates(entity.getX(), entity.getY());
//applying translation
GraphicsMapPoint spriteTopLeftGraphicsMapPoint = entityPositionGraphicsMapPoint.translate(- sprite_width/2, - sprite_height/2);
int direction = entity.getDirection().ordinal();
......
......@@ -12,6 +12,7 @@ import gameloop.DummyLocalGameLoop;
import gameloop.GameStarter;
import graphics.graphical_abstraction.panel.GamePanelAbstraction;
import graphics.graphical_abstraction.panel.GamePanelAbstractionController;
import graphics.graphical_utility.GraphicalBridgeConfiguration;
import graphics.graphical_utility.coreProcesses.GameContentMapChangeListener;
import graphics.guiSkeleton.*;
import graphics.guiSkeleton.entityDisplayer.HealthBarDisplayer;
......@@ -85,7 +86,7 @@ public class GamePanel extends GUIPanel implements GameContentMapChangeListener,
//Getting the map, creating a bufferedImage out of it and storing it
GraphicsMap graphicsMap = MapDrawer.drawMap(gameContent.getMap());
GraphicsMapPoint initialTopLeftGraphicsMapPoint = graphicsMap.makeMapPointFromCoreCoordinates(followedRelayer.getCharacter().getX(), followedRelayer.getCharacter().getY());
GraphicsMapPoint initialTopLeftGraphicsMapPoint = GraphicalBridgeConfiguration.makeMapPointFromCoreCoordinates(followedRelayer.getCharacter().getX(), followedRelayer.getCharacter().getY());
visionBox = new VisionBox(initialTopLeftGraphicsMapPoint, getSize().width, getSize().height, graphicsMap);
topLeftLabel = new JLabel("Press ESC to go back to main menu");
......@@ -162,7 +163,7 @@ public class GamePanel extends GUIPanel implements GameContentMapChangeListener,
// System.out.println("coreEntityTopLeft "+processedEntity.getTopLeft().getPosX()+","+processedEntity.getTopLeft().getPosY());
//Debug
// System.out.println("coreColBoxTopLeft "+collisionBox.getTopLeft().getPosX()+","+collisionBox.getTopLeft().getPosY());
GraphicsMapPoint graphicsTopLeft = visionBox.getGraphicsMap().makeMapPointFromCoreCoordinates(coreTopLeft.getPosX(), coreTopLeft.getPosY());
GraphicsMapPoint graphicsTopLeft = GraphicalBridgeConfiguration.makeMapPointFromCoreCoordinates(coreTopLeft.getPosX(), coreTopLeft.getPosY());
//Debug
// GraphicsMapPoint graphicsEntityTopLeft = visionBox.getGraphicsMap().makeMapPointFromCoreCoordinates(processedEntity.getTopLeft().getPosX(), processedEntity.getTopLeft().getPosY());
//Debug
......@@ -175,11 +176,11 @@ public class GamePanel extends GUIPanel implements GameContentMapChangeListener,
if(zone instanceof Rectangle){
Rectangle rectColBox = (Rectangle) zone;
//getWidth and getHeight may have to be swapped (these are method from the core, and I'm unsure about what their return mean in swing coordinate system)
g.drawRect(gpmp.getX(), gpmp.getY(), DistanceConverter.core2Graphics(rectColBox.getWidth()), DistanceConverter.core2Graphics(rectColBox.getHeight()));
g.drawRect(gpmp.getX(), gpmp.getY(), GraphicalBridgeConfiguration.core2Graphics(rectColBox.getWidth()), GraphicalBridgeConfiguration.core2Graphics(rectColBox.getHeight()));
}
if(zone instanceof Circle){
Circle circleColBox = (Circle) zone;
g.drawOval(gpmp.getX(), gpmp.getY(), DistanceConverter.core2Graphics(2 * circleColBox.getRadius()), DistanceConverter.core2Graphics(2 * circleColBox.getRadius()));
g.drawOval(gpmp.getX(), gpmp.getY(), GraphicalBridgeConfiguration.core2Graphics(2 * circleColBox.getRadius()), GraphicalBridgeConfiguration.core2Graphics(2 * circleColBox.getRadius()));
}
}
......@@ -193,7 +194,7 @@ public class GamePanel extends GUIPanel implements GameContentMapChangeListener,
}
/** Get the GraphicsMapPoint of the position of the entity followed by the gamePanel **/
GraphicsMapPoint followedEntityPositionGraphicsMapPoint = visionBox.getGraphicsMap().makeMapPointFromCoreCoordinates(followedRelayer.getCharacter().getX(), followedRelayer.getCharacter().getY());
GraphicsMapPoint followedEntityPositionGraphicsMapPoint = GraphicalBridgeConfiguration.makeMapPointFromCoreCoordinates(followedRelayer.getCharacter().getX(), followedRelayer.getCharacter().getY());
if (debugMapPoint) {
System.out.println("followedEntityPositionGraphicsMapPoint:");
followedEntityPositionGraphicsMapPoint.print();
......@@ -282,7 +283,7 @@ public class GamePanel extends GUIPanel implements GameContentMapChangeListener,
@Override
public void mapChange() {
GraphicsMap graphicsMap = MapDrawer.drawMap(DummyLocalGameLoop.getInstance().getContent().getMap());
GraphicsMapPoint initialTopLeftMapPoint = graphicsMap.makeMapPointFromCoreCoordinates(followedRelayer.getCharacter().getX(), followedRelayer.getCharacter().getY());
GraphicsMapPoint initialTopLeftMapPoint = GraphicalBridgeConfiguration.makeMapPointFromCoreCoordinates(followedRelayer.getCharacter().getX(), followedRelayer.getCharacter().getY());
visionBox = new VisionBox(initialTopLeftMapPoint, getSize().width, getSize().height, graphicsMap);
repaint();
}
......
......@@ -10,6 +10,7 @@ import gameloop.DummyLocalGameLoop;
import gameloop.GameStarter;
import graphics.graphical_abstraction.panel.GamePanelAbstraction;
import graphics.graphical_abstraction.panel.GamePanelAbstractionController;
import graphics.graphical_utility.GraphicalBridgeConfiguration;
import graphics.graphical_utility.coreProcesses.GameContentMapChangeListener;
import graphics.guiSkeleton.*;
import graphics.guiSkeleton.entityDisplayer.HealthBarDisplayer;
......@@ -84,7 +85,7 @@ public class GamePanel2 extends GUIPanel implements GameContentMapChangeListener
//Getting the map, creating a bufferedImage out of it and storing it
GraphicsMap graphicsMap = MapDrawer.drawMap(gameContent.getMap());
GraphicsMapPoint initialTopLeftGraphicsMapPoint = graphicsMap.makeMapPointFromCoreCoordinates(followedRelayer.getCharacter().getX(), followedRelayer.getCharacter().getY());
GraphicsMapPoint initialTopLeftGraphicsMapPoint = GraphicalBridgeConfiguration.makeMapPointFromCoreCoordinates(followedRelayer.getCharacter().getX(), followedRelayer.getCharacter().getY());
visionBox = new VisionBox(initialTopLeftGraphicsMapPoint, getSize().width, getSize().height, graphicsMap);
topLeftLabel = new JLabel("Press ESC to go back to main menu");
......@@ -161,7 +162,7 @@ public class GamePanel2 extends GUIPanel implements GameContentMapChangeListener
// System.out.println("coreEntityTopLeft "+processedEntity.getTopLeft().getPosX()+","+processedEntity.getTopLeft().getPosY());
//Debug
// System.out.println("coreColBoxTopLeft "+collisionBox.getTopLeft().getPosX()+","+collisionBox.getTopLeft().getPosY());
GraphicsMapPoint graphicsTopLeft = visionBox.getGraphicsMap().makeMapPointFromCoreCoordinates(coreTopLeft.getPosX(), coreTopLeft.getPosY());
GraphicsMapPoint graphicsTopLeft = GraphicalBridgeConfiguration.makeMapPointFromCoreCoordinates(coreTopLeft.getPosX(), coreTopLeft.getPosY());
//Debug
// GraphicsMapPoint graphicsEntityTopLeft = visionBox.getGraphicsMap().makeMapPointFromCoreCoordinates(processedEntity.getTopLeft().getPosX(), processedEntity.getTopLeft().getPosY());
//Debug
......@@ -174,11 +175,11 @@ public class GamePanel2 extends GUIPanel implements GameContentMapChangeListener
if(zone instanceof Rectangle){
Rectangle rectColBox = (Rectangle) zone;
//getWidth and getHeight may have to be swapped (these are method from the core, and I'm unsure about what their return mean in swing coordinate system)
g.drawRect(gpmp.getX(), gpmp.getY(), DistanceConverter.core2Graphics(rectColBox.getWidth()), DistanceConverter.core2Graphics(rectColBox.getHeight()));
g.drawRect(gpmp.getX(), gpmp.getY(), GraphicalBridgeConfiguration.core2Graphics(rectColBox.getWidth()), GraphicalBridgeConfiguration.core2Graphics(rectColBox.getHeight()));
}
if(zone instanceof Circle){
Circle circleColBox = (Circle) zone;
g.drawOval(gpmp.getX(), gpmp.getY(), DistanceConverter.core2Graphics(2 * circleColBox.getRadius()), DistanceConverter.core2Graphics(2 * circleColBox.getRadius()));
g.drawOval(gpmp.getX(), gpmp.getY(), GraphicalBridgeConfiguration.core2Graphics(2 * circleColBox.getRadius()), GraphicalBridgeConfiguration.core2Graphics(2 * circleColBox.getRadius()));
}
}
......@@ -192,7 +193,7 @@ public class GamePanel2 extends GUIPanel implements GameContentMapChangeListener
}
/** Get the GraphicsMapPoint of the position of the entity followed by the gamePanel **/
GraphicsMapPoint followedEntityPositionGraphicsMapPoint = visionBox.getGraphicsMap().makeMapPointFromCoreCoordinates(followedRelayer.getCharacter().getX(), followedRelayer.getCharacter().getY());
GraphicsMapPoint followedEntityPositionGraphicsMapPoint = GraphicalBridgeConfiguration.makeMapPointFromCoreCoordinates(followedRelayer.getCharacter().getX(), followedRelayer.getCharacter().getY());
if (debugMapPoint) {
System.out.println("followedEntityPositionGraphicsMapPoint:");
followedEntityPositionGraphicsMapPoint.print();
......@@ -274,7 +275,7 @@ public class GamePanel2 extends GUIPanel implements GameContentMapChangeListener
@Override
public void mapChange() {
GraphicsMap graphicsMap = MapDrawer.drawMap(DummyLocalGameLoop.getInstance().getContent().getMap());
GraphicsMapPoint initialTopLeftMapPoint = graphicsMap.makeMapPointFromCoreCoordinates(followedRelayer.getCharacter().getX(), followedRelayer.getCharacter().getY());
GraphicsMapPoint initialTopLeftMapPoint = GraphicalBridgeConfiguration.makeMapPointFromCoreCoordinates(followedRelayer.getCharacter().getX(), followedRelayer.getCharacter().getY());
visionBox = new VisionBox(initialTopLeftMapPoint, getSize().width, getSize().height, graphicsMap);
repaint();
}
......
......@@ -45,14 +45,5 @@ public class GraphicsMap {
return Width * TileSprite.TileSpriteWidth();
}
/**
* Convert the coordinates of a Point instance (defined in the core) to an instance of GraphicsMapPoint (with coordinates in the Swing system)
* @param x: the x coordinate of an instance of Point (IN THE CORE COORDINATE SYSTEM !)
* @param y: the y coordinate of the same instance of Point (IN THE CORE COORDINATE SYSTEM !)
* @return
*/
public GraphicsMapPoint makeMapPointFromCoreCoordinates(int x, int y)
{
return new GraphicsMapPoint(y,x);
}
}
package graphics.guiSkeleton.mapManagement;
package graphics.guiSkeleton.mapManagement.trash;
import core.zone.Point;
import graphics.guiSkeleton.tileSpriteLinker.TileSprite;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment