diff --git a/core/src/com/mygdx/game/GameScreens/GamePlay.java b/core/src/com/mygdx/game/GameScreens/GamePlay.java index 245d121d3a8e33748d79da56845875b2d37f6a16..0386f60fd5129a06497981ff3bd1d25104ada57c 100644 --- a/core/src/com/mygdx/game/GameScreens/GamePlay.java +++ b/core/src/com/mygdx/game/GameScreens/GamePlay.java @@ -268,7 +268,8 @@ public class GamePlay extends GameScreen } if(pleft.getContactStatus().equals("2")) pleft.setContactStatus(0); if(pright.getContactStatus().equals("2")) pright.setContactStatus(0); - pleft.interact(pressed(Input.Keys.Q), pressed(Input.Keys.D), pressed(Input.Keys.Z), pressed(Input.Keys.S)); + if(isAI) pleft.interact(ball.getPos()); + else pleft.interact(pressed(Input.Keys.Q), pressed(Input.Keys.D), pressed(Input.Keys.Z), pressed(Input.Keys.S)); pright.interact(pressed(Input.Keys.J), pressed(Input.Keys.L), pressed(Input.Keys.I), pressed(Input.Keys.K)); } diff --git a/core/src/com/mygdx/game/bodies/Ball.java b/core/src/com/mygdx/game/bodies/Ball.java index 37a463d8a54a3cb886e88c6a339e163340542e7f..781f5a15d6ef83f319ce842a6664fee89bd51761 100644 --- a/core/src/com/mygdx/game/bodies/Ball.java +++ b/core/src/com/mygdx/game/bodies/Ball.java @@ -1,5 +1,6 @@ package com.mygdx.game.bodies; +import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; @@ -55,4 +56,9 @@ public class Ball { tb.setPosition(new Vector2(GameScreen.Width()/2f, GameScreen.Height()/2f)); } + + public Vector2 getPos() + { + return new Vector2(tb.getX(), tb.getY()); + } } diff --git a/core/src/com/mygdx/game/bodies/Player.java b/core/src/com/mygdx/game/bodies/Player.java index 2c8fb5d1712bd2bbf9ffa1783c7355ba2224ee5b..5ae06c15991a28c6cb37007dcbb388a99ebf46e6 100644 --- a/core/src/com/mygdx/game/bodies/Player.java +++ b/core/src/com/mygdx/game/bodies/Player.java @@ -57,22 +57,25 @@ public class Player public void interact(boolean left, boolean right, boolean up, boolean down) { - if(type == TYPE.AI) - { + int hor = (left ? -250 : 0) + (right ? 250 : 0); + int ver = (down ? -250 : 0) + (up ? 250 : 0); + Vector2 impulse = new Vector2(hor, ver); + tb.applyForce(impulse.scl(Gdx.graphics.getDeltaTime()), true); + } + public void interact(Vector2 delta) + { + if(type != TYPE.AI) + { + tb.applyForce(delta.scl(Gdx.graphics.getDeltaTime()), true); } else { - int hor = (left ? -250 : 0) + (right ? 250 : 0); - int ver = (down ? -250 : 0) + (up ? 250 : 0); - Vector2 impulse = new Vector2(hor, ver); - tb.applyForce(impulse.scl(Gdx.graphics.getDeltaTime()), true); - } - } + delta.x -= tb.getX(); + delta.y -= tb.getY(); - public void interact(Vector2 delta) - { - tb.applyForce(delta.scl(Gdx.graphics.getDeltaTime()), true); + tb.applyForce(delta.scl(Gdx.graphics.getDeltaTime()), true); + } } public void reset(boolean hasScored)