| |
---|
| | public class MyBullet extends Actor implements GameBaseModel, CallBack { |
---|
| | private String instanceId; |
---|
| | private String playerId; |
---|
| | private String uuid; |
---|
| | private BulletGetConnection bulletGetConnection; |
---|
| | private DummyBullet bullet; |
---|
| | final private int INIT_UPDATE_INTERVAL = 100; |
---|
| | private int updateInterval = INIT_UPDATE_INTERVAL; |
---|
| | private boolean isCreatedOnServer = false; |
---|
| | private boolean isWaitCreatingOnServer = false; |
---|
| | private boolean isDelete = false; |
---|
| | |
---|
| | public MyBullet(Object3D body, Animation3D animation) { |
---|
| | super(body, animation); |
---|
| |
---|
| | @Override |
---|
| | final public void update(double interval) { |
---|
| | progress(interval); |
---|
| | // サーバに弾を作成 |
---|
| | if (!isCreatedOnServer && !instanceId.equals("") && !playerId.equals("")) { |
---|
| | if (!isCreatedOnServer && !instanceId.equals("") && !playerId.equals("") && !isWaitCreatingOnServer) { |
---|
| | JSON json = new JSON(); |
---|
| | Quaternion3D q = ((Solid3D)(getBody())).getQuaternion(); |
---|
| | BulletCreateConnection con = new BulletCreateConnection(instanceId, playerId); |
---|
| | con.setCallBack(this); |
---|
| | con.addFormParam("bulletID", getUuid()); |
---|
| | con.addFormParam("position", json.encode(getPosition())); |
---|
| | con.addFormParam("angle", "{ \"x\":" + q.getX() + ", \"y\":" + q.getY() + ", \"z\":" + q.getZ() + ", \"w\":" + q.getW() + "}"); |
---|
| | con.doPost(); |
---|
| | isWaitCreatingOnServer = true; |
---|
| | System.out.println("create shot uuid:" + getUuid()); |
---|
| | } |
---|
| | else if (isCreatedOnServer) { |
---|
| | else if (isCreatedOnServer && !isWaitCreatingOnServer) { |
---|
| | // サーバの弾の情報を更新 |
---|
| | updateInterval -= interval; |
---|
| | if (updateInterval <= 0 && isCreatedOnServer) { |
---|
| | JSON json = new JSON(); |
---|
| | Quaternion3D q = ((Solid3D)(getBody())).getQuaternion(); |
---|
| | updateInterval = INIT_UPDATE_INTERVAL; |
---|
| | BulletUpdateConnection con = new BulletUpdateConnection(instanceId, playerId, getUuid()); |
---|
| | con.setCallBack(this); |
---|
| | con.addFormParam("position", json.encode(getPosition())); |
---|
| | con.addFormParam("angle", "{ \"x\":" + q.getX() + ", \"y\":" + q.getY() + ", \"z\":" + q.getZ() + ", \"w\":" + q.getW() + "}"); |
---|
| | con.doPut(); |
---|
| | } |
---|
| |
---|
| | } |
---|
| | |
---|
| | @Override |
---|
| | public void onResponse(String response) { |
---|
| | isWaitCreatingOnServer = false; |
---|
| | isCreatedOnServer = true; |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | |