Skip to content

Commit

Permalink
Merge pull request #6 from booksaw/RebalanceCollege
Browse files Browse the repository at this point in the history
Rebalanced college fights
  • Loading branch information
booksaw authored Feb 22, 2022
2 parents bbf552f + 375fb00 commit 3e28f8f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
17 changes: 15 additions & 2 deletions core/src/com/mygdx/pirategame/gameobjects/CollegeFire.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.mygdx.pirategame.PirateGame;
import com.mygdx.pirategame.screen.GameScreen;

import java.util.Random;

/**
* College Fire
* Defines college attack method
Expand Down Expand Up @@ -35,7 +37,8 @@ public class CollegeFire extends Sprite {
*/
public CollegeFire(GameScreen screen, float x, float y) {
this.world = screen.getWorld();
playerPos = screen.getPlayerPos();
playerPos = screen.getCenteredPlayerPos();

cannonBall = new Texture("cannonBall.png");
//Set the position and size of the ball
setRegion(cannonBall);
Expand All @@ -53,6 +56,9 @@ public void defineCannonBall() {
bDef.position.set(getX(), getY());
bDef.type = BodyDef.BodyType.DynamicBody;
b2body = world.createBody(bDef);
MassData mass = new MassData();
mass.mass = (float) 0.01;
b2body.setMassData(mass);
//Sets collision boundaries
FixtureDef fDef = new FixtureDef();
CircleShape shape = new CircleShape();
Expand All @@ -67,6 +73,13 @@ public void defineCannonBall() {

// Math for firing the cannonball at the player
playerPos.sub(b2body.getPosition());

// adding randomness to cannon firing
Random rnd = new Random();
float rndX = (float) (rnd.nextInt(2) - 1 + rnd.nextDouble());
float rndY = (float) (rnd.nextInt(2) - 1 + rnd.nextDouble());
playerPos.sub(rndX, rndY);

playerPos.nor();
float speed = 5f;
b2body.setLinearVelocity(playerPos.scl(speed));
Expand All @@ -80,7 +93,7 @@ public void defineCannonBall() {
*/
public void update(float dt){
stateTime += dt;
//If college is set to destroy and isnt, destroy it
//If college is set to destroy and isn't, destroy it
setPosition(b2body.getPosition().x - getWidth() / 2, b2body.getPosition().y - getHeight() / 2);
if((setToDestroy) && !destroyed) {
world.destroyBody(b2body);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ protected void defineEnemy() {
bdef.type = BodyDef.BodyType.DynamicBody;
b2body = world.createBody(bdef);

b2body.setLinearDamping(1);
//Sets collision boundaries
FixtureDef fdef = new FixtureDef();
CircleShape shape = new CircleShape();
Expand Down
8 changes: 8 additions & 0 deletions core/src/com/mygdx/pirategame/screen/GameScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,14 @@ public Vector2 getPlayerPos(){
return new Vector2(player.b2body. getPosition().x,player.b2body.getPosition().y);
}

/**
* Calculates the players position centered in the middle of the player
* @return The centered position of the player
*/
public Vector2 getCenteredPlayerPos(){
return getPlayerPos().add(player.getWidth(), player.getHeight());
}

/**
* Updates acceleration by a given percentage. Accessed by skill tree
*
Expand Down

0 comments on commit 3e28f8f

Please sign in to comment.