Commit 9d4f9ffe authored by Guillaume Hocquet's avatar Guillaume Hocquet

Minimap Display

parent 41dc1eca
......@@ -44,9 +44,14 @@ public class MainFrame extends JFrame implements FrameAbstraction {
@Override
public void init(FrameKeyListenerAbstraction keyListenerAbstraction) {
boolean fullscreen = false;
this.setFocusable(true); //For the keyListener to work
this.addKeyListener((KeyListener)keyListenerAbstraction);
this.revalidate();
if (fullscreen) {
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
this.setUndecorated(true);
}
this.setVisible(true);
}
......
package graphics.guiSkeleton;
import core.gamestate.GameContent;
import core.relayer.Relayer;
import graphics.guiSkeleton.guiPanel.GamePanel;
import graphics.guiSkeleton.mapManagement.GraphicsMap;
import graphics.guiSkeleton.mapManagement.MapDrawer;
import graphics.guiSkeleton.tileSpriteLinker.TileSprite;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.WritableRaster;
/**
* Created by ghocquet on 02/01/16.
*
* Display the minimap
*/
public class MinimapDisplayer
{
private Graphics2D g_map;
private Relayer relayer;
private GamePanel gamePanel;
private BufferedImage map;
private int mapWidth;
private int mapHeight;
private int tileW = TileSprite.TileSpriteWidth();
private int tileH = TileSprite.TileSpriteHeight();
private Color playerColor = new Color(255,0,0);
private Color stairsColor = new Color(255,255,0);
/**
* @param gameContent: used to get the map generated
* @param followedRelayer: used to get the position of the player
* @param gamePanel: used to get the width of the displayed screen
*/
public MinimapDisplayer(GameContent gameContent,
Relayer followedRelayer,
GamePanel gamePanel)
{
this.relayer = followedRelayer;
this.gamePanel = gamePanel;
// Compute the Map
GraphicsMap graphicsMap = MapDrawer.drawMap(gameContent.getMap());
mapWidth = graphicsMap.getMapPixelWidth();
mapHeight = graphicsMap.getMapPixelWidth();
map = new BufferedImage((mapWidth-1) / tileW + 1, (mapHeight-1) / tileH + 1, BufferedImage.TYPE_INT_ARGB);
g_map = map.createGraphics();
for (int i = 0 / tileW; i <= (mapWidth-1) / tileW ; i++)
{
for (int j = 0 / tileH; j <= (mapHeight-1) / tileH ; j++)
{
g_map.drawImage(graphicsMap.getSprite(i,j), i, j, 1, 1, null);
}
}
// Draw the Stairs
core.zone.Point out = gameContent.getMap().getPositionStairs().getPoint();
g_map.setColor(stairsColor);
g_map.drawRect(out.getPosY()/tileW-1,out.getPosX()/tileH-1,3,3);
}
public void displayMap(Graphics g) {
// Copy the map
ColorModel cm = map.getColorModel();
boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
WritableRaster raster = map.copyData(null);
BufferedImage newMap = new BufferedImage(cm, raster, isAlphaPremultiplied, null);
// Update the map
Graphics2D g_newMap = newMap.createGraphics();
g_newMap.setColor(playerColor);
g_newMap.drawRect(relayer.getCharacter().getY()/tileW-1,relayer.getCharacter().getX()/tileH-1,3,3);
// Draw on the Screen
g.drawImage(newMap, gamePanel.getSize().width - (mapWidth-1) / tileW, 0, null);
}
}
......@@ -54,6 +54,9 @@ public class GamePanel extends GUIPanel implements GameContentMapChangeListener,
//Avatar of the character
private AvatarDisplayer MyAvatarDisplayer;
//Minimap
private MinimapDisplayer MyMinimapDisplayer;
//private boolean spellReleased=true;
//private boolean attackReleased=true;
......@@ -98,6 +101,9 @@ public class GamePanel extends GUIPanel implements GameContentMapChangeListener,
topLeftLabel.setBackground(new Color(0, 0, 0));
this.add(topLeftLabel, BorderLayout.NORTH);
//Draw the minimap
MyMinimapDisplayer = new MinimapDisplayer(gameContent, followedRelayer, this);
initialised = true;
}
......@@ -254,13 +260,12 @@ public class GamePanel extends GUIPanel implements GameContentMapChangeListener,
}
}
// Spell Display :
/** Spell Display **/
MySpellDisplayer = new SpellDisplayer(g,followedEntityPositionGraphicsMapPoint, getWidth(), getHeight(), followedRelayer.getCharacter().getAbilityList());
MySpellDisplayer.displaySpell();
//TODO: here we should display the minimap (so entities shouldn't pass on it)
/** Minimap Display **/
MyMinimapDisplayer.displayMap(g);
}
}
......
......@@ -14,7 +14,7 @@ import java.awt.image.BufferedImage;
* - the size of the map (in quarter of tile)
*/
public class GraphicsMap {
public class GraphicsMap{
private final int Height;
private final int Width;
......
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