List of usage examples for com.badlogic.gdx.math Vector2 Vector2
public Vector2(float x, float y)
From source file:com.codefiddler.libgdx.tetris.domain.Tetrimino.java
License:Apache License
public List<Vector2> getPoints() { ArrayList<Vector2> points = new ArrayList<Vector2>(); for (int[] point : blocks[blockSet]) { points.add(new Vector2(point[0], point[1])); }/*from w ww . jav a2 s . co m*/ return points; }
From source file:com.codefiddler.libgdx.tetris.WorldRenderer.java
License:Apache License
private void renderScore() { font.setScale(7, 7);/*from w w w .j ava2s.com*/ font.setColor(Color.BLACK); spriteBatch.begin(); // spriteBatch.setProjectionMatrix(camera.combined); font.draw(spriteBatch, "SCORE", 1100, VIEWPORT_HEIGHT); font.draw(spriteBatch, "" + controller.getScore(), 1100, VIEWPORT_HEIGHT - FONT_HEIGHT); font.draw(spriteBatch, "LEVEL", 1100, VIEWPORT_HEIGHT - FONT_HEIGHT * 3); font.draw(spriteBatch, "" + controller.getLevel(), 1100, VIEWPORT_HEIGHT - FONT_HEIGHT * 4); Tetrimino nextShape = controller.getNextShape(); nextShape.setPosition(new Vector2(11f, 16 - 10f)); nextShape.forEachBlock(new RenderBlock() { public void renderBlock(float x, float y, Color color) { render(x, y, color); } }); if (!controller.isGameRunning()) { font.setColor(Color.RED); font.setScale(12, 12); font.draw(spriteBatch, "GAME OVER", VIEWPORT_WIDTH / 4, (VIEWPORT_HEIGHT) / 2); } spriteBatch.end(); }
From source file:com.dagondev.drop.GameScreen.java
License:Apache License
/** * Loads data from *.json scene file and get {@link #world} object from scene. * Create all bodies except player related. *///from www . j a v a 2 s . c om private void createBodies() { RubeSceneLoader loader = new RubeSceneLoader(); RubeScene scene = loader.addScene(Gdx.files.internal(SCENE_NAME)); world = scene.getWorld(); world.setContactListener(this); //get arena boundaries //TODO: find nice way to get height/width of rectangles without getting into vertices arenaStart = new Vector2(-35, 27); arenaEnd = new Vector2(36, -32); createLights(scene); dynamicBoxes = scene.getNamed(Body.class, DYNAMIC_BOXES_NAME); for (int i = 1; i < 3; i++) { //not sure why i use i=1 instead 0 but whatever createPlayer(i); } //get cameraPosition from body and remove Body cameraPosBody = scene.getNamed(Body.class, ARENA_CAMERA_POSITION_NAME).get(0); Vector2 cameraPos = cameraPosBody.getPosition(); camera.translate(cameraPos.x - baseWidth / 2, cameraPos.y - baseHeight / 2); camera.zoom = 0.125f; world.destroyBody(cameraPosBody); //when scene is not needed anymore scene.clear(); }
From source file:com.dagondev.drop.GameScreen.java
License:Apache License
/** * Handles creation of player object. That means physic body and lights. * Should be called only after existing one (if there is any) was destroyed with {@link #playerDie(int)} . * @param i Number of player, Can be 1 or 2. Not sure why didn`t choose 0-1 *//*from w w w .ja va2 s .com*/ private void createPlayer(int i) { BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyDef.BodyType.DynamicBody; bodyDef.position.set(new Vector2(getStartXInArena(), STARTING_Y_FOR_OBJECTS)); Body body = world.createBody(bodyDef); PolygonShape shape = new PolygonShape(); shape.setAsBox(PLAYER_RADIUS, PLAYER_RADIUS); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = shape; fixtureDef.density = 1.0f; fixtureDef.friction = 0.3f; body.createFixture(fixtureDef); Color color = COLOR_PLAYER1; if (i > 1) { color = COLOR_PLAYER2; player2Body = body; } else player1Body = body; //TODO: don`t create new light where there is existing one - https://github.com/libgdx/box2dlights/wiki/Performance-Tuning - PointLight pointLight1 = new PointLight(rayHandler, (int) (MAX_RAYS_IN_LIGHTS_LOW / 1.5), color, 25, 0, 0); pointLight1.attachToBody(body, 0, 0); if (i > 1) player2Light = pointLight1; else player1Light = pointLight1; body.setUserData(i); }
From source file:com.dagondev.drop.GameScreen.java
License:Apache License
/** * Handles most of the input, by polling specific keys and contains logic that is releated to those keys. * Should be called every tick./*from www . j av a 2 s. co m*/ */ private void handleInput() { if (endOfRound) return; if (Gdx.input.isKeyPressed(Input.Keys.PAGE_DOWN)) { camera.zoom += 0.01; } if (Gdx.input.isKeyPressed(Input.Keys.PAGE_UP)) { camera.zoom -= 0.01; } if (Gdx.input.isKeyPressed(Input.Keys.LEFT)) { player2Body.applyForceToCenter(new Vector2(-MOVE_SPEED, 0), true); } if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) { player2Body.applyForceToCenter(new Vector2(MOVE_SPEED, 0), true); } if (Gdx.input.isKeyPressed(Input.Keys.UP)) { player2Body.applyForceToCenter(new Vector2(0, MOVE_SPEED + ADD_TO_UP_MOVE_SPEED), true); } if (Gdx.input.isKeyPressed(Input.Keys.W)) { player1Body.applyForceToCenter(new Vector2(0, MOVE_SPEED + ADD_TO_UP_MOVE_SPEED), true); } if (Gdx.input.isKeyPressed(Input.Keys.A)) { player1Body.applyForceToCenter(new Vector2(-MOVE_SPEED, 0), true); } if (Gdx.input.isKeyPressed(Input.Keys.D)) { player1Body.applyForceToCenter(new Vector2(MOVE_SPEED, 0), true); } }
From source file:com.dagondev.drop.GameScreen.java
License:Apache License
/** * Create all scheduled task that should be execute every X seconds. *//*from ww w. j av a 2 s.c om*/ //http://stackoverflow.com/questions/21781161/how-can-i-do-something-every-second-libgdx private void createScheduledTasks() { Timer.schedule(new Timer.Task() { @Override public void run() { for (Body body : dynamicBoxes) { if (!body.isAwake() || body.getPosition().y < DEATH_HEIGHT) { body.setTransform(new Vector2(getStartXInArena(), arenaStart.y - 1), 0); body.setAwake(true); } } } }, 0, RESPAWN_DYNAMIC_BOXES_EVERY_SECONDS); }
From source file:com.dgzt.core.Table.java
License:Open Source License
/** * The constructor./*from www .j ava 2 s.c o m*/ * * @param shader - The shader. * @param gameControl - The game control. */ public Table(final ShaderProgram shader, final GameControl gameControl) { super(shader, Color.GRAY); box2DWorld = new World(new Vector2(0, 0), true); final EventListener eventListener = new EventListener(this, gameControl); box2DWorld.setContactListener(eventListener); addBox2DWalls(); map = new Map(shader, box2DWorld, (Table.WIDTH - Map.WIDTH) / 2, (Table.HEIGHT - Map.HEIGHT) / 2); leftGate = new LeftGate(shader, box2DWorld, (Table.WIDTH - Map.WIDTH) / 2 - LeftGate.WIDTH + LineShape.LINE_WIDTH, (Table.HEIGHT - LeftGate.HEIGHT) / 2); rightGate = new RightGate(shader, box2DWorld, Table.WIDTH - (Table.WIDTH - Map.WIDTH) / 2 - LineShape.LINE_WIDTH, (Table.HEIGHT - RightGate.HEIGHT) / 2); playerButtons = new ArrayList<Button>(); opponentButtons = new ArrayList<Button>(); addButtons(shader, eventListener); ball = new Ball(this, shader, eventListener, box2DWorld, Table.WIDTH / 2, Table.HEIGHT / 2); arrow = new Arrow(this, shader); }
From source file:com.disc.jammers.boxsprite.players.Player.java
private Vector2 getMoveStep(float x, float y, float dt) { if (x < 0) { x -= dt;/*from www.j a v a 2 s. com*/ } else { x += dt; } if (y < 0) { y -= dt; } else { y += dt; } return new Vector2(x, y); }
From source file:com.disc.jammers.states.StatePlay.java
public StatePlay(GameStateManager gsm) { super(gsm);/*from w ww. j ava 2s. c om*/ eventQueue = new EventQueue(); camera.setToOrtho(false, WIDTH, HEIGHT); Gdx.input.setInputProcessor(new MyInputProcessor(eventQueue)); //Box2d Initialization world = new World(new Vector2(0, 0), true); world.setContactListener(new MyContactListener(eventQueue)); b2dr = new Box2DDebugRenderer(); manager = new GameManager(world, eventQueue); //--Sprites createBoxBoundaries(); tempBackground = new Texture("court.png"); }
From source file:com.dongbat.game.buff.effects.Forced.java
@Override public void durationStart(World world, Entity source, Entity t) { if (direction == null) { if (target != null) { direction = target.cpy().sub(PhysicsUtil.getPosition(world, t)); } else {/* w ww . j a va 2 s. c o m*/ direction = new Vector2(0, 0); } } MovementUtil.disableMovement(t); PhysicsUtil.setVelocity(world, t, new Vector2()); }