Skip to content

Commit

Permalink
Ship visuals refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
TEXH4Pb committed Nov 10, 2021
1 parent 0ec8c3d commit 57f2bab
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions core/src/com/mygdx/game/Ship.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class Ship extends Entity{
private int immuneTimer;//ship is immune for a few seconds after getting damage
private int cooldownTimer;//cooldown between laser shots
private int stunTimer;//if the ship is hit by laser, it becomes stunned for a while
private float alphaOffset;//summarize effects
private static final float FORWARD_ACCELERATION = 0.7f;
private static final float STRAFE_ACCELERATION = 0.3f;
private static final int SHOT_COOLDOWN = 20;
Expand All @@ -21,6 +22,7 @@ public class Ship extends Entity{
lifes = 3;
score = 0;
immuneTimer = 0;
alphaOffset = 0;

body = SHAPES.createBody("playerShip", world, SCALE, SCALE);
body.setUserData(this);
Expand All @@ -36,7 +38,7 @@ public void collideWith(Entity target) {
if(immuneTimer == 0) {
lifes--;
immuneTimer = 180;
sprite.setAlpha(0.4f);
alphaOffset += 0.5f;
target.queuedForRemoval = true;
}
}
Expand All @@ -59,13 +61,13 @@ public void update(){
if (immuneTimer > 0){
immuneTimer--;
if (immuneTimer == 0) //just become zero
sprite.setAlpha(1);
alphaOffset -= 0.5f;
}
if(stunTimer > 0){
stunTimer--;
if(stunTimer == 0) {
body.setFixedRotation(true);
sprite.setAlpha(1);
alphaOffset -= 0.2f;
}
}
if(cooldownTimer > 0)
Expand All @@ -80,6 +82,7 @@ void draw(SpriteBatch batch) {
sprite.setOrigin(sprite.getWidth()/2, sprite.getHeight()/2);
sprite.setPosition(pos.x - sprite.getOriginX(), pos.y - sprite.getOriginY());
sprite.setRotation((float) Math.toDegrees(body.getAngle()));
sprite.setAlpha(1 - alphaOffset);
sprite.draw(batch);
}

Expand Down Expand Up @@ -125,8 +128,10 @@ public void getBonus(int bonus){
}

public void stun(){
body.setFixedRotation(false);
sprite.setAlpha(0.9f);
if(stunTimer == 0) {
body.setFixedRotation(false);
alphaOffset += 0.2f;
}
stunTimer = 90;
}
}

0 comments on commit 57f2bab

Please sign in to comment.