mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 11:29:46 +02:00
Merge branch 'master' of github.com:jokerx3/prp
This commit is contained in:
@@ -27,13 +27,8 @@ public class DynamicObject extends JComponent{
|
|||||||
public void paintComponent(Graphics g) {
|
public void paintComponent(Graphics g) {
|
||||||
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 {
|
|
||||||
if ( bf1 == null ) {
|
if ( bf1 == null ) {
|
||||||
this.bf1 = ImageIO.read(new File("src/de/heatup/resources/images/little_green_guy.png"));
|
loadBufferedImage();
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//g2d.rotate(0.3, 10, 10);
|
//g2d.rotate(0.3, 10, 10);
|
||||||
@@ -47,6 +42,14 @@ public class DynamicObject extends JComponent{
|
|||||||
System.out.println("paintComponent");
|
System.out.println("paintComponent");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadBufferedImage() {
|
||||||
|
try {
|
||||||
|
this.bf1 = ImageIO.read(new File("src/de/heatup/resources/images/dummy_image.png"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setImage(BufferedImage image) {
|
public void setImage(BufferedImage image) {
|
||||||
this.bf1 = image;
|
this.bf1 = image;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,12 +9,10 @@ import javax.imageio.ImageIO;
|
|||||||
|
|
||||||
public class ImageLoader {
|
public class ImageLoader {
|
||||||
|
|
||||||
public static BufferedImage getBufferedImage(String imageFileName) throws IOException{
|
/*
|
||||||
return ImageIO.read(new File(imageFileName));
|
* TODO: Better solution like try catch if image not found
|
||||||
|
*/
|
||||||
}
|
public static BufferedImage getBufferedImage(char key) {
|
||||||
|
|
||||||
public static BufferedImage getBufferedImage(char key) throws IOException{
|
|
||||||
String imageFileName;
|
String imageFileName;
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'u':
|
case 'u':
|
||||||
@@ -30,13 +28,17 @@ public class ImageLoader {
|
|||||||
imageFileName="src/de/heatup/resources/images/little_green_guy_right.png";
|
imageFileName="src/de/heatup/resources/images/little_green_guy_right.png";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
imageFileName="src/de/heatup/resources/images/25x25_orange.png";
|
imageFileName="src/de/heatup/resources/images/dummy_image.png";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
BufferedImage loadedBufferedImage = null;
|
||||||
//System.out.println(imageFileName);
|
//System.out.println(imageFileName);
|
||||||
|
try {
|
||||||
|
loadedBufferedImage = ImageIO.read(new File(imageFileName));
|
||||||
return ImageIO.read(new File(imageFileName));
|
} catch (Exception e) {
|
||||||
|
// TODO: handle exception
|
||||||
|
}
|
||||||
|
return loadedBufferedImage;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,90 +15,94 @@ import javax.swing.JLabel;
|
|||||||
|
|
||||||
|
|
||||||
public class Objekt {
|
public class Objekt {
|
||||||
private static int numberOfInstances;
|
/*
|
||||||
private BufferedImage objectImage;
|
* Deprecated
|
||||||
private JLabel objectLabel;
|
|
||||||
private Point objectArea;
|
|
||||||
private Point actionArea;
|
|
||||||
public Thread t;
|
|
||||||
private char objectIdentifier; // TODO: Identifizierung für Map Engine
|
|
||||||
|
|
||||||
public Objekt(char objectIdentifier) throws IOException {
|
|
||||||
numberOfInstances++;
|
|
||||||
setObjectIdentifier(objectIdentifier);
|
|
||||||
setObjectImage();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setObjectImage() throws IOException {
|
|
||||||
String filename = getImageFilename(objectIdentifier);
|
|
||||||
System.out.println("Filename: " + filename);
|
|
||||||
//objectImage = ImageIO.read(new File(filename));
|
|
||||||
//objectLabel = new JLabel(new ImageIcon(objectImage));
|
|
||||||
|
|
||||||
objectImage = ImageLoader.getBufferedImage(filename);
|
|
||||||
objectLabel = new JLabel(new ImageIcon(objectImage));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Load corresponding image
|
|
||||||
*/
|
*/
|
||||||
private String getImageFilename(char objectIdentifier) {
|
|
||||||
String objectFilename;
|
|
||||||
switch (objectIdentifier) {
|
|
||||||
case '#':
|
|
||||||
// Path
|
|
||||||
objectFilename="src/de/heatup/resources/images/25x25_black.png";
|
|
||||||
break;
|
|
||||||
case '2':
|
|
||||||
// Hardware
|
|
||||||
objectFilename="src/de/heatup/resources/images/25x25_red.png";
|
|
||||||
break;
|
|
||||||
case '-':
|
|
||||||
// Wall
|
|
||||||
objectFilename="src/de/heatup/resources/images/25x25_blue.png";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
objectFilename="src/de/heatup/resources/images/25x25_orange.png";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
System.out.println(objectFilename);
|
|
||||||
return objectFilename;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
// private static int numberOfInstances;
|
||||||
* Sets position of object via int x int y
|
// private BufferedImage objectImage;
|
||||||
*/
|
// private JLabel objectLabel;
|
||||||
public void setPosition(int x, int y) {
|
// private Point objectArea;
|
||||||
System.out.println(x + " " + y + " " + this.getDimensionX() + " " + this.getDimensionY());
|
// private Point actionArea;
|
||||||
this.objectLabel.setBounds(x, y, this.getDimensionX(), this.getDimensionY());
|
// public Thread t;
|
||||||
}
|
// private char objectIdentifier; // TODO: Identifizierung für Map Engine
|
||||||
|
//
|
||||||
public int getX() {
|
// public Objekt(char objectIdentifier) throws IOException {
|
||||||
return this.objectLabel.getX();
|
// numberOfInstances++;
|
||||||
}
|
// setObjectIdentifier(objectIdentifier);
|
||||||
|
// setObjectImage();
|
||||||
public int getY() {
|
//
|
||||||
return this.objectLabel.getY();
|
// }
|
||||||
}
|
//
|
||||||
|
// private void setObjectImage() throws IOException {
|
||||||
public int getDimensionX() {
|
// String filename = getImageFilename(objectIdentifier);
|
||||||
return this.objectImage.getWidth();
|
// System.out.println("Filename: " + filename);
|
||||||
}
|
// //objectImage = ImageIO.read(new File(filename));
|
||||||
|
// //objectLabel = new JLabel(new ImageIcon(objectImage));
|
||||||
public int getDimensionY() {
|
//
|
||||||
return this.objectImage.getHeight();
|
// objectImage = ImageLoader.getBufferedImage(filename);
|
||||||
}
|
// objectLabel = new JLabel(new ImageIcon(objectImage));
|
||||||
|
// }
|
||||||
public JLabel getLabel() {
|
//
|
||||||
return this.objectLabel;
|
// /*
|
||||||
}
|
// * Load corresponding image
|
||||||
|
// */
|
||||||
public char getOjectIdentifier() {
|
// private String getImageFilename(char objectIdentifier) {
|
||||||
return this.objectIdentifier;
|
// String objectFilename;
|
||||||
}
|
// switch (objectIdentifier) {
|
||||||
|
// case '#':
|
||||||
public void setObjectIdentifier(char objectIdentifier) {
|
// // Path
|
||||||
this.objectIdentifier = objectIdentifier;
|
// objectFilename="src/de/heatup/resources/images/25x25_black.png";
|
||||||
}
|
// break;
|
||||||
|
// case '2':
|
||||||
|
// // Hardware
|
||||||
|
// objectFilename="src/de/heatup/resources/images/25x25_red.png";
|
||||||
|
// break;
|
||||||
|
// case '-':
|
||||||
|
// // Wall
|
||||||
|
// objectFilename="src/de/heatup/resources/images/25x25_blue.png";
|
||||||
|
// break;
|
||||||
|
// default:
|
||||||
|
// objectFilename="src/de/heatup/resources/images/25x25_orange.png";
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// System.out.println(objectFilename);
|
||||||
|
// return objectFilename;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /*
|
||||||
|
// * Sets position of object via int x int y
|
||||||
|
// */
|
||||||
|
// public void setPosition(int x, int y) {
|
||||||
|
// System.out.println(x + " " + y + " " + this.getDimensionX() + " " + this.getDimensionY());
|
||||||
|
// this.objectLabel.setBounds(x, y, this.getDimensionX(), this.getDimensionY());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public int getX() {
|
||||||
|
// return this.objectLabel.getX();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public int getY() {
|
||||||
|
// return this.objectLabel.getY();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public int getDimensionX() {
|
||||||
|
// return this.objectImage.getWidth();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public int getDimensionY() {
|
||||||
|
// return this.objectImage.getHeight();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public JLabel getLabel() {
|
||||||
|
// return this.objectLabel;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public char getOjectIdentifier() {
|
||||||
|
// return this.objectIdentifier;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void setObjectIdentifier(char objectIdentifier) {
|
||||||
|
// this.objectIdentifier = objectIdentifier;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package de.heatup.objects;
|
|||||||
|
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Point;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -18,29 +19,62 @@ 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 Point location;
|
||||||
|
private char staticObjectType;
|
||||||
|
private int staticObjectWidth;
|
||||||
|
private int staticObjectHeight;
|
||||||
|
|
||||||
public StaticObject() {
|
/*
|
||||||
|
* #: Path
|
||||||
|
* -: Wall
|
||||||
|
* 0 - 9: Hardware
|
||||||
|
*/
|
||||||
|
public StaticObject(char staticObjectType, Point location, int staticObjectWidth, int staticObjectHeight) {
|
||||||
|
this.staticObjectType = staticObjectType;
|
||||||
|
this.location = location;
|
||||||
|
this.staticObjectWidth = staticObjectWidth;
|
||||||
|
this.staticObjectHeight = staticObjectHeight;
|
||||||
|
loadBufferedImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
public StaticObject(char staticObjectType, Point location) {
|
||||||
|
this(staticObjectType, location, 25, 25);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void paintComponent(Graphics g) {
|
public void paintComponent(Graphics g) {
|
||||||
|
|
||||||
this.g2d = (Graphics2D)g;
|
this.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 {
|
if ( bf1 == null ) {
|
||||||
this.bf1 = ImageIO.read(new File("src/de/heatup/resources/images/little_green_guy.png"));
|
loadBufferedImage();
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
System.out.println(this.bf1.getWidth() + " " + this.bf1.getHeight());
|
System.out.println(this.bf1.getWidth() + " " + this.bf1.getHeight());
|
||||||
//g2d.rotate(0.2, 10, 10);
|
//g2d.rotate(0.2, 10, 10);
|
||||||
//g2d.scale(1.5, 1.5);
|
|
||||||
|
if ( rescaleFactor != 0.0 ) {
|
||||||
|
g2d.scale(rescaleFactor, rescaleFactor);
|
||||||
|
}
|
||||||
g2d.drawImage(bf1, 0, 0, this);
|
g2d.drawImage(bf1, 0, 0, this);
|
||||||
g2d.finalize();
|
g2d.finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reloadImage() {
|
private void loadBufferedImage() {
|
||||||
|
this.bf1 = ImageLoader.getBufferedImage(this.staticObjectType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setImage(BufferedImage image) {
|
||||||
|
this.bf1 = image;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRescale(double rescaleFactor) {
|
||||||
|
this.rescaleFactor = rescaleFactor;
|
||||||
|
//this.setBounds(x, y, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAutoBounds(int x, int y) {
|
||||||
|
this.setBounds(x, y, this.bf1.getWidth(), this.bf1.getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,42 +58,22 @@ public class logic {
|
|||||||
movex -= 4;
|
movex -= 4;
|
||||||
mx=-4;
|
mx=-4;
|
||||||
my=0;
|
my=0;
|
||||||
try {
|
|
||||||
dynObj.setImage(ImageLoader.getBufferedImage('l'));
|
dynObj.setImage(ImageLoader.getBufferedImage('l'));
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} else if ( move == 2 && movex >= 0) {
|
} else if ( move == 2 && movex >= 0) {
|
||||||
movex -= 4;
|
movex -= 4;
|
||||||
mx=4;
|
mx=4;
|
||||||
my=0;
|
my=0;
|
||||||
try {
|
|
||||||
dynObj.setImage(ImageLoader.getBufferedImage('r'));
|
dynObj.setImage(ImageLoader.getBufferedImage('r'));
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} else if (move == -1 && movey >= 0) {
|
} else if (move == -1 && movey >= 0) {
|
||||||
movey -= 4;
|
movey -= 4;
|
||||||
my=-4;
|
my=-4;
|
||||||
mx=0;
|
mx=0;
|
||||||
try {
|
|
||||||
dynObj.setImage(ImageLoader.getBufferedImage('u'));
|
dynObj.setImage(ImageLoader.getBufferedImage('u'));
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} else if (move == 1 && movey >= 0) {
|
} else if (move == 1 && movey >= 0) {
|
||||||
movey -= 4;
|
movey -= 4;
|
||||||
my=4;
|
my=4;
|
||||||
mx=0;
|
mx=0;
|
||||||
try {
|
|
||||||
dynObj.setImage(ImageLoader.getBufferedImage('d'));
|
dynObj.setImage(ImageLoader.getBufferedImage('d'));
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
move = 0;
|
move = 0;
|
||||||
mx=0;
|
mx=0;
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
@@ -3,6 +3,7 @@ import java.awt.BorderLayout;
|
|||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.EventQueue;
|
import java.awt.EventQueue;
|
||||||
import java.awt.GridLayout;
|
import java.awt.GridLayout;
|
||||||
|
import java.awt.Point;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
@@ -60,7 +61,6 @@ public class GameInterface extends JFrame {
|
|||||||
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.add(outerPanel);
|
||||||
|
|
||||||
|
|
||||||
@@ -82,19 +82,32 @@ public class GameInterface extends JFrame {
|
|||||||
GameInterface gameWindow = new GameInterface();
|
GameInterface gameWindow = new GameInterface();
|
||||||
gameWindow.createGUI();
|
gameWindow.createGUI();
|
||||||
|
|
||||||
DynamicObject opponent1 = new DynamicObject();
|
/*
|
||||||
opponent1.setBounds(0, 0, opponent1.getWidth(), opponent1.getHeight());
|
* Test dynamic objects
|
||||||
gameWindow.gamePanel.add(opponent1);
|
*/
|
||||||
|
//DynamicObject opponent1 = new DynamicObject();
|
||||||
|
//opponent1.setBounds(0, 0, opponent1.getWidth(), opponent1.getHeight());
|
||||||
|
//gameWindow.gamePanel.add(opponent1);
|
||||||
|
|
||||||
DynamicObject opponent2 = new DynamicObject();
|
//DynamicObject opponent2 = new DynamicObject();
|
||||||
opponent2.setBounds(0, 0, opponent2.getWidth(), opponent2.getWidth());
|
//opponent2.setBounds(0, 0, opponent2.getWidth(), opponent2.getWidth());
|
||||||
|
//gameWindow.gamePanel.add(opponent2);
|
||||||
|
|
||||||
gameWindow.gamePanel.add(opponent2);
|
//logic.startMovement(opponent1);
|
||||||
|
//logic.startMovement(opponent2);
|
||||||
|
//opponent1.setRescale(0.4);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Test static objects
|
||||||
|
*/
|
||||||
|
Point p1 = new Point(100, 100);
|
||||||
|
StaticObject sObj1 = new StaticObject('d',p1);
|
||||||
|
//sObj1.setBounds(100, 10, 36, 64);
|
||||||
|
sObj1.setAutoBounds(100, 100);
|
||||||
|
gameWindow.gamePanel.add(sObj1);
|
||||||
|
|
||||||
|
|
||||||
logic.startMovement(opponent1);
|
// TODO: Gameloop needs to be added here!!!
|
||||||
logic.startMovement(opponent2);
|
|
||||||
opponent1.setRescale(0.4);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user