mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 11:39:45 +02:00
Anpassungen GameInterface für Graphis2d
This commit is contained in:
@@ -18,12 +18,14 @@ public class DynamicObject extends JComponent{
|
|||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
//private Image image;
|
//private Image image;
|
||||||
private BufferedImage bf1;
|
private BufferedImage bf1;
|
||||||
|
private Graphics2D g2d;
|
||||||
|
private double rescaleFactor = 0.0;
|
||||||
|
|
||||||
public DynamicObject() {
|
public DynamicObject() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void paintComponent(Graphics g) {
|
public void paintComponent(Graphics g) {
|
||||||
Graphics2D g2d = (Graphics2D)g;
|
g2d = (Graphics2D)g;
|
||||||
//this.image = Toolkit.getDefaultToolkit().getImage("src/de/heatup/resources/images/little_green_guy.png");
|
//this.image = Toolkit.getDefaultToolkit().getImage("src/de/heatup/resources/images/little_green_guy.png");
|
||||||
try {
|
try {
|
||||||
if ( bf1 == null ) {
|
if ( bf1 == null ) {
|
||||||
@@ -35,17 +37,23 @@ public class DynamicObject extends JComponent{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//g2d.rotate(0.3, 10, 10);
|
//g2d.rotate(0.3, 10, 10);
|
||||||
//g2d.scale(1.0, 1.0);
|
if ( rescaleFactor != 0.0 ) {
|
||||||
|
g2d.scale(rescaleFactor, rescaleFactor);
|
||||||
|
}
|
||||||
//g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
|
//g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
g2d.drawImage(bf1, 0, 0, this);
|
g2d.drawImage(bf1, 0, 0, this);
|
||||||
//g2d.setStroke(new BasicStroke(8.0f));
|
//g2d.setStroke(new BasicStroke(8.0f));
|
||||||
g2d.finalize();
|
g2d.finalize();
|
||||||
|
System.out.println("paintComponent");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setImage(BufferedImage image) {
|
public void setImage(BufferedImage image) {
|
||||||
this.bf1 = image;
|
this.bf1 = image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setRescale(double rescaleFactor) {
|
||||||
|
this.rescaleFactor = rescaleFactor;
|
||||||
|
//this.setBounds(x, y, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,152 +1,102 @@
|
|||||||
package de.heatup.ui;
|
package de.heatup.ui;
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
|
import java.awt.EventQueue;
|
||||||
import java.awt.GridLayout;
|
import java.awt.GridLayout;
|
||||||
import java.awt.event.KeyAdapter;
|
|
||||||
import java.awt.event.KeyEvent;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
import de.heatup.objects.Gegner;
|
import de.heatup.objects.DynamicObject;
|
||||||
import de.heatup.objects.Objekt;
|
import de.heatup.objects.StaticObject;
|
||||||
|
import de.heatup.objects.logic;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class GameInterface extends JFrame {
|
public class GameInterface extends JFrame {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
private JPanel outerPanel;
|
private JPanel outerPanel;
|
||||||
private JPanel statusPanel;
|
private JPanel statusPanel;
|
||||||
private JPanel gamePanel;
|
private JPanel gamePanel;
|
||||||
private JPanel actionPanel;
|
private JPanel actionPanel;
|
||||||
private BufferedImage image;
|
//private BufferedImage image;
|
||||||
|
|
||||||
|
public void createGUI() {
|
||||||
|
final JFrame frame = new JFrame();
|
||||||
|
|
||||||
public GameInterface() throws IOException {
|
frame.setTitle("HeatUP!");
|
||||||
setTitle("HeatUP!");
|
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
frame.setVisible(true);
|
||||||
setVisible(true);
|
frame.setResizable(true);
|
||||||
setResizable(true);
|
//frame.createBufferStrategy(2);
|
||||||
|
|
||||||
|
|
||||||
createLayout();
|
|
||||||
pack();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createLayout() throws IOException {
|
|
||||||
/*
|
|
||||||
* outerPanel ist der Rahmen in dem das Spielfeld und der statusFrame vereinigt werden
|
|
||||||
*/
|
|
||||||
outerPanel = new JPanel();
|
outerPanel = new JPanel();
|
||||||
outerPanel.setLayout(new BorderLayout());
|
outerPanel.setLayout(new BorderLayout());
|
||||||
outerPanel.setBorder(BorderFactory.createTitledBorder("outerPanel"));
|
outerPanel.setBorder(BorderFactory.createTitledBorder("outerPanel"));
|
||||||
outerPanel.setVisible(true);
|
outerPanel.setVisible(true);
|
||||||
|
|
||||||
/*
|
|
||||||
* statusPanel enthält Elemente wie Score, Zeit, Level etc.
|
|
||||||
*/
|
|
||||||
statusPanel = new JPanel();
|
statusPanel = new JPanel();
|
||||||
statusPanel.setLayout(new GridLayout(1,4));
|
statusPanel.setLayout(new GridLayout(1,4));
|
||||||
statusPanel.setPreferredSize(new Dimension(800,80));
|
statusPanel.setPreferredSize(new Dimension(800,80));
|
||||||
statusPanel.setBorder(BorderFactory.createTitledBorder("statusPanel"));
|
statusPanel.setBorder(BorderFactory.createTitledBorder("statusPanel"));
|
||||||
/*
|
|
||||||
* gamePanel enthält das Spielfeld
|
|
||||||
*/
|
|
||||||
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.setBorder(BorderFactory.createTitledBorder("gamePanel"));
|
gamePanel.setBorder(BorderFactory.createTitledBorder("gamePanel"));
|
||||||
/*
|
|
||||||
* actionPanel enthält Informationen zum durchführen einer Tätigkeit
|
|
||||||
*/
|
|
||||||
actionPanel = new JPanel();
|
actionPanel = new JPanel();
|
||||||
actionPanel.setLayout(new GridLayout(1,1));
|
actionPanel.setLayout(new GridLayout(1,1));
|
||||||
actionPanel.setBorder(BorderFactory.createTitledBorder("actionPanel"));
|
actionPanel.setBorder(BorderFactory.createTitledBorder("actionPanel"));
|
||||||
actionPanel.setPreferredSize(new Dimension(800,80));
|
actionPanel.setPreferredSize(new Dimension(800,80));
|
||||||
|
|
||||||
/*
|
|
||||||
* Panel korrekt im Layout ausrichten.
|
|
||||||
*/
|
|
||||||
this.getContentPane().add(outerPanel);
|
|
||||||
outerPanel.add(statusPanel,BorderLayout.NORTH);
|
outerPanel.add(statusPanel,BorderLayout.NORTH);
|
||||||
outerPanel.add(gamePanel,BorderLayout.CENTER);
|
outerPanel.add(gamePanel,BorderLayout.CENTER);
|
||||||
outerPanel.add(actionPanel,BorderLayout.SOUTH);
|
outerPanel.add(actionPanel,BorderLayout.SOUTH);
|
||||||
|
|
||||||
|
gamePanel.add(new StaticObject());
|
||||||
|
frame.add(outerPanel);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
frame.pack();
|
||||||
|
frame.setVisible(true);
|
||||||
|
frame.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We need to use EQ for EDT
|
||||||
|
*/
|
||||||
public static void main(String[] args) throws IOException, InterruptedException {
|
public static void main(String[] args) throws IOException, InterruptedException {
|
||||||
|
|
||||||
GameInterface gameWindow = new GameInterface();
|
EventQueue.invokeLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
GameInterface gameWindow = new GameInterface();
|
||||||
|
gameWindow.createGUI();
|
||||||
|
|
||||||
/*
|
DynamicObject opponent1 = new DynamicObject();
|
||||||
* Gegner Routine instanzieren
|
opponent1.setBounds(0, 0, opponent1.getWidth(), opponent1.getHeight());
|
||||||
*/
|
gameWindow.gamePanel.add(opponent1);
|
||||||
Gegner g1 = new Gegner();
|
|
||||||
Gegner g2 = new Gegner();
|
|
||||||
Gegner g3 = new Gegner();
|
|
||||||
|
|
||||||
//Objekt o1 = new Objekt('0');
|
|
||||||
//o1.getLabel().setVisible(true);
|
|
||||||
|
|
||||||
|
|
||||||
Objekt s1 = new Objekt('0');
|
|
||||||
Objekt s2 = new Objekt('0');
|
|
||||||
Objekt s3 = new Objekt('0');
|
|
||||||
Objekt s4 = new Objekt('0');
|
|
||||||
Objekt s5 = new Objekt('0');
|
|
||||||
Objekt s6 = new Objekt('0');
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Gegner auf Spielfläche hinzufügen und positionieren
|
|
||||||
*/
|
|
||||||
gameWindow.gamePanel.add(g1.getLabel());
|
|
||||||
gameWindow.gamePanel.add(g2.getLabel());
|
|
||||||
gameWindow.gamePanel.add(g3.getLabel());
|
|
||||||
|
|
||||||
//gameWindow.gamePanel.add(o1.getLabel());
|
|
||||||
|
|
||||||
g1.getLabel().setBounds(300, 100, 20, 20);
|
|
||||||
g2.getLabel().setBounds(300, 200, 20, 20);
|
|
||||||
g3.getLabel().setBounds(300, 300, 20, 20);
|
|
||||||
|
|
||||||
//Objekt bg = new Objekt("images/bg_gray.png");
|
|
||||||
//bg.setPosition(0, 0);
|
|
||||||
|
|
||||||
gameWindow.gamePanel.add(s1.getLabel());
|
|
||||||
gameWindow.gamePanel.add(s2.getLabel());
|
|
||||||
gameWindow.gamePanel.add(s3.getLabel());
|
|
||||||
gameWindow.gamePanel.add(s4.getLabel());
|
|
||||||
gameWindow.gamePanel.add(s5.getLabel());
|
|
||||||
gameWindow.gamePanel.add(s6.getLabel());
|
|
||||||
//gameWindow.gamePanel.add(bg.getLabel());
|
|
||||||
|
|
||||||
//bg.getLabel().repaint();
|
|
||||||
|
|
||||||
//gameWindow.gamePanel.setComponentZOrder(o1.getLabel(), 0);
|
|
||||||
//gameWindow.gamePanel.setComponentZOrder(bg.getLabel(), 5);
|
|
||||||
gameWindow.gamePanel.setComponentZOrder(g1.getLabel(), 1);
|
|
||||||
gameWindow.gamePanel.setComponentZOrder(g2.getLabel(), 1);
|
|
||||||
gameWindow.gamePanel.setComponentZOrder(g3.getLabel(), 1);
|
|
||||||
gameWindow.gamePanel.setComponentZOrder(s1.getLabel(), 2);
|
|
||||||
gameWindow.gamePanel.setComponentZOrder(s2.getLabel(), 2);
|
|
||||||
gameWindow.gamePanel.setComponentZOrder(s3.getLabel(), 2);
|
|
||||||
gameWindow.gamePanel.setComponentZOrder(s4.getLabel(), 2);
|
|
||||||
gameWindow.gamePanel.setComponentZOrder(s5.getLabel(), 2);
|
|
||||||
gameWindow.gamePanel.setComponentZOrder(s6.getLabel(), 2);
|
|
||||||
|
|
||||||
s1.setPosition(0, 0);
|
|
||||||
s2.setPosition(25, 0);
|
|
||||||
s3.setPosition(50, 0);
|
|
||||||
s4.setPosition(75, 0);
|
|
||||||
|
|
||||||
|
DynamicObject opponent2 = new DynamicObject();
|
||||||
|
opponent2.setBounds(0, 0, opponent2.getWidth(), opponent2.getWidth());
|
||||||
|
|
||||||
|
gameWindow.gamePanel.add(opponent2);
|
||||||
|
|
||||||
|
|
||||||
|
logic.startMovement(opponent1);
|
||||||
|
logic.startMovement(opponent2);
|
||||||
|
opponent1.setRescale(0.4);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public JPanel getGamePanel() {
|
public JPanel getGamePanel() {
|
||||||
|
|||||||
Reference in New Issue
Block a user