Commit e20256eb authored by Lukas Marik's avatar Lukas Marik

#940 check if object points are on the wall

parent 7d161d4c
......@@ -433,6 +433,22 @@ public class GameObject extends ObjectModel {
return rotate;
}
public Vector2 getrBPoint() {
return rBPoint;
}
public Vector2 getlBPoint() {
return lBPoint;
}
public Vector2 getlTPoint() {
return lTPoint;
}
public Vector2 getrTPoint() {
return rTPoint;
}
@Override
public TypeObjectDescriptor getTypePosition() {
return furniture != null ? furniture.getType() : null;
......
......@@ -39,7 +39,7 @@ public enum WallObjectDescriptor {
private List<float[]> wallFixRatio;
WallObjectDescriptor(GameObjectType objectType, WallType wallOrientation, float[] rBRatio, float[]lBRatio, float[]rTRatio, float[] lTRatio, List<float[]> wallFixRatio){
WallObjectDescriptor(GameObjectType objectType, WallType wallOrientation, float[] lTRatio, float[]lBRatio, float[]rTRatio, float[] rBRatio, List<float[]> wallFixRatio){
this.objectType = objectType;
this.wallOrientation = wallOrientation;
......
......@@ -18,8 +18,8 @@
package cz.nic.tablexia.game.games.protocol.gameobjects.wall;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2;
import cz.nic.tablexia.game.difficulty.GameDifficulty;
import cz.nic.tablexia.game.games.protocol.gameobjects.GameObjectType;
import cz.nic.tablexia.game.games.protocol.gameobjects.TypeObjectDescriptor;
......@@ -28,14 +28,24 @@ import cz.nic.tablexia.game.games.protocol.gameobjects.TypeObjectDescriptor;
*/
public enum WallType implements TypeObjectDescriptor{
LEFT_WALL (new Color(0xff0000ff)),
MIDDLE_WALL (new Color(0xff00ffff)),
RIGHT_WALL (new Color(0x00ffffff));
LEFT_WALL (new Color(0xff0000ff), new float[]{0.018f, 0.31f}, new float[]{0.354f, 0.586f}, new float[]{0.018f, 0.709f}, new float[]{0.353f, 0.98f}),
MIDDLE_WALL (new Color(0xff00ffff), new float[]{0.354f, 0.586f}, new float[]{0.65f, 0.586f}, new float[]{0.353f, 0.98f}, new float[]{0.65f, 0.98f}),
RIGHT_WALL (new Color(0x00ffffff), new float[]{0.65f, 0.586f}, new float[]{0.98f, 0.31f} , new float[]{0.65f, 0.98f}, new float[]{0.98f, 0.709f});
private Color wallColor;
WallType(Color wallColor){
private float[] lBRatio;
private float[] rBRatio;
private float[] lTRatio;
private float[] rTRatio;
WallType(Color wallColor, float[] lBRatio, float[] rBRatio, float[] lTRatio, float[] rTRatio){
this.wallColor = wallColor;
this.lBRatio = lBRatio;
this.rBRatio = rBRatio;
this.lTRatio = lTRatio;
this.rTRatio = rTRatio;
}
public static WallType getWallTypeByGameObjectType(GameObjectType objectType) {
......@@ -57,6 +67,22 @@ public enum WallType implements TypeObjectDescriptor{
return null;
}
public Vector2 getlBPoint(float w, float h) {
return new Vector2(w * lBRatio[0], h * lBRatio[1]);
}
public Vector2 getrBPoint(float w, float h) {
return new Vector2(w * rBRatio[0], h * rBRatio[1]);
}
public Vector2 getlTPoint(float w, float h) {
return new Vector2(w * lTRatio[0], h * lTRatio[1]);
}
public Vector2 getrTPoint(float w, float h) {
return new Vector2(w * rTRatio[0], h * rTRatio[1]);
}
@Override
public int getOriginType() {
return ordinal();
......
......@@ -134,6 +134,8 @@ public class RoomGroup extends Group {
addActor(gameObject);
roomObjects.get(roomPosition).add(gameObject);
controlWallPosition(gameObject, wallType);
}
public void removeObject(GameObject gameObject) {
......@@ -270,11 +272,64 @@ public class RoomGroup extends Group {
changedObject.rotateObject(isRotate ^ needRotate);
}
}
if(position == RoomPosition.WALL)
controlWallPosition(changedObject, wallType);
changedObject.setRoomPosition(position);
changedObject.setWallPositionType(wallType);
controlObjectsPosition(changedObject);
}
private void controlWallPosition(GameObject gameObject, WallType wallType){
Vector2 lBObject = new Vector2(gameObject.getX() + gameObject.getlBPoint().x, gameObject.getY() + gameObject.getlBPoint().y);
Vector2 lTObject = new Vector2(gameObject.getX() + gameObject.getlTPoint().x, gameObject.getY() + gameObject.getlTPoint().y);
Vector2 rBObject = new Vector2(gameObject.getX() + gameObject.getrBPoint().x, gameObject.getY() + gameObject.getrBPoint().y);
Vector2 rTObject = new Vector2(gameObject.getX() + gameObject.getrTPoint().x, gameObject.getY() + gameObject.getrTPoint().y);
float roomWidth = getWidth();
float roomHeight = getHeight();
Vector2 lBWall = wallType.getlBPoint(roomWidth, roomHeight);
Vector2 lTWall = wallType.getlTPoint(roomWidth, roomHeight);
Vector2 rBWall = wallType.getrBPoint(roomWidth, roomHeight);
Vector2 rTWall = wallType.getrTPoint(roomWidth, roomHeight);
boolean checkLBPoints = checkPointBetweenTwoLines(rBWall, lBWall, lTWall, lBObject);
boolean checkLTPoints = checkPointBetweenTwoLines(rTWall, lTWall, lBWall, lTObject);
boolean checkRBPoints = checkPointBetweenTwoLines(rTWall, rBWall, lBWall, rBObject);
boolean checkRTPoints = checkPointBetweenTwoLines(lTWall, rTWall, rBWall, rTObject);
Log.info("WALL_CHECK", "LB ON WALL: " + checkLBPoints + "\n" +
"LT ON WALL: " + checkLTPoints + "\n" +
"RB ON WALL: " + checkRBPoints + "\n" +
"RT ON WALL: " + checkRTPoints);
if(checkLBPoints && checkLTPoints && checkRBPoints && checkRTPoints)
Log.info("WALL_CHECK", "object is on wall");
else
Log.info("WALL_CHECK", "only part of object is on wall");
}
private boolean checkPointBetweenTwoLines(Vector2 A, Vector2 B, Vector2 C, Vector2 point){
float[] u = new float[]{-B.y + A.y, B.x - A.x, 0}; //line AB
float[] v = new float[]{-C.y + B.y, C.x - B.x, 0}; //line BX
u[2] = -u[0]*A.x-u[1]*A.y;
v[2] = -v[0]*B.x-v[1]*B.y;
return checkPointsInHalfSpace(u[0], u[1], u[2], C, point) && checkPointsInHalfSpace(v[0], v[1], v[2], A, point);
}
private boolean checkPointsInHalfSpace(float u1, float u2, float u3, Vector2 point1, Vector2 point2){
/*
* half-space u1x + u2y + u3 = 0
*/
return ((u1 * point1.x + u2 * point1.y + u3) * (u1 * point2.x + u2 * point2.y + u3) > 0);
}
private void transferObjectBetweenFurniture(GameObject changedObject, FurnitureType furnitureType) {
Furniture oldFurniture = changedObject.getFurniture();
Furniture newFurniture = getFurnitureByType(furnitureType);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment