Skip to content

Commit

Permalink
Cleanup and added method for reseteting an object so that it's ready
Browse files Browse the repository at this point in the history
to be used next time.
  • Loading branch information
markusranda committed Nov 21, 2019
1 parent aac4a97 commit f003413
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
1 change: 0 additions & 1 deletion core/src/no/ntnu/trostespel/state/GameState.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.badlogic.gdx.maps.tiled.TiledMapTileLayer;

import java.util.HashMap;
import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
Expand Down
25 changes: 24 additions & 1 deletion core/src/no/ntnu/trostespel/state/MovableState.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import java.util.concurrent.atomic.AtomicLong;

import static no.ntnu.trostespel.state.Action.KILL;

public class MovableState extends ObjectState {

private long id;
Expand All @@ -14,6 +16,7 @@ public class MovableState extends ObjectState {

private transient int timeAlive;
public final transient int damage = 15;
private static AtomicLong idCounter = new AtomicLong();

public MovableState(long pid, double velocity) {
super(24f, 24f, Vector2.Zero);
Expand All @@ -25,6 +28,16 @@ public MovableState(long pid, double velocity) {
this.heading.setLength((float) velocity);
}

public MovableState(double velocity) {
super(24f, 24f, Vector2.Zero);
this.heading = new Vector2(1, 0); // Unit vector
this.id = createID();
this.pid = 0;
this.action = Action.CREATE;
this.heading = new Vector2(1, 0);
this.heading.setLength((float) velocity);
}

public void setPositionWithSpawnOffset(Vector2 position) {
this.setPosition(position.add(GameRules.Projectile.SPAWN_OFFSET));
}
Expand Down Expand Up @@ -73,7 +86,6 @@ public void setPid(long pid) {
this.pid = pid;
}

private static AtomicLong idCounter = new AtomicLong();
public static long createID() {
return idCounter.getAndIncrement();
}
Expand All @@ -93,4 +105,15 @@ public int getTimeAlive() {
public void incrementTimeAlive() {
this.timeAlive++;
}

/**
* This method is intented for reseting the object and make it ready for reuse.
*/
public void resetObject() {
id = 0;
pid = 0;
action = KILL;
heading = Vector2.Zero;
timeAlive = 0;
}
}

0 comments on commit f003413

Please sign in to comment.