mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 12:29:44 +02:00
Anpassungen für Fullscreen und die Skalierung von Bildern.
This commit is contained in:
@@ -16,10 +16,13 @@ import javax.swing.JComponent;
|
||||
*/
|
||||
public class DynamicObject extends JComponent{
|
||||
private static final long serialVersionUID = 1L;
|
||||
//private Image image;
|
||||
//private Image image;
|
||||
private BufferedImage bf1;
|
||||
private Graphics2D g2d;
|
||||
private double rescaleFactor = 0.0;
|
||||
|
||||
private boolean doRescale = false;
|
||||
private double rescaleFactorX = 0.0;
|
||||
private double rescaleFactorY = 0.0;
|
||||
|
||||
public DynamicObject() {
|
||||
}
|
||||
@@ -32,8 +35,8 @@ public class DynamicObject extends JComponent{
|
||||
}
|
||||
|
||||
//g2d.rotate(0.3, 10, 10);
|
||||
if ( rescaleFactor != 0.0 ) {
|
||||
g2d.scale(rescaleFactor, rescaleFactor);
|
||||
if ( doRescale ) {
|
||||
g2d.scale(rescaleFactorX, rescaleFactorY);
|
||||
}
|
||||
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
@@ -54,9 +57,21 @@ public class DynamicObject extends JComponent{
|
||||
this.bf1 = image;
|
||||
}
|
||||
|
||||
public void setRescale(double rescaleFactor) {
|
||||
this.rescaleFactor = rescaleFactor;
|
||||
//this.setBounds(x, y, width, height);
|
||||
public void setRescale(double rescaleFactorX, double rescaleFactorY) {
|
||||
this.rescaleFactorX = rescaleFactorX;
|
||||
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";
|
||||
break;
|
||||
case '-':
|
||||
imageFileName="src/de/heatup/resources/images/25x25_red.png";
|
||||
imageFileName="src/de/heatup/resources/images/25x25_wall_orange_2.png";
|
||||
break;
|
||||
case 'u':
|
||||
imageFileName="src/de/heatup/resources/images/little_green_guy_up.png";
|
||||
@@ -48,7 +48,12 @@ public class ImageLoader {
|
||||
loadedBufferedImage = ImageIO.read(new File(imageFileName));
|
||||
} catch (Exception e) {
|
||||
// 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;
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,11 @@ public class StaticObject extends JComponent {
|
||||
//private Image image;
|
||||
private BufferedImage bf1;
|
||||
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 char staticObjectType;
|
||||
private int staticObjectWidth;
|
||||
@@ -47,9 +51,10 @@ public class StaticObject extends JComponent {
|
||||
}
|
||||
//g2d.rotate(0.2, 10, 10);
|
||||
|
||||
if ( rescaleFactor != 0.0 ) {
|
||||
g2d.scale(rescaleFactor, rescaleFactor);
|
||||
if ( doRescale ) {
|
||||
g2d.scale(rescaleFactorX, rescaleFactorY);
|
||||
}
|
||||
|
||||
g2d.drawImage(bf1, 0, 0, this);
|
||||
g2d.finalize();
|
||||
}
|
||||
@@ -62,9 +67,16 @@ public class StaticObject extends JComponent {
|
||||
this.bf1 = image;
|
||||
}
|
||||
|
||||
public void setRescale(double rescaleFactor) {
|
||||
this.rescaleFactor = rescaleFactor;
|
||||
//this.setBounds(x, y, width, height);
|
||||
public void setRescale(double rescaleFactorX, double rescaleFactorY) {
|
||||
this.rescaleFactorX = rescaleFactorX;
|
||||
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) {
|
||||
@@ -72,7 +84,7 @@ public class StaticObject extends JComponent {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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--#
|
||||
#--11-----#-----------#222222--#
|
||||
#--1111----#----------#222222--#
|
||||
#--1111----#----------#222222--#
|
||||
#######################222222###
|
||||
#---------#----------#########-#
|
||||
###############-######---------#
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package de.heatup.testing;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
|
||||
import de.heatup.mapengine.MapEngine;
|
||||
import de.heatup.objects.DynamicObject;
|
||||
import de.heatup.objects.StaticObject;
|
||||
@@ -21,13 +23,16 @@ public class GameLoop {
|
||||
DynamicObject dynO4 = new DynamicObject();
|
||||
GameInterface.getGamePanel().add(dynO4);
|
||||
|
||||
dynO4.setRescale(0.5);
|
||||
//dynO3.setRescale(1.5,3.5);
|
||||
|
||||
|
||||
MapEngine me = new MapEngine(1);
|
||||
for (StaticObject currentStaticObject : me.getAllMapObjects()) {
|
||||
GameInterface.getGamePanel().add(currentStaticObject);
|
||||
}
|
||||
|
||||
GameInterface.getGamePanel().setVisible(true);
|
||||
|
||||
//GameInterface.getGamePanel().repaint();
|
||||
//GameInterface.getGamePanel().setComponentZOrder(dynO1, 1);
|
||||
//GameInterface.getGamePanel().add(dynO1);
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.io.IOException;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.UnsupportedLookAndFeelException;
|
||||
@@ -49,12 +50,12 @@ public class GameInterface extends JFrame {
|
||||
|
||||
final JFrame frame = new JFrame();
|
||||
|
||||
// Fullscreen testing
|
||||
// frame.setUndecorated(true);
|
||||
// frame.setResizable(false);
|
||||
// frame.setExtendedState(Frame.MAXIMIZED_BOTH);
|
||||
// frame.validate();
|
||||
// GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(frame);
|
||||
// Fullscreen testing: Remember not to use pack() when using fullscreen mode
|
||||
frame.setUndecorated(true);
|
||||
frame.setResizable(false);
|
||||
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
|
||||
frame.validate();
|
||||
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(frame);
|
||||
|
||||
frame.setTitle("HeatUP!");
|
||||
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
@@ -78,8 +79,9 @@ public class GameInterface extends JFrame {
|
||||
gamePanel = new JPanel();
|
||||
gamePanel.setLayout(null);
|
||||
gamePanel.setPreferredSize(new Dimension(800,600));
|
||||
gamePanel.setVisible(true);
|
||||
//gamePanel.setBorder(BorderFactory.createTitledBorder("gamePanel"));
|
||||
|
||||
|
||||
actionPanel = new JPanel();
|
||||
actionPanel.setLayout(new GridLayout(1,1));
|
||||
//actionPanel.setBorder(BorderFactory.createTitledBorder("actionPanel"));
|
||||
@@ -91,7 +93,8 @@ public class GameInterface extends JFrame {
|
||||
outerPanel.add(actionPanel,BorderLayout.SOUTH);
|
||||
|
||||
frame.add(outerPanel);
|
||||
frame.pack();
|
||||
// Comment out for fullscreen
|
||||
//frame.pack();
|
||||
frame.setVisible(true);
|
||||
frame.repaint();
|
||||
}
|
||||
@@ -106,10 +109,11 @@ public class GameInterface extends JFrame {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
//GameInterface gameWindow = new GameInterface();
|
||||
// GameInterface is static now.
|
||||
//GameInterface gameWindow = new GameInterface();
|
||||
GameInterface.createGUI();
|
||||
|
||||
// TODO: Gameloop needs to be added here!!!
|
||||
|
||||
// Start game loop to add player, opponents, maps and everything you need
|
||||
GameLoop.startGameLoop();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user