Commit 0d784506 authored by Lukas Marik's avatar Lukas Marik

#940 add controll wall padding and add hang verb for wall object

parent e65553a3
......@@ -69,6 +69,9 @@ game_protocol_descriptor_verb_is_p = jsou
game_protocol_descriptor_verb_lie_s = leží
game_protocol_descriptor_verb_lie_p = leží
game_protocol_descriptor_verb_hang_s = visí
game_protocol_descriptor_verb_hang_p = visí
game_protocol_descriptor_pronoun_m_l_s =
game_protocol_descriptor_pronoun_m_l_p = ří
......
......@@ -85,6 +85,9 @@ game_protocol_descriptor_verb_is_p = sind
game_protocol_descriptor_verb_lie_s = liegt
game_protocol_descriptor_verb_lie_p = liegen
game_protocol_descriptor_verb_hang_s = hängt
game_protocol_descriptor_verb_hang_p = hängen
game_protocol_easy_angel = Engel
game_protocol_easy_baby_carriage = Wagen
game_protocol_easy_bag_of_marbles = Murmelbeutel
......
......@@ -69,6 +69,9 @@ game_protocol_descriptor_verb_is_p = sú
game_protocol_descriptor_verb_lie_s = leží
game_protocol_descriptor_verb_lie_p = leží
game_protocol_descriptor_verb_hang_s = visí
game_protocol_descriptor_verb_hang_p = visí
game_protocol_descriptor_pronoun_m_s =
game_protocol_descriptor_pronoun_f_s =
game_protocol_descriptor_pronoun_n_s =
......
......@@ -22,6 +22,7 @@ import com.badlogic.gdx.math.Vector2;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
......@@ -46,6 +47,7 @@ public class ObjectsController {
public static final int HORIZONTAL_CIRCULAR_SECTOR = 65;
private Map<GameObjectType, List<PositionPair>> solution = new HashMap<>();
private List<GameObjectType> objectsOnWall = new LinkedList<>();
public ObjectsController() {
......@@ -63,10 +65,18 @@ public class ObjectsController {
solution.put(keyObject, new ArrayList<>());
}
solution.get(keyObject).add(new PositionPair(preposition, valueObject));
if(valueObject instanceof WallType)
objectsOnWall.add(keyObject);
}
public void clearSolution() {
solution.clear();
objectsOnWall.clear();
}
public boolean isObjectOnWall(GameObjectType objectType){
return objectsOnWall.contains(objectType);
}
//////////////////////////// OBJECTS CONTROL
......
......@@ -128,7 +128,8 @@ public abstract class AbstractObjectDescriptor {
public enum Verb{
IS ("_is"),
LIE ("_lie");
LIE ("_lie"),
HANG("_hang");
String pathResource;
Verb(String pathResource){
......@@ -143,8 +144,9 @@ public abstract class AbstractObjectDescriptor {
return getVerbText(screen, NounType.PLURAL);
}
public static Verb getVerbByIndex(int index){
return values()[index];
public static Verb getVerb(int index, boolean wall){
return index == 0 ? IS : wall ? HANG : LIE;
}
}
......
......@@ -24,10 +24,10 @@ import cz.nic.tablexia.game.games.protocol.gameobjects.GameObjectType;
import cz.nic.tablexia.game.games.protocol.gameobjects.wall.WallType;
public enum WallObjectDescriptor {
CUCKOO_CLOCK (GameObjectType.CUCKOO_CLOCK, WallType.LEFT_WALL, new float[]{0.06f, 0.97f}, new float[]{0.1f, 0.03f}, new float[]{0.92f, 0.98f}, new float[]{0.93f, 0.04f}, Arrays.asList( new float[]{0.044f, 0.55f}, new float[]{0.5f, 0.80f}, new float[]{0.92f, 0.65f})),
LADY_AND_PANDA (GameObjectType.LADY_AND_PANDA, WallType.LEFT_WALL, new float[]{0.11f, 0.68f}, new float[]{0.19f, 0.04f}, new float[]{0.86f, 0.94f}, new float[]{0.93f, 0.31f}, Arrays.asList( new float[]{0.08f, 0.66f}, new float[]{0.5f, 0.80f}, new float[]{0.92f, 0.65f})),
LANDSCAPE (GameObjectType.LANDSCAPE, WallType.RIGHT_WALL, new float[]{0.09f, 0.93f}, new float[]{0.08f, 0.38f}, new float[]{0.9f, 0.62f}, new float[]{0.9f, 0.05f}, Arrays.asList( new float[]{0.08f, 0.66f}, new float[]{0.5f, 0.80f}, new float[]{0.92f, 0.65f})),
MIRROR (GameObjectType.MIRROR, WallType.RIGHT_WALL, new float[]{0.2f, 0.97f}, new float[]{0.07f, 0.18f}, new float[]{0.91f, 0.82f}, new float[]{0.74f, 0.03f}, Arrays.asList( new float[]{0.08f, 0.52f}, new float[]{0.5f, 0.80f}, new float[]{0.92f, 0.52f}));
CUCKOO_CLOCK (GameObjectType.CUCKOO_CLOCK, WallType.LEFT_WALL, new float[]{0.06f, 0.97f}, new float[]{0.1f, 0.03f}, new float[]{0.92f, 0.98f}, new float[]{0.93f, 0.04f}, Arrays.asList( new float[]{0.044f, 0.55f}, new float[]{0.42f, 0.87f}, new float[]{0.92f, 0.65f})),
LADY_AND_PANDA (GameObjectType.LADY_AND_PANDA, WallType.LEFT_WALL, new float[]{0.11f, 0.68f}, new float[]{0.19f, 0.04f}, new float[]{0.86f, 0.94f}, new float[]{0.93f, 0.31f}, Arrays.asList( new float[]{0.08f, 0.66f}, new float[]{0.45f, 0.8f}, new float[]{0.92f, 0.65f})),
LANDSCAPE (GameObjectType.LANDSCAPE, WallType.RIGHT_WALL, new float[]{0.09f, 0.93f}, new float[]{0.08f, 0.38f}, new float[]{0.9f, 0.62f}, new float[]{0.9f, 0.05f}, Arrays.asList( new float[]{0.08f, 0.66f}, new float[]{0.57f, 0.87f}, new float[]{0.92f, 0.65f})),
MIRROR (GameObjectType.MIRROR, WallType.RIGHT_WALL, new float[]{0.2f, 0.97f}, new float[]{0.07f, 0.18f}, new float[]{0.91f, 0.82f}, new float[]{0.74f, 0.03f}, Arrays.asList( new float[]{0.08f, 0.52f}, new float[]{0.5f, 0.78f}, new float[]{0.92f, 0.52f}));
private GameObjectType objectType;
private WallType wallOrientation;
......
......@@ -51,8 +51,8 @@ import cz.nic.tablexia.util.Log;
public class RoomGroup extends Group {
public static final int MIN_OBJECTS_DISTANCE = 60;
private static final float WALL_PADDING = 5f;
public static final int MIN_OBJECTS_DISTANCE = 60;
private static final float WALL_PADDING = 10f;
private int countObjects = 0;
private ProtocolGame protocolGame;
......@@ -124,7 +124,7 @@ public class RoomGroup extends Group {
protocolGame.setDropEvent(gameObject.getType());
}
private void addObjectToWall(GameObject gameObject, WallType wallType, RoomPosition roomPosition, float xPosition, float yPosition){
private void addObjectToWall(GameObject gameObject, WallType wallType, RoomPosition roomPosition, float xPosition, float yPosition) {
WallObjectDescriptor descriptor = WallObjectDescriptor.getDescriptorByType(gameObject.getType());
WallType objectOrientation = descriptor.getWallOrientation();
......@@ -132,7 +132,6 @@ public class RoomGroup extends Group {
gameObject.middleTexture(wallType == WallType.MIDDLE_WALL);
gameObject.rotateObject(objectOrientation != wallType && wallType != WallType.MIDDLE_WALL);
//TODO zkontrolovat precuhovani
gameObject.setPosition(xPosition, yPosition);
gameObject.setLastPosition(new Vector2(xPosition, yPosition));
gameObject.setWallPositionType(wallType);
......@@ -267,13 +266,13 @@ public class RoomGroup extends Group {
WallType wallType = positionTransfer.getWallType();
if((position == RoomPosition.WALL || previousPosition == RoomPosition.WALL) && wallType != changedObject.getWallPositionType()) {
if ((position == RoomPosition.WALL || previousPosition == RoomPosition.WALL) && wallType != changedObject.getWallPositionType()) {
WallObjectDescriptor descriptor = WallObjectDescriptor.getDescriptorByType(changedObject.getType());
changedObject.middleTexture(wallType == WallType.MIDDLE_WALL);
changedObject.rotateObject((position == RoomPosition.WALL) && (descriptor.getWallOrientation() != wallType && wallType != WallType.MIDDLE_WALL));
}
if(position == RoomPosition.WALL)
if (position == RoomPosition.WALL)
controlWallPosition(changedObject, wallType);
changedObject.setRoomPosition(position);
......@@ -281,9 +280,7 @@ public class RoomGroup extends Group {
controlObjectsPosition(changedObject);
}
Image lastIntersect; //TODO smazat po otestovaní a refactoringu
private void controlWallPosition(GameObject gameObject, WallType wallType){
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);
......@@ -303,11 +300,11 @@ public class RoomGroup extends Group {
boolean checkRTPoints = checkPointBetweenTwoLines(lTWall, rTWall, rBWall, rTObject);
if(!(checkLBPoints && checkLTPoints && checkRBPoints && checkRTPoints)){
if (!(checkLBPoints && checkLTPoints && checkRBPoints && checkRTPoints)) {
int pointsCNT = (checkLBPoints ? 0 : 1) + (checkLTPoints ? 0 : 1) + (checkRBPoints ? 0 : 1) + (checkRTPoints ? 0 : 1);
if(pointsCNT == 3){
if (pointsCNT == 3) {
boolean useLB = !checkLBPoints && checkRTPoints;
boolean useLT = !checkLTPoints && checkRBPoints;
......@@ -322,7 +319,7 @@ public class RoomGroup extends Group {
float correctY = gameObject.getY() + (wall.y - object.y) + WALL_PADDING * ((useLT || useRT) ? -1 : 1);
gameObject.moveToPosition(true, correctX, correctY, null);
}else if(pointsCNT == 2) {
} else if (pointsCNT == 2) {
boolean bottom = checkLTPoints && checkRTPoints;
boolean right = checkLBPoints && checkLTPoints;
......@@ -331,107 +328,84 @@ public class RoomGroup extends Group {
Vector2[] wallPoints = new Vector2[2];
Vector2[] objectPoints = new Vector2[2];
float paddingX = WALL_PADDING;
float paddingY = WALL_PADDING;
float paddingX = 0.f;
float paddingY = 0.f;
wallPoints[0] = top ? lTWall : right ? rBWall : lBWall;
wallPoints[1] = bottom ? rBWall : left ? lTWall : rTWall;
Vector2 check;
if(top){
if (top) {
objectPoints[0] = wallType == WallType.LEFT_WALL ? rTObject : lTObject;
objectPoints[1] = wallType == WallType.LEFT_WALL ? rBObject : lBObject;
paddingX *= wallType == WallType.LEFT_WALL ? 1 : -1;
paddingY *= wallType == WallType.LEFT_WALL ? 1 : -1;
paddingY -= WALL_PADDING;
check = wallType == WallType.LEFT_WALL ? rTObject : lTObject;
}else if (bottom){
} else if (bottom) {
objectPoints[0] = wallType == WallType.LEFT_WALL ? rTObject : lTObject;
objectPoints[1] = wallType == WallType.LEFT_WALL ? rBObject : lBObject;
paddingX *= wallType == WallType.LEFT_WALL ? 1 : -1;
paddingY *= wallType == WallType.LEFT_WALL ? 1 : -1;
paddingY += WALL_PADDING;
check = wallType == WallType.LEFT_WALL ? rBObject : lBObject;
}else if(right){
} else if (right) {
objectPoints[0] = wallType == WallType.RIGHT_WALL ? lTObject : lBObject;
objectPoints[1] = wallType == WallType.RIGHT_WALL ? rTObject : rBObject;
paddingX = 0;
paddingY = 0;
paddingX -= WALL_PADDING / 2;
check = wallType == WallType.RIGHT_WALL ? rTObject : rBObject;
}else {
} else {
objectPoints[0] = wallType == WallType.LEFT_WALL ? lTObject : lBObject;
objectPoints[1] = wallType == WallType.LEFT_WALL ? rTObject : rBObject;
paddingX = 0;
paddingY = 0;
check= wallType == WallType.LEFT_WALL ? lTObject : lBObject;
paddingX += WALL_PADDING / 2;
check = wallType == WallType.LEFT_WALL ? lTObject : lBObject;
}
Log.info("WALL_CHECK", "TOP: " + top + "\n LEFT: " + left + "\n RIGHT: " + right + "\n BOTTOM: " + bottom);
Vector2 intersect = intersectVerticalLines(wallPoints[0], wallPoints[1], objectPoints[0], objectPoints[1]);
if(intersect == null)
if (intersect == null)
return;
float correctX = gameObject.getX() - (check.x - intersect.x);
float correctY = gameObject.getY() - (check.y - intersect.y);
float correctX = gameObject.getX() - (check.x - intersect.x) + paddingX;
float correctY = gameObject.getY() - (check.y - intersect.y) + paddingY;
gameObject.moveToPosition(true, correctX, correctY, null);
//TODO smazat po otestovaní a refactoringu
if(lastIntersect == null){
lastIntersect = new Image(ApplicationAtlasManager.getInstance().getColorTexture(Color.RED));
addActor(lastIntersect);
}
lastIntersect.setBounds(intersect.x - 2.5f, intersect.y - 2.5f, 5f, 5f);
}
}
}
private Vector2 intersectVerticalLines(Vector2 p1, Vector2 p2, Vector2 q1, Vector2 q2){
private Vector2 intersectVerticalLines(Vector2 p1, Vector2 p2, Vector2 q1, Vector2 q2) {
float f1 = -(p2.y - p1.y) / (p1.x - p2.x);
float f2 = -(q2.y - q1.y) / (q1.x - q2.x);
float g1 = p1.y - f1 * p1.x;
float g2 = q1.y - f2 * q1.x;
if(f1 == f2)
return null;
if (f1 == f2)
return null;
if(p1.x == p2.x) return new Vector2(p1.x, f2 * p1.x + g2);
else if(q1.x == q2.x) return new Vector2(q1.x, f1 * q1.x + g1);
else{
Vector2 inter = new Vector2((g2-g1)/(f1 -f2),0);
if (p1.x == p2.x) return new Vector2(p1.x, f2 * p1.x + g2);
else if (q1.x == q2.x) return new Vector2(q1.x, f1 * q1.x + g1);
else {
Vector2 inter = new Vector2((g2 - g1) / (f1 - f2), 0);
inter.y = f1 * inter.x + g1;
return inter;
}
}
private boolean checkPointBetweenTwoLines(Vector2 A, Vector2 B, Vector2 C, Vector2 point){
private boolean checkPointBetweenTwoLines(Vector2 A, Vector2 B, Vector2 C, Vector2 point) {
float[] u = new float[]{-B.y + A.y, B.x - A.x, 0}; //general form line AB
float[] v = new float[]{-C.y + B.y, C.x - B.x, 0}; //general form line BX
u[2] = -u[0]*A.x-u[1]*A.y;
v[2] = -v[0]*B.x-v[1]*B.y;
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
*/
private boolean checkPointsInHalfSpace(float u1, float u2, float u3, Vector2 point1, Vector2 point2) {
return ((u1 * point1.x + u2 * point1.y + u3) * (u1 * point2.x + u2 * point2.y + u3) > 0);
}
......
......@@ -21,9 +21,11 @@ package cz.nic.tablexia.game.games.protocol.model.gameprotocol;
import com.google.common.collect.ImmutableMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
......@@ -460,6 +462,7 @@ public abstract class ProtocolGenerator {
TextDescriptor textDescriptor = getTextDescriptor(protocolText);
Map<Sentence, Integer[]> sentenceMap = textDescriptor.getSentenceMap();
List<FurnitureType> furnitureTypes = FurnitureType.getFurnitureByDifficulty(difficulty);
List<WallType> wallTypes = new LinkedList<>(Arrays.asList(WallType.values()));
int sentenceCnt = 0;
startIndexVerb = random.nextInt(2);
......@@ -475,7 +478,7 @@ public abstract class ProtocolGenerator {
if (sentence.furnitureCnt != 0) {
typePositions = new ArrayList<>();
needAlternative = generateFurnitureForSentence(typePositions, furnitureTypes, textTypes, descriptorIndex, sentence.canBeMerge);
needAlternative = generateFurnitureForSentence(typePositions, furnitureTypes, wallTypes, textTypes, descriptorIndex, sentence.canBeMerge);
if (needAlternative) {
sentence = Sentence.getAlternativeSentence(sentence);
......@@ -507,7 +510,7 @@ public abstract class ProtocolGenerator {
return message;
}
private boolean generateFurnitureForSentence(List<TypeObjectDescriptor> typePositions, List<FurnitureType> furnitureTypes, TextType[] textTypes, Integer[] descriptorIndex, boolean canBeMerge) {
private boolean generateFurnitureForSentence(List<TypeObjectDescriptor> typePositions, List<FurnitureType> furnitureTypes, List<WallType> wallTypes, TextType[] textTypes, Integer[] descriptorIndex, boolean canBeMerge) {
for (int i = 0; i < textTypes.length; i++) {
if (textTypes[i] == TextType.Furniture_Wall) {
......@@ -533,17 +536,23 @@ public abstract class ProtocolGenerator {
controller.addPositionToSolution(objectType, Preposition.ON, furnitureType);
typePositions.add(furnitureType);
} else {
WallType wallType = WallType.getWallTypeByGameObjectType(objectType);
if(wallTypes == null || wallTypes.isEmpty())
wallTypes = Arrays.asList(WallType.values());
int rnd = random.nextInt(wallTypes.size());
WallType wallType = wallTypes.get(rnd);
controller.addPositionToSolution(objectType, Preposition.ON, wallType);
typePositions.add(wallType);
}
}
}
//Remove used furniture type
//Remove used furniture type and wall type
for (TypeObjectDescriptor position : typePositions) {
if (position instanceof FurnitureType && furnitureTypes.contains(position)) {
furnitureTypes.remove(position);
}else if (position instanceof WallType && wallTypes.contains(position)){
wallTypes.remove(position);
}
}
......@@ -586,7 +595,8 @@ public abstract class ProtocolGenerator {
texts[i] = preparePronoun(screen, descriptor);
break;
case Verb:
texts[i] = prepareVerb(screen, descriptor.getNounType(), startIndexVerb, alternative);
boolean wall = controller.isObjectOnWall(objectType);
texts[i] = prepareVerb(screen, descriptor.getNounType(), startIndexVerb, alternative, wall);
startIndexVerb = (startIndexVerb + 1) % 2;
break;
case Furniture_Wall:
......@@ -643,8 +653,8 @@ public abstract class ProtocolGenerator {
return descriptor.getPronounInflection(screen);
}
private String prepareVerb(AbstractTablexiaScreen screen, AbstractObjectDescriptor.NounType nounType, int startIndexVerb, boolean alternative) {
Verb verb = Verb.getVerbByIndex(startIndexVerb);
private String prepareVerb(AbstractTablexiaScreen screen, AbstractObjectDescriptor.NounType nounType, int startIndexVerb, boolean alternative, boolean wall) {
Verb verb = Verb.getVerb(startIndexVerb, wall);
return alternative ? verb.getPluralVerbText(screen) : verb.getVerbText(screen, nounType);
}
......
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