Skip to content
Snippets Groups Projects
Commit bed82c4b authored by ALGLAVE Ivan's avatar ALGLAVE Ivan
Browse files

Added a very rudimentary AI that only goes towards the ball, the further away the fastest

parent f407d80a
No related branches found
No related tags found
No related merge requests found
...@@ -268,7 +268,8 @@ public class GamePlay extends GameScreen ...@@ -268,7 +268,8 @@ public class GamePlay extends GameScreen
} }
if(pleft.getContactStatus().equals("2")) pleft.setContactStatus(0); if(pleft.getContactStatus().equals("2")) pleft.setContactStatus(0);
if(pright.getContactStatus().equals("2")) pright.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)); pright.interact(pressed(Input.Keys.J), pressed(Input.Keys.L), pressed(Input.Keys.I), pressed(Input.Keys.K));
} }
......
package com.mygdx.game.bodies; package com.mygdx.game.bodies;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
...@@ -55,4 +56,9 @@ public class Ball ...@@ -55,4 +56,9 @@ public class Ball
{ {
tb.setPosition(new Vector2(GameScreen.Width()/2f, GameScreen.Height()/2f)); tb.setPosition(new Vector2(GameScreen.Width()/2f, GameScreen.Height()/2f));
} }
public Vector2 getPos()
{
return new Vector2(tb.getX(), tb.getY());
}
} }
...@@ -57,22 +57,25 @@ public class Player ...@@ -57,22 +57,25 @@ public class Player
public void interact(boolean left, boolean right, boolean up, boolean down) 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 else
{ {
int hor = (left ? -250 : 0) + (right ? 250 : 0); delta.x -= tb.getX();
int ver = (down ? -250 : 0) + (up ? 250 : 0); delta.y -= tb.getY();
Vector2 impulse = new Vector2(hor, ver);
tb.applyForce(impulse.scl(Gdx.graphics.getDeltaTime()), true);
}
}
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) public void reset(boolean hasScored)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment