From 9d5b6fabcc0489fbf86fcd47d8dc773c39476443 Mon Sep 17 00:00:00 2001 From: andreas Date: Tue, 4 Nov 2014 10:05:46 +0100 Subject: [PATCH] =?UTF-8?q?Anpassungen=20f=C3=BCr=20Fullscreen=20und=20die?= =?UTF-8?q?=20Skalierung=20von=20Bildern.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/de/heatup/objects/DynamicObject.java | 29 +++++++++++++----- HeatUp/src/de/heatup/objects/ImageLoader.java | 9 ++++-- .../src/de/heatup/objects/StaticObject.java | 26 +++++++++++----- .../heatup/resources/images/25x25_theGrid.png | Bin 0 -> 260 bytes .../resources/images/25x25_wall_orange.png | Bin 0 -> 343 bytes .../resources/images/25x25_wall_orange_1.png | Bin 0 -> 406 bytes .../resources/images/25x25_wall_orange_2.png | Bin 0 -> 233 bytes HeatUp/src/de/heatup/resources/maps/map1.txt | 4 +-- HeatUp/src/de/heatup/testing/GameLoop.java | 7 ++++- HeatUp/src/de/heatup/ui/GameInterface.java | 26 +++++++++------- 10 files changed, 71 insertions(+), 30 deletions(-) create mode 100644 HeatUp/src/de/heatup/resources/images/25x25_theGrid.png create mode 100644 HeatUp/src/de/heatup/resources/images/25x25_wall_orange.png create mode 100644 HeatUp/src/de/heatup/resources/images/25x25_wall_orange_1.png create mode 100644 HeatUp/src/de/heatup/resources/images/25x25_wall_orange_2.png diff --git a/HeatUp/src/de/heatup/objects/DynamicObject.java b/HeatUp/src/de/heatup/objects/DynamicObject.java index 45c81d1..d3bb555 100644 --- a/HeatUp/src/de/heatup/objects/DynamicObject.java +++ b/HeatUp/src/de/heatup/objects/DynamicObject.java @@ -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()); + } + + } diff --git a/HeatUp/src/de/heatup/objects/ImageLoader.java b/HeatUp/src/de/heatup/objects/ImageLoader.java index ef433ed..b63576d 100644 --- a/HeatUp/src/de/heatup/objects/ImageLoader.java +++ b/HeatUp/src/de/heatup/objects/ImageLoader.java @@ -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; } diff --git a/HeatUp/src/de/heatup/objects/StaticObject.java b/HeatUp/src/de/heatup/objects/StaticObject.java index 09c9f7c..ebf1066 100644 --- a/HeatUp/src/de/heatup/objects/StaticObject.java +++ b/HeatUp/src/de/heatup/objects/StaticObject.java @@ -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; } } diff --git a/HeatUp/src/de/heatup/resources/images/25x25_theGrid.png b/HeatUp/src/de/heatup/resources/images/25x25_theGrid.png new file mode 100644 index 0000000000000000000000000000000000000000..5fc705a218ca5549834f15ffae7667fc37e0f9ed GIT binary patch literal 260 zcmeAS@N?(olHy`uVBq!ia0vp^k|4~%1|*NXY)uAIY)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmPqHxn1Pa;Ysd$VkZ&*N775{M_8syb=cIqSVBa)D(sC z%#sWRcTeAd@J2pyprRa47sn8f<8LP)^`RI#H`C4PQ(DU&pV vzVdFlg`GBY<`nbF-#qoqc$tc-{lpma9~R+J3xeH%_A+?7`njxgN@xNA{vA%? literal 0 HcmV?d00001 diff --git a/HeatUp/src/de/heatup/resources/images/25x25_wall_orange.png b/HeatUp/src/de/heatup/resources/images/25x25_wall_orange.png new file mode 100644 index 0000000000000000000000000000000000000000..7615d0590792728949582a52e4f29af8e4eda69f GIT binary patch literal 343 zcmeAS@N?(olHy`uVBq!ia0vp^k|4~%1|*NXY)uAIY)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmPqHxrkT_1{1v7od=2iEBiObAE1aYF-J0b5UwyNotBh zd1gt5g1e`0KzJjcI8f1kPZ!4!kK=Ez8S))6;Awq$-*17|t4quZVmtox?qKP;`!Y;L zLThWUq?AgT4x31Rx9-IR0@7Sas=s7KSn-kIa zYQY699X=0+yv|krXV?Tkv8+90cOd1yvUFp6VrH$|3GJwe#+!*khCd?qerne8aO4V_ z(DcVv=>ANf6P;>)Cs*uzFU@H=x$=q2=NsoIT$nI%?g0g-tLopgpK3a-b=%W-VWr{h g|M6F{N|g67cv{((^8EZ<0`v-lr>mdKI;Vst0NqG_;s5{u literal 0 HcmV?d00001 diff --git a/HeatUp/src/de/heatup/resources/images/25x25_wall_orange_1.png b/HeatUp/src/de/heatup/resources/images/25x25_wall_orange_1.png new file mode 100644 index 0000000000000000000000000000000000000000..ed5763ca97b7e880636081981638b521ea16dc69 GIT binary patch literal 406 zcmeAS@N?(olHy`uVBq!ia0vp^k|4~%1|*NXY)uAIY)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmPqHxrkvV*BdrAAv%WC9V-A&iT2ysd*&~&PAz-C8;S2 z<(VZJ3hti10pX2&;y^|JJY5_^JdVGew$Y2(QJ`)A%vc+}B`1Y%tVmVZx_*MydW|0f zW!IXbPJUh1-TJ`sU0Ki_F~;{oU)>x}gmH8KH~-9Uyt$~n(N}cakNKSkf_V#96;!gN za%(a^T9CJZ@t(_yD;?2R4u$Isf-__l7%O~5Ub`dB0kluRbh)%72ct zsOe9!hs^Da#fsd2pZc`5&6Qq~AJebD=jqg!Yjdh+w(OalE4i!p8RHEV6LvXuCTYR0 v(xU%s_jCuW5}cpC;!4Ju{q|m_tE9@h^PG2IWcaiU7!nMgu6{1-oD!Mq}*~r(xdMx3NS1teF?`bj&^B3Iq z<8TqH3uhfW*zkjeK~$dq VvVGWvr$ECQJYD@<);T3K0RV6KOk4l} literal 0 HcmV?d00001 diff --git a/HeatUp/src/de/heatup/resources/maps/map1.txt b/HeatUp/src/de/heatup/resources/maps/map1.txt index 688914d..3c648a4 100644 --- a/HeatUp/src/de/heatup/resources/maps/map1.txt +++ b/HeatUp/src/de/heatup/resources/maps/map1.txt @@ -1,6 +1,6 @@ ################################ -#--11-----#-----------#222222--# -#--11-----#-----------#222222--# +#--1111----#----------#222222--# +#--1111----#----------#222222--# #######################222222### #---------#----------#########-# ###############-######---------# diff --git a/HeatUp/src/de/heatup/testing/GameLoop.java b/HeatUp/src/de/heatup/testing/GameLoop.java index dde61f1..be6d589 100644 --- a/HeatUp/src/de/heatup/testing/GameLoop.java +++ b/HeatUp/src/de/heatup/testing/GameLoop.java @@ -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); diff --git a/HeatUp/src/de/heatup/ui/GameInterface.java b/HeatUp/src/de/heatup/ui/GameInterface.java index 3be2d03..1f2d99b 100644 --- a/HeatUp/src/de/heatup/ui/GameInterface.java +++ b/HeatUp/src/de/heatup/ui/GameInterface.java @@ -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(); } });