Skip to content

Commit

Permalink
add no-args constructor to state classes to satisfy Kryo requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
0us committed Nov 12, 2019
1 parent 2809618 commit d36fb93
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
1 change: 0 additions & 1 deletion core/src/no/ntnu/trostespel/PlayerActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@ public PlayerActions(int pid) {
}

public PlayerActions() {
pid = new Random().nextInt();
}
}
5 changes: 5 additions & 0 deletions core/src/no/ntnu/trostespel/state/MovableState.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package no.ntnu.trostespel.state;

import com.badlogic.gdx.math.Vector2;
import no.ntnu.trostespel.entity.Movable;

import java.util.concurrent.atomic.AtomicLong;

Expand All @@ -14,6 +15,10 @@ public class MovableState extends ObjectState {
private transient int timeAlive;
public final transient int damage = 15;

private MovableState() {
// kryo requires a no-args constructor to work properly
}

public MovableState(long pid, double velocity) {
super(24f, 24f, Vector2.Zero);
this.heading = new Vector2(1, 0); // Unit vector
Expand Down
4 changes: 4 additions & 0 deletions core/src/no/ntnu/trostespel/state/ObjectState.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ public class ObjectState {
private transient Rectangle hitbox;
private volatile Vector2 position;

private ObjectState() {
// kryo requires a no-args constructor to work properly
}

public ObjectState(float x, float y, Vector2 position) {
this.hitbox = new Rectangle(0, 0, x, y);
this.position = position;
Expand Down
3 changes: 2 additions & 1 deletion core/src/no/ntnu/trostespel/state/PlayerState.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ public class PlayerState extends ObjectState{
private long timeOfDeath;
private String username;

public PlayerState() {
private PlayerState() {
super(72, 90, new Vector2(55, 55));
// kryo requires a no-args constructor to work properly
}

public PlayerState(long pid) {
Expand Down

0 comments on commit d36fb93

Please sign in to comment.