SHARE
TWEET
Untitled
a guest
Nov 28th, 2016
22
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- package com.shawn;
- import com.badlogic.gdx.math.Vector2;
- import com.github.czyzby.websocket.serialization.SerializationException;
- import com.github.czyzby.websocket.serialization.Transferable;
- import com.github.czyzby.websocket.serialization.impl.Deserializer;
- import com.github.czyzby.websocket.serialization.impl.Serializer;
- import com.github.czyzby.websocket.serialization.impl.Size;
- public class Entity implements Transferable<Entity>{
- public Entity() {
- //Register the entity ID.
- ID = -1;
- }
- public Entity(EntityPosition pos, final int ID) {
- this.entity_pos = pos;
- this.ID = ID;
- //Set the starting position to the EntityPosition.
- this.position = pos.get();
- }
- public void updateEntity(EntityPosition pa){
- this.entity_pos = pa;
- }
- public void setTarget(MousePosition pos){
- target_location = pos;
- }
- public MousePosition getTarget(){
- return target_location;
- }
- private EntityPosition entity_pos;
- private MousePosition target_location;
- private Vector2 position;
- public final int ID;
- public Vector2 getPosition(){
- return position;
- }
- //In future iterations, make a "Connections" class to handle updating.
- //speed is equal to distance / time
- public void moveTo(EntityPosition target, float time, float delta){
- Vector2 direction = target.get().cpy().sub(position).nor();
- position.add(direction.scl((target.get().dst(position)/time) * delta));
- }
- public void updateLocally(float delta){
- if(position.dst2(entity_pos.get()) >= 1f){
- moveTo(entity_pos, 1f/20f, 1f);
- }
- }
- @Override
- public void serialize(Serializer serializer) throws SerializationException {
- serializer.
- serializeTransferable(entity_pos).
- serializeInt(ID);
- }
- @Override
- public Entity deserialize(Deserializer deserializer) throws SerializationException {
- return new Entity(
- deserializer.deserializeTransferable(new EntityPosition()),
- deserializer.deserializeInt()
- );
- }
- }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

