- package com.intelligentprocedure.TexasTreadmill.entity;
- import com.badlogic.gdx.graphics.g2d.SpriteBatch;
- import com.badlogic.gdx.graphics.g2d.TextureRegion;
- import com.badlogic.gdx.math.Vector2;
- import com.badlogic.gdx.physics.box2d.Body;
- import com.badlogic.gdx.physics.box2d.BodyDef;
- import com.badlogic.gdx.physics.box2d.FixtureDef;
- import com.badlogic.gdx.physics.box2d.PolygonShape;
- import com.intelligentprocedure.TexasTreadmill.gamestates.ActualGame;
- import com.intelligentprocedure.TexasTreadmill.management.Assets;
- import java.util.Random;
- /**
- * Created by Justin on 8/31/2014.
- */
- public class JumpObject extends Entity {
- public Body body;
- final float WIDTH = 64;
- final float HEIGHT = 64;
- int x, y;
- int ver = 0;
- TextureRegion tex;
- public int objectType = 0;
- public JumpObject(int x, int y){
- super(7);
- this.x = x; this.y = y;
- ver = new Random().nextInt(3);
- objectType = ver;
- switch(ver){
- case 0: tex = Assets.objects.get(0); break;
- case 1: tex = Assets.objects.get(1); break; // chicken object!
- case 2: tex = Assets.objects.get(2); break;
- }
- BodyDef bDef = new BodyDef();
- bDef.type = BodyDef.BodyType.DynamicBody;
- FixtureDef fDef = new FixtureDef();
- PolygonShape pShape = new PolygonShape();
- pShape.setAsBox(WIDTH/2/ ActualGame.C, HEIGHT/2/ActualGame.C, new Vector2(x/ActualGame.C, y/ActualGame.C), 0);
- fDef.shape = pShape;
- fDef.friction = 0;
- body = ActualGame.world.createBody(bDef);
- body.createFixture(fDef);
- body.setUserData(this);
- body.setLinearVelocity(-400/ActualGame.C, 0/ActualGame.C);
- // body.setAngularVelocity(new Random().nextFloat()-.5f);
- }
- public void render(SpriteBatch sb){
- if(body != null) {
- sb.draw(tex, getX() - WIDTH / 2, getY() - HEIGHT / 2, WIDTH, HEIGHT);
- }
- }
- public float getX() {return body.getPosition().x * ActualGame.C + x; }
- public float getY() {return body.getPosition().y * ActualGame.C + y; }
- public float getAng() {return body.getAngle() * ActualGame.C + y; }
- }
SHARE
TWEET
Untitled
a guest
Sep 4th, 2014
2
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
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.
