SHARE
TWEET

Untitled

a guest Sep 4th, 2014 2 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.intelligentprocedure.TexasTreadmill.entity;
  2.  
  3. import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  4. import com.badlogic.gdx.graphics.g2d.TextureRegion;
  5. import com.badlogic.gdx.math.Vector2;
  6. import com.badlogic.gdx.physics.box2d.Body;
  7. import com.badlogic.gdx.physics.box2d.BodyDef;
  8. import com.badlogic.gdx.physics.box2d.FixtureDef;
  9. import com.badlogic.gdx.physics.box2d.PolygonShape;
  10. import com.intelligentprocedure.TexasTreadmill.gamestates.ActualGame;
  11. import com.intelligentprocedure.TexasTreadmill.management.Assets;
  12.  
  13. import java.util.Random;
  14.  
  15. /**
  16.  * Created by Justin on 8/31/2014.
  17.  */
  18. public class JumpObject extends Entity {
  19.  
  20.     public Body body;
  21.     final float WIDTH = 64;
  22.     final float HEIGHT = 64;
  23.  
  24.     int x, y;
  25.     int ver = 0;
  26.     TextureRegion tex;
  27.     public int objectType = 0;
  28.  
  29.     public JumpObject(int x, int y){
  30.         super(7);
  31.         this.x = x; this.y = y;
  32.         ver = new Random().nextInt(3);
  33.         objectType = ver;
  34.  
  35.         switch(ver){
  36.             case 0: tex = Assets.objects.get(0); break;
  37.             case 1: tex = Assets.objects.get(1); break; // chicken object!
  38.             case 2: tex = Assets.objects.get(2); break;
  39.         }
  40.  
  41.         BodyDef bDef = new BodyDef();
  42.         bDef.type = BodyDef.BodyType.DynamicBody;
  43.         FixtureDef fDef = new FixtureDef();
  44.         PolygonShape pShape = new PolygonShape();
  45.         pShape.setAsBox(WIDTH/2/ ActualGame.C, HEIGHT/2/ActualGame.C, new Vector2(x/ActualGame.C, y/ActualGame.C), 0);
  46.         fDef.shape = pShape;
  47.         fDef.friction = 0;
  48.         body = ActualGame.world.createBody(bDef);
  49.         body.createFixture(fDef);
  50.  
  51.         body.setUserData(this);
  52.  
  53.         body.setLinearVelocity(-400/ActualGame.C, 0/ActualGame.C);
  54. //        body.setAngularVelocity(new Random().nextFloat()-.5f);
  55.     }
  56.  
  57.     public void render(SpriteBatch sb){
  58.         if(body != null) {
  59.             sb.draw(tex, getX() - WIDTH / 2, getY() - HEIGHT / 2, WIDTH, HEIGHT);
  60.         }
  61.     }
  62.  
  63.     public float getX() {return body.getPosition().x * ActualGame.C + x; }
  64.     public float getY() {return body.getPosition().y * ActualGame.C + y; }
  65.     public float getAng() {return body.getAngle() * ActualGame.C + y; }
  66.  
  67. }
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. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top