Implemented the data model and drawing of rectangular hitboxes, IsometricCoordsConverter functions have been transferred to Hitbox class as static, since they are generally needed for hitboxes only
This commit is contained in:
@ -1,23 +1,23 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<objecttypes>
|
<objecttypes>
|
||||||
<objecttype name="misato" color="#a0a0a4">
|
<objecttype color="#a0a0a4" name="misato">
|
||||||
<property name="class" type="string" default="Solid"/>
|
<property default="Solid" name="class" type="string"/>
|
||||||
<property name="drawbox" type="string" default="2 1 254 1 254 338 2 336"/>
|
<property default="22 10 232 3 264 199 5 198 " name="drawbox" type="string"/>
|
||||||
<property name="hitbox" type="string" default="Circle 4 6 24"/>
|
<property default="Circle 4 6 24" name="hitbox" type="string"/>
|
||||||
</objecttype>
|
</objecttype>
|
||||||
<objecttype name="starlight" color="#a0a0a4">
|
<objecttype color="#a0a0a4" name="starlight">
|
||||||
<property name="class" type="string" default="Solid"/>
|
<property default="Solid" name="class" type="string"/>
|
||||||
<property name="drawbox" type="string" default="2 1 253 1 254 468 2 490"/>
|
<property default="2 1 253 1 254 468 2 490" name="drawbox" type="string"/>
|
||||||
<property name="hitbox" type="string" default="Rectangle 0 0 76 119"/>
|
<property default="Rectangle 0 0 76 119" name="hitbox" type="string"/>
|
||||||
</objecttype>
|
</objecttype>
|
||||||
<objecttype name="tavern" color="#a0a0a4">
|
<objecttype color="#a0a0a4" name="tavern">
|
||||||
<property name="class" type="string" default="Solid"/>
|
<property default="Solid" name="class" type="string"/>
|
||||||
<property name="drawbox" type="string" default="3 2 252 1 253 605 6 608"/>
|
<property default="3 2 252 1 253 605 6 608" name="drawbox" type="string"/>
|
||||||
<property name="hitbox" type="string" default="Rectangle 0 0 96 98"/>
|
<property default="Rectangle 0 0 96 98" name="hitbox" type="string"/>
|
||||||
</objecttype>
|
</objecttype>
|
||||||
<objecttype name="TopHome" color="#a0a0a4">
|
<objecttype color="#a0a0a4" name="TopHome">
|
||||||
<property name="class" type="string" default="Solid"/>
|
<property default="Solid" name="class" type="string"/>
|
||||||
<property name="drawbox" type="string" default="3 2 252 1 253 605 6 608"/>
|
<property default="3 2 252 1 253 605 6 608" name="drawbox" type="string"/>
|
||||||
<property name="hitbox" type="string" default="Rectangle 0 0 96 98"/>
|
<property default="Rectangle 0 0 96 98" name="hitbox" type="string"/>
|
||||||
</objecttype>
|
</objecttype>
|
||||||
</objecttypes>
|
</objecttypes>
|
||||||
|
|||||||
@ -83,6 +83,7 @@ public class DrawboxEditor extends Editable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mousePressed(MouseEvent e) {
|
public void mousePressed(MouseEvent e) {
|
||||||
|
|
||||||
if(drawboxPoints.size() < 4) {
|
if(drawboxPoints.size() < 4) {
|
||||||
Point p = new Point(e.getX(), e.getY());
|
Point p = new Point(e.getX(), e.getY());
|
||||||
drawboxPoints.add(p);
|
drawboxPoints.add(p);
|
||||||
|
|||||||
@ -3,50 +3,95 @@ package gui;
|
|||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.swing.JTabbedPane;
|
||||||
import javax.swing.ImageIcon;
|
|
||||||
import javax.swing.JLabel;
|
import model.Hitbox;
|
||||||
import javax.swing.JPanel;
|
import model.Point;
|
||||||
|
|
||||||
|
|
||||||
public class HitboxRectangleEditor extends Editable {
|
public class HitboxRectangleEditor extends Editable {
|
||||||
|
Point firstIsoPoint = null;
|
||||||
|
Point currentIsoPoint = null;
|
||||||
|
Point firstCartesianPoint = new Point(0,0), currentCartesianPoint = new Point(0,0);
|
||||||
|
Hitbox nowHitbox = entity.getHitbox();
|
||||||
|
|
||||||
HitboxRectangleEditor(ListGUI listGUI) {
|
HitboxRectangleEditor(ListGUI listGUI) {
|
||||||
super(listGUI);
|
super(listGUI);
|
||||||
// TODO Auto-generated constructor stub
|
// TODO Auto-generated cons2tructor stub
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawing(Graphics2D g) {
|
public void drawing(Graphics2D g) {
|
||||||
// TODO Auto-generated method stub
|
if(firstIsoPoint != null) {
|
||||||
|
int x1,y1,x2,y2;
|
||||||
|
int size = nowHitbox.getListPointsIso().size();
|
||||||
|
for(int i = 0; i < size;i++) {
|
||||||
|
x1 = (int)nowHitbox.getListPointsIso().get(i % size).x;
|
||||||
|
y1 = (int)nowHitbox.getListPointsIso().get(i % size).y;
|
||||||
|
x2 = (int)nowHitbox.getListPointsIso().get((i+1) % size).x;
|
||||||
|
y2 = (int)nowHitbox.getListPointsIso().get((i+1) % size).y;
|
||||||
|
g.drawLine(x1, y1, x2, y2);
|
||||||
|
}
|
||||||
|
x1 = (int)nowHitbox.getListPointsIso().get(0).x;
|
||||||
|
y1 = (int)nowHitbox.getListPointsIso().get(0).y;
|
||||||
|
x2 = (int)nowHitbox.getListPointsIso().get(3).x;
|
||||||
|
y2 = (int)nowHitbox.getListPointsIso().get(3).y;
|
||||||
|
g.drawLine(x1, y1, x2, y2);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveDataInEntity() {
|
public void saveDataInEntity() {
|
||||||
// TODO Auto-generated method stub
|
// saveDataInEntity - сохранение данных в сущности.
|
||||||
|
//Она нам тут не нужна.
|
||||||
|
//Все данные и так лежат где необходимо, используя ссылки.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
// TODO Auto-generated method stub
|
if(firstIsoPoint == null) {
|
||||||
|
firstIsoPoint = new Point(currentIsoPoint.x,currentIsoPoint.y);
|
||||||
|
firstCartesianPoint = Hitbox.isometricToCartesian(firstIsoPoint.x, firstIsoPoint.y,firstCartesianPoint);
|
||||||
|
}else{
|
||||||
|
/*
|
||||||
|
* В данном месте при нажатии закрепляющей точки, необходимо вызывать функцию,
|
||||||
|
* которая будет формировать из текущих декартовых координат:
|
||||||
|
* 1. Точку старта и ширину с высотой.
|
||||||
|
* 2. Так же необходимо реализовать слушатель сохранения новых хитбоксов в дерево.
|
||||||
|
*
|
||||||
|
* */
|
||||||
|
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseMoved(MouseEvent e) {
|
public void mouseMoved(MouseEvent e) {
|
||||||
// TODO Auto-generated method stub
|
currentIsoPoint.x = e.getX();
|
||||||
|
currentIsoPoint.y = e.getY();
|
||||||
|
if(firstIsoPoint != null) {
|
||||||
|
currentCartesianPoint = Hitbox.isometricToCartesian(currentIsoPoint.x, currentIsoPoint.y, currentCartesianPoint);
|
||||||
|
nowHitbox.getListPointsCartesian().get(0).setXY(firstCartesianPoint.x, firstCartesianPoint.y);
|
||||||
|
nowHitbox.getListPointsCartesian().get(1).setXY(currentCartesianPoint.x, firstCartesianPoint.y);
|
||||||
|
nowHitbox.getListPointsCartesian().get(2).setXY(currentCartesianPoint.x, currentCartesianPoint.y);
|
||||||
|
nowHitbox.getListPointsCartesian().get(3).setXY(firstCartesianPoint.x, currentCartesianPoint.y);
|
||||||
|
nowHitbox.convertCartesianPointsToIso();
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
// TODO Auto-generated method stub
|
JTabbedPane parent = (JTabbedPane) getParent();
|
||||||
|
if(parent.getSelectedComponent() == this){
|
||||||
|
if(entity != null) {
|
||||||
|
firstIsoPoint = null;
|
||||||
|
currentIsoPoint = null;
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import java.awt.Image;
|
|||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -91,12 +92,12 @@ public class ListGUI extends JPanel {
|
|||||||
return (String) list.getSelectedValue();
|
return (String) list.getSelectedValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//ТУТ МОЖЕТ БЫТЬ ТРАБЛ Т,К, СОЗДАНИЕ ХИТБОКСА - ХАРДКОД. Он может быть не только Rectangle
|
||||||
public void addListElement(String name,String solid) throws DuplicateEntryException {
|
public void addListElement(String name,String solid) throws DuplicateEntryException {
|
||||||
// плейсхолдеры для новых хитбоксов и дроубоксов, иначе всё валится с NPE
|
// плейсхолдеры для новых хитбоксов и дроубоксов, иначе всё валится с NPE
|
||||||
List<Point> hitboxPoints = new LinkedList<Point>();
|
Hitbox hitbox = new Hitbox();
|
||||||
List<Point> drawboxPoints = new LinkedList<Point>();
|
Drawbox drawbox = new Drawbox();
|
||||||
Hitbox hitbox = new Hitbox("Rectangle", hitboxPoints);
|
|
||||||
Drawbox drawbox = new Drawbox(drawboxPoints);
|
|
||||||
|
|
||||||
// а тут уже создание новой сущности
|
// а тут уже создание новой сущности
|
||||||
Entity e = new Entity(name, hitbox, drawbox);
|
Entity e = new Entity(name, hitbox, drawbox);
|
||||||
|
|||||||
@ -4,8 +4,12 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Drawbox {
|
public class Drawbox {
|
||||||
private List<Point> drawboxlistPoints ;//для прямоугольника дравбокса.
|
private List<Point> drawboxlistPoints = new ArrayList<Point>();//для прямоугольника дравбокса.
|
||||||
private List<Point> baseListPoints ;//2 точки для линии основания
|
private List<Point> baseListPoints = new ArrayList<Point>();//2 точки для линии основания
|
||||||
|
|
||||||
|
public Drawbox(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public Drawbox(List<Point> drawboxlistPoints){
|
public Drawbox(List<Point> drawboxlistPoints){
|
||||||
this.drawboxlistPoints = new ArrayList<Point>(drawboxlistPoints) ;
|
this.drawboxlistPoints = new ArrayList<Point>(drawboxlistPoints) ;
|
||||||
@ -15,8 +19,6 @@ public class Drawbox {
|
|||||||
public Drawbox(String informationDrawbox){
|
public Drawbox(String informationDrawbox){
|
||||||
|
|
||||||
if(informationDrawbox!= null) {
|
if(informationDrawbox!= null) {
|
||||||
drawboxlistPoints = new ArrayList<Point>();
|
|
||||||
baseListPoints = new ArrayList<Point>();
|
|
||||||
String[] informations = informationDrawbox.split(" ");
|
String[] informations = informationDrawbox.split(" ");
|
||||||
parseStringToDrawbox(informations);
|
parseStringToDrawbox(informations);
|
||||||
createBasePoint();
|
createBasePoint();
|
||||||
|
|||||||
@ -1,21 +1,27 @@
|
|||||||
package model;
|
package model;
|
||||||
|
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
public class Entity {
|
public class Entity {
|
||||||
private String thisName;
|
private String thisName;
|
||||||
private Drawbox thisDrawbox;
|
private Drawbox thisDrawbox;
|
||||||
private Hitbox thisHitbox;
|
private Hitbox thisHitbox;
|
||||||
private String type;
|
private String type;
|
||||||
|
private BufferedImage thisImage;
|
||||||
|
//private
|
||||||
|
|
||||||
public Entity(String name,String drawbox,String hitbox) {
|
public Entity(String name,String drawbox,String hitbox) {
|
||||||
thisName = new String(name);
|
thisName = new String(name);
|
||||||
thisDrawbox = new Drawbox(drawbox);
|
thisDrawbox = new Drawbox(drawbox);
|
||||||
thisHitbox = new Hitbox(hitbox);
|
thisHitbox = new Hitbox(hitbox);
|
||||||
|
thisHitbox.setOwnerEntity(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Entity(String name, Hitbox hitbox, Drawbox drawbox) {
|
public Entity(String name, Hitbox hitbox, Drawbox drawbox) {
|
||||||
this.thisName = name;
|
this.thisName = name;
|
||||||
this.thisHitbox = hitbox;
|
this.thisHitbox = hitbox;
|
||||||
this.thisDrawbox = drawbox;
|
this.thisDrawbox = drawbox;
|
||||||
|
thisHitbox.setOwnerEntity(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String outName) {
|
public void setName(String outName) {
|
||||||
@ -38,6 +44,10 @@ public class Entity {
|
|||||||
thisHitbox = outHitbox;
|
thisHitbox = outHitbox;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public void setImage(BufferedImage outImage) {
|
||||||
|
thisImage = outImage;
|
||||||
|
};
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return thisName;
|
return thisName;
|
||||||
};
|
};
|
||||||
@ -50,6 +60,10 @@ public class Entity {
|
|||||||
return thisHitbox;
|
return thisHitbox;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public BufferedImage getImage() {
|
||||||
|
return thisImage;
|
||||||
|
};
|
||||||
|
|
||||||
public void PrintEntity() {
|
public void PrintEntity() {
|
||||||
System.out.println("---------------------");
|
System.out.println("---------------------");
|
||||||
System.out.println("Name: "+thisName);
|
System.out.println("Name: "+thisName);
|
||||||
|
|||||||
@ -5,72 +5,137 @@ import java.util.List;
|
|||||||
|
|
||||||
public class Hitbox {
|
public class Hitbox {
|
||||||
private String shape = null;// shape - Форма хитбокса. Понадобится при написании сохранения. Один из параметров в xml-file.
|
private String shape = null;// shape - Форма хитбокса. Понадобится при написании сохранения. Один из параметров в xml-file.
|
||||||
private List<Point> listPoints = null;//для прямоугольника - 4 точки. Для круга - надо посмотреть.
|
private List<Point> listPointsIso = new ArrayList<Point>();
|
||||||
|
private List<Point> listPointsCartesian = new ArrayList<Point>();
|
||||||
|
private Point referencePoint = new Point(0, 0); //Точка отсчета хитбокса, от нее рассчитывается высота+ширина/радиус(при круге) хитбокса.
|
||||||
|
private float widthHitbox = 0,heightHitbox = 0; // Ширина и высота хитбокса в декартовых координатах.
|
||||||
|
private float radiusHitbox = 0;
|
||||||
|
private Entity owner;
|
||||||
|
|
||||||
public Hitbox(String shape,List<Point> listPoints){
|
public Hitbox(){
|
||||||
this.shape = new String(shape);
|
initListsPoints();
|
||||||
this.listPoints = new ArrayList<Point>(listPoints) ;
|
}
|
||||||
|
public Hitbox(String shape,List<Point> listPointsIso,List<Point> listPointsCartesian){
|
||||||
|
this.shape = new String(shape);
|
||||||
|
this.listPointsIso = listPointsIso;
|
||||||
|
this.listPointsCartesian = listPointsCartesian;
|
||||||
|
initListsPoints();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Hitbox(String informationHitbox){
|
public Hitbox(String informationHitbox){
|
||||||
if(informationHitbox!= null) {
|
if(informationHitbox!= null) {
|
||||||
listPoints = new ArrayList<Point>();
|
initListsPoints();
|
||||||
String[] informations = informationHitbox.split(" ");
|
String[] informations = informationHitbox.split(" ");
|
||||||
//в 0-м индексе всегда идет название фигуры.Так сделан наш xml.
|
//в 0-м индексе всегда идет название фигуры.Так сделан наш xml.
|
||||||
shape = new String(informations[0]);
|
shape = new String(informations[0]);
|
||||||
//заполняем лист точками. Пока что делаю тупо и топорно. Хардкод. Потом можно переделать.
|
|
||||||
if(shape.equals("Rectangle")) {
|
if(shape.equals("Rectangle")) {
|
||||||
parseStringToRectangleHitbox(informations);
|
parseStringToRectangleHitbox(informations);
|
||||||
|
createCartesianPointsFromWidthAndHeigh();
|
||||||
|
convertCartesianPointsToIso();
|
||||||
}else if(shape.equals("Circle")) {
|
}else if(shape.equals("Circle")) {
|
||||||
parseStringToCircleHitbox(informations);
|
parseStringToCircleHitbox(informations);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseStringToRectangleHitbox(String[] informations) {
|
private void initListsPoints() {
|
||||||
//составляем точки по которым строится прямоугольник, и запихиваем их в лист с точками
|
if(listPointsIso.size()<1) {
|
||||||
for(int i = 1;i<informations.length;i+=2) {
|
for(int i=0;i<4;i++) {
|
||||||
float x = Float.parseFloat(informations[i]);
|
listPointsIso.add(new Point(0,0));
|
||||||
float y = Float.parseFloat(informations[i+1]);
|
|
||||||
Point point = new Point(x, y);
|
|
||||||
listPoints.add(point);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(listPointsCartesian.size()<1) {
|
||||||
|
for(int i=0;i<4;i++) {
|
||||||
|
listPointsCartesian.add(new Point(0,0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void parseStringToRectangleHitbox(String[] informations) {
|
||||||
|
referencePoint.x = Float.parseFloat(informations[1]);
|
||||||
|
referencePoint.y = Float.parseFloat(informations[2]);
|
||||||
|
widthHitbox = Float.parseFloat(informations[3]);
|
||||||
|
heightHitbox = Float.parseFloat(informations[4]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void parseStringToCircleHitbox(String[] informations) {
|
private void parseStringToCircleHitbox(String[] informations) {
|
||||||
//ЭТО ХАРДКОД.ДА.Но в данном случае, имхо, разумный(в каком то смысле).
|
referencePoint.x = Float.parseFloat(informations[1]);
|
||||||
//первая точка где строится круг
|
referencePoint.y = Float.parseFloat(informations[2]);
|
||||||
float x1 = Float.parseFloat(informations[1]);
|
radiusHitbox = Float.parseFloat(informations[3]);
|
||||||
float y1 = Float.parseFloat(informations[2]);
|
|
||||||
Point point1 = new Point(x1, y1);
|
|
||||||
//вторая точка x2 - диаметр, а y2 = 0, потому что нам на него пофиг.
|
|
||||||
//Просто же не создавать для круга новый класс хитбокса? Нет. Так что так.
|
|
||||||
float x2 = Float.parseFloat(informations[3]);
|
|
||||||
Point point2 = new Point(x2, 0);
|
|
||||||
listPoints.add(point2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void convertIsoPointsToCartesian() {
|
||||||
public void addPoint(Point point) {
|
Point isoPoint;
|
||||||
listPoints.add(point);
|
for (int i = 0 ; i<4;i++) {
|
||||||
|
isoPoint = listPointsIso.get(i);
|
||||||
|
cartesianToIsometric(isoPoint.x,isoPoint.y,listPointsCartesian.get(i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearPoints() {
|
|
||||||
listPoints.clear();
|
//+++++++
|
||||||
|
public void convertCartesianPointsToIso() {
|
||||||
|
Point cartesianPoint;
|
||||||
|
for (int i = 0 ; i<4;i++) {
|
||||||
|
cartesianPoint = listPointsCartesian.get(i);
|
||||||
|
cartesianToIsometric(cartesianPoint.x,cartesianPoint.y,listPointsIso.get(i));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
//+++++++
|
||||||
|
private void createCartesianPointsFromWidthAndHeigh(){
|
||||||
|
Point refIsoPoint = new Point(owner.getImage().getWidth()/2+referencePoint.x,owner.getImage().getHeight()+referencePoint.y);
|
||||||
|
Point refCartesianPoint = isometricToCartesian(refIsoPoint.x,refIsoPoint.y,new Point(0,0));
|
||||||
|
listPointsCartesian.clear();
|
||||||
|
listPointsCartesian.add(new Point(refCartesianPoint.x-widthHitbox,refCartesianPoint.y));
|
||||||
|
listPointsCartesian.add(new Point(refCartesianPoint.x,refCartesianPoint.y));
|
||||||
|
listPointsCartesian.add(new Point(refCartesianPoint.x,refCartesianPoint.y-heightHitbox));
|
||||||
|
listPointsCartesian.add(new Point(refCartesianPoint.x-widthHitbox,refCartesianPoint.y-heightHitbox));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param result - Point object to store the result
|
||||||
|
* @return x and y converted to isometic coords
|
||||||
|
* */
|
||||||
|
public static Point cartesianToIsometric(float cartX, float cartY, Point result) {
|
||||||
|
result.x = cartX - cartY;
|
||||||
|
result.y = (cartX + cartY) / 2;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param result - Point object to store the result
|
||||||
|
* @return x and y converted to cartesian coords
|
||||||
|
* */
|
||||||
|
public static Point isometricToCartesian(float x, float y, Point result) {
|
||||||
|
result.x = (2 * y + x) / 2;
|
||||||
|
result.y = (2 * y - x) / 2;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public void setOwnerEntity(Entity owner) {
|
||||||
|
this.owner = owner;
|
||||||
|
}
|
||||||
|
public Entity getOwnerEntity() {
|
||||||
|
return owner;
|
||||||
|
}
|
||||||
|
|
||||||
public String getShape() {
|
public String getShape() {
|
||||||
return shape;
|
return shape;
|
||||||
}
|
}
|
||||||
public List<Point> getListPoints() {
|
public List<Point> getListPointsIso() {
|
||||||
return listPoints;
|
return listPointsIso;
|
||||||
|
}
|
||||||
|
public List<Point> getListPointsCartesian() {
|
||||||
|
return listPointsCartesian;
|
||||||
}
|
}
|
||||||
|
|
||||||
//not the same as toString()! the latter is for XML while printToConsole() is for console
|
//not the same as toString()! the latter is for XML while printToConsole() is for console
|
||||||
public void printToConsole() {
|
public void printToConsole() {
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println("|||Hitbox:");
|
System.out.println("|||Hitbox:");
|
||||||
if(shape!=null&&listPoints!=null) {
|
/* if(shape!=null&&listPoints!=null) {
|
||||||
System.out.println("shape: " + shape);
|
System.out.println("shape: " + shape);
|
||||||
for(Point point: listPoints) {
|
for(Point point: listPoints) {
|
||||||
System.out.print("("+point.x+";"+point.y+") ");
|
System.out.print("("+point.x+";"+point.y+") ");
|
||||||
@ -78,7 +143,7 @@ public class Hitbox {
|
|||||||
System.out.println();
|
System.out.println();
|
||||||
}else {
|
}else {
|
||||||
System.out.println("null");
|
System.out.println("null");
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
//дописать функцию возвращения listPonts и shape(форма), если будет нужно.
|
//дописать функцию возвращения listPonts и shape(форма), если будет нужно.
|
||||||
// так же при написании функции возвращения нужных координат, надо их сделать целочисленными.
|
// так же при написании функции возвращения нужных координат, надо их сделать целочисленными.
|
||||||
|
|||||||
@ -1,25 +0,0 @@
|
|||||||
package model;
|
|
||||||
|
|
||||||
public class IsometricCoordsConverter {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param result - Point object to store the result
|
|
||||||
* @return x and y converted to isometic coords
|
|
||||||
* */
|
|
||||||
public static Point cartesianToIsometric(float cartX, float cartY, Point result) {
|
|
||||||
result.x = cartX - cartY;
|
|
||||||
result.y = (cartX + cartY) / 2;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param result - Point object to store the result
|
|
||||||
* @return x and y converted to cartesian coords
|
|
||||||
* */
|
|
||||||
public static Point isometricToCartesian(float x, float y, Point result) {
|
|
||||||
result.x = (2 * y + x) / 2;
|
|
||||||
result.y = (2 * y - x) / 2;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -8,4 +8,8 @@ public class Point {
|
|||||||
x = mainX;
|
x = mainX;
|
||||||
y = mainY;
|
y = mainY;
|
||||||
}
|
}
|
||||||
|
public void setXY(float x, float y){
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -190,6 +190,7 @@ public class Project implements Iterable<Entity>, EntityDrawboxChangedListener {
|
|||||||
if (!imageFile.exists())
|
if (!imageFile.exists())
|
||||||
throw new FileNotFoundException();
|
throw new FileNotFoundException();
|
||||||
BufferedImage image = ImageIO.read(imageFile);
|
BufferedImage image = ImageIO.read(imageFile);
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
} catch (FileNotFoundException fe) {
|
} catch (FileNotFoundException fe) {
|
||||||
logger.warning("Image file \""+path+name+'.'+extension+"\" is not found!");
|
logger.warning("Image file \""+path+name+'.'+extension+"\" is not found!");
|
||||||
|
|||||||
Reference in New Issue
Block a user