Commit d78793ec authored by Lukáš Mařík's avatar Lukáš Mařík

#940 prepare specific wall fix position for object

parent c688eec5
......@@ -526,7 +526,9 @@ public class ProtocolGame extends AbstractTablexiaGame<ProtocolGameState> {
addGameObjectToRoom(object, xPosition, yPosition, new PositionTransfer(RoomPosition.FURNITURE, furnitureType, null));
} else if (positionPairs.get(0).getObjectType() instanceof WallType) {
WallType wallType = (WallType) positionPairs.get(0).getObjectType();
float[] fixRatio = wallType.getFixRatio(getGameDifficulty());
WallType.WallObjectPosition position = WallType.WallObjectPosition.getWallObjectPositionByType(objectType);
float[] fixRatio = position.getWallRatio(getGameDifficulty(), wallType);
float xPosition = roomGroup.getWidth() * fixRatio[0] - object.getWallPoint().x;
float yPosition = roomGroup.getHeight() * fixRatio[1] - object.getWallPoint().y;
......
......@@ -19,11 +19,13 @@ package cz.nic.tablexia.game.games.protocol.gameobjects.wall;
import com.badlogic.gdx.graphics.Color;
import cz.nic.tablexia.game.common.TablexiaRandom;
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;
import java.util.Arrays;
import java.util.List;
/**
* Created by lmarik on 18.8.17.
*/
......@@ -33,15 +35,47 @@ public enum WallType implements TypeObjectDescriptor{
MIDDLE_WALL (new Color(0xff00ffff), new float[]{0.5f, 0.80f}, new float[]{0.5f, 0.82f}),
RIGHT_WALL (new Color(0x00ffffff), new float[]{0.92f, 0.65f}, new float[]{0.91f, 0.5f});
public enum WallObjectPosition{
CUCKOO_CLOCK (GameObjectType.CUCKOO_CLOCK, Arrays.asList(new float[]{0.08f, 0.66f}, new float[]{0.5f, 0.80f}, new float[]{0.92f, 0.65f}), Arrays.asList(new float[]{0.3f, 0.82f}, new float[]{0.5f, 0.82f}, new float[]{0.91f, 0.5f})),
LADY_AND_PANDA (GameObjectType.LADY_AND_PANDA, Arrays.asList(new float[]{0.08f, 0.66f}, new float[]{0.5f, 0.80f}, new float[]{0.92f, 0.65f}), Arrays.asList(new float[]{0.3f, 0.82f}, new float[]{0.5f, 0.82f}, new float[]{0.91f, 0.5f})),
LANDSCAPE (GameObjectType.LANDSCAPE, Arrays.asList(new float[]{0.08f, 0.66f}, new float[]{0.5f, 0.80f}, new float[]{0.92f, 0.65f}), Arrays.asList(new float[]{0.3f, 0.82f}, new float[]{0.5f, 0.82f}, new float[]{0.91f, 0.5f})),
MIRROR (GameObjectType.MIRROR, Arrays.asList(new float[]{0.08f, 0.66f}, new float[]{0.5f, 0.80f}, new float[]{0.92f, 0.65f}), Arrays.asList(new float[]{0.3f, 0.82f}, new float[]{0.5f, 0.82f}, new float[]{0.91f, 0.5f}));
private GameObjectType objectType;
private List<float[]> fixMediumRatio;
private List<float[]> fixHardRatio;
WallObjectPosition(GameObjectType objectType, List<float[]> fixMediumRatio, List<float[]> fixHardRatio){
this.objectType = objectType;
this.fixMediumRatio = fixMediumRatio;
this.fixHardRatio = fixHardRatio;
}
public float[] getWallRatio(GameDifficulty difficulty, WallType wallType){
int index = wallType.getOriginType();
return difficulty == GameDifficulty.MEDIUM ? fixMediumRatio.get(index) : fixHardRatio.get(index);
}
public static WallObjectPosition getWallObjectPositionByType(GameObjectType objectType) {
for (WallObjectPosition objectPosition: values()){
if(objectPosition.objectType == objectType)
return objectPosition;
}
throw new RuntimeException("Couldn't get wall position for object: " + objectType);
}
}
private Color wallColor;
private float[] fixMediumRatio;
private float[] fixHardRatio;
private float[] testMediumRatio;
private float[] testHardRatio;
WallType(Color wallColor, float[] fixMediumRatio, float[] fixHardRatio){
WallType(Color wallColor, float[] testMediumRatio, float[] testHardRatio){
this.wallColor = wallColor;
this.fixMediumRatio = fixMediumRatio;
this.fixHardRatio = fixHardRatio;
this.testMediumRatio = testMediumRatio;
this.testHardRatio = testHardRatio;
}
public static WallType getWallTypeByGameObjectType(GameObjectType objectType) {
......@@ -63,8 +97,8 @@ public enum WallType implements TypeObjectDescriptor{
return null;
}
public float[] getFixRatio(GameDifficulty difficulty) {
return difficulty == GameDifficulty.MEDIUM ? fixMediumRatio : fixHardRatio;
public float[] getTestRatio(GameDifficulty difficulty) {
return difficulty == GameDifficulty.MEDIUM ? testMediumRatio : testHardRatio;
}
......@@ -73,3 +107,4 @@ public enum WallType implements TypeObjectDescriptor{
return ordinal();
}
}
......@@ -36,6 +36,7 @@ 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.furniture.Furniture;
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.utils.ObjectsPositionComparator;
import cz.nic.tablexia.game.games.protocol.utils.PositionTransfer;
import cz.nic.tablexia.util.Log;
......@@ -82,6 +83,7 @@ public class RoomGroup extends Group {
countObjects++;
RoomPosition roomPosition = positionTransfer.getRoomPosition();
FurnitureType furnitureType = positionTransfer.getFurnitureType();
WallType wallType = positionTransfer.getWallType();
if (roomPosition == RoomPosition.FURNITURE && furnitureType != null) {
Furniture furniture = getFurnitureByType(furnitureType);
......@@ -97,10 +99,22 @@ public class RoomGroup extends Group {
furniture.addObjectOnFurniture(gameObject, xPosition, yPosition);
gameObject.setFurniture(furniture);
} else {
} else if(roomPosition == RoomPosition.WALL && wallType != null){
addObjectToWall(gameObject, wallType);
//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 {
gameObject.setPosition(xPosition, yPosition);
gameObject.setLastPosition(new Vector2(xPosition, yPosition));
gameObject.setWallPositionType(positionTransfer.getWallType());
gameObject.setWallPositionType(null);
addActor(gameObject);
roomObjects.get(roomPosition).add(gameObject);
......@@ -112,6 +126,10 @@ public class RoomGroup extends Group {
protocolGame.setDropEvent(gameObject.getType());
}
private void addObjectToWall(GameObject gameObject, WallType wallType){
}
public void removeObject(GameObject gameObject) {
countObjects--;
if (gameObject.getRoomPosition() == RoomPosition.FURNITURE) {
......@@ -185,6 +203,7 @@ public class RoomGroup extends Group {
public void objectPositionChanges(GameObject changedObject, PositionTransfer positionTransfer) {
RoomPosition position = positionTransfer.getRoomPosition();
//TODO zkontrolovat pozici zmeny na zed fixnout na pozici
if ((position == RoomPosition.FLOOR || position == RoomPosition.WALL) && changedObject.getRoomPosition() == RoomPosition.FURNITURE) {
transferObjectFromFurnitureToRoomGroup(changedObject, position);
......
......@@ -298,7 +298,7 @@ public class TestGameProtocol extends AbstractTestGame {
correct();
}
float[] fixRatio = wallType.getFixRatio(difficulty);
float[] fixRatio = wallType.getTestRatio(difficulty);
float xPosition = roomGroup.getX() + roomGroup.getWidth() * fixRatio[0]/* - gameObject.getCenterPosition().x*/;
float yPosition = roomGroup.getY() + roomGroup.getHeight() * fixRatio[1]/* - gameObject.getCenterPosition().y*/;
......
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