List of usage examples for com.badlogic.gdx.math Vector2 scl
public Vector2 scl(float x, float y)
From source file:br.cefetmg.games.minigames.CollectItens.java
private void spawnLollipop() { // pega x e y entre 0 e 1 Vector2 position = new Vector2(rand.nextFloat(), rand.nextFloat()); if (quantAtualLollipops < totalLollipops) { // multiplica x e y pela largura e altura da tela position.scl( this.screen.viewport.getScreenWidth() - lollipopTexture.getWidth() * initialCharactersScale, this.screen.viewport.getScreenHeight() - lollipopTexture.getHeight() * initialCharactersScale); Sprite lollipop = new Sprite(lollipopTexture); lollipop.setPosition(position.x, position.y); lollipop.setScale(initialCharactersScale); this.characters.add(lollipop); this.enemiesAppearing.play(); }/*from w w w .j a v a 2s . c om*/ }
From source file:br.cefetmg.games.minigames.CollectItens.java
private void spawnCandy() { // pega x e y entre 0 e 1 Vector2 position = new Vector2(rand.nextFloat(), rand.nextFloat()); if (quantAtualCandies < totalCandies) { // multiplica x e y pela largura e altura da tela position.scl(this.screen.viewport.getScreenWidth() - candyTexture.getWidth() * initialCharactersScale, this.screen.viewport.getScreenHeight() - candyTexture.getHeight() * initialCharactersScale); Sprite candy = new Sprite(candyTexture); candy.setPosition(position.x, position.y); candy.setScale(initialCharactersScale); this.characters.add(candy); friends++;//from w ww . j a v a 2 s . co m // toca um efeito sonoro this.enemiesAppearing.play(); } }
From source file:br.cefetmg.games.minigames.CollectItens.java
private void spawnToothpaste() { // pega x e y entre 0 e 1 Vector2 position = new Vector2(rand.nextFloat(), rand.nextFloat()); if (quantAtualToothpaste < totalToothpaste) { // multiplica x e y pela largura e altura da tela position.scl( this.screen.viewport.getScreenWidth() - toothpasteTexture.getWidth() * initialCharactersScale, this.screen.viewport.getScreenHeight() - toothpasteTexture.getHeight() * initialCharactersScale); Sprite toothpaste = new Sprite(toothpasteTexture); toothpaste.setPosition(position.x, position.y); toothpaste.setScale(initialCharactersScale); this.characters.add(toothpaste); // toca um efeito sonoro this.friendsAppearing.play(); friends++;/*from ww w . j a va 2s . c o m*/ } }
From source file:br.cefetmg.games.minigames.CollectItens.java
private void spawnToothbrush() { // pega x e y entre 0 e 1 Vector2 position = new Vector2(rand.nextFloat(), rand.nextFloat()); if (quantAtualToothbrush < totalToothbrush) { // multiplica x e y pela largura e altura da tela position.scl( this.screen.viewport.getScreenWidth() - toothbrushTexture.getWidth() * initialCharactersScale, this.screen.viewport.getScreenHeight() - toothbrushTexture.getHeight() * initialCharactersScale); Sprite toothbrush = new Sprite(toothbrushTexture); toothbrush.setPosition(position.x, position.y); toothbrush.setScale(initialCharactersScale); this.characters.add(toothbrush); }//from www. j a va 2 s.co m // toca um efeito sonoro this.friendsAppearing.play(); }
From source file:br.cefetmg.games.minigames.EscoveOsDentes.java
private void spawnEnemy() { // pega x e y entre 0 e 1 Vector2 position = new Vector2(rand.nextFloat(), rand.nextFloat()); // multiplica x e y pela largura e altura da tela position.scl(this.screen.viewport.getWorldWidth() - toothTexture.getWidth() * initialToothScale, this.screen.viewport.getWorldHeight() - toothTexture.getHeight() * initialToothScale); Sprite enemy = new Sprite(toothTexture); Escova novo = new Escova(); enemy.setPosition(position.x, position.y); enemy.setScale(minimumToothScale);// w w w . j a v a2 s .c o m Tooths.add(enemy); Escovar.add(novo); }
From source file:br.cefetmg.games.minigames.OrientacaoSnake.java
private void spawnEnemy() { // pega x e y entre 0 e 1 Vector2 position = new Vector2(rand.nextFloat(), rand.nextFloat()); // multiplica x e y pela largura e altura da tela position.scl(this.screen.viewport.getWorldWidth() - cariesTexture.getWidth(), this.screen.viewport.getWorldHeight() - cariesTexture.getHeight()); Sprite enemy = new Sprite(cariesTexture); enemy.setPosition(position.x, position.y); enemies.add(enemy);/*w w w . j av a2s . c o m*/ }
From source file:es.eucm.ead.engine.systems.positiontracking.ChaseEntitySystem.java
License:Open Source License
private void move(EngineEntity chasing, EngineEntity target, float speedX, float speedY, boolean fromBorder) { /*/* w w w. ja v a 2s. c o m*/ * Calculate distance vector. It is a vector that has the direction of * distance vector between target and chasing entities, and module * equals to the speed calculated */ Vector2 distanceVector = Pools.obtain(Vector2.class); BoundingAreaComponent targetBoundingArea = getBoundingArea(target); BoundingAreaComponent chasingBoundingArea = getBoundingArea(chasing); chasingBoundingArea.distanceTo(targetBoundingArea, distanceVector, fromBorder); float l = distanceVector.len(); distanceVector.scl(speedX / l, speedY / l); // Move chasing.getGroup().moveBy(distanceVector.x, distanceVector.y); Pools.free(distanceVector); }
From source file:org.ams.core.CameraNavigator.java
License:Open Source License
/** * @param screenX pixel.// w w w .j a v a 2 s . c o m * @param screenY pixel. * @return position of touch in "world units", with center of screen as origin. */ public Vector2 getPositionOfTouch(float screenX, float screenY) { float halfWidth = Gdx.graphics.getWidth() * 0.5f; float halfHeight = Gdx.graphics.getHeight() * 0.5f; Vector2 pos = new Vector2(screenX - halfWidth, halfHeight - screenY); pos.scl(1f / halfWidth, 1f / halfHeight); pos.scl(camera.zoom); // convert to world units relative to center of screen pos.scl(camera.viewportWidth * 0.5f, camera.viewportHeight * 0.5f); return pos; }
From source file:org.ams.core.CoordinateHelper.java
License:Open Source License
public static Vector2 getWorldCoordinates(OrthographicCamera camera, float screenX, float screenY) { float halfWidth = Gdx.graphics.getWidth() * 0.5f; float halfHeight = Gdx.graphics.getHeight() * 0.5f; Vector2 pos = new Vector2(screenX - halfWidth, halfHeight - screenY); pos.scl(1f / halfWidth, 1f / halfHeight); pos.scl(camera.zoom);/* w ww .j a v a 2 s . c om*/ // convert to world units relative to center of screen pos.scl(camera.viewportWidth * 0.5f, camera.viewportHeight * 0.5f); return pos.add(camera.position.x, camera.position.y); }
From source file:org.ams.testapps.paintandphysics.cardhouse.Tips.java
License:Open Source License
/** * Instantly show a tip on the screen.// w ww. j av a 2 s . c o m * * @param key String for remembering whether to display this tips in the feature. * @param text The tips. * @param arrowTo If not null an arrow will point to this location. */ private void showTip(final String key, final String text, final ChangingVector arrowTo) { if (debug) debug("Showing tip with key " + key + "."); final Array<OutlinePolygon> arrow = new Array<OutlinePolygon>(); stage.getActors().removeValue(window, true); // update this tip on resize Tips.this.onResize = new Runnable() { @Override public void run() { arrows.removeAll(arrow, true); stage.getActors().removeValue(window, true); showTip(key, text, arrowTo); } }; // prepare text table Label label = new Label(text, skin); label.setColor(Color.BLACK); Table textTable = new Table(); textTable.add(label); // prepare button table TextButton hide = new TextButton("Hide", skin); hide.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { stage.getActors().removeValue(window, true); arrows.removeAll(arrow, true); showNextTip(); } }); TextButton ok = new TextButton("Got It", skin); ok.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { stage.getActors().removeValue(window, true); arrows.removeAll(arrow, true); preferences.putBoolean(key, true); preferences.flush(); showNextTip(); } }); Table buttonTable = new Table(); buttonTable.add(hide).pad(SceneUtil.getPreferredPadding(stage)); buttonTable.add(ok).pad(SceneUtil.getPreferredPadding(stage)); // put it all in table Table mainTable = new Table(); mainTable.add(textTable).row(); mainTable.add(buttonTable); // prepare arrow if (arrowTo != null) { float sw = stage.getWidth(); float sh = stage.getHeight(); // figure out where to start the arrow Vector2 arrowFrom = new Vector2(mainTable.getPrefWidth() * 0.5f, 0); Vector2 v = new Vector2(arrowTo.get()).sub(sw * 0.5f, sh * 0.5f); arrowFrom.rotateRad(v.angleRad()); arrowFrom.add(sw * 0.5f, sh * 0.5f); arrowFrom.scl(1, -1).add(0, sh); // convert to world coordinates Vector2 screenCoordinates = stage.stageToScreenCoordinates(arrowFrom); Vector2 from = CoordinateHelper.getWorldCoordinates(arrowCamera, screenCoordinates.x, screenCoordinates.y); // we know where to end the arrow, just convert to world coordinates screenCoordinates = stage.stageToScreenCoordinates(new Vector2(arrowTo.get()).scl(1, -1).add(0, sh)); Vector2 to = CoordinateHelper.getWorldCoordinates(arrowCamera, screenCoordinates.x, screenCoordinates.y); // make and save arrow arrow.addAll(makeArrow(from, to)); arrows.addAll(arrow); } window = new Window("", skin); window.setBackground(new TextureRegionDrawable(skin.getRegion("gray"))); window.add(mainTable).center(); window.setSize(mainTable.getPrefWidth(), mainTable.getPrefHeight()); // center on stage float x = stage.getWidth() * 0.5f; float y = stage.getHeight() * 0.5f; window.setPosition(x, y, Align.center); stage.addActor(window); }