mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 08:39:45 +02:00
Player erbt nun von Static Object, alle von Static Object erbenen Klassen nutzen nun den Classloader
This commit is contained in:
@@ -41,6 +41,9 @@ public class ImageLoader {
|
||||
case 'r':
|
||||
imageFileName="de/heatup/resources/images/little_green_guy_verysmall.png";
|
||||
break;
|
||||
case 'p':
|
||||
imageFileName="de/heatup/resources/images/little_blue_guy_verysmall.png";
|
||||
break;
|
||||
default:
|
||||
imageFileName="de/heatup/resources/images/dummy_image.png";
|
||||
break;
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
package de.heatup.objects;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import de.heatup.cfg.Config;
|
||||
import de.heatup.logging.Logger;
|
||||
import de.heatup.mapengine.CollisionHandler;
|
||||
import de.heatup.mapengine.MapGrid;
|
||||
import de.heatup.mapengine.MapGridCell;
|
||||
import de.heatup.ui.Main;
|
||||
|
||||
public class Opponent extends Player {
|
||||
|
||||
@@ -1,27 +1,14 @@
|
||||
package de.heatup.objects;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import de.heatup.cfg.Config;
|
||||
import de.heatup.logging.Logger;
|
||||
import de.heatup.mapengine.CollisionHandler;
|
||||
|
||||
public class Player extends JComponent {
|
||||
|
||||
// TODO: Magische Nummern entfernen
|
||||
|
||||
public class Player extends StaticObject {
|
||||
private static final long serialVersionUID = 1L;
|
||||
protected BufferedImage bf1;
|
||||
protected Graphics2D g2d;
|
||||
private double rescaleFactorX = 0.0;
|
||||
private double rescaleFactorY = 0.0;
|
||||
public boolean startMove = false;
|
||||
public boolean animate = false;
|
||||
protected int speedMultiplicator = Config.initialSpeedMultiplicator;
|
||||
@@ -35,8 +22,9 @@ public class Player extends JComponent {
|
||||
private Point currentGridPosition;
|
||||
|
||||
public Player() {
|
||||
super('p', new Point());
|
||||
CollisionHandler.addMovingObject(this);
|
||||
if (bf1 == null) {
|
||||
if (super.bf1 == null) {
|
||||
loadBufferedImage();
|
||||
}
|
||||
}
|
||||
@@ -61,37 +49,13 @@ public class Player extends JComponent {
|
||||
public Point getGridLocation() {
|
||||
return currentGridPosition;
|
||||
}
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
g2d = (Graphics2D) g;
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2d.drawImage(bf1, 0, 0, this);
|
||||
g2d.setStroke(new BasicStroke(8.0f));
|
||||
g2d.finalize();
|
||||
}
|
||||
|
||||
public void spawnAt(Point spawnPoint) {
|
||||
this.currentGridPosition = spawnPoint;
|
||||
this.setAutoBounds(spawnPoint.x*25, spawnPoint.y*25);
|
||||
super.setAutoBounds(spawnPoint.x*25, spawnPoint.y*25);
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
protected void loadBufferedImage() {
|
||||
try {
|
||||
this.bf1 = ImageIO.read(this.getClass().getClassLoader().getResourceAsStream("de/heatup/resources/images/little_blue_guy_verysmall.png"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setImage(BufferedImage image) {
|
||||
this.bf1 = image;
|
||||
}
|
||||
|
||||
public void setAutoBounds(int x, int y) {
|
||||
this.setBounds(x, y, this.bf1.getWidth(), this.bf1.getHeight());
|
||||
}
|
||||
|
||||
public void step(char d, int i) {
|
||||
this.direction = d;
|
||||
this.i = i;
|
||||
@@ -120,10 +84,8 @@ public class Player extends JComponent {
|
||||
}
|
||||
if (stepCounter <= 0) {
|
||||
stepCounter = 25;
|
||||
//debug
|
||||
Logger.write("on grid - x: "+getGridLocation().x + " y: "+getGridLocation().y);
|
||||
}
|
||||
}
|
||||
startMove = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,104 +1,86 @@
|
||||
package de.heatup.objects;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import de.heatup.cfg.Config;
|
||||
import de.heatup.ui.PanelBuilder;
|
||||
|
||||
/*
|
||||
* Draft for static objects
|
||||
*/
|
||||
public class StaticObject extends JComponent {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
//private Image image;
|
||||
private BufferedImage bf1;
|
||||
private Graphics2D g2d;
|
||||
|
||||
protected BufferedImage bf1;
|
||||
protected Graphics2D g2d;
|
||||
private boolean doRescale = false;
|
||||
private double rescaleFactorX = 0.0;
|
||||
private double rescaleFactorY = 0.0;
|
||||
|
||||
private Point location;
|
||||
private boolean scale = false;
|
||||
protected Point currentGridPosition;
|
||||
private char staticObjectType;
|
||||
private int staticObjectWidth;
|
||||
private int staticObjectHeight;
|
||||
|
||||
public StaticObject(char staticObjectType, Point location, int staticObjectWidth, int staticObjectHeight) {
|
||||
this.staticObjectType = staticObjectType;
|
||||
this.location = location;
|
||||
this.staticObjectWidth = staticObjectWidth;
|
||||
this.staticObjectHeight = staticObjectHeight;
|
||||
loadBufferedImage();
|
||||
setAutoBounds(location.x, location.y);
|
||||
setAutoBounds(location.x, location.y, staticObjectWidth, staticObjectHeight);
|
||||
}
|
||||
|
||||
public StaticObject(char staticObjectType, Point location) {
|
||||
this(staticObjectType, location, Config.singleTilePixels, Config.singleTilePixels);
|
||||
}
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
this.g2d = (Graphics2D)g;
|
||||
//this.image = Toolkit.getDefaultToolkit().getImage("src/de/heatup/resources/images/little_green_guy.png");
|
||||
if ( bf1 == null ) {
|
||||
this.g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
//this.g2d.setStroke(new BasicStroke(8.0f));
|
||||
if ( this.bf1 == null ) {
|
||||
loadBufferedImage();
|
||||
}
|
||||
//g2d.rotate(0.2, 10, 10);
|
||||
|
||||
// TODO: Check if we can store a rescaled image in bf1???
|
||||
// if ( doRescale ) {
|
||||
// System.out.println("Hit: " + rescaleFactorX + " " + rescaleFactorY);
|
||||
g2d.scale(2, 2);
|
||||
// }
|
||||
|
||||
g2d.drawImage(bf1, 0, 0, this);
|
||||
g2d.finalize();
|
||||
|
||||
/*
|
||||
* Skalieren der Bilder wenn größer als Bounds
|
||||
*/
|
||||
if ( scale ) {
|
||||
this.g2d.scale(((double)this.getSize().width/(double)bf1.getWidth()) , ((double)this.getSize().height/(double)bf1.getHeight()));
|
||||
}
|
||||
|
||||
this.g2d.drawImage(bf1, 0, 0, this);
|
||||
this.g2d.finalize();
|
||||
}
|
||||
|
||||
private void loadBufferedImage() {
|
||||
|
||||
protected void loadBufferedImage() {
|
||||
this.bf1 = PanelBuilder.getImageLoader().getBufferedImage(this.staticObjectType);
|
||||
}
|
||||
|
||||
public void setImage(BufferedImage image) {
|
||||
this.bf1 = image;
|
||||
}
|
||||
|
||||
private void autoRescale() {
|
||||
// TODO: get original width and hight of bf1
|
||||
// Calculate factor new/original
|
||||
// Rescale image using factor
|
||||
// Save new bf in bf1 ???
|
||||
this.rescaleFactorX = (double)this.staticObjectWidth / (double)this.bf1.getWidth();
|
||||
this.rescaleFactorY = (double)this.staticObjectHeight / (double)this.bf1.getHeight();
|
||||
|
||||
//System.out.println("Object: " + this.staticObjectType + "\tBuffered Image: Height: " + this.bf1.getHeight() + "\t Width: " + this.bf1.getWidth() + "\tStatic Object: Height: " + this.staticObjectHeight + "\t Width: " + this.staticObjectWidth);
|
||||
|
||||
if (this.rescaleFactorX != 1 || this.rescaleFactorY != 1 ) {
|
||||
this.doRescale = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// TODO: getter für höhe breite position
|
||||
|
||||
public void setAutoBounds(int x, int y) {
|
||||
//this.setBounds(x, y, this.bf1.getWidth(), this.bf1.getHeight());
|
||||
this.setSize(this.bf1.getWidth(), this.bf1.getHeight());
|
||||
this.setLocation(x, y);
|
||||
}
|
||||
|
||||
public void setAutoBounds(int x, int y, int width, int height) {
|
||||
this.setSize(width, height);
|
||||
this.setLocation(x, y);
|
||||
if ( ((bf1.getWidth() != this.getSize().width ) || (bf1.getHeight() != this.getSize().height)) ) {
|
||||
scale = true;
|
||||
}
|
||||
}
|
||||
|
||||
public String getDebugInfo() {
|
||||
String info = "Debug: " + "Rescale? " + this.doRescale + "\tScale X:" + this.rescaleFactorX + "\tScale Y: " + this.rescaleFactorY + "\tsH: " + this.staticObjectHeight + "\tsW: " + this.staticObjectWidth + "\tStaticObjectType: " + this.staticObjectType + "\tbW : " + this.bf1.getWidth() + "\tbH :" + this.bf1.getHeight();
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user