Commit 14d26591 authored by Lukas Marik's avatar Lukas Marik

#940 rotate image by wall position

parent c7e592ee
...@@ -100,6 +100,7 @@ public class GameObject extends ObjectModel { ...@@ -100,6 +100,7 @@ public class GameObject extends ObjectModel {
private boolean selected; private boolean selected;
private boolean fixed; private boolean fixed;
private boolean scaling; private boolean scaling;
private boolean rotate;
public GameObject(GameObjectType type, ProtocolGame protocolGame, String cardText, boolean inPicture) { public GameObject(GameObjectType type, ProtocolGame protocolGame, String cardText, boolean inPicture) {
this.type = type; this.type = type;
...@@ -110,6 +111,7 @@ public class GameObject extends ObjectModel { ...@@ -110,6 +111,7 @@ public class GameObject extends ObjectModel {
roomPosition = null; roomPosition = null;
selected = false; selected = false;
fixed = false; fixed = false;
rotate = false;
cardDrawable = protocolGame.getScreenTextureRegion(type.getCardTexturePath()); cardDrawable = protocolGame.getScreenTextureRegion(type.getCardTexturePath());
objectDrawable = protocolGame.getScreenTextureRegion(type.getObjectTexturePath()); objectDrawable = protocolGame.getScreenTextureRegion(type.getObjectTexturePath());
...@@ -260,6 +262,13 @@ public class GameObject extends ObjectModel { ...@@ -260,6 +262,13 @@ public class GameObject extends ObjectModel {
return type.checkPosition(position); return type.checkPosition(position);
} }
public void rotateObject(boolean rotateX){
if(rotateX) {
rotate = !rotate;
}
objectDrawable.flip(rotateX, false);
}
//////////////////////////// SCALE ACTIONS //////////////////////////// SCALE ACTIONS
...@@ -420,6 +429,10 @@ public class GameObject extends ObjectModel { ...@@ -420,6 +429,10 @@ public class GameObject extends ObjectModel {
return scaling; return scaling;
} }
public boolean isRotate() {
return rotate;
}
@Override @Override
public TypeObjectDescriptor getTypePosition() { public TypeObjectDescriptor getTypePosition() {
return furniture != null ? furniture.getType() : null; return furniture != null ? furniture.getType() : null;
......
...@@ -24,19 +24,18 @@ import cz.nic.tablexia.game.games.protocol.gameobjects.GameObjectType; ...@@ -24,19 +24,18 @@ import cz.nic.tablexia.game.games.protocol.gameobjects.GameObjectType;
import cz.nic.tablexia.game.games.protocol.gameobjects.wall.WallType; import cz.nic.tablexia.game.games.protocol.gameobjects.wall.WallType;
public enum WallObjectDescriptor { public enum WallObjectDescriptor {
//TODO upravit fixni body pro kazdou zed 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})),
CUCKOO_CLOCK (GameObjectType.CUCKOO_CLOCK, WallType.LEFT_WALL, new float[]{0.06f, 0.98f}, new float[]{0.1f, 0.04f}, new float[]{0.92f, 0.97f}, new float[]{0.93f, 0.03f}, 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})),
LADY_AND_PANDA (GameObjectType.LADY_AND_PANDA, WallType.LEFT_WALL, new float[]{0.15f, 0.94f}, new float[]{0.04f, 0.31f}, new float[]{0.92f, 0.68f}, new float[]{0.78f, 0.04f}, 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})),
LANDSCAPE (GameObjectType.LANDSCAPE, WallType.RIGHT_WALL, new float[]{0.07f, 0.62f}, new float[]{0.1f, 0.05f}, new float[]{0.88f, 0.93f}, new float[]{0.94f, 0.38f}, 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}));
MIRROR (GameObjectType.MIRROR, WallType.RIGHT_WALL, new float[]{0.08f, 0.83f}, new float[]{0.28f, 0.03f}, new float[]{0.8f, 0.97f}, new float[]{0.94f, 0.18f}, Arrays.asList( new float[]{0.08f, 0.52f}, new float[]{0.5f, 0.80f}, new float[]{0.92f, 0.52f}));
private GameObjectType objectType; private GameObjectType objectType;
private WallType wallOrientation; private WallType wallOrientation;
private float[] rBRatio; //blue private float[] rBRatio;
private float[] lBRatio; //red private float[] lBRatio;
private float[] rTRatio; //yellow private float[] rTRatio;
private float[] lTRatio; //green private float[] lTRatio;
private List<float[]> wallFixRatio; private List<float[]> wallFixRatio;
......
...@@ -34,6 +34,7 @@ import cz.nic.tablexia.game.games.protocol.controller.RoomPosition; ...@@ -34,6 +34,7 @@ import cz.nic.tablexia.game.games.protocol.controller.RoomPosition;
import cz.nic.tablexia.game.games.protocol.gameobjects.GameObject; import cz.nic.tablexia.game.games.protocol.gameobjects.GameObject;
import cz.nic.tablexia.game.games.protocol.gameobjects.GameObjectType; import cz.nic.tablexia.game.games.protocol.gameobjects.GameObjectType;
import cz.nic.tablexia.game.games.protocol.gameobjects.ObjectModel; import cz.nic.tablexia.game.games.protocol.gameobjects.ObjectModel;
import cz.nic.tablexia.game.games.protocol.gameobjects.descriptors.WallObjectDescriptor;
import cz.nic.tablexia.game.games.protocol.gameobjects.furniture.Furniture; import cz.nic.tablexia.game.games.protocol.gameobjects.furniture.Furniture;
import cz.nic.tablexia.game.games.protocol.gameobjects.furniture.FurnitureType; import cz.nic.tablexia.game.games.protocol.gameobjects.furniture.FurnitureType;
import cz.nic.tablexia.game.games.protocol.gameobjects.wall.WallType; import cz.nic.tablexia.game.games.protocol.gameobjects.wall.WallType;
...@@ -101,15 +102,8 @@ public class RoomGroup extends Group { ...@@ -101,15 +102,8 @@ public class RoomGroup extends Group {
} else if(roomPosition == RoomPosition.WALL && wallType != null){ } else if(roomPosition == RoomPosition.WALL && wallType != null){
addObjectToWall(gameObject, wallType); addObjectToWall(gameObject, wallType, roomPosition, xPosition, yPosition);
//TODO fix na jednu urcitou pozici na zdi
gameObject.setPosition(xPosition, yPosition);
gameObject.setLastPosition(new Vector2(xPosition, yPosition));
gameObject.setWallPositionType(wallType);
addActor(gameObject);
roomObjects.get(roomPosition).add(gameObject);
}else { }else {
gameObject.setPosition(xPosition, yPosition); gameObject.setPosition(xPosition, yPosition);
...@@ -126,8 +120,20 @@ public class RoomGroup extends Group { ...@@ -126,8 +120,20 @@ public class RoomGroup extends Group {
protocolGame.setDropEvent(gameObject.getType()); protocolGame.setDropEvent(gameObject.getType());
} }
private void addObjectToWall(GameObject gameObject, WallType wallType){ private void addObjectToWall(GameObject gameObject, WallType wallType, RoomPosition roomPosition, float xPosition, float yPosition){
WallObjectDescriptor descriptor = WallObjectDescriptor.getDescriptorByType(gameObject.getType());
WallType objectOrientation = descriptor.getWallOrientation();
gameObject.rotateObject(objectOrientation != wallType && wallType != WallType.MIDDLE_WALL);
//TODO zkontrolovat precuhovani
gameObject.setPosition(xPosition, yPosition);
gameObject.setLastPosition(new Vector2(xPosition, yPosition));
gameObject.setWallPositionType(wallType);
addActor(gameObject);
roomObjects.get(roomPosition).add(gameObject);
} }
public void removeObject(GameObject gameObject) { public void removeObject(GameObject gameObject) {
...@@ -148,6 +154,8 @@ public class RoomGroup extends Group { ...@@ -148,6 +154,8 @@ public class RoomGroup extends Group {
gameObject.setFurniture(null); gameObject.setFurniture(null);
gameObject.setRoomPosition(null); gameObject.setRoomPosition(null);
gameObject.setWallPositionType(null);
gameObject.rotateObject(gameObject.isRotate());
} }
public void resetData() { public void resetData() {
...@@ -202,28 +210,28 @@ public class RoomGroup extends Group { ...@@ -202,28 +210,28 @@ public class RoomGroup extends Group {
public void objectPositionChanges(GameObject changedObject, PositionTransfer positionTransfer) { public void objectPositionChanges(GameObject changedObject, PositionTransfer positionTransfer) {
RoomPosition position = positionTransfer.getRoomPosition(); RoomPosition position = positionTransfer.getRoomPosition();
RoomPosition previousPosition = changedObject.getRoomPosition();
//TODO zkontrolovat pozici zmeny na zed fixnout na pozici if ((position == RoomPosition.FLOOR || position == RoomPosition.WALL) && previousPosition == RoomPosition.FURNITURE) {
if ((position == RoomPosition.FLOOR || position == RoomPosition.WALL) && changedObject.getRoomPosition() == RoomPosition.FURNITURE) {
transferObjectFromFurnitureToRoomGroup(changedObject, position); transferObjectFromFurnitureToRoomGroup(changedObject, position);
} else if (position == RoomPosition.FURNITURE && changedObject.getRoomPosition() == RoomPosition.FURNITURE && positionTransfer.getFurnitureType() != changedObject.getFurniture().getType()) { } else if (position == RoomPosition.FURNITURE && previousPosition == RoomPosition.FURNITURE && positionTransfer.getFurnitureType() != changedObject.getFurniture().getType()) {
transferObjectBetweenFurniture(changedObject, positionTransfer.getFurnitureType()); transferObjectBetweenFurniture(changedObject, positionTransfer.getFurnitureType());
} else if (position == RoomPosition.FURNITURE && (changedObject.getRoomPosition() == RoomPosition.FLOOR || changedObject.getRoomPosition() == RoomPosition.WALL)) { } else if (position == RoomPosition.FURNITURE && (previousPosition == RoomPosition.FLOOR || previousPosition == RoomPosition.WALL)) {
transferObjectFromRoomGroupToFurniture(changedObject, positionTransfer.getFurnitureType()); transferObjectFromRoomGroupToFurniture(changedObject, positionTransfer.getFurnitureType());
} else if (position == RoomPosition.WALL && changedObject.getRoomPosition() == RoomPosition.FLOOR) { } else if (position == RoomPosition.WALL && previousPosition == RoomPosition.FLOOR) {
roomObjects.get(RoomPosition.FLOOR).remove(changedObject); roomObjects.get(RoomPosition.FLOOR).remove(changedObject);
roomObjects.get(RoomPosition.WALL).add(changedObject); roomObjects.get(RoomPosition.WALL).add(changedObject);
changedObject.setLastPosition(new Vector2(changedObject.getX(), changedObject.getY())); changedObject.setLastPosition(new Vector2(changedObject.getX(), changedObject.getY()));
addActor(changedObject); addActor(changedObject);
} else if (position == RoomPosition.FLOOR && changedObject.getRoomPosition() == RoomPosition.WALL) { } else if (position == RoomPosition.FLOOR && previousPosition == RoomPosition.WALL) {
roomObjects.get(RoomPosition.WALL).remove(changedObject); roomObjects.get(RoomPosition.WALL).remove(changedObject);
roomObjects.get(RoomPosition.FLOOR).add(changedObject); roomObjects.get(RoomPosition.FLOOR).add(changedObject);
...@@ -232,7 +240,7 @@ public class RoomGroup extends Group { ...@@ -232,7 +240,7 @@ public class RoomGroup extends Group {
} else if (position == changedObject.getRoomPosition()) { } else if (position == changedObject.getRoomPosition()) {
if (changedObject.getRoomPosition() == RoomPosition.FURNITURE) { if (previousPosition == RoomPosition.FURNITURE) {
Furniture furniture = changedObject.getFurniture(); Furniture furniture = changedObject.getFurniture();
float xPosition = changedObject.getX() - furniture.getX(); float xPosition = changedObject.getX() - furniture.getX();
...@@ -249,8 +257,21 @@ public class RoomGroup extends Group { ...@@ -249,8 +257,21 @@ public class RoomGroup extends Group {
} }
WallType wallType = positionTransfer.getWallType();
if((position == RoomPosition.WALL || previousPosition == RoomPosition.WALL) && wallType != changedObject.getWallPositionType()) {
WallObjectDescriptor descriptor = WallObjectDescriptor.getDescriptorByType(changedObject.getType());
boolean isRotate = changedObject.isRotate();
if(position != RoomPosition.WALL){
changedObject.rotateObject(isRotate);
}else {
boolean needRotate = descriptor.getWallOrientation() != wallType && wallType != WallType.MIDDLE_WALL;
changedObject.rotateObject(isRotate ^ needRotate);
}
}
changedObject.setRoomPosition(position); changedObject.setRoomPosition(position);
changedObject.setWallPositionType(positionTransfer.getWallType()); changedObject.setWallPositionType(wallType);
controlObjectsPosition(changedObject); controlObjectsPosition(changedObject);
} }
......
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