Skip to content

Commit

Permalink
Small tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
TEXH4Pb committed Nov 11, 2021
1 parent 57f2bab commit 0486f20
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 18 deletions.
4 changes: 2 additions & 2 deletions core/src/com/mygdx/game/Asteroid.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class Asteroid extends Entity{
Vector2 velocity = new Vector2();
velocity.x = (float)Math.random() - 0.5f;
velocity.y = (float)Math.random() - 0.5f;
velocity.setLength((float)Math.random() * 2 + 1);
velocity.setLength((float)Math.random() * 2 + 4);
body.setLinearVelocity(velocity);
body.setUserData(this);

Expand All @@ -87,5 +87,5 @@ public class Asteroid extends Entity{
@Override
public void collideWith(Entity target) {}
@Override
public void update() {};//no updates for asteroids
public void update() {}//no updates for asteroids
}
10 changes: 6 additions & 4 deletions core/src/com/mygdx/game/Laser.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import com.badlogic.gdx.math.Vector2;

public class Laser extends Entity{
private static final float VELOCITY = 3;
private static final int ENERGY_MAX = 60;
private Ship owner;
private final Ship owner;
private int energy;
public boolean firstContact;
public boolean firstContact;//flag for handling collision just after the shot

Laser(Ship shooter){
energy = ENERGY_MAX;
Expand All @@ -17,7 +18,7 @@ public class Laser extends Entity{

body = SHAPES.createBody("laser", owner.body.getWorld(), SCALE, SCALE);
body.setUserData(this);
Vector2 dir = new Vector2(4,4);
Vector2 dir = new Vector2(VELOCITY, VELOCITY);
body.setTransform(owner.getPosition(), owner.body.getAngle());
dir.setAngleRad(body.getAngle());
dir.rotate90(0);
Expand All @@ -41,8 +42,9 @@ public void collideWith(Entity target) {
}else if(target instanceof Ship){
((Ship) target).stun();
}
else
else {
target.queuedForRemoval = true;
}
}

@Override
Expand Down
8 changes: 3 additions & 5 deletions core/src/com/mygdx/game/MyGdxGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.utils.ScreenUtils;

import javax.swing.*;
import java.util.ArrayList;
import java.util.Iterator;

public class MyGdxGame extends ApplicationAdapter {
static final float STEP_TIME = 1f / 60f;
static final int VELOCITY_ITERATIONS = 6;
static final int POSITION_ITERATIONS = 2;
static final int ASTEROID_COUNT = 20;
static final int ASTEROID_COUNT = 15;
static final float SCALE = 0.02f;

SpriteBatch batch;
Expand Down Expand Up @@ -68,7 +67,7 @@ public void create () {
contactListener = new BoxListener();
world = new World(new Vector2(0,0), true);
world.setContactListener(contactListener);
entities = new ArrayList<Entity>();
entities = new ArrayList<>();

restartGame(true);

Expand Down Expand Up @@ -107,7 +106,7 @@ public void render () {
batch.setProjectionMatrix(uiCam.combined);
batch.begin();
font.draw(batch, "SCORE: " + player.getScore(), 0 + screenWidth * 0.02f, screenHeight * 0.95f);
font.draw(batch, "LIFES: " + player.getLifes(), 0 + screenWidth - 150, screenHeight * 0.95f);
font.draw(batch, "LIFES: " + player.getLifes(), screenWidth - 150, screenHeight * 0.95f);
if(debugMode)
font.draw(batch, "FPS " + Gdx.graphics.getFramesPerSecond(), 0 + screenWidth * 0.05f, screenHeight * 0.05f);
if(player.getLifes() <= 0)
Expand Down Expand Up @@ -141,7 +140,6 @@ private void updateGame()
checkBorders(player);

int asteroidCount = 0;
Vector2 newPos;
Iterator<Entity> iterator = entities.iterator();
while (iterator.hasNext()) {
Entity e = iterator.next();
Expand Down
7 changes: 2 additions & 5 deletions core/src/com/mygdx/game/Ship.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Ship extends Entity{
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 FORWARD_ACCELERATION = 0.5f;
private static final float STRAFE_ACCELERATION = 0.3f;
private static final int SHOT_COOLDOWN = 20;

Expand Down Expand Up @@ -94,10 +94,7 @@ public void accelerate() {
}

public boolean canShoot() {
if(cooldownTimer > 0 || stunTimer > 0)
return false;
else
return true;
return cooldownTimer <= 0 && stunTimer <= 0;
}

public boolean isStunned(){
Expand Down
2 changes: 0 additions & 2 deletions desktop/src/com/mygdx/game/desktop/DesktopLauncher.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.mygdx.game.desktop;

import com.badlogic.gdx.Files;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.mygdx.game.MyGdxGame;
Expand Down

0 comments on commit 0486f20

Please sign in to comment.