mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 11:29:46 +02:00
Anpassungen für Fullscreen und die Skalierung von Bildern.
This commit is contained in:
@@ -19,7 +19,10 @@ public class DynamicObject extends JComponent{
|
|||||||
//private Image image;
|
//private Image image;
|
||||||
private BufferedImage bf1;
|
private BufferedImage bf1;
|
||||||
private Graphics2D g2d;
|
private Graphics2D g2d;
|
||||||
private double rescaleFactor = 0.0;
|
|
||||||
|
private boolean doRescale = false;
|
||||||
|
private double rescaleFactorX = 0.0;
|
||||||
|
private double rescaleFactorY = 0.0;
|
||||||
|
|
||||||
public DynamicObject() {
|
public DynamicObject() {
|
||||||
}
|
}
|
||||||
@@ -32,8 +35,8 @@ public class DynamicObject extends JComponent{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//g2d.rotate(0.3, 10, 10);
|
//g2d.rotate(0.3, 10, 10);
|
||||||
if ( rescaleFactor != 0.0 ) {
|
if ( doRescale ) {
|
||||||
g2d.scale(rescaleFactor, rescaleFactor);
|
g2d.scale(rescaleFactorX, rescaleFactorY);
|
||||||
}
|
}
|
||||||
|
|
||||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
@@ -54,9 +57,21 @@ public class DynamicObject extends JComponent{
|
|||||||
this.bf1 = image;
|
this.bf1 = image;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRescale(double rescaleFactor) {
|
public void setRescale(double rescaleFactorX, double rescaleFactorY) {
|
||||||
this.rescaleFactor = rescaleFactor;
|
this.rescaleFactorX = rescaleFactorX;
|
||||||
//this.setBounds(x, y, width, height);
|
this.rescaleFactorY = rescaleFactorY;
|
||||||
|
this.doRescale = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void unsetRescale() {
|
||||||
|
this.rescaleFactorX = 0.0;
|
||||||
|
this.rescaleFactorY = 0.0;
|
||||||
|
this.doRescale = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAutoBounds(int x, int y) {
|
||||||
|
this.setBounds(x, y, this.bf1.getWidth(), this.bf1.getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class ImageLoader {
|
|||||||
imageFileName="src/de/heatup/resources/images/25x25_black.png";
|
imageFileName="src/de/heatup/resources/images/25x25_black.png";
|
||||||
break;
|
break;
|
||||||
case '-':
|
case '-':
|
||||||
imageFileName="src/de/heatup/resources/images/25x25_red.png";
|
imageFileName="src/de/heatup/resources/images/25x25_wall_orange_2.png";
|
||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
imageFileName="src/de/heatup/resources/images/little_green_guy_up.png";
|
imageFileName="src/de/heatup/resources/images/little_green_guy_up.png";
|
||||||
@@ -49,6 +49,11 @@ public class ImageLoader {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// TODO: handle exception
|
// TODO: handle exception
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// loadedBufferedImage shouldn't be null here anymore, if so an error occurred
|
||||||
|
if (loadedBufferedImage == null) {
|
||||||
|
System.out.println("No texture defined, failed to use default texture.");
|
||||||
|
}
|
||||||
return loadedBufferedImage;
|
return loadedBufferedImage;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,11 @@ public class StaticObject extends JComponent {
|
|||||||
//private Image image;
|
//private Image image;
|
||||||
private BufferedImage bf1;
|
private BufferedImage bf1;
|
||||||
private Graphics2D g2d;
|
private Graphics2D g2d;
|
||||||
private double rescaleFactor = 0.0;
|
|
||||||
|
private boolean doRescale = false;
|
||||||
|
private double rescaleFactorX = 0.0;
|
||||||
|
private double rescaleFactorY = 0.0;
|
||||||
|
|
||||||
private Point location;
|
private Point location;
|
||||||
private char staticObjectType;
|
private char staticObjectType;
|
||||||
private int staticObjectWidth;
|
private int staticObjectWidth;
|
||||||
@@ -47,9 +51,10 @@ public class StaticObject extends JComponent {
|
|||||||
}
|
}
|
||||||
//g2d.rotate(0.2, 10, 10);
|
//g2d.rotate(0.2, 10, 10);
|
||||||
|
|
||||||
if ( rescaleFactor != 0.0 ) {
|
if ( doRescale ) {
|
||||||
g2d.scale(rescaleFactor, rescaleFactor);
|
g2d.scale(rescaleFactorX, rescaleFactorY);
|
||||||
}
|
}
|
||||||
|
|
||||||
g2d.drawImage(bf1, 0, 0, this);
|
g2d.drawImage(bf1, 0, 0, this);
|
||||||
g2d.finalize();
|
g2d.finalize();
|
||||||
}
|
}
|
||||||
@@ -62,9 +67,16 @@ public class StaticObject extends JComponent {
|
|||||||
this.bf1 = image;
|
this.bf1 = image;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRescale(double rescaleFactor) {
|
public void setRescale(double rescaleFactorX, double rescaleFactorY) {
|
||||||
this.rescaleFactor = rescaleFactor;
|
this.rescaleFactorX = rescaleFactorX;
|
||||||
//this.setBounds(x, y, width, height);
|
this.rescaleFactorY = rescaleFactorY;
|
||||||
|
this.doRescale = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unsetRescale() {
|
||||||
|
this.rescaleFactorX = 0.0;
|
||||||
|
this.rescaleFactorY = 0.0;
|
||||||
|
this.doRescale = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAutoBounds(int x, int y) {
|
public void setAutoBounds(int x, int y) {
|
||||||
@@ -72,7 +84,7 @@ public class StaticObject extends JComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getDebugInfo() {
|
public String getDebugInfo() {
|
||||||
String info = "Debug: " + "Rescale Factor:" + this.rescaleFactor + " Heigth:" + this.staticObjectHeight + " Width:" + this.staticObjectWidth + " StaticObjectType:" + this.staticObjectType + " X Position:" + this.location.x + " Y Position:" + this.location.y;
|
String info = "Debug: " + "Rescale enabled:" + this.doRescale + "Rescale X:" + this.rescaleFactorX + "Rescale Y:" + this.rescaleFactorY + " Heigth:" + this.staticObjectHeight + " Width:" + this.staticObjectWidth + " StaticObjectType:" + this.staticObjectType + " X Position:" + this.location.x + " Y Position:" + this.location.y;
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 260 B |
Binary file not shown.
|
After Width: | Height: | Size: 343 B |
Binary file not shown.
|
After Width: | Height: | Size: 406 B |
Binary file not shown.
|
After Width: | Height: | Size: 233 B |
@@ -1,6 +1,6 @@
|
|||||||
################################
|
################################
|
||||||
#--11-----#-----------#222222--#
|
#--1111----#----------#222222--#
|
||||||
#--11-----#-----------#222222--#
|
#--1111----#----------#222222--#
|
||||||
#######################222222###
|
#######################222222###
|
||||||
#---------#----------#########-#
|
#---------#----------#########-#
|
||||||
###############-######---------#
|
###############-######---------#
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package de.heatup.testing;
|
package de.heatup.testing;
|
||||||
|
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
|
||||||
import de.heatup.mapengine.MapEngine;
|
import de.heatup.mapengine.MapEngine;
|
||||||
import de.heatup.objects.DynamicObject;
|
import de.heatup.objects.DynamicObject;
|
||||||
import de.heatup.objects.StaticObject;
|
import de.heatup.objects.StaticObject;
|
||||||
@@ -21,13 +23,16 @@ public class GameLoop {
|
|||||||
DynamicObject dynO4 = new DynamicObject();
|
DynamicObject dynO4 = new DynamicObject();
|
||||||
GameInterface.getGamePanel().add(dynO4);
|
GameInterface.getGamePanel().add(dynO4);
|
||||||
|
|
||||||
dynO4.setRescale(0.5);
|
//dynO3.setRescale(1.5,3.5);
|
||||||
|
|
||||||
|
|
||||||
MapEngine me = new MapEngine(1);
|
MapEngine me = new MapEngine(1);
|
||||||
for (StaticObject currentStaticObject : me.getAllMapObjects()) {
|
for (StaticObject currentStaticObject : me.getAllMapObjects()) {
|
||||||
GameInterface.getGamePanel().add(currentStaticObject);
|
GameInterface.getGamePanel().add(currentStaticObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GameInterface.getGamePanel().setVisible(true);
|
||||||
|
|
||||||
//GameInterface.getGamePanel().repaint();
|
//GameInterface.getGamePanel().repaint();
|
||||||
//GameInterface.getGamePanel().setComponentZOrder(dynO1, 1);
|
//GameInterface.getGamePanel().setComponentZOrder(dynO1, 1);
|
||||||
//GameInterface.getGamePanel().add(dynO1);
|
//GameInterface.getGamePanel().add(dynO1);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.UnsupportedLookAndFeelException;
|
import javax.swing.UnsupportedLookAndFeelException;
|
||||||
@@ -49,12 +50,12 @@ public class GameInterface extends JFrame {
|
|||||||
|
|
||||||
final JFrame frame = new JFrame();
|
final JFrame frame = new JFrame();
|
||||||
|
|
||||||
// Fullscreen testing
|
// Fullscreen testing: Remember not to use pack() when using fullscreen mode
|
||||||
// frame.setUndecorated(true);
|
frame.setUndecorated(true);
|
||||||
// frame.setResizable(false);
|
frame.setResizable(false);
|
||||||
// frame.setExtendedState(Frame.MAXIMIZED_BOTH);
|
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
|
||||||
// frame.validate();
|
frame.validate();
|
||||||
// GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(frame);
|
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(frame);
|
||||||
|
|
||||||
frame.setTitle("HeatUP!");
|
frame.setTitle("HeatUP!");
|
||||||
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||||
@@ -78,6 +79,7 @@ public class GameInterface extends JFrame {
|
|||||||
gamePanel = new JPanel();
|
gamePanel = new JPanel();
|
||||||
gamePanel.setLayout(null);
|
gamePanel.setLayout(null);
|
||||||
gamePanel.setPreferredSize(new Dimension(800,600));
|
gamePanel.setPreferredSize(new Dimension(800,600));
|
||||||
|
gamePanel.setVisible(true);
|
||||||
//gamePanel.setBorder(BorderFactory.createTitledBorder("gamePanel"));
|
//gamePanel.setBorder(BorderFactory.createTitledBorder("gamePanel"));
|
||||||
|
|
||||||
actionPanel = new JPanel();
|
actionPanel = new JPanel();
|
||||||
@@ -91,7 +93,8 @@ public class GameInterface extends JFrame {
|
|||||||
outerPanel.add(actionPanel,BorderLayout.SOUTH);
|
outerPanel.add(actionPanel,BorderLayout.SOUTH);
|
||||||
|
|
||||||
frame.add(outerPanel);
|
frame.add(outerPanel);
|
||||||
frame.pack();
|
// Comment out for fullscreen
|
||||||
|
//frame.pack();
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
frame.repaint();
|
frame.repaint();
|
||||||
}
|
}
|
||||||
@@ -106,10 +109,11 @@ public class GameInterface extends JFrame {
|
|||||||
EventQueue.invokeLater(new Runnable() {
|
EventQueue.invokeLater(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
//GameInterface gameWindow = new GameInterface();
|
// GameInterface is static now.
|
||||||
|
//GameInterface gameWindow = new GameInterface();
|
||||||
GameInterface.createGUI();
|
GameInterface.createGUI();
|
||||||
|
|
||||||
// TODO: Gameloop needs to be added here!!!
|
// Start game loop to add player, opponents, maps and everything you need
|
||||||
GameLoop.startGameLoop();
|
GameLoop.startGameLoop();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user