Guest User

Untitled

a guest
May 20th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. protected Body body;
  2.  
  3. public Creature(final float pX, final float pY, final ITextureRegion textureRegion, GameEngine i_Engine) {
  4.         super(pX, pY, textureRegion);
  5.         this.speed_multi = 1;
  6.         this.flips = false;
  7.         this.mEngine = i_Engine;
  8.         this.fixDef = PhysicsFactory.createFixtureDef(0, 0, 0);
  9.         this.body = PhysicsFactory.createBoxBody(this.mEngine.getPhy(), this, BodyType.DynamicBody, this.fixDef);
  10.         this.body.setUserData(this);
  11.         this.mEngine.getPhy().registerPhysicsConnector(new PhysicsConnector(this, body, true, true));
  12. }
  13.    
  14. public void setVelocity(float vX, float vY) {          
  15.     Vector2 mVelocity = Vector2Pool.obtain(vX, vY);
  16.         this.body.setLinearVelocity(mVelocity);
  17.     Vector2Pool.recycle(mVelocity);
  18. }
  19.  
  20. public void randomizeVelocity() {
  21.         Random gen = new Random();
  22.        
  23.         float x = gen.nextInt(10)-5;
  24.         float y = gen.nextInt(10)-5;
  25.         Debug.d("Setting Velocity", "Val: " + x + " " + y);
  26.         this.setVelocity(x, y);
  27.  
  28. }
Add Comment
Please, Sign In to add comment