diff --git a/android/src/com/aqwsxlostfly/packandgo/client/AndroidLauncher.java b/android/src/com/aqwsxlostfly/packandgo/client/AndroidLauncher.java
index bfdc3fd..7413d9b 100644
--- a/android/src/com/aqwsxlostfly/packandgo/client/AndroidLauncher.java
+++ b/android/src/com/aqwsxlostfly/packandgo/client/AndroidLauncher.java
@@ -80,7 +80,7 @@ private WebSocketListener getWebsocketListener(EventListenerCallback callback) {
WebSocketListener webSocketListener = new WebSocketListener() {
@Override
public void onMessageReceived(String message) {
- Gdx.app.log("MESSAGE RECEIVED", "MESSAGE: " + message);
+// Gdx.app.log("MESSAGE RECEIVED", "MESSAGE: " + message);
WsEvent wsEvent = new WsEvent();
wsEvent.setData(message);
callback.onEvent(wsEvent);
diff --git a/android/src/com/aqwsxlostfly/packandgo/client/MessageProcessor.java b/android/src/com/aqwsxlostfly/packandgo/client/MessageProcessor.java
index effff1e..e6c8797 100644
--- a/android/src/com/aqwsxlostfly/packandgo/client/MessageProcessor.java
+++ b/android/src/com/aqwsxlostfly/packandgo/client/MessageProcessor.java
@@ -16,7 +16,7 @@ public MessageProcessor(Main main) {
public void processEvent(WsEvent event) {
String data = event.getData();
- Gdx.app.log("PROCESSED EVENT", data);
+// Gdx.app.log("PROCESSED EVENT", data);
if (data != null) {
JsonReader jsonReader = new JsonReader();
@@ -65,7 +65,6 @@ private void processObject(JsonValue object) {
String id = object.getString("id");
float x = object.getFloat("x");
float y = object.getFloat("y");
- Gdx.app.log("CASE PLAYER MSGPROC", "id " + id + " x " +x + " y " + y );
main.renderer.getGameScreen().updatePlayerArray(id, x, y);
break;
diff --git a/assets/Map.tmx b/assets/Map.tmx
index 3f5295a..18d6802 100644
--- a/assets/Map.tmx
+++ b/assets/Map.tmx
@@ -25,10 +25,21 @@
- eJztmVlsVFUYxz+S0lJpCy6Jxg4z05Z2KLglaiguD+IuSNIWWXyagi8u4BYB8cm6RMFXoLhO4gJlirGFoPiksmgMLl1mphSNCyq4vKiJ+4O/6703cz1zOnPPnUtsEx9++b77nTPn+8+535x7v3Zoqrw1CMMwNIl811ocqZbk1diFcBVMBh/N4nyPFLHUH5UiYZCbKkk19if8pfgjTk7dmB+f75IctEnhpzZViehoj4t0QCcsjevneMmyphrbDE8pfsbJqRvz47PnSfY+yT1IcT9S504TsWiIiTRCU8y+7kfzAOyBvXE75jI/KtIGCyAJXbClRpJnJ0TOSeTn1UNE8bNOTt2YH3+hrT3p1s8uYhYXoPtCuChmXxfjGvReC9fBGljr6F+P9g2J/Lw09Cl+zsmpG/Pjq/XTPUXkEbgc3VfAlTH72o3rbDt6O6ATNsJD0EI8h/bRhD3nUQX3syOenC+S66VYfu0e/O3wNDwDz8Jz8Dy8AKlYYf0U02liW3zOzXhyvoaefo/+l/FfgR2wE3qtWoA09MHuWGH9nCr9WxtFtkEPbG/Mx7MBc+5H+5ux8etHtU9QE0/CJtgcNdf/C5p/hd/gd4/+XJl75rd+tqB5K2yDHh/6rfPfG1vWJLIcVsDKJn39B7F+6+db9uw7+B5+aCy9dlbRvw/Nr8MbsN+jP1Omfr/1cyM5b4JFsLip9NoZRf94drzfeYXzO45h484ZWKE5C/3WTy+ad0Ea+nzoHylTv2vPQ/P5Rc5wv/VTPVvkNJgONbPN6z/o/i/AXlZk//3Wj6lV6z/o/od1/phav/Uf9Pw3rR9T67f+yz3/T1X9+K3/cs9/tX5Yz7r31n21NEgY191T8ji1Fdr6av2U6nc+dfoqkx5J3bNi663hfXVtQr/e3cTvSRTvv3Q9zvX0KzfEbf8Tp68y6ZFU/d4xdz03xwfo+zBhjy3iejHcDEvgI+IfJ+zPu/PV+tH1ODuYtzNu+8eYq/ZCvXN4tkEa+uYUft46I714x9z13BzesTTXfbAbXo3/O6c7X62fLO9mORiN5nucIfzhqO2PMVfthapbebbBdKhpLeyR1P33junWOzRX5PDcwp5LF1fr5zg6v4Kvo/l8n+F/7lwfZa6q53Y03wF3wl2tZmeIbr3medyneYXzdXHT59eoJl85tkUTfwyNj2v06+Jq/Yyxz8ec93tdz6TLF6b+rgaRVbAabmsoHVfr5wTaTzr6dT1T2Pqzyv18G23vwAE42FA6Xqx+dD1TJuT6KXe9Yu8/up5pJGT95a7n1g/fQY5U//N3UStmfS8J03dRnwXesSDrozllabcYdhj0XIflu6j6h0PKO79CpK3CzJrQNs46D/A8WgcP8l6wEfp5fgzAHtjbmo+X0vMuvGdog+hX18mgPQtH0TgGp+OfAWfCWZ54KT1B9n8i2SD7P5Hsf71/fm17s0hH8+Td/360DzRP3v3/v/4npu2qDM4qWK34h+tFLq4VuQQurTX33683y/9jGfwEPyu+pf8AOg7CoVpz39Jvkv/hquB0W39jsP5HHOFsg86Irb+zTmQp3FJn7lv6TfJ/w2dOwMm64P4X6P4SjkfCqR+T3OtmiKyHDTOC+/fOErkP7p8VTv2Y5K6cKVIF02aG44dRPyb5wqgfr7+MGloOK2BlAP/WiFm+vwFEpZ5j
-
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -43,7 +54,6 @@
- eJztl0lOw0AQRStKAiwY9sACRUoOQhg2EO7AeBBYAScBEiTGezDeBVjwLWzRarpdXbJD3FY96UnVrXT5x3JiFZFSBT6miD7hV6q59tWuPbtXwnaHaNAJy3HTJLqFd/AePsDHJn/udJroDJ6nmmtf7dqzeyUMkX0UmH+1RdSHa3AdbsDNFn9ucYZoCS6nmmtf7dqze211cf/hAO50+RxPyPoMX+ArfIPvAfkvcK1LeJVqrn21a+9PL2QewhG8Dsi/2ybag/vwAB7CozZ/LuO48avks+YZs57tEc3BebjQc/c5afyY19d1naoQe34J0vyxf2/NX16GImf/K3/Zv9lJ58/2yuw3Tur2f6koCo90rgqpJdcs2ls6V4XUHNJ+eb2lc1VIzSHtl9dbOleF1BzSfnm9sxnCnCPstU3Z70lfj1jewUXmLu5ejxtulq57/qoQS9b+yqQTKDGTPD8hVpXY8ytxEfvzFHt+RVEURakT3zUj56E=
@@ -76,7 +86,7 @@
-
+
diff --git a/core/src/com/aqwsxlostfly/packandgo/Heroes/Bullet.java b/core/src/com/aqwsxlostfly/packandgo/Heroes/Bullet.java
deleted file mode 100644
index 30c7fdf..0000000
--- a/core/src/com/aqwsxlostfly/packandgo/Heroes/Bullet.java
+++ /dev/null
@@ -1,32 +0,0 @@
-//package com.aqwsxlostfly.packandgo.Heroes;
-//
-//
-//import com.aqwsxlostfly.packandgo.Main;
-//import com.aqwsxlostfly.packandgo.Tools.Point2D;
-//import com.badlogic.gdx.graphics.Texture;
-//import com.badlogic.gdx.graphics.g2d.SpriteBatch;
-//
-//public class Bullet extends Heroes {
-// public boolean isOut;
-//
-//
-// public Bullet(Texture img, Point2D position, float speed, float radius, Point2D direction) {
-// super(img, position, speed, radius);
-// this.direction = new Point2D(direction);
-// }
-//
-// @Override
-// public void draw(SpriteBatch batch) {
-// batch.draw(img, position.getX() - radius, position.getY() - radius, radius * 2, radius * 2);
-//
-//
-// }
-//
-// @Override
-// public void update() {
-// isOut = (position.getX() - radius > Main.screenWidth) || (position.getX() + radius < 0)
-// || (position.getY() - radius > Main.screenHeight) || (position.getY() + radius < 0);
-// position.addCords(direction.getX() * speed, direction.getY() * speed);
-// bounds.centerPos.setPoint(position);
-// }
-//}
diff --git a/core/src/com/aqwsxlostfly/packandgo/Heroes/Enemy.java b/core/src/com/aqwsxlostfly/packandgo/Heroes/Enemy.java
deleted file mode 100644
index 699bf3c..0000000
--- a/core/src/com/aqwsxlostfly/packandgo/Heroes/Enemy.java
+++ /dev/null
@@ -1,69 +0,0 @@
-//package com.aqwsxlostfly.packandgo.Heroes;
-//
-//import com.aqwsxlostfly.packandgo.Main;
-//import com.aqwsxlostfly.packandgo.Tools.Circle;
-//import com.aqwsxlostfly.packandgo.Tools.Point2D;
-//import com.badlogic.gdx.graphics.Texture;
-//import com.badlogic.gdx.graphics.g2d.SpriteBatch;
-//
-//public class Enemy extends Heroes {
-// private int health;
-// private int score;
-// private int rank;
-//
-// public Enemy(Texture img, Point2D position, int rank) {
-// super(img, position);
-// switch (rank) {
-// case 1:
-// radius = (float) Main.screenWidth / 25;
-// speed = 10;
-// score = health = 10;
-// break;
-// case 2:
-// radius = (float) Main.screenWidth / 15;
-// speed = 4;
-// score = health = 20;
-// break;
-// case 3:
-// radius = (float) Main.screenWidth / 10;
-// speed = 2;
-// score = health = 30;
-// break;
-//// default:
-//// radius = (float) Main.screenWidth / 30;
-//// speed = 1;
-//// score = health = 10;
-//// break;
-// }
-// bounds = new Circle(position, radius);
-// direction.setX((float) Math.sin(Math.toRadians(Math.random()*360)));
-// direction.setY((float) Math.cos(Math.toRadians(Math.random()*360)));
-//
-//
-//
-// }
-//
-// @Override
-// public void draw(SpriteBatch batch) {
-// batch.draw(img,position.getX()-radius,position.getY()-radius,radius*2,radius*2);
-// }
-//
-// @Override
-// public void update() {
-// if(position.getX() + radius > Main.screenWidth) direction.setX(-direction.getX());
-// if(position.getX() - radius < 0) direction.setX(-direction.getX());
-// if(position.getY() + radius > Main.screenHeight) direction.setY(-direction.getY());;
-// if(position.getY() - radius < 0) direction.setY(-direction.getY());;
-//
-// position.addCords(direction.getX()*speed,direction.getY()*speed);
-// bounds.centerPos.setPoint(position);
-//
-// }
-// public void hit(){
-// health--;
-// }
-//
-// public int getHealth(){
-// return health;
-// }
-//}
diff --git a/core/src/com/aqwsxlostfly/packandgo/Heroes/Player.java b/core/src/com/aqwsxlostfly/packandgo/Heroes/Player.java
index c2d3ff5..5b10c9a 100644
--- a/core/src/com/aqwsxlostfly/packandgo/Heroes/Player.java
+++ b/core/src/com/aqwsxlostfly/packandgo/Heroes/Player.java
@@ -1,203 +1,37 @@
package com.aqwsxlostfly.packandgo.Heroes;
-import static com.aqwsxlostfly.packandgo.Tools.TileMapHelper.collisionLayer;
import static com.aqwsxlostfly.packandgo.Tools.TileMapHelper.worldHeight;
import static com.aqwsxlostfly.packandgo.Tools.TileMapHelper.worldWigth;
-import com.aqwsxlostfly.packandgo.Tools.TileMapHelper;
-import com.badlogic.gdx.Gdx;
-import com.badlogic.gdx.graphics.Color;
-import com.badlogic.gdx.graphics.g2d.BitmapFont;
-import com.badlogic.gdx.graphics.g2d.GlyphLayout;
+import com.aqwsxlostfly.packandgo.Tools.Point2D;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
-import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
-import com.badlogic.gdx.maps.MapObject;
-import com.badlogic.gdx.maps.MapObjects;
import com.badlogic.gdx.maps.objects.TextureMapObject;
-import com.badlogic.gdx.maps.tiled.TiledMapTileLayer;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
-import com.badlogic.gdx.scenes.scene2d.ui.Label;
-import com.badlogic.gdx.scenes.scene2d.ui.Skin;
-import com.badlogic.gdx.utils.ObjectMap;
-
-import java.util.HashMap;
-import java.util.Objects;
public class Player extends Heroes {
- Label gameNameLabel;
-
-
-
- private float increment;
-
- public static boolean inPoint = false;
-
- Skin skin;
-
- private MapObject textT;
-
- private BitmapFont font;
- public String currentCheckpointLetter = "";
-
+ private static final float VELOCITY_SCALE = 70.0f;
public Player(Body body, TextureMapObject textureMapObject) {
-
super(body, textureMapObject);
+ }
-// skin = new Skin(Gdx.files.internal("skin/uiskin.json"));
-
-
+ public void setDirection(Point2D direction) {
+ this.direction = direction;
+ updateVelocity();
}
- public void setText(String text){
- gameNameLabel = new Label(text, skin);
+ private void updateVelocity() {
+ // Задаем линейную скорость в соответствии с направлением.
+ // Если есть стена, Box2D автоматически обработает коллизию и остановит движение в этом направлении.
+ Vector2 newDir = new Vector2(direction.getX()*VELOCITY_SCALE, direction.getY()*VELOCITY_SCALE);
+ body.setLinearVelocity(newDir);
}
@Override
public void update() {
-// float oldX = body.getPosition().x;
-// float oldY = body.getPosition().y;
-
- float newXDir = direction.getX()*body.getAngularVelocity();
- float newYDir = direction.getY()*body.getAngularVelocity();
-
- float newX = getX() + newXDir;
- float newY = getY() + newYDir;
-
-// float newX = oldX+newXDir;
-// float newY = oldY+newYDir;
-//
-// if (newX <= 0){
-// newX = 0;
-// }
-// if (newY <= 0) {
-// newY = 0;
-// }
-// if (newX >= worldWigth) {
-// newX = oldX;
-// }
-// if (newY >= worldHeight) {
-// newY = oldY;
-// }
-
- Vector2 velocity = new Vector2(newXDir, newYDir);
-
- // save old position
- float oldX = body.getPosition().x, oldY = body.getPosition().y;
- boolean collisionX = false, collisionY = false;
-
- // calculate the increment for step in #collidesLeft() and #collidesRight()
- increment = collisionLayer.getTileWidth();
- increment = getWidth() < increment ? getWidth() / 2 : increment / 2;
-
-// Gdx.app.log("VELOCITY", "vlx " + newXDir + " vly " + newYDir);
-
- boolean isBlock = false;
-
- if (collisionLayer.getCell((int)newX,(int)newY)!= null){
- isBlock = collisionLayer.getCell((int)newX,(int)newY).getTile().getProperties().containsKey("blocked");
- }
-
-// Gdx.app.log("COLLIDE BLOCK", "playerPosX " + body.getPosition().x + " vly " + body.getPosition().y
-// + " " + isBlock
-// );
-
- if(velocity.x < 0) // going left
- collisionX = collidesLeft();
- else if(velocity.x > 0) // going right
- collisionX = collidesRight();
-
- // react to x collision
- if(collisionX) {
- newX = oldX;
- velocity.x = 0;
- }
-
- // move on y
-// setY(getY() + velocity.y * delta * 5f);
-
- // calculate the increment for step in #collidesBottom() and #collidesTop()
- increment = collisionLayer.getTileHeight();
- increment = getHeight() < increment ? getHeight() / 2 : increment / 2;
-
- boolean canJump;
- if(velocity.y < 0) // going down
- canJump = collisionY = collidesBottom();
- else if(velocity.y > 0) // going up
- collisionY = collidesTop();
-
- // react to y collision
- if(collisionY) {
- newY = oldY;
- velocity.y = 0;
- }
-
-
- if (newX <= 0){
- newX = 0;
- }
- if (newY <= 0) {
- newY = 0;
- }
- if (newX >= worldWigth) {
- newX = oldX;
- }
- if (newY >= worldHeight) {
- newY = oldY;
- }
-// Gdx.app.log("VELOCITY", "vlx " + newX + " vly " + newY);
-// if (newX >= 593) {
-// if ((newY >= 663) && (newY <= 769)) {
-// flag
-// newX = oldX;
-// newY = oldY;
-// }
-// }
-
- ObjectMap hashMap = TileMapHelper.walls;
- inPoint = false; // Чтобы текст обновился только один раз при входе в точку
-
- for(MapObject taskPoint: hashMap.values()){
-
-// if (Objects.equals(taskPoint.getName(), "text")){
-// textT = taskPoint;
-// }
-
- float objXleft = (float) taskPoint.getProperties().get("x");
- float objXright = (float) taskPoint.getProperties().get("x") + (float) taskPoint.getProperties().get("width");
-
- float objYbottom = (float) taskPoint.getProperties().get("y") + (float) taskPoint.getProperties().get("height");
- float objYtop = (float) taskPoint.getProperties().get("y");
-
-
-// Gdx.app.log("CHECK COLLISIN", "pX " + newX + " pY " + newY + " oX " +
-//
-// objXleft + ' ' + objXright + " oY " + objYtop + ' ' + objYbottom + " " + taskPoint.getName());
-
-
- if(newX >= objXleft - 10 && newX <= objXright){
- if(newY >= objYtop && newY <= objYbottom){
- inPoint = true;
-
-// checkpoint.getLetter();
- newX = oldX;
- newY = oldY;
- }
- }
-
-
-
-
- }
-
-
-
-
- body.setTransform(new Vector2(newX, newY), direction.getX()*10f + direction.getY()*10f);
-
}
public void testUpdate(float newX, float newY){
@@ -208,49 +42,6 @@ public void setAngle(float angle){
body.setTransform(getX(), getY(), angle);
}
- private boolean isCellBlocked(float x, float y) {
- TiledMapTileLayer.Cell cell = collisionLayer.getCell((int) (x / collisionLayer.getTileWidth()), (int) (y / collisionLayer.getTileHeight()));
- String blockedKey = "blocked";
- return cell != null && cell.getTile() != null && cell.getTile().getProperties().containsKey(blockedKey);
- }
-
- public boolean collidesRight() {
- for(float step = 0; step <= getHeight(); step += increment)
- if(isCellBlocked(getX() + getWidth(), getY() + step))
- return true;
- return false;
- }
-
- public boolean collidesLeft() {
- for(float step = 0; step <= getHeight(); step += increment)
- if(isCellBlocked(getX(), getY() + step))
- return true;
- return false;
- }
-
- public boolean collidesTop() {
- for(float step = 0; step <= getWidth(); step += increment)
- if(isCellBlocked(getX() + step, getY() + getHeight()))
- return true;
- return false;
-
- }
-
- public boolean collidesBottom() {
- for(float step = 0; step <= getWidth(); step += increment)
- if(isCellBlocked(getX() + step, getY()))
- return true;
- return false;
- }
-
- public boolean isInPoint() {
- return inPoint;
- }
-
- public void setInPoint(boolean inPoint) {
- this.inPoint = inPoint;
- }
-
public float getX(){
return body.getPosition().x;
}
@@ -275,18 +66,11 @@ public float getHeight(){
@Override
public void draw(SpriteBatch batch) {
-// batch.begin();
batch.draw(textureRegion,
- body.getPosition().x, body.getPosition().y,
+ body.getPosition().x-textureRegion.getRegionWidth()/ 2.0f, body.getPosition().y-textureRegion.getRegionHeight() / 2.0f,
textureRegion.getRegionWidth() / 2.0f, textureRegion.getRegionHeight() / 2.0f,
textureRegion.getRegionWidth(), textureRegion.getRegionHeight(),
- textureMapObject.getScaleX(),textureMapObject.getScaleY(), body.getAngle());
-
-// batch.end();
-// batch.begin();
-
-
-// batch.end();
+ textureMapObject.getScaleX(),textureMapObject.getScaleY(), 0);
}
}
diff --git a/core/src/com/aqwsxlostfly/packandgo/Main.java b/core/src/com/aqwsxlostfly/packandgo/Main.java
index 4a43eca..5da0f63 100644
--- a/core/src/com/aqwsxlostfly/packandgo/Main.java
+++ b/core/src/com/aqwsxlostfly/packandgo/Main.java
@@ -47,17 +47,11 @@ public Main(InputState inputState) {
@Override
public void create() {
-
-// batch = new SpriteBatch();
-// img = new Texture("packlogo.png");
-// circle = new Texture("circle.png");
-
screenWidth = Gdx.graphics.getWidth();
screenHeight = Gdx.graphics.getHeight();
-// this.waitingSc = new WaitingSc(this);
+
renderer = new Renderer();
renderer.setHomeScreen(new HomeSc(this));
-// setScreen(new WaitingSc(this));
}
@Override
@@ -71,10 +65,6 @@ public void evict(String idToEvict) {
PlayScreen.players.remove(idToEvict);
}
-// public void handleTimer() {
-// this.waitingSc.handleTimer();
-// }
-
@Override
public void dispose() {
diff --git a/core/src/com/aqwsxlostfly/packandgo/Screens/DeadInside.java b/core/src/com/aqwsxlostfly/packandgo/Screens/DeadInside.java
deleted file mode 100644
index 52f9e0a..0000000
--- a/core/src/com/aqwsxlostfly/packandgo/Screens/DeadInside.java
+++ /dev/null
@@ -1,92 +0,0 @@
-//package com.aqwsxlostfly.packandgo.Screens;
-//
-//import com.aqwsxlostfly.packandgo.Main;
-//import com.badlogic.gdx.Gdx;
-//import com.badlogic.gdx.Screen;
-//import com.badlogic.gdx.graphics.Color;
-//import com.badlogic.gdx.graphics.GL20;
-//import com.badlogic.gdx.graphics.g2d.BitmapFont;
-//import com.badlogic.gdx.graphics.g2d.GlyphLayout;
-//import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
-//
-//public class DeadInside implements Screen {
-// Main main;
-// BitmapFont font;
-// GlyphLayout gl;
-// GlyphLayout gl2;
-// GlyphLayout gl3;
-//
-// public DeadInside(Main main, String score) {
-// this.main = main;
-// FreeTypeFontGenerator gen = new FreeTypeFontGenerator((Gdx.files.internal(("font.ttf"))));
-// FreeTypeFontGenerator.FreeTypeFontParameter p = new FreeTypeFontGenerator.FreeTypeFontParameter();
-// p.size = Main.screenWidth / 10;
-// p.color = new Color(Color.RED);
-// font = gen.generateFont(p);
-// gl = new GlyphLayout();
-// gl.setText(font, score);
-// gl2 = new GlyphLayout();
-// gl3 = new GlyphLayout();
-// gl3.setText(font, "Tap to begin");
-// String info;
-// if (Integer.parseInt(score) > Main.record) {
-// info = "New record";
-// Main.write(score);
-// Main.record = Integer.parseInt(score);
-//
-// } else {
-// info = "Record: " + Main.record;
-// }
-// gl2.setText(font, info);
-//
-// }
-//
-// @Override
-// public void show() {
-//
-// }
-//
-// @Override
-// public void render(float delta) {
-// Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
-// update();
-// main.batch.begin();
-// font.draw(main.batch, gl, Main.screenWidth / 2 - gl.width / 2, Main.screenHeight / 2);
-// font.draw(main.batch, gl2, Main.screenWidth / 2 - gl2.width / 2, (Main.screenHeight / 2 - gl.height));
-// font.draw(main.batch, gl3, Main.screenWidth / 2 - gl3.width / 2, Main.screenHeight);
-// main.batch.end();
-//
-//
-// }
-//
-// @Override
-// public void resize(int width, int height) {
-//
-// }
-//
-// @Override
-// public void pause() {
-//
-// }
-//
-// @Override
-// public void resume() {
-//
-// }
-//
-// @Override
-// public void hide() {
-//
-// }
-//
-// @Override
-// public void dispose() {
-//
-// }
-//
-// public void update() {
-// if (Gdx.input.justTouched()) {
-// main.setScreen(new GameSc(main));
-// }
-// }
-//}
diff --git a/core/src/com/aqwsxlostfly/packandgo/Screens/GameSc.java b/core/src/com/aqwsxlostfly/packandgo/Screens/GameSc.java
deleted file mode 100644
index 8e69f51..0000000
--- a/core/src/com/aqwsxlostfly/packandgo/Screens/GameSc.java
+++ /dev/null
@@ -1,209 +0,0 @@
-//package com.aqwsxlostfly.packandgo.Screens;
-//
-//import com.aqwsxlostfly.packandgo.Heroes.Bullet;
-//import com.aqwsxlostfly.packandgo.Heroes.Enemy;
-//import com.aqwsxlostfly.packandgo.Heroes.Player;
-//import com.aqwsxlostfly.packandgo.Main;
-//import com.aqwsxlostfly.packandgo.Tools.BulletGenerator;
-//import com.aqwsxlostfly.packandgo.Tools.GameHud;
-//import com.aqwsxlostfly.packandgo.Tools.Joystick;
-//import com.aqwsxlostfly.packandgo.Tools.Point2D;
-//import com.aqwsxlostfly.packandgo.Tools.Wave;
-//import com.badlogic.gdx.Gdx;
-//import com.badlogic.gdx.InputProcessor;
-//import com.badlogic.gdx.Screen;
-//import com.badlogic.gdx.graphics.GL20;
-//import com.badlogic.gdx.graphics.g2d.SpriteBatch;
-//import com.badlogic.gdx.utils.ScreenUtils;
-//
-//import java.util.ArrayList;
-//
-//public class GameSc implements Screen {
-//
-//
-// Main main;
-// Joystick joy;
-// Joystick joyBullet;
-// public static Player player;
-// public static ArrayList bullets;
-// public static ArrayList enemies;
-// public static ArrayList players;
-// public static Wave wave;
-//
-//
-// public static BulletGenerator bulletGenerator;
-// public static GameHud hud;
-//
-// public GameSc(Main main){
-// this.main = main;
-// }
-// @Override
-// public void show() {
-// Gdx.input.setInputProcessor(new InputProcessor() {
-// @Override
-// public boolean keyDown(int keycode) {
-// return false;
-// }
-//
-// @Override
-// public boolean keyUp(int keycode) {
-// return false;
-// }
-//
-// @Override
-// public boolean keyTyped(char character) {
-// return false;
-// }
-//
-// @Override
-// public boolean touchDown(int screenX, int screenY, int pointer, int button) {
-// screenY = Main.screenHeight - screenY;
-// multitouch((int)screenX, (int)screenY, true, pointer);
-// return false;
-// }
-//
-// @Override
-// public boolean touchUp(int screenX, int screenY, int pointer, int button) {
-// screenY = Main.screenHeight - screenY;
-// multitouch((int)screenX, (int)screenY, false, pointer);
-// return false;
-// }
-//
-// @Override
-// public boolean touchCancelled(int screenX, int screenY, int pointer, int button) {
-// screenY = Main.screenHeight - screenY;
-// multitouch((int)screenX, (int)screenY, false, pointer);
-// return false;
-// }
-//
-// @Override
-// public boolean touchDragged(int screenX, int screenY, int pointer) {
-// screenY = Main.screenHeight - screenY;
-// multitouch((int)screenX, (int)screenY, true, pointer);
-// return false;
-// }
-//
-// @Override
-// public boolean mouseMoved(int screenX, int screenY) {
-// return false;
-// }
-//
-// @Override
-// public boolean scrolled(float amountX, float amountY) {
-// return false;
-// }
-// });
-//
-// loadHeroes();
-// }
-//
-// @Override
-// public void render(float delta) {
-// Gdx.gl.glClearColor(0,1,0,1);
-// Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
-// gameUpdate();
-// Main.batch.begin();
-// gameRender(Main.batch);
-// Main.batch.end();
-// }
-//
-// @Override
-// public void resize(int width, int height) {
-//
-// }
-//
-// @Override
-// public void pause() {
-//
-// }
-//
-// @Override
-// public void resume() {
-//
-// }
-//
-// @Override
-// public void hide() {
-//
-// }
-//
-// @Override
-// public void dispose() {
-//
-// }
-//
-// public void loadHeroes(){
-// joy = new Joystick(Main.circle, Main.capibara, new Point2D(((Main.screenHeight/3)/2+(Main.screenHeight/3)/4), (Main.screenHeight/3)/2+(Main.screenHeight/3)/4), Main.screenHeight/3);
-// joyBullet = new Joystick(Main.circle, Main.capibara, new Point2D(Main.screenWidth-((Main.screenHeight/3)/2+(Main.screenHeight/3)/4), (Main.screenHeight/3)/2+(Main.screenHeight/3)/4), Main.screenHeight/3);
-// player = new Player(Main.capibara, new Point2D(Main.screenWidth/2, Main.screenHeight/2), 10F, (float) (Main.screenHeight/5), 5);
-//
-// bullets = new ArrayList();
-// enemies = new ArrayList();
-// wave = new Wave(4,1,5);
-// bulletGenerator= new BulletGenerator();
-// hud = new GameHud();
-//
-// }
-//
-// public void multitouch(float x, float y, boolean isDownTouch, int pointer){
-// for(int i =0; i < 3; i++){
-// joy.update(x,y,isDownTouch, pointer);
-// joyBullet.update(x,y,isDownTouch, pointer);
-// }
-// }
-//
-// public void collision(){
-// for (int i=0;i= 0; i--) {
-// bullets.get(i).draw(batch);
-// }
-// for (int i = enemies.size() - 1; i >= 0; i--) {
-// enemies.get(i).draw(batch);
-// }
-// if (wave.isDraw())wave.draw(batch);
-// hud.draw(batch);
-// }
-//
-//}
diff --git a/core/src/com/aqwsxlostfly/packandgo/Screens/HomeSc.java b/core/src/com/aqwsxlostfly/packandgo/Screens/HomeSc.java
index 5125853..f575751 100644
--- a/core/src/com/aqwsxlostfly/packandgo/Screens/HomeSc.java
+++ b/core/src/com/aqwsxlostfly/packandgo/Screens/HomeSc.java
@@ -41,9 +41,6 @@ public class HomeSc implements Screen {
Stage stage;
Skin skin;
- private BitmapFont font;
- private String currentCheckpointLetter = "";
-
Texture backgroundTexture;
Label gameNameLabel;
TextButton createRoomBtn;
@@ -100,11 +97,17 @@ public HomeSc(Main main) {
private Texture getRandomTexture() {
int rand = MathUtils.random(0, 4);
switch (rand) {
- case 0: return chairTexture;
- case 1: return bathTexture;
- case 2: return wardrobeTexture;
- case 3: return tableTexture;
- case 4: default: return lampTexture;
+ case 0:
+ return chairTexture;
+ case 1:
+ return bathTexture;
+ case 2:
+ return wardrobeTexture;
+ case 3:
+ return tableTexture;
+ case 4:
+ default:
+ return lampTexture;
}
}
@@ -266,59 +269,24 @@ private void connectToServer(String password, String roomId, boolean isCreating)
if (isCreating) {
Gdx.app.log("CREATE ROOM", "Creating a room with ID: " + roomId + " and password: " + password);
SessionState sessionState = new SessionStateToSend("createRoom", roomId, password);
- setGameScreen(new PlayScreen());
- main.messageSender.sendMessage(sessionState);
+ try {
+ main.messageSender.sendMessage(sessionState);
+ setGameScreen(new PlayScreen());
+ } catch (Exception e) {
+ Gdx.app.log("ERROR CREATE", "createState " + main.gameSession.getSessionMsg());
+ }
} else {
Gdx.app.log("JOIN ROOM", "Joining a room with ID: " + roomId + " and password: " + password);
SessionState sessionState = new SessionStateToSend("joinRoom", roomId, password);
- setGameScreen(new PlayScreen());
- main.messageSender.sendMessage(sessionState);
+ try {
+ main.messageSender.sendMessage(sessionState);
+ setGameScreen(new PlayScreen());
+ } catch (Exception e) {
+ Gdx.app.log("ERROR JOIN", "joinState " + main.gameSession.getSessionMsg());
+ }
}
}
-// @Override
-// public void render(float delta) {
-// Gdx.gl.glClearColor(0, 0, 0, 1);
-// Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
-//
-// Main.batch.begin();
-// Main.batch.draw(backgroundTexture, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
-// Main.batch.end();
-//
-// showState();
-//
-// stage.act(Math.min(delta, 1 / 30f));
-// stage.draw();
-// }
-
- public void showState(){
- Gdx.app.log("SESSION_STATE", main.gameSession.getId() + " " + main.gameSession.getPassword() + " " +
- main.gameSession.getSessionMsg() +" " + main.gameSession.getConnected() );
- }
-
-// @Override
-// public void show() {
-// }
-//
-// @Override
-// public void resize(int width, int height) {
-// stage.getViewport().update(width, height, true);
-// }
-//
-// @Override
-// public void pause() {
-//
-// }
-
-// @Override
-// public void resume() {
-//
-// }
-//
-// @Override
-// public void hide() {
-//
-// }
@Override
public void render(SpriteBatch batch, OrthographicCamera camera) {
@@ -330,7 +298,7 @@ public void render(SpriteBatch batch, OrthographicCamera camera) {
batch.draw(backgroundTexture, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
batch.end();
- showState();
+// showState();
stage.act(Math.min(1 / 30F, 1 / 30f));
stage.draw();
diff --git a/core/src/com/aqwsxlostfly/packandgo/Screens/PlayScreen.java b/core/src/com/aqwsxlostfly/packandgo/Screens/PlayScreen.java
index c30d08f..11bff39 100644
--- a/core/src/com/aqwsxlostfly/packandgo/Screens/PlayScreen.java
+++ b/core/src/com/aqwsxlostfly/packandgo/Screens/PlayScreen.java
@@ -5,6 +5,7 @@
import static com.aqwsxlostfly.packandgo.Main.messageSender;
import static com.aqwsxlostfly.packandgo.Main.screenHeight;
import static com.aqwsxlostfly.packandgo.Main.screenWidth;
+import static com.aqwsxlostfly.packandgo.Tools.TileMapHelper.world;
import com.aqwsxlostfly.packandgo.Heroes.Player;
import com.aqwsxlostfly.packandgo.InputState;
@@ -23,6 +24,7 @@
import com.badlogic.gdx.maps.MapObject;
import com.badlogic.gdx.maps.MapProperties;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
+import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.Timer;
@@ -39,16 +41,11 @@ public class PlayScreen implements Screen {
private static final float frameRate = 1/60f;
public GameHud gameHud;
-// public final Player player;
- private Player line;
public static ObjectMap players = new ObjectMap<>();
private final OrthogonalTiledMapRenderer orthogonalTiledMapRenderer;
private final OrthographicCamera hudCamera;
-
-
-
- public static int count;
+ private Box2DDebugRenderer box2DDebugRenderer = new Box2DDebugRenderer();
public PlayScreen() {
@@ -127,56 +124,35 @@ public boolean scrolled(float amountX, float amountY) {
public void updatePlayerArray(String id, float x_, float y_) {
- Gdx.app.log("updatePlayerArray", "id " + id + " x " + x_ + " y " + y_ );
-
-// Player player = players.get(id);
if (players.get(id) == null) {
Gdx.app.log("ADD NEW PLAYER", "id " + id + " x " + x_ + " y " + y_ );
-// Main.players.put(id, new Player(Main.capibara, new Point2D(Main.screenWidth / 2, Main.screenHeight / 2), 10F, (float) (Main.screenHeight / 5), 5));
+
if (Objects.equals(id, meId)){
players.put(id, tileMapHelper.getPlayer());
- }else{
- players.put(id, tileMapHelper.getOtherPlayer());
}
} else if (!Objects.equals(id, meId)){
- Gdx.app.log("UPDATE GAME STATE ARRAY", "NEW MSG SERVER STATE" + "new x " + x_ + " new y " + y_ );
-// player.setDirection(new Point2D(x_, y_));
-// player.setScoreValue(score);
-// player.setHealth(health);
-// player.setGhost(ghost);
players.get(id).testUpdate(x_, y_);
}
}
-
-
-
-// public Player getPlayer(){
-// return player;
-// }
-
public void multitouch(float x, float y, boolean isDownTouch, int pointer) {
for (int i = 0; i < 3; i++) {
joy.update(x, y, isDownTouch, pointer);
}
}
- private int isActive = 0;
-
public void render(SpriteBatch batch, OrthographicCamera camera) {
updatePlayers();
cameraUpdate(camera);
+ world.step(1/60f, 6, 2);
+
orthogonalTiledMapRenderer.setView(camera); // Устанавливаем камеру для рендерера карты
orthogonalTiledMapRenderer.render(); // Рендерим карту
-// for (String key : players.keys()) {
-// players.get(key).draw(batch);
-// }
-
Array keys = new Array<>(players.keys().toArray());
for (String key : keys) {
players.get(key).draw(batch);
@@ -189,6 +165,9 @@ public void render(SpriteBatch batch, OrthographicCamera camera) {
joy.draw(batch); // Рисуем джойстик с использованием камеры HUD
gameHud.update(Math.min(1 / 30F, 1 / 30f));
gameHud.draw();
+
+ box2DDebugRenderer.render(world,camera.combined.scl(1));
+
}
public void updatePlayers(){
@@ -253,7 +232,7 @@ public void handleTimer() {
if (!players.isEmpty()) {
Player me = players.get(meId);
InputState playerState = updateAndGetInputState(me);
- Gdx.app.log("SEND MESSAGE", "HANDLE TIMER, send state");
+// Gdx.app.log("SEND MESSAGE", "HANDLE TIMER, send state");
messageSender.sendMessage(playerState);
}
}
diff --git a/core/src/com/aqwsxlostfly/packandgo/Screens/WaitingSc.java b/core/src/com/aqwsxlostfly/packandgo/Screens/WaitingSc.java
deleted file mode 100644
index b89f0a1..0000000
--- a/core/src/com/aqwsxlostfly/packandgo/Screens/WaitingSc.java
+++ /dev/null
@@ -1,169 +0,0 @@
-//package com.aqwsxlostfly.packandgo.Screens;
-//
-//import com.aqwsxlostfly.packandgo.Heroes.Bullet;
-//import com.aqwsxlostfly.packandgo.Heroes.Player;
-//import com.aqwsxlostfly.packandgo.InputState;
-//import com.aqwsxlostfly.packandgo.Main;
-//import com.aqwsxlostfly.packandgo.Tools.BulletGenerator;
-//import com.aqwsxlostfly.packandgo.Tools.Point2D;
-//import com.aqwsxlostfly.packandgo.TouchProcessor;
-//import com.badlogic.gdx.Gdx;
-//import com.badlogic.gdx.Screen;
-//import com.badlogic.gdx.graphics.Color;
-//import com.badlogic.gdx.graphics.GL20;
-//import com.badlogic.gdx.graphics.g2d.BitmapFont;
-//import com.badlogic.gdx.graphics.g2d.GlyphLayout;
-//import com.badlogic.gdx.graphics.g2d.SpriteBatch;
-//import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
-//import com.badlogic.gdx.utils.ObjectMap;
-//import com.badlogic.gdx.utils.Timer;
-//
-//import java.util.ArrayList;
-//import java.util.Objects;
-//
-//public class WaitingSc implements Screen {
-//
-// private TouchProcessor inputProcessor;
-// Main main;
-// public static ArrayList bullets;
-// public static ObjectMap players = new ObjectMap<>();
-//
-// BitmapFont font;
-// GlyphLayout textWaiting, textJoin, textErrorWsConnection;
-//// public static BulletGenerator bulletGenerator;
-//
-// public WaitingSc(Main main){
-// this.main = main;
-// FreeTypeFontGenerator gen = new FreeTypeFontGenerator((Gdx.files.internal(("font.ttf"))));
-// FreeTypeFontGenerator.FreeTypeFontParameter p = new FreeTypeFontGenerator.FreeTypeFontParameter();
-// p.size = Main.screenWidth / 30;
-// p.color = new Color(Color.RED);
-// font = gen.generateFont(p);
-// textWaiting = new GlyphLayout();
-// textWaiting.setText(font, "WAITING OTHER PLAYER");
-// textJoin = new GlyphLayout();
-// textJoin.setText(font, "PLAYER HAS JOINED");
-// textErrorWsConnection = new GlyphLayout();
-// textErrorWsConnection.setText(font, "NETWORK CONNECTION FAILED!");
-// this.inputProcessor = new TouchProcessor(main.inputState);
-// }
-// @Override
-// public void show() {
-// Gdx.input.setInputProcessor(inputProcessor);
-// loadHeroes();
-// }
-//
-// @Override
-// public void render(float delta) {
-// Gdx.gl.glClearColor(0, 1, 0, 1);
-// Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
-// gameUpdate();
-// Main.batch.begin();
-// gameRender(Main.batch);
-// Main.batch.end();
-// }
-// @Override
-// public void resize(int width, int height) {
-//
-// }
-//
-// @Override
-// public void pause() {
-//
-// }
-//
-// @Override
-// public void resume() {}
-//
-// @Override
-// public void hide() {
-//
-// }
-//
-// @Override
-// public void dispose() {
-// Main.batch.dispose();
-// for (Player value : Main.players.values()) {
-// value.dispose();
-// }
-// }
-//
-//
-// public void loadHeroes() {
-// Player me = new Player(Main.capibara, new Point2D(Main.screenWidth / 2, Main.screenHeight / 2), 10F, (float) (Main.screenHeight / 5), 5);
-// players.put(main.getMeId(), me);
-//// bullets = new ArrayList();
-//// bulletGenerator = new BulletGenerator();
-// Timer timer = new Timer();
-// timer.scheduleTask(new Timer.Task() {
-// @Override
-// public void run() {
-// handleTimer();
-// }
-// }, 0, 1 / 60f);
-// }
-//
-//
-// public void gameUpdate() {
-//// Color cl = Color.RED;
-//
-// players = Main.players;
-// for (String key : players.keys()) {
-// if(!Objects.equals(key, main.getMeId())){
-// players.get(key).update();
-// }else{
-// players.get(key).setDirection(inputProcessor.joy.getDir());
-// players.get(key).update();
-// }
-//
-// }
-//
-//// if (player == null) {
-//// String id = main.getMeId();
-//// player = new Player(Main.capibara, new Point2D(Main.screenWidth / 2, Main.screenHeight / 2), 10F, (float) (Main.screenHeight / 5), 5);
-//// Main.players.put(id, player);
-//// } else {
-//// player.setDirection(inputProcessor.joy.getDir());
-//// player.update();
-//// }
-//
-//// bulletGenerator.update(inputProcessor.joyBullet);
-//// for (int i = 0; i < bullets.size(); i++) {
-//// bullets.get(i).update();
-//// if (bullets.get(i).isOut) {
-//// bullets.remove(i--);
-//// }
-//// }
-// }
-//
-// public void gameRender(SpriteBatch batch) {
-//// if (!main.getSocketState()){
-//// font.draw(batch, textErrorWsConnection, Main.screenWidth / 2 - textErrorWsConnection.width / 2, Main.screenHeight -Main.screenHeight/10);
-//// } else
-// if (players.size < 2) {
-// font.draw(batch, textWaiting, Main.screenWidth / 2 - textWaiting.width / 2, Main.screenHeight -Main.screenHeight/10);
-// } else {
-// font.draw(batch, textJoin, Main.screenWidth / 2 - textWaiting.width / 2, Main.screenHeight -Main.screenHeight/10 );
-// }
-// for (String key : players.keys()) {
-//// Gdx.app.log("PLAYER", String.valueOf(Main.players.get(key).position));
-// players.get(key).draw(batch);
-// }
-// inputProcessor.joy.draw(batch);
-//// inputProcessor.joyBullet.draw(batch);
-//// for (int i = bullets.size() - 1; i >= 0; i--) {
-//// bullets.get(i).draw(batch);
-//// }
-// }
-//
-//// public void handleTimer() {
-//// if (inputProcessor != null && !players.isEmpty()) {
-//// Player me = players.get(main.getMeId());
-//// InputState playerState = inputProcessor.updateAndGetInputState(me);
-//// Gdx.app.log("SEND MESSAGE", "HANDLE TIMER, send state");
-//// main.messageSender.sendMessage(playerState);
-//// }
-//// }
-//
-//
-//}
diff --git a/core/src/com/aqwsxlostfly/packandgo/Tools/BodyHelperService.java b/core/src/com/aqwsxlostfly/packandgo/Tools/BodyHelperService.java
index f42f858..42ba6fd 100644
--- a/core/src/com/aqwsxlostfly/packandgo/Tools/BodyHelperService.java
+++ b/core/src/com/aqwsxlostfly/packandgo/Tools/BodyHelperService.java
@@ -1,6 +1,7 @@
package com.aqwsxlostfly.packandgo.Tools;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
+import com.badlogic.gdx.maps.objects.RectangleMapObject;
import com.badlogic.gdx.maps.objects.TextureMapObject;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
@@ -17,26 +18,29 @@ public static Body createBody(TextureMapObject textureObject, World world, boole
float width = textureRegion.getRegionWidth();
float height = textureRegion.getRegionHeight();
- float x = textureObject.getX() + width / 2;
+ float x = textureObject.getX() + width /2 ;
float y = textureObject.getY() + height / 2;
BodyDef bodyDef = new BodyDef();
- bodyDef.type = isStatic ? BodyDef.BodyType.StaticBody : BodyDef.BodyType.DynamicBody;
- bodyDef.position.set(x / 32.0f, y / 32.0f);
- bodyDef.angularVelocity = 4f;
+ bodyDef.type = BodyDef.BodyType.DynamicBody;
+ bodyDef.position.set(x / 16.0f, y / 16.0f);
+ bodyDef.angularVelocity = 0f;
bodyDef.fixedRotation = true;
Body body = world.createBody(bodyDef);
PolygonShape shape = new PolygonShape();
- shape.setAsBox(width / 2 / 32.0f, height / 2 / 32.0f);
+ shape.setAsBox(width / 2 , height / 2 );
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = shape;
+ fixtureDef.density = 1.0F;
+ fixtureDef.friction = 0.3f;
body.createFixture(fixtureDef);
shape.dispose();
+
return body;
}
}
\ No newline at end of file
diff --git a/core/src/com/aqwsxlostfly/packandgo/Tools/BulletGenerator.java b/core/src/com/aqwsxlostfly/packandgo/Tools/BulletGenerator.java
deleted file mode 100644
index dc84564..0000000
--- a/core/src/com/aqwsxlostfly/packandgo/Tools/BulletGenerator.java
+++ /dev/null
@@ -1,18 +0,0 @@
-//package com.aqwsxlostfly.packandgo.Tools;
-//
-//import com.aqwsxlostfly.packandgo.Heroes.Bullet;
-//import com.aqwsxlostfly.packandgo.Main;
-//import com.aqwsxlostfly.packandgo.Screens.GameSc;
-//import com.aqwsxlostfly.packandgo.Screens.WaitingSc;
-//
-//public class BulletGenerator {
-// boolean isFire;
-//
-// public void update(Joystick joy) {
-// isFire = joy.getDir().getX() != 0 || joy.getDir().getY() != 0;
-// if (isFire) WaitingSc.bullets.add(new Bullet(Main.bullet, Main.players.get(Main.meId).position,
-// 25, Main.players.get(Main.meId).radius / 8, joy.getDir()));
-//
-//
-// }
-//}
diff --git a/core/src/com/aqwsxlostfly/packandgo/Tools/TileMapHelper.java b/core/src/com/aqwsxlostfly/packandgo/Tools/TileMapHelper.java
index db263a4..d3ad7fa 100644
--- a/core/src/com/aqwsxlostfly/packandgo/Tools/TileMapHelper.java
+++ b/core/src/com/aqwsxlostfly/packandgo/Tools/TileMapHelper.java
@@ -13,13 +13,22 @@
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
+import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
+import com.badlogic.gdx.physics.box2d.BodyDef;
+import com.badlogic.gdx.physics.box2d.Contact;
+import com.badlogic.gdx.physics.box2d.ContactImpulse;
+import com.badlogic.gdx.physics.box2d.ContactListener;
+import com.badlogic.gdx.physics.box2d.Fixture;
+import com.badlogic.gdx.physics.box2d.FixtureDef;
+import com.badlogic.gdx.physics.box2d.Manifold;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.physics.box2d.Shape;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.utils.ObjectMap;
+import java.util.ArrayList;
import java.util.Objects;
public class TileMapHelper {
@@ -28,14 +37,35 @@ public class TileMapHelper {
public static int worldHeight;
public static int worldWigth;
private Player player;
- private Player tabouret;
-// private Body body;
-// private TextureMapObject textureMapObject;
- private final World world;
+ public static World world;
public TileMapHelper() {
- this.world = new World(new Vector2(0, 0), false);
+
+ TileMapHelper.world = new World(new Vector2(0, 0), false);
+
+ TileMapHelper.world.setContactListener(new ContactListener() {
+ @Override
+ public void beginContact(Contact contact) {
+ Fixture fixtureA = contact.getFixtureA();
+ Fixture fixtureB = contact.getFixtureB();
+
+ Gdx.app.log("Contact", "beginContact between " + fixtureA.getBody().getUserData() + " and " + fixtureB.getBody().getUserData());
+ }
+
+ @Override
+ public void endContact(Contact contact) {
+ // Обработка окончания контакта между двумя фикстурами.
+ }
+
+ @Override
+ public void preSolve(Contact contact, Manifold oldManifold) {
+ }
+
+ @Override
+ public void postSolve(Contact contact, ContactImpulse impulse) {
+ }
+ });
}
public static ObjectMap walls = new ObjectMap<>();
@@ -44,8 +74,8 @@ public TileMapHelper() {
public OrthogonalTiledMapRenderer setupMap() {
this.tiledMap = new TmxMapLoader().load("Map.tmx");
MapProperties properties = tiledMap.getProperties();
- worldHeight = properties.get("height", Integer.class) * 16 - 16;
- worldWigth = properties.get("width", Integer.class) * 16 - 16;
+ worldHeight = properties.get("height", Integer.class) * 16;
+ worldWigth = properties.get("width", Integer.class) * 16;
parseMapObjects(tiledMap.getLayers().get("hero").getObjects());
@@ -56,15 +86,19 @@ public OrthogonalTiledMapRenderer setupMap() {
// Gdx.app.log("CHECK LAYER", "id " + mapLayer.getName());
if (Objects.equals(mapLayer.getName(), "ground")){
+ MapObjects wallsObjs = new MapObjects();
+
for(MapObject mapObject : mapLayer.getObjects()){
- Gdx.app.log("CHECK OBJECT COUNT CLASS", "id " + mapObject.getName());
- if (mapObject.getName()!=null && Objects.equals(mapObject.getName(), "wall")) {
- walls.put( String.valueOf(mapObject.getProperties().get("id")), mapObject);
-// Gdx.app.log("CHECK OBJECT", "getX " + mapObject.getProperties().get("x"));
+ if (mapObject.getName()!=null && Objects.equals(mapObject.getName(), "wall")) {
+ walls.put( String.valueOf(mapObject.getProperties().get("id")), mapObject);
+ wallsObjs.add(mapObject);
}
}
+ createWalls(wallsObjs);
+ createMapBounds(worldWigth, worldHeight);
+
}
}
@@ -82,68 +116,91 @@ private void parseMapObjects(MapObjects mapObjects) {
if (textureMapObjectName != null && textureMapObjectName.equals("hero")) {
+
+
Body body = BodyHelperService.createBody(textureMapObject,
world, false);
body.setTransform(textureMapObject.getX(), textureMapObject.getY(), 0);
-// this.body = body;
-// this.textureMapObject = textureMapObject;
-
player = new Player(body, textureMapObject);
- TextureMapObject textureMapObject_t = ((TextureMapObject) mapObject);
- Body body_t = BodyHelperService.createBody(textureMapObject_t,
- world, false);
-
- body_t.setTransform(textureMapObject_t.getX() + 1, textureMapObject_t.getY(), 0);
+ }
- tabouret = new Player(body_t, textureMapObject_t);
+ }
+ }
- } else if (textureMapObjectName != null && textureMapObjectName.equals("tabouret")) {
- Body body_t = BodyHelperService.createBody(textureMapObject,
- world, false);
+ private void createWalls(MapObjects mapObjects) {
+ BodyDef bodyDef = new BodyDef();
+ bodyDef.type = BodyDef.BodyType.StaticBody;
+ PolygonShape shape = new PolygonShape();
+ FixtureDef fixtureDef = new FixtureDef();
+ fixtureDef.shape = shape;
+ fixtureDef.density = 0; // Стены не имеют веса.
+ fixtureDef.friction = 0.3f; // Небольшое трение.
- body_t.setTransform(textureMapObject.getX(), textureMapObject.getY(), 0);
+ for (MapObject mapObject : mapObjects) {
+ // Получаем прямоугольник стены из объекта карты.
+ RectangleMapObject rectangleObject = (RectangleMapObject) mapObject;
+ Rectangle rect = rectangleObject.getRectangle();
-// textureMapObject.setScaleX(1.5f);
-// textureMapObject.setScaleY(0.5f);
+ // Set body position to the center of the rectangle.
+ bodyDef.position.set(
+ (rect.x + rect.width * 0.5f) ,
+ (rect.y + rect.height * 0.5f)
+ );
-// tabouret = new Player(body_t, textureMapObject);
+ // Create the body from the definition.
+ Body body = world.createBody(bodyDef);
- }
+ // Set the shape as a box using the rectangle's dimensions.
+ shape.setAsBox(rect.width * 0.5f , rect.height * 0.5f );
+ // Add the fixture to the body.
+ body.createFixture(fixtureDef);
}
- }
- public Player getPlayer() {
+ // Clean up after ourselves. Calling dispose is important to avoid memory leaks!
+ shape.dispose();
+ }
- Gdx.app.log("ADD NEW PLAYER", "GET NEW PLAYER IN TILE MAP MEE");
+ private void createMapBounds(int mapWidth, int mapHeight) {
+ float halfWidth = mapWidth / 2.0f;
+ float halfHeight = mapHeight / 2.0f;
+ createWall(halfWidth, -1, mapWidth, 1); // Нижняя граница
+ createWall(halfWidth, mapHeight, mapWidth, 1); // Верхняя граница
+ createWall(-1, halfHeight, 1, mapHeight); // Левая граница
+ createWall(mapWidth, halfHeight, 1, mapHeight); // Правая граница
+ }
+ private void createWall(float x, float y, float width, float height) {
+ BodyDef bodyDef = new BodyDef();
+ bodyDef.type = BodyDef.BodyType.StaticBody;
+ bodyDef.position.set(x , y );
-// return new Player(this.body, this.textureMapObject);
+ Body body = world.createBody(bodyDef);
- return player;
- }
+ PolygonShape shape = new PolygonShape();
+ shape.setAsBox(width / 2 , height / 2 );
- public Player getOtherPlayer() {
+ FixtureDef fixtureDef = new FixtureDef();
+ fixtureDef.shape = shape;
+ fixtureDef.density = 0; // Стены не имеют веса.
+ fixtureDef.friction = 0.5f;
+ body.createFixture(fixtureDef);
- Gdx.app.log("ADD NEW PLAYER", "GET NEW PLAYER IN TILE MAP TABOURET");
+ shape.dispose();
+ }
+ public Player getPlayer() {
-// return new Player(this.body, this.textureMapObject);
+ Gdx.app.log("ADD NEW PLAYER", "GET NEW PLAYER IN TILE MAP MEE");
- return tabouret;
+ return player;
}
- private Shape createRectangleShape(RectangleMapObject rectangleMapObject) {
- PolygonShape shape = new PolygonShape();
- Vector2 size = new Vector2((rectangleMapObject.getRectangle().width / 2) / 32.0f, (rectangleMapObject.getRectangle().height / 2) / 32.0f);
- shape.setAsBox(size.x, size.y, rectangleMapObject.getRectangle().getCenter(new Vector2()).scl(1 / 32.0f), 0.0f);
- return shape;
- }
}
diff --git a/core/src/com/aqwsxlostfly/packandgo/Tools/Wave.java b/core/src/com/aqwsxlostfly/packandgo/Tools/Wave.java
deleted file mode 100644
index 5f99a9c..0000000
--- a/core/src/com/aqwsxlostfly/packandgo/Tools/Wave.java
+++ /dev/null
@@ -1,67 +0,0 @@
-//package com.aqwsxlostfly.packandgo.Tools;
-//
-//import com.aqwsxlostfly.packandgo.Heroes.Enemy;
-//import com.aqwsxlostfly.packandgo.Main;
-//import com.aqwsxlostfly.packandgo.Screens.GameSc;
-//import com.badlogic.gdx.Gdx;
-//import com.badlogic.gdx.graphics.Color;
-//import com.badlogic.gdx.graphics.g2d.BitmapFont;
-//import com.badlogic.gdx.graphics.g2d.GlyphLayout;
-//import com.badlogic.gdx.graphics.g2d.SpriteBatch;
-//import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
-//
-//public class Wave {
-// private int delay;
-// private int minEnemy;
-//
-// private long startTimer;
-//
-// private String info = "wave - ";
-// BitmapFont font;
-//
-// private int waveNumber;
-//
-//
-// public Wave(int delay, int waveNumber,int minEnemy) {
-// FreeTypeFontGenerator gen = new FreeTypeFontGenerator((Gdx.files.internal(("font.ttf"))));
-// FreeTypeFontGenerator.FreeTypeFontParameter p =new FreeTypeFontGenerator.FreeTypeFontParameter();
-// p.size=Main.screenWidth/10;
-// p.color = new Color(Color.RED);
-// font = gen.generateFont(p);
-// this.delay = delay;
-// this.minEnemy = minEnemy;
-// this.waveNumber = waveNumber;
-// }
-//
-// public void update(){
-// if (GameSc.enemies.isEmpty() && startTimer==0) startTimer=System.currentTimeMillis();
-// int seconds = 0;
-// if (startTimer>0){
-// seconds = (int) ((System.currentTimeMillis()-startTimer)/1000);
-// }
-// if (seconds>delay) {
-// setWave();
-// waveNumber++;
-// startTimer =0;
-// seconds=0;
-// }
-// }
-//
-// public void setWave() {
-// int enemies = minEnemy + waveNumber * 2;
-// int maxRank = 1;
-// if (waveNumber > 5) maxRank = 2;
-// if (waveNumber > 10) maxRank = 3;
-// for (int i = 0; i < enemies; i++) {
-// GameSc.enemies.add(new Enemy(Main.enemy, new Point2D((float) Main.screenWidth / 2, (float) Main.screenHeight / 4), (int) (Math.random() * maxRank+1)));
-// }
-// }
-// public void draw(SpriteBatch batch){
-// GlyphLayout gl = new GlyphLayout();
-// gl.setText(font,info+waveNumber);
-// font.draw(batch,gl,Main.screenWidth/2-gl.width/2,Main.screenHeight/2);
-// }
-// public boolean isDraw(){
-// return startTimer >0;
-// }
-//}
diff --git a/core/src/com/aqwsxlostfly/packandgo/render/Renderer.java b/core/src/com/aqwsxlostfly/packandgo/render/Renderer.java
index fc193e8..d0712ea 100644
--- a/core/src/com/aqwsxlostfly/packandgo/render/Renderer.java
+++ b/core/src/com/aqwsxlostfly/packandgo/render/Renderer.java
@@ -32,7 +32,7 @@ public Renderer() {
FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
parameter.size = 13;
parameter.color = new Color(Color.RED);
- font = generator.generateFont(parameter); // Здесь шрифт создаётся и может быть использован повторно
+ font = generator.generateFont(parameter);
generator.dispose();
@@ -61,35 +61,13 @@ public void render() {
batch.setProjectionMatrix(camera.combined); // Устанавливаем матрицу проекции для рендеринга с позиции камеры игры
batch.begin();
-// SpriteBatch spriteBatch = new SpriteBatch();
-// spriteBatch.begin();
-
-// spriteBatch.end();
gameScreen.render(batch, camera);
-// batch.setProjectionMatrix(camera.combined); // Устанавливаем матрицу проекции для рендеринга с позиции камеры игры
-
-
batch.end();
}
-// Gdx.gl.glClearColor(0, 0, 0, 1);
-// Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
-
-// batch.setProjectionMatrix(camera.combined); // Устанавливаем матрицу проекции для рендеринга с позиции камеры игры
-// batch.begin();
-
-// SpriteBatch spriteBatch = new SpriteBatch();
-// spriteBatch.begin();
-
-// spriteBatch.end();
-// homeScreen.render(batch, camera);
-
-// batch.setProjectionMatrix(camera.combined); // Устанавливаем матрицу проекции для рендеринга с позиции камеры игры
-
-// batch.end();
}
public void setHomeScreen(HomeSc screen) {