Advertisement
Guest User

Box2DWorldPostActionController

a guest
Jun 26th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.43 KB | None | 0 0
  1. package com.ekit.castles.war.controller
  2.  
  3. import java.util.ArrayList
  4. import com.badlogic.gdx.physics.box2d.joints.DistanceJointDef
  5. import com.ekit.castles.war.model.Model
  6.  
  7. /**
  8.  * @author Konstant
  9.  */
  10. class WorldPostActionController {
  11.  
  12.   private var destroyrequests = new ArrayList[DestroyDef]()
  13.   private var djointrequests = new ArrayList[DistanceJointDef]()
  14.  
  15.   /**Destroy body before next box2d world step*/
  16.   def requestDestroy(destroy: DestroyDef) = {
  17.     destroyrequests.add(destroy)
  18.   }
  19.  
  20.   /**Create new distance joint before next box2d world step*/
  21.   def requestDistanceJoint(joint: DistanceJointDef) = {
  22.     djointrequests.add(joint)
  23.   }
  24.  
  25.   /**Process all requests and clear requests arrays*/
  26.   def Process = {
  27.     //Process destroy requests
  28.     if (!destroyrequests.isEmpty()) {
  29.       for (request <- destroyrequests.toArray(new Array[DestroyDef](1))) {
  30.         request.body.setActive(false)
  31.         Model.getGameWorld.world destroyBody request.body
  32.       }
  33.       destroyrequests clear ()
  34.     }
  35.     //Process distence joints requests
  36.     if (!djointrequests.isEmpty()) {
  37.       for (request <- djointrequests.toArray(new Array[DistanceJointDef](1))) {
  38.         request.bodyA.setActive(false)
  39.         request.bodyB.setActive(false)
  40.         Model.getGameWorld.world createJoint request
  41.         request.bodyA.setActive(true)
  42.         request.bodyB.setActive(true)
  43.       }
  44.       djointrequests clear ()
  45.     }
  46.   }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement