List of usage examples for com.badlogic.gdx.math Vector2 Vector2
public Vector2(float x, float y)
From source file:com.indignado.games.smariano.utils.dermetfan.math.GeometryUtils.java
License:Apache License
/** * @param floats the float[] to convert to a Vector2[] * @return the Vector2[] converted from the given float[] */// w w w . j a va2 s .c o m public static Vector2[] toVector2Array(float[] floats, Vector2[] output) { if (floats.length % 2 != 0) throw new IllegalArgumentException( "the float array's length is not dividable by two, so it won't make up a Vector2 array: " + floats.length); output = new Vector2[floats.length / 2]; int fi = -1; for (int i = 0; i < output.length; i++) output[i] = new Vector2(floats[++fi], floats[++fi]); return output; }
From source file:com.invader.collide.Loader.java
License:Open Source License
void levelLoader() { //Create and load sprites for level //Dispose Previously used global vars Constants.paused_game = 0;/*from www . j ava 2 s.c o m*/ Constants.hole.clear(); Constants.goal.clear(); Constants.coin.clear(); Constants.wall.clear(); //STart initialisation Constants.LevelScreen = new Scene(); Constants.LevelbgAtlas = new BitmapTextureAtlas(Constants.tm, 256, 256, TextureOptions.REPEATING_BILINEAR); Constants.background_grass = (TextureRegion) BitmapTextureAtlasTextureRegionFactory .createFromAsset(Constants.LevelbgAtlas, Constants.context, "ground.png", 0, 0); Constants.background_grass.setTextureHeight(Constants.CAMERA_HEIGHT); Constants.background_grass.setTextureWidth(Constants.CAMERA_WIDTH); Constants.LevelbgAtlas.load(); Constants.LevelAtlas = new BitmapTextureAtlas(Constants.tm, 650, 165); Constants.comp_sprite_texture = (TiledTextureRegion) BitmapTextureAtlasTextureRegionFactory .createTiledFromAsset(Constants.LevelAtlas, Constants.context, "comp_striker.png", 0, 27, 2, 1); //96*48 Constants.user_sprite_texture = (TiledTextureRegion) BitmapTextureAtlasTextureRegionFactory .createTiledFromAsset(Constants.LevelAtlas, Constants.context, "user_striker.png", 54, 27, 2, 1); //96x48 Constants.hole_sprite_texture = (TiledTextureRegion) BitmapTextureAtlasTextureRegionFactory .createTiledFromAsset(Constants.LevelAtlas, Constants.context, "hole.png", 0, 0, 8, 1); //750x50 Constants.wall_sprite_texture = (TiledTextureRegion) BitmapTextureAtlasTextureRegionFactory .createTiledFromAsset(Constants.LevelAtlas, Constants.context, "wall.png", 108, 27, 1, 1); Constants.goal_sprite_texture = (TextureRegion) BitmapTextureAtlasTextureRegionFactory .createFromAsset(Constants.LevelAtlas, Constants.context, "goal.png", 135, 27); Constants.menu_sprite_texture = (TextureRegion) BitmapTextureAtlasTextureRegionFactory .createFromAsset(Constants.LevelAtlas, Constants.context, "menu_but.png", 216, 0); Constants.pause_sprite_texture = (TextureRegion) BitmapTextureAtlasTextureRegionFactory .createFromAsset(Constants.LevelAtlas, Constants.context, "pause_but.png", 270, 0); Constants.play_sprite_texture = (TextureRegion) BitmapTextureAtlasTextureRegionFactory .createFromAsset(Constants.LevelAtlas, Constants.context, "play_but.png", 324, 0); Constants.reset_sprite_texture = (TextureRegion) BitmapTextureAtlasTextureRegionFactory .createFromAsset(Constants.LevelAtlas, Constants.context, "reset.png", 459, 0); Constants.next_sprite_texture = (TextureRegion) BitmapTextureAtlasTextureRegionFactory .createFromAsset(Constants.LevelAtlas, Constants.context, "next_but.png", 514, 0); Constants.prev_sprite_texture = (TextureRegion) BitmapTextureAtlasTextureRegionFactory .createFromAsset(Constants.LevelAtlas, Constants.context, "prev_but.png", 395, 0); Constants.comp_disappear_texture = (TiledTextureRegion) BitmapTextureAtlasTextureRegionFactory .createTiledFromAsset(Constants.LevelAtlas, Constants.context, "comp_disappear.png", 0, 108, 12, 1); Constants.user_disappear_texture = (TiledTextureRegion) BitmapTextureAtlasTextureRegionFactory .createTiledFromAsset(Constants.LevelAtlas, Constants.context, "user_disappear.png", 0, 54, 12, 1); Constants.LevelAtlas.load(); SpriteBackground background_sprite = new SpriteBackground( new Sprite(0, 0, Constants.background_grass, Constants.vbom)); Constants.LevelScreen.setBackground(background_sprite); Constants.physicsWorld = new PhysicsWorld(new Vector2(0, 0), false); ; Constants.physicsWorld.setContactListener(contactListener()); Constants.Enable_Listener = 1; final FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0, 0.5f, 0.5f); final Rectangle ground = new Rectangle(-2, Constants.CAMERA_HEIGHT, Constants.CAMERA_WIDTH + 4, 2, Constants.vbom); final Rectangle roof = new Rectangle(-2, -2, Constants.CAMERA_WIDTH + 4, 2, Constants.vbom); final Rectangle left = new Rectangle(-2, -2, 2, Constants.CAMERA_HEIGHT + 4, Constants.vbom); final Rectangle right = new Rectangle(Constants.CAMERA_WIDTH, -2, 2, Constants.CAMERA_HEIGHT + 4, Constants.vbom); Body b_ground = PhysicsFactory.createBoxBody(Constants.physicsWorld, ground, BodyType.StaticBody, wallFixtureDef); Body b_roof = PhysicsFactory.createBoxBody(Constants.physicsWorld, roof, BodyType.StaticBody, wallFixtureDef); Body b_left = PhysicsFactory.createBoxBody(Constants.physicsWorld, left, BodyType.StaticBody, wallFixtureDef); Body b_right = PhysicsFactory.createBoxBody(Constants.physicsWorld, right, BodyType.StaticBody, wallFixtureDef); b_ground.setUserData("GROUNDWALL"); b_roof.setUserData("ROOFWALL"); b_left.setUserData("LEFTWALL"); b_right.setUserData("RIGHTWALL"); Constants.LevelScreen.attachChild(ground); Constants.LevelScreen.attachChild(roof); Constants.LevelScreen.attachChild(left); Constants.LevelScreen.attachChild(right); Constants.menu = new Sprite(0, 0, Constants.menu_sprite_texture, Constants.vbom); Constants.resume = new Sprite(Constants.CAMERA_WIDTH - 54, 0, Constants.play_sprite_texture, Constants.vbom); Constants.pause = new Sprite(Constants.CAMERA_WIDTH - 54, 0, Constants.pause_sprite_texture, Constants.vbom); Constants.reset = new Sprite(381, 0, Constants.reset_sprite_texture, Constants.vbom); Constants.next = new Sprite(543, 0, Constants.next_sprite_texture, Constants.vbom); Constants.prev = new Sprite(219, 0, Constants.prev_sprite_texture, Constants.vbom); Constants.pause.setAlpha(0.7f); Constants.menu.setAlpha(0.7f); Constants.resume.setAlpha(0.7f); Constants.reset.setAlpha(0.7f); Constants.next.setAlpha(0.7f); Constants.prev.setAlpha(0.7f); Constants.NO_USER = 0; //Load Level try { Scanner in; Log.e("LOADING", String.valueOf(Constants.CUR_LEVEL)); try { in = new Scanner( new InputStreamReader(Constants.context.getAssets().open("level/" + Constants.CUR_LEVEL))); } catch (Exception e) { in = new Scanner(new InputStreamReader(Constants.context.getAssets().open("level/finallevel"))); } for (int i = 0; i < 20; i++) for (int j = 0; j < 30; j++) { String inp = in.next(); if (inp.compareTo("enemy") == 0) Constants.coin.add(new Coin("COMP", j * 27, 24 * i, false)); else if (inp.compareTo("user") == 0) { Constants.coin.add(new Coin("USER", j * 27, 24 * i, false)); Constants.NO_USER++; } else if (inp.compareTo("wall") == 0) Constants.wall.add(new Wall(j * 27, 24 * i)); else if (inp.compareTo("hole") == 0) Constants.hole.add(new Hole(j * 27, i * 24)); else if (inp.compareTo("goal") == 0) Constants.goal.add(new Goal(j * 27, i * 24)); else if (inp.compareTo("stat") == 0) Constants.coin.add(new Coin("COMP", j * 27, 24 * i, true)); //Log.e("READ",inp+" "+i+" "+j); } } catch (IOException e1) { e1.printStackTrace(); } Constants.LevelScreen.attachChild(Constants.menu); Constants.LevelScreen.attachChild(Constants.pause); Constants.LevelScreen.attachChild(Constants.prev); Constants.LevelScreen.attachChild(Constants.next); Constants.LevelScreen.attachChild(Constants.reset); Constants.resume.setVisible(false); if (Constants.CUR_LEVEL == Constants.getLevel()) Constants.next.setVisible(false); if (Constants.CUR_LEVEL == 0) Constants.prev.setVisible(false); Constants.LevelScreen.attachChild(Constants.resume); Constants.load_inprogress = 2; }
From source file:com.jemge.box2d.Physics2D.java
License:Apache License
@Override public void init() { worlds = new HashMap<String, World>(1); worlds.put("main", new World(new Vector2(0, -20f), true)); }
From source file:com.jmolina.orb.elements.LinearMagnetic.java
License:Open Source License
/** * Punto de inicio del segmento.//w ww .j a va 2 s. co m */ private Vector2 getStart() { float startX = getPosition().x + 0.5f * getWidth() * MathUtils.cosDeg(180 + getRotation()); float startY = getPosition().y + 0.5f * getWidth() * MathUtils.sinDeg(180 + getRotation()); return new Vector2(startX, startY); }
From source file:com.jmolina.orb.elements.LinearMagnetic.java
License:Open Source License
/** * Punto de fin del segmento./*from ww w.j a va2 s .co m*/ */ private Vector2 getEnd() { float endX = getPosition().x + 0.5f * getWidth() * MathUtils.cosDeg(getRotation()); float endY = getPosition().y + 0.5f * getWidth() * MathUtils.sinDeg(getRotation()); return new Vector2(endX, endY); }
From source file:com.jmolina.orb.elements.LinearMagnetic.java
License:Open Source License
/** * Devuelve la fuerza que ejerce este elemento sobre un punto dado. * * La fuerza es cero si la proyeccin del punto sobre el eje del elemento cae fuera del segmento * del elemento./*from w ww . ja v a 2s. c om*/ * * @param point Punto expresado en unidades del mundo */ @Override public Vector2 getForce(Vector2 point) { Vector2 force = new Vector2(0, 0); if (closeRange(point)) { if (insideField(point)) { float factor = MAX_FORCE * (getThreshold() - distanceLine(point)) / getThreshold(); force.set(Utils.normal(getSegment())); force.scl(factor); if (getPolarity() == Polarity.REPULSIVE) force.scl(-1); } } return force; }
From source file:com.jmolina.orb.elements.RadialMagnetic.java
License:Open Source License
/** * Devuelve la fuerza que ejerce este elemento sobre un punto dado. * <p>/*from www. j a v a2 s.c om*/ * La frmula de la atraccin est simplificada: * - Slo depende de la inversa de la distancia, siempre que el punto haya sobrepasado el umbral. * - Slo se computan los centroides (i.e. no se atrae el Orb si su centroide no cae dentro del * campo de actuacin). * * @param point Punto expresado en unidades del mundo */ @Override public Vector2 getForce(Vector2 point) { Vector2 force = new Vector2(0, 0); if (belowThreshold(point)) { float factor = MAX_FORCE * (getThreshold() - distance(point)) / getThreshold(); Vector2 direction = getPosition().sub(point).nor(); force.set(direction).scl(factor); if (getPolarity() == Polarity.REPULSIVE) force.scl(-1); } return force; }
From source file:com.jmolina.orb.elements.WorldElement.java
License:Open Source License
/** * Crea un tringulo equiltero de lado {@link #width}. El parmetro {@link #height} se ignora. * El punto de origen es su centroide (punto de cruce de las 3 alturas). *///from w ww . j a v a 2 s . c o m private Shape triangle() { Vector2[] points = new Vector2[3]; points[0] = new Vector2(-0.5f * width, -width * MathUtils.sinDeg(60) / 3); points[1] = new Vector2(0.5f * width, -width * MathUtils.sinDeg(60) / 3); points[2] = new Vector2(0, width * MathUtils.sinDeg(60) / 3 * 2); PolygonShape shape = new PolygonShape(); shape.set(points); return shape; }
From source file:com.jmolina.orb.elements.WorldElement.java
License:Open Source License
/** * Devuelve la posicion actual del elemento *///from w ww . java 2s .c om public Vector2 getPosition() { return new Vector2(getBody().getPosition().x, getBody().getPosition().y); }
From source file:com.jmolina.orb.screens.Level.java
License:Open Source License
/** * Calcula las fuerzas de atraccin y repulsin activas sobre el orbe y las aplica. *///from w w w . j a v a 2s .c om private void computeMagneticFoces() { Vector2 force = new Vector2(0, 0); for (Situation situation : situationManager.getVisible()) { for (Element element : situation.getElements()) { if (element instanceof Magnetic) { Vector2 partial = ((Magnetic) element).getForce(getOrb().getPosition()); force.add(partial); } } } getOrb().getBody().applyLinearImpulse(force, getOrb().getPosition(), true); }