Fix hitbox. Nothing worked, now it is.
This commit is contained in:
@ -12,18 +12,17 @@ import model.Point;
|
|||||||
|
|
||||||
public class HitboxRectangleEditor extends Editable {
|
public class HitboxRectangleEditor extends Editable {
|
||||||
Point firstIsoPoint = null;
|
Point firstIsoPoint = null;
|
||||||
Point currentIsoPoint = null;
|
Point currentIsoPoint = new Point(0,0);
|
||||||
Point firstCartesianPoint = new Point(0,0), currentCartesianPoint = new Point(0,0);
|
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 cons2tructor stub
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawing(Graphics2D g) {
|
public void drawing(Graphics2D g) {
|
||||||
if(firstIsoPoint != null) {
|
Hitbox nowHitbox = entity.getHitbox();
|
||||||
|
//if(firstIsoPoint != null) {
|
||||||
int x1,y1,x2,y2;
|
int x1,y1,x2,y2;
|
||||||
int size = nowHitbox.getListPointsIso().size();
|
int size = nowHitbox.getListPointsIso().size();
|
||||||
for(int i = 0; i < size;i++) {
|
for(int i = 0; i < size;i++) {
|
||||||
@ -38,7 +37,7 @@ public class HitboxRectangleEditor extends Editable {
|
|||||||
x2 = (int)nowHitbox.getListPointsIso().get(3).x;
|
x2 = (int)nowHitbox.getListPointsIso().get(3).x;
|
||||||
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);
|
||||||
}
|
//}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,6 +52,7 @@ public class HitboxRectangleEditor extends Editable {
|
|||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
if(firstIsoPoint == null) {
|
if(firstIsoPoint == null) {
|
||||||
firstIsoPoint = new Point(currentIsoPoint.x,currentIsoPoint.y);
|
firstIsoPoint = new Point(currentIsoPoint.x,currentIsoPoint.y);
|
||||||
|
//System.out.println("firstPoint("+firstIsoPoint.x+";"+firstIsoPoint.y+");");
|
||||||
firstCartesianPoint = Hitbox.isometricToCartesian(firstIsoPoint.x, firstIsoPoint.y,firstCartesianPoint);
|
firstCartesianPoint = Hitbox.isometricToCartesian(firstIsoPoint.x, firstIsoPoint.y,firstCartesianPoint);
|
||||||
}else{
|
}else{
|
||||||
/*
|
/*
|
||||||
@ -71,14 +71,18 @@ public class HitboxRectangleEditor extends Editable {
|
|||||||
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(firstIsoPoint != null) {
|
if(entity!=null) {
|
||||||
currentCartesianPoint = Hitbox.isometricToCartesian(currentIsoPoint.x, currentIsoPoint.y, currentCartesianPoint);
|
Hitbox nowHitbox = entity.getHitbox();
|
||||||
nowHitbox.getListPointsCartesian().get(0).setXY(firstCartesianPoint.x, firstCartesianPoint.y);
|
if(firstIsoPoint != null) {
|
||||||
nowHitbox.getListPointsCartesian().get(1).setXY(currentCartesianPoint.x, firstCartesianPoint.y);
|
//System.out.println("firstPoint("+firstIsoPoint.x+";"+firstIsoPoint.y+");");
|
||||||
nowHitbox.getListPointsCartesian().get(2).setXY(currentCartesianPoint.x, currentCartesianPoint.y);
|
currentCartesianPoint = Hitbox.isometricToCartesian(currentIsoPoint.x, currentIsoPoint.y, currentCartesianPoint);
|
||||||
nowHitbox.getListPointsCartesian().get(3).setXY(firstCartesianPoint.x, currentCartesianPoint.y);
|
nowHitbox.getListPointsCartesian().get(0).setXY(firstCartesianPoint.x, firstCartesianPoint.y);
|
||||||
nowHitbox.convertCartesianPointsToIso();
|
nowHitbox.getListPointsCartesian().get(1).setXY(currentCartesianPoint.x, firstCartesianPoint.y);
|
||||||
repaint();
|
nowHitbox.getListPointsCartesian().get(2).setXY(currentCartesianPoint.x, currentCartesianPoint.y);
|
||||||
|
nowHitbox.getListPointsCartesian().get(3).setXY(firstCartesianPoint.x, currentCartesianPoint.y);
|
||||||
|
nowHitbox.convertCartesianPointsToIso();
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +92,7 @@ public class HitboxRectangleEditor extends Editable {
|
|||||||
if(parent.getSelectedComponent() == this){
|
if(parent.getSelectedComponent() == this){
|
||||||
if(entity != null) {
|
if(entity != null) {
|
||||||
firstIsoPoint = null;
|
firstIsoPoint = null;
|
||||||
currentIsoPoint = null;
|
currentIsoPoint.setXY(0,0);
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,6 +32,7 @@ public class Hitbox {
|
|||||||
parseStringToRectangleHitbox(informations);
|
parseStringToRectangleHitbox(informations);
|
||||||
createCartesianPointsFromWidthAndHeigh();
|
createCartesianPointsFromWidthAndHeigh();
|
||||||
convertCartesianPointsToIso();
|
convertCartesianPointsToIso();
|
||||||
|
printToConsole();
|
||||||
}else if(shape.equals("Circle")) {
|
}else if(shape.equals("Circle")) {
|
||||||
parseStringToCircleHitbox(informations);
|
parseStringToCircleHitbox(informations);
|
||||||
}
|
}
|
||||||
@ -136,15 +137,23 @@ public class Hitbox {
|
|||||||
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&&listPointsCartesian!=null) {
|
||||||
System.out.println("shape: " + shape);
|
System.out.println("Shape: " + shape);
|
||||||
for(Point point: listPoints) {
|
System.out.println("Cartesian: ");
|
||||||
|
for(Point point: listPointsCartesian) {
|
||||||
System.out.print("("+point.x+";"+point.y+") ");
|
System.out.print("("+point.x+";"+point.y+") ");
|
||||||
|
System.out.println("");
|
||||||
}
|
}
|
||||||
System.out.println();
|
System.out.println("-----------");
|
||||||
|
System.out.println("Iso: ");
|
||||||
|
for(Point point: listPointsIso){
|
||||||
|
System.out.print("("+point.x+";"+point.y+") ");
|
||||||
|
System.out.println("");
|
||||||
|
}
|
||||||
|
System.out.println(" ");
|
||||||
}else {
|
}else {
|
||||||
System.out.println("null");
|
System.out.println("null");
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
//дописать функцию возвращения listPonts и shape(форма), если будет нужно.
|
//дописать функцию возвращения listPonts и shape(форма), если будет нужно.
|
||||||
// так же при написании функции возвращения нужных координат, надо их сделать целочисленными.
|
// так же при написании функции возвращения нужных координат, надо их сделать целочисленными.
|
||||||
|
|||||||
5
src/model/HitboxCircle.java
Normal file
5
src/model/HitboxCircle.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package model;
|
||||||
|
|
||||||
|
public class HitboxCircle extends Hitbox {
|
||||||
|
private float radiusHitbox = 0;
|
||||||
|
}
|
||||||
88
src/model/HitboxRectangle.java
Normal file
88
src/model/HitboxRectangle.java
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
package model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class HitboxRectangle extends Hitbox {
|
||||||
|
private List<Point> listPointsIso = new ArrayList<Point>();
|
||||||
|
private List<Point> listPointsCartesian = new ArrayList<Point>();
|
||||||
|
private float widthHitbox = 0,heightHitbox = 0; // Ширина и высота хитбокса в декартовых координатах.
|
||||||
|
/*
|
||||||
|
public HitboxRectangle(){
|
||||||
|
initListsPoints();
|
||||||
|
}
|
||||||
|
public HitboxRectangle(String shape,List<Point> listPointsIso,List<Point> listPointsCartesian){
|
||||||
|
super(shape);
|
||||||
|
this.listPointsIso = listPointsIso;
|
||||||
|
this.listPointsCartesian = listPointsCartesian;
|
||||||
|
initListsPoints();
|
||||||
|
}
|
||||||
|
public HitboxRectangle(String informationHitbox, Entity owner){
|
||||||
|
if(informationHitbox!= null) {
|
||||||
|
setOwnerEntity(owner);
|
||||||
|
initListsPoints();
|
||||||
|
String[] informations = informationHitbox.split(" ");
|
||||||
|
//в 0-м индексе всегда идет название фигуры.Так сделан наш xml.
|
||||||
|
shape = new String(informations[0]);
|
||||||
|
if(shape.equals("Rectangle")) {
|
||||||
|
parseStringToRectangleHitbox(informations);
|
||||||
|
createCartesianPointsFromWidthAndHeigh();
|
||||||
|
convertCartesianPointsToIso();
|
||||||
|
printToConsole();
|
||||||
|
}else if(shape.equals("Circle")) {
|
||||||
|
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]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user