New hitbox architecture. But need change function addListElement in class ListGUI and load in class Project
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="src" path="src"/>
|
<classpathentry kind="src" path="src"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk-19">
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk-24">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="module" value="true"/>
|
<attribute name="module" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
eclipse.preferences.version=1
|
eclipse.preferences.version=1
|
||||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
|
||||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=15
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=15
|
||||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
org.eclipse.jdt.core.compiler.compliance=15
|
org.eclipse.jdt.core.compiler.compliance=23
|
||||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
|||||||
@ -21,7 +21,7 @@ public class HitboxEditor extends Editable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawing(Graphics2D g) {
|
public void drawing(Graphics2D g) {
|
||||||
Hitbox nowHitbox = entity.getHitbox();
|
/*Hitbox nowHitbox = entity.getHitbox();
|
||||||
//if(firstIsoPoint != null) {
|
//if(firstIsoPoint != null) {
|
||||||
int x1,y1,x2,y2;
|
int x1,y1,x2,y2;
|
||||||
int size = nowHitbox.getListPointsIso().size();
|
int size = nowHitbox.getListPointsIso().size();
|
||||||
@ -38,7 +38,7 @@ public class HitboxEditor extends Editable {
|
|||||||
y2 = (int)nowHitbox.getListPointsIso().get(3).y;
|
y2 = (int)nowHitbox.getListPointsIso().get(3).y;
|
||||||
g.drawLine(x1, y1, x2, y2);
|
g.drawLine(x1, y1, x2, y2);
|
||||||
//}
|
//}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -69,7 +69,7 @@ public class HitboxEditor extends Editable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseMoved(MouseEvent e) {
|
public void mouseMoved(MouseEvent e) {
|
||||||
currentIsoPoint.x = e.getX();
|
/*currentIsoPoint.x = e.getX();
|
||||||
currentIsoPoint.y = e.getY();
|
currentIsoPoint.y = e.getY();
|
||||||
if(entity!=null) {
|
if(entity!=null) {
|
||||||
Hitbox nowHitbox = entity.getHitbox();
|
Hitbox nowHitbox = entity.getHitbox();
|
||||||
@ -83,7 +83,7 @@ public class HitboxEditor extends Editable {
|
|||||||
nowHitbox.convertCartesianPointsToIso();
|
nowHitbox.convertCartesianPointsToIso();
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -89,13 +89,7 @@ public class ListGUI extends JPanel {
|
|||||||
|
|
||||||
|
|
||||||
public void addListElement(String name, String solid) throws DuplicateEntryException {
|
public void addListElement(String name, String solid) throws DuplicateEntryException {
|
||||||
|
Entity e = new Entity(name);
|
||||||
// плейсхолдеры для новых хитбоксов и дроубоксов, иначе всё валится с NPE
|
|
||||||
Hitbox hitbox = new Hitbox();
|
|
||||||
Drawbox drawbox = new Drawbox();
|
|
||||||
|
|
||||||
Entity e = new Entity(name, hitbox, drawbox);
|
|
||||||
hitbox.setOwnerEntity(e);
|
|
||||||
e.setType(solid);
|
e.setType(solid);
|
||||||
logger.finer("Entity \""+name+"\" was created.");
|
logger.finer("Entity \""+name+"\" was created.");
|
||||||
Project.getInstance().addEntity(e);
|
Project.getInstance().addEntity(e);
|
||||||
|
|||||||
@ -18,10 +18,10 @@ public class Entity {
|
|||||||
thisHitbox = new Hitbox(hitbox,this);
|
thisHitbox = new Hitbox(hitbox,this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Entity(String name, Hitbox hitbox, Drawbox drawbox) {
|
public Entity(String name) {
|
||||||
this.thisName = name;
|
this.thisName = name;
|
||||||
this.thisHitbox = hitbox;
|
this.thisHitbox = new Hitbox();
|
||||||
this.thisDrawbox = drawbox;
|
this.thisDrawbox = new Drawbox();
|
||||||
thisHitbox.setOwnerEntity(this);
|
thisHitbox.setOwnerEntity(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,99 +4,33 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Hitbox {
|
public class Hitbox {
|
||||||
private String shape = null;// shape - Форма хитбокса. Понадобится при написании сохранения. Один из параметров в xml-file.
|
String shape = null;// shape - Форма хитбокса. Понадобится при написании сохранения. Один из параметров в xml-file.
|
||||||
private List<Point> listPointsIso = new ArrayList<Point>();
|
Point referencePoint = new Point(0, 0); //Точка отсчета хитбокса, от нее рассчитывается высота+ширина/радиус(при круге) хитбокса.
|
||||||
private List<Point> listPointsCartesian = new ArrayList<Point>();
|
Entity owner;
|
||||||
private Point referencePoint = new Point(0, 0); //Точка отсчета хитбокса, от нее рассчитывается высота+ширина/радиус(при круге) хитбокса.
|
|
||||||
private float widthHitbox = 0,heightHitbox = 0; // Ширина и высота хитбокса в декартовых координатах.
|
|
||||||
private float radiusHitbox = 0;
|
|
||||||
private Entity owner;
|
|
||||||
|
|
||||||
public Hitbox(){
|
public Hitbox(){
|
||||||
initListsPoints();
|
|
||||||
}
|
}
|
||||||
public Hitbox(String shape,List<Point> listPointsIso,List<Point> listPointsCartesian){
|
public Hitbox(String shape){
|
||||||
this.shape = new String(shape);
|
this.shape = new String(shape);
|
||||||
this.listPointsIso = listPointsIso;
|
|
||||||
this.listPointsCartesian = listPointsCartesian;
|
|
||||||
initListsPoints();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//informationHitbox - default="Rectangle 0 0 96 98"
|
||||||
public Hitbox(String informationHitbox, Entity owner){
|
public Hitbox(String informationHitbox, Entity owner){
|
||||||
if(informationHitbox!= null) {
|
if(informationHitbox!= null) {
|
||||||
setOwnerEntity(owner);
|
setOwnerEntity(owner);
|
||||||
initListsPoints();
|
|
||||||
String[] informations = informationHitbox.split(" ");
|
String[] informations = informationHitbox.split(" ");
|
||||||
//в 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();
|
createCartesianPointsFromWidthAndHeigh();
|
||||||
convertCartesianPointsToIso();
|
convertCartesianPointsToIso();
|
||||||
printToConsole();
|
printToConsole();*/
|
||||||
}else if(shape.equals("Circle")) {
|
}else if(shape.equals("Circle")) {
|
||||||
parseStringToCircleHitbox(informations);
|
//parseStringToCircleHitbox(informations);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initListsPoints() {
|
|
||||||
if(listPointsIso.size()<1) {
|
|
||||||
for(int i=0;i<4;i++) {
|
|
||||||
listPointsIso.add(new Point(0,0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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) {
|
|
||||||
referencePoint.x = Float.parseFloat(informations[1]);
|
|
||||||
referencePoint.y = Float.parseFloat(informations[2]);
|
|
||||||
radiusHitbox = Float.parseFloat(informations[3]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void convertIsoPointsToCartesian() {
|
|
||||||
Point isoPoint;
|
|
||||||
for (int i = 0 ; i<4;i++) {
|
|
||||||
isoPoint = listPointsIso.get(i);
|
|
||||||
cartesianToIsometric(isoPoint.x,isoPoint.y,listPointsCartesian.get(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//+++++++
|
|
||||||
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.getWidth()/2+referencePoint.x,owner.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
|
* @param result - Point object to store the result
|
||||||
* @return x and y converted to isometic coords
|
* @return x and y converted to isometic coords
|
||||||
@ -126,16 +60,11 @@ public class Hitbox {
|
|||||||
public String getShape() {
|
public String getShape() {
|
||||||
return shape;
|
return shape;
|
||||||
}
|
}
|
||||||
public List<Point> getListPointsIso() {
|
|
||||||
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&&listPointsCartesian!=null) {
|
if(shape!=null&&listPointsCartesian!=null) {
|
||||||
System.out.println("Shape: " + shape);
|
System.out.println("Shape: " + shape);
|
||||||
@ -153,7 +82,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,5 +1,16 @@
|
|||||||
package model;
|
package model;
|
||||||
|
|
||||||
public class HitboxCircle extends Hitbox {
|
public class HitboxCircle extends Hitbox {
|
||||||
private float radiusHitbox = 0;
|
private float radiusHitbox;
|
||||||
|
|
||||||
|
public HitboxCircle(String[] dataHitbox, Entity owner){
|
||||||
|
super(dataHitbox[0]);
|
||||||
|
parseStringToCircleHitbox(dataHitbox);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void parseStringToCircleHitbox(String[] informations) {
|
||||||
|
referencePoint.x = Float.parseFloat(informations[1]);
|
||||||
|
referencePoint.y = Float.parseFloat(informations[2]);
|
||||||
|
radiusHitbox = Float.parseFloat(informations[3]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,7 @@ public class HitboxRectangle extends Hitbox {
|
|||||||
private List<Point> listPointsIso = new ArrayList<Point>();
|
private List<Point> listPointsIso = new ArrayList<Point>();
|
||||||
private List<Point> listPointsCartesian = new ArrayList<Point>();
|
private List<Point> listPointsCartesian = new ArrayList<Point>();
|
||||||
private float widthHitbox = 0,heightHitbox = 0; // Ширина и высота хитбокса в декартовых координатах.
|
private float widthHitbox = 0,heightHitbox = 0; // Ширина и высота хитбокса в декартовых координатах.
|
||||||
/*
|
|
||||||
public HitboxRectangle(){
|
public HitboxRectangle(){
|
||||||
initListsPoints();
|
initListsPoints();
|
||||||
}
|
}
|
||||||
@ -17,22 +17,17 @@ public class HitboxRectangle extends Hitbox {
|
|||||||
this.listPointsCartesian = listPointsCartesian;
|
this.listPointsCartesian = listPointsCartesian;
|
||||||
initListsPoints();
|
initListsPoints();
|
||||||
}
|
}
|
||||||
public HitboxRectangle(String informationHitbox, Entity owner){
|
|
||||||
if(informationHitbox!= null) {
|
//informationHitbox - default="Rectangle 0 0 96 98"
|
||||||
setOwnerEntity(owner);
|
public HitboxRectangle(String[] dataHitbox, Entity owner){
|
||||||
initListsPoints();
|
super(dataHitbox[0]);
|
||||||
String[] informations = informationHitbox.split(" ");
|
setOwnerEntity(owner);
|
||||||
//в 0-м индексе всегда идет название фигуры.Так сделан наш xml.
|
initListsPoints();
|
||||||
shape = new String(informations[0]);
|
//в 0-м индексе всегда идет название фигуры.Так сделан наш xml.
|
||||||
if(shape.equals("Rectangle")) {
|
parseStringToRectangleHitbox(dataHitbox);
|
||||||
parseStringToRectangleHitbox(informations);
|
createCartesianPointsFromWidthAndHeigh();
|
||||||
createCartesianPointsFromWidthAndHeigh();
|
convertCartesianPointsToIso();
|
||||||
convertCartesianPointsToIso();
|
printToConsole();
|
||||||
printToConsole();
|
|
||||||
}else if(shape.equals("Circle")) {
|
|
||||||
parseStringToCircleHitbox(informations);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initListsPoints() {
|
private void initListsPoints() {
|
||||||
@ -48,14 +43,14 @@ public class HitboxRectangle extends Hitbox {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseStringToRectangleHitbox(String[] informations) {
|
private void parseStringToRectangleHitbox(String[] dataHitbox) {
|
||||||
referencePoint.x = Float.parseFloat(informations[1]);
|
referencePoint.x = Float.parseFloat(dataHitbox[1]);
|
||||||
referencePoint.y = Float.parseFloat(informations[2]);
|
referencePoint.y = Float.parseFloat(dataHitbox[2]);
|
||||||
widthHitbox = Float.parseFloat(informations[3]);
|
widthHitbox = Float.parseFloat(dataHitbox[3]);
|
||||||
heightHitbox = Float.parseFloat(informations[4]);
|
heightHitbox = Float.parseFloat(dataHitbox[4]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//тут не правильно реализована функция, т.к. до сих пор нигде не используется. Надо переделать будет.
|
||||||
public void convertIsoPointsToCartesian() {
|
public void convertIsoPointsToCartesian() {
|
||||||
Point isoPoint;
|
Point isoPoint;
|
||||||
for (int i = 0 ; i<4;i++) {
|
for (int i = 0 ; i<4;i++) {
|
||||||
@ -83,6 +78,11 @@ public class HitboxRectangle extends Hitbox {
|
|||||||
listPointsCartesian.add(new Point(refCartesianPoint.x,refCartesianPoint.y-heightHitbox));
|
listPointsCartesian.add(new Point(refCartesianPoint.x,refCartesianPoint.y-heightHitbox));
|
||||||
listPointsCartesian.add(new Point(refCartesianPoint.x-widthHitbox,refCartesianPoint.y-heightHitbox));
|
listPointsCartesian.add(new Point(refCartesianPoint.x-widthHitbox,refCartesianPoint.y-heightHitbox));
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
|
public List<Point> getListPointsIso() {
|
||||||
|
return listPointsIso;
|
||||||
|
}
|
||||||
|
public List<Point> getListPointsCartesian() {
|
||||||
|
return listPointsCartesian;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user