Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UTF-8!!! #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions core/src/com/mygdx/game/Battle.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class Battle {
private Server server;
private Array<Player> players;
private Player enemy;
private long[] lastActTime;//������ ������� ��������� �������� �������. ������������� ������� �������
private long[] lastActTime;//массив времени последних запросов игроков. Соответствует массиву игроков

private AsteroidField asteroidField;

Expand Down Expand Up @@ -71,16 +71,16 @@ public void received(Connection c, Object p) {
players[0].getCurrentShip().setTransform(20, 20, 200);
players[0].getCurrentShip().setTargetRotation(200);

enemy = new Player(); //������������ ������� ���������� � ������ enemy
enemy.setName("enemy");// � �������� ������
enemy = new Player(); //Искусственно создаем противника с именем enemy
enemy.setName("enemy");// и передаем игроку
//PhysicShip tempShip=new Fury(55,30,0);
//tempShip.create(world);
enemy.setCurrentShip(new StarFighter(60, 30, 180));

//

for (int i = 0; i < players.length; i++) {
players[i].getCurrentShip().setId(i + 1); //����������� ������������� ������� �������
players[i].getCurrentShip().setId(i + 1); //присваиваем идентификатор каждому кораблю
System.out.println(players[i].getCurrentShip().getId());
}

Expand Down Expand Up @@ -114,7 +114,7 @@ void update() {
//}

asteroidField.update();
if (lrt + 5 < System.currentTimeMillis()) {
if (lrt + 20 < System.currentTimeMillis()) {
System.out.println("x: " + players.get(0).getCurrentShip().getBody().getPosition().x
+ " y: " + players.get(0).getCurrentShip().getBody().getPosition().y
+ " r: " + Math.toDegrees(players.get(0).getCurrentShip().getBody().getAngle()));
Expand Down Expand Up @@ -171,7 +171,7 @@ public void connect(ServPlayer player) {
}

void PlayerAct(PlayerActions acts) {
if (lastActTime[acts.getShipID() - 1] < acts.getTime())//��������� �������� �� ������ ����� �����������
if (lastActTime[acts.getShipID() - 1] < acts.getTime())//проверяем является ли запрос новее предыдущего
{
players.get(acts.getShipID() - 1).getCurrentShip().setMovementPosition(acts.getMovementPosition());
players.get(acts.getShipID() - 1).getCurrentShip().setTargetRotation(acts.getTargetRotation());
Expand Down
12 changes: 6 additions & 6 deletions core/src/com/mygdx/game/ServerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@

public class ServerListener extends Listener {
public void connected(Connection c) {
System.out.println("�� ������ ����������� " + c.getRemoteAddressTCP().getHostString());
System.out.println("На сервер подключился " + c.getRemoteAddressTCP().getHostString());

BattleInfo info = new BattleInfo();
info.setMessage("������ �����: " + new Date().getHours() + ":" + new Date().getMinutes());
info.setMessage("Сейчас время: " + new Date().getHours() + ":" + new Date().getMinutes());
c.sendTCP(info);
}

public void received(Connection c, Object p) {
if (p instanceof Player) {
Player player = (Player) p;
System.out.println("��� ���:" + player.getName());
System.out.println("����:" + c.getReturnTripTime());
System.out.println("Его имя:" + player.getName());
System.out.println("Пинг:" + c.getReturnTripTime());
}
}

//������������ ����� ������ �������� ������.
//Используется когда клиент покидает сервер.
public void disconnected(Connection c) {
System.out.println("������ ������� ������!");
System.out.println("Клиент покинул сервер!");
}

}
40 changes: 20 additions & 20 deletions core/src/com/mygdx/game/SpaceBattle.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ public class SpaceBattle extends ApplicationAdapter {

@Override
public void create() {
//������� ������
server = new Server(32768, 32768);//� ��������� ������ ������� ��������� � �������
//создаем сервер
server = new Server(32768, 32768);//В скобочках размер буферов написания и объекта
listener = new ServerListener();
players = new ArrayList<ServPlayer>();
waitQueue = new ArrayList<BattleInfo>();

World world = new World(new Vector2(0, 0), false);

//������������ �����
//регистрируем класс
kryo = server.getKryo();
kryo.register(BattleInfo.class);

Expand All @@ -84,20 +84,20 @@ public void create() {
kryo.register(PlayerActions.class);
kryo.register(ServBattleInfo.class);

//������������ ����
//регистрируем порт
try {
server.bind(tcpPort, udpPort);
} catch (IOException e) {

e.printStackTrace();
}

//��������� ������
//запускаем сервер
server.start();

server.addListener(new Listener() {
public void connected(Connection c) {
System.out.println("�� ������ ����������� " + c.getRemoteAddressTCP().getHostString());
System.out.println("На сервер подключился " + c.getRemoteAddressTCP().getHostString());


}
Expand All @@ -106,28 +106,28 @@ public void received(Connection c, Object p) {
if (p instanceof BattleInfo) {
BattleInfo info = (BattleInfo) p;
if (info.getRequestType().equals(BattleInfo.RequestType.Adding)) {
System.out.println("������ ������ ���������� � �������");
System.out.println("Клиент просит добавления в очередь");
info.setConnectionID(c.getID());
info.setStatus("inQueue");
waitQueue.add(info);
System.out.println("������ �������� � �������");
System.out.println("Клиент добавлен в очередь");
info.setQueueTurn(waitQueue.size());
info.setQueueSize(waitQueue.size());
c.sendTCP(info);
System.out.println("���������� �����");
System.out.println("Отправляем ответ");
} else if (info.getRequestType().equals(BattleInfo.RequestType.Info)) {
System.out.println("������ ����������� ���������� �� �������");
System.out.println("Клиент запрашивает информацию об очереди");
info.setQueueSize(waitQueue.size());
c.sendTCP(info);
System.out.println("���������� ����������");
System.out.println("Отправляем информацию");
}

} else if (p instanceof HostStartInfo) {
System.out.println("���� �������� ��������� ������");
System.out.println("Хост высылает начальные данные");
HostStartInfo hsi = (HostStartInfo) p;
server.sendToTCP(hsi.getEnemyConID(), hsi);
} else if (p instanceof ClientStartInfo) {
System.out.println("������ �������� ��������� ������");
System.out.println("Клиент высылает начальные данные");
ClientStartInfo csi = (ClientStartInfo) p;
server.sendToTCP(csi.getEnemyConID(), csi);
} else if (p instanceof ServPlayer) {
Expand All @@ -139,7 +139,7 @@ public void received(Connection c, Object p) {
System.out.println("Id: " + player.getCurrentShip().getId());

battle = new Battle(battleID, server, players);
System.out.println("� ��� �����" + player.getName());
System.out.println("В бой вошел" + player.getName());
//System.out.println("Id: "+player.getConID());
} else if (p instanceof PlayerActions) {
PlayerActions acts = (PlayerActions) p;
Expand All @@ -149,15 +149,15 @@ public void received(Connection c, Object p) {

}

//������������ ����� ������ �������� ������.
//Используется когда клиент покидает сервер.
public void disconnected(Connection c) {
System.out.println("������ ������� ������!");
System.out.println("Клиент покинул сервер!");
for (int i = 0; i < waitQueue.size(); i++) {
if (waitQueue.get(i).getConnectionID() == c.getID()) {
waitQueue.remove(i);
}
}
System.out.println("������ ��� ������ �� �������");
System.out.println("Клиент был удален из очереди");
}
});

Expand All @@ -176,14 +176,14 @@ public void render() {
waitQueue.get(1).setStatus("inBattle");
server.sendToTCP(waitQueue.get(0).getConnectionID(), waitQueue.get(0));
server.sendToTCP(waitQueue.get(1).getConnectionID(), waitQueue.get(1));
System.out.println("����������� ���� ������� � ���");
System.out.println("Направвляем двух игроков в бой");
waitQueue.remove(1);
waitQueue.remove(0);
System.out.println("������� �� �� �������");
System.out.println("Удаляем их из очереди");
}
if (battle != null) {
battle.update();
//System.out.println("��������� ���");
//System.out.println("Обновляем бои");
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/model/EnergyPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ void draw(SpriteBatch batch) {
}
}

void toShip(float x, float y, float rotation)//������������� ���� � ������� �� ���������� ����������� ��������
{//�� ���� ���������� ���������� �������
void toShip(float x, float y, float rotation)//телепортирует тело к кораблю на расстояние нормального смещения
{//на вход передаются координаты корабля
energyModule.setTransform(x + localAnchor.x * (float) (Math.cos(Math.toRadians(rotation))) - localAnchor.y * (float) (Math.sin(Math.toRadians(rotation))),
y + localAnchor.y * (float) (Math.cos(Math.toRadians(rotation))) + localAnchor.x * (float) (Math.sin(Math.toRadians(rotation))), rotation);
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/model/EnginePoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ void draw(SpriteBatch batch) {
}
}

void toShip(float x, float y, float rotation)//������������� ���� � ������� �� ���������� ����������� ��������
{//�� ���� ���������� ���������� �������
void toShip(float x, float y, float rotation)//телепортирует тело к кораблю на расстояние нормального смещения
{//на вход передаются координаты корабля
engine.setTransform(x + localAnchor.x * (float) (Math.cos(Math.toRadians(rotation))) - localAnchor.y * (float) (Math.sin(Math.toRadians(rotation))),
y + localAnchor.y * (float) (Math.cos(Math.toRadians(rotation))) + localAnchor.x * (float) (Math.sin(Math.toRadians(rotation))), rotation);
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/model/Modules/WeaponModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void create(World world) {
this.world = world;
}

public boolean shot(float l, Vector2 speedVector) //l - ��� ���������� �� ������ ����� �� ����� �������
public boolean shot(float l, Vector2 speedVector) //l - это расстояние от центра пушки до конца корабля
{
return false;
}
Expand Down
16 changes: 8 additions & 8 deletions core/src/model/PhysicShip.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class PhysicShip extends PhysicObject {
private int movementPosition;
private float rotationSpeed;
private float targetRotation;
private float linearDamping;//�� ���� 0.01
private int rotationDirection;//-1-����� 1-������ 0-��� ��������
private float linearDamping;//не ниже 0.01
private int rotationDirection;//-1-влево 1-вправо 0-без вращения
//private float enginePower;
private WeaponPoint[] weapons;
private EnginePoint[] engines;
Expand Down Expand Up @@ -202,11 +202,11 @@ private void findRotDir() {

while (shipRotation >= 360) { //
shipRotation -= 360; //
} //������������ ��������� ���� ������� � ����� 0 �� 360
} //Установление градусной меры корабля в рамки 0 до 360
while (shipRotation <= 0) { //
shipRotation += 360; //
} //
int spriteRotation = (int) targetRotation; // �������� �������� �� ������ � ������� �������������� �� Int
int spriteRotation = (int) targetRotation; // Обрезаем значение до целого с помощью преобразование до Int
while (spriteRotation >= 360) {
spriteRotation -= 360;
}
Expand All @@ -215,8 +215,8 @@ private void findRotDir() {
}
//shipRotation=(Math.toDegrees(ship.getRotation())>360)?(float)Math.toDegrees(ship.getRotation())-360:(float)Math.toDegrees(ship.getRotation());
//spriteRotation=(sprite.getRotation()>360)?sprite.getRotation()-360:sprite.getRotation();
int internalArc = Math.abs(shipRotation - spriteRotation); //������� ������� � ��������� ��������� � �������� �����
int externalArc = 360 - internalArc; // ����� ������� � ��������
int internalArc = Math.abs(shipRotation - spriteRotation); //Находим внешнее и внутренне растояние в градусах между
int externalArc = 360 - internalArc; // фазой корабля и штурвала
/*if(internalArc<externalArc)
{
ship.setRotationDirection(1);
Expand All @@ -226,7 +226,7 @@ else if(internalArc>externalArc)
ship.setRotationDirection(-1);
}
else ship.setRotationDirection(0);*/
int tempShip = (shipRotation < 180) ? shipRotation + 360 : shipRotation;// ����������� �������� ��������� ���������� �� 360 ��� ���� ����� �������� �������� ��� ��������� �������� ����� 0
int tempShip = (shipRotation < 180) ? shipRotation + 360 : shipRotation;// Увеличиваем половину градусной окружности на 360 для того чтобы избежать проблемы при вычитании перехода через 0
int tempSprite = (spriteRotation < 180) ? spriteRotation + 360 : spriteRotation;

if (Math.abs(tempShip - tempSprite) > rotationSpeed) {
Expand Down Expand Up @@ -458,7 +458,7 @@ public static PhysicShip fromServ(ServShip servShip) {
} else if (servShip.getName().equals("StarFighter")) {
ship = new StarFighter(servShip.getX(), servShip.getY(), servShip.getRotation());
} else {
System.out.println("������� � ������ ������ �� ����������");
System.out.println("Корабль с данным именем не существует");
return null;
}

Expand Down
12 changes: 6 additions & 6 deletions core/src/model/WeaponPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public WeaponPoint(World world) {
public WeaponPoint(WeaponModule weapon, Vector2 localAnchor) {

this.weapon = weapon;
weapon.setTransform(weapon.getX() + localAnchor.x, weapon.getY() + localAnchor.y, (float) Math.toDegrees(weapon.getAngle()));//������� ���������� ���� �� ������� ��������� ����� ��� ���������
//������� ����� ���������, ��� ��� �������� ������ ������� �� �������� ���� ��� ����������
weapon.setTransform(weapon.getX() + localAnchor.x, weapon.getY() + localAnchor.y, (float) Math.toDegrees(weapon.getAngle()));//смещаем координату тела до нужного положения перед его созданием
//следует также учитывать, что при создании любого корабля мы передаем телу его координаты
this.localAnchor = localAnchor;
jointDef = new WeldJointDef();
jointDef.bodyA = shipBody; //_______________________________WATCH A MISTAKE______________________
Expand All @@ -45,12 +45,12 @@ public WeaponPoint(WeaponModule weapon, Vector2 localAnchor) {
public boolean installModule(WeaponModule weapon, Body shipBody, Vector2 localAnchor) {
if (weapon.getType().equals(ModuleType.Weapon)) {
this.weapon = weapon;
weapon.setTransform(weapon.getX() + localAnchor.x, weapon.getY() + localAnchor.y, (float) Math.toDegrees(weapon.getAngle()));//������� ���������� ���� �� ������� ��������� ����� ��� ���������
weapon.setTransform(weapon.getX() + localAnchor.x, weapon.getY() + localAnchor.y, (float) Math.toDegrees(weapon.getAngle()));//смещаем координату тела до нужного положения перед его созданием
this.localAnchor = localAnchor;
jointDef = new WeldJointDef();
jointDef.bodyA = shipBody;
jointDef.bodyB = weapon.getBody();
jointDef.localAnchorA.set(localAnchor.x, localAnchor.y);//��������� ���������� ����� ������� � �������� ����������� ����
jointDef.localAnchorA.set(localAnchor.x, localAnchor.y);//указываем координату точки корабля к которому прекрепляем тело
jointDef.collideConnected = false;
joint = world.createJoint(jointDef);

Expand Down Expand Up @@ -90,8 +90,8 @@ void destroy() {
weapon.destroy();
}

void toShip(float x, float y, float rotation)//������������� ���� � ������� �� ���������� ����������� ��������
{//�� ���� ���������� ���������� �������
void toShip(float x, float y, float rotation)//телепортирует тело к кораблю на расстояние нормального смещения
{//на вход передаются координаты корабля
weapon.setTransform(x + localAnchor.x * (float) (Math.cos(Math.toRadians(rotation))) - localAnchor.y * (float) (Math.sin(Math.toRadians(rotation))),
y + localAnchor.y * (float) (Math.cos(Math.toRadians(rotation))) + localAnchor.x * (float) (Math.sin(Math.toRadians(rotation))), rotation);
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/requests/PlayerActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class PlayerActions {
private int shipID;
private int movementPosition;
private float targetRotation;
private long time;//����� �������� �������
private long time;//время создания запроса

public PlayerActions() {
time = System.currentTimeMillis();
Expand Down