List of usage examples for com.badlogic.gdx.math Vector2 Vector2
public Vector2(float x, float y)
From source file:com.jmolina.orb.stages.GestureStage.java
License:Open Source License
/** * Convierte de unidades en pantalla a unidades en el viewport. Esto normalmente se hace * mediante Camera#unproject(), pero no estaba funcionando correctamente por algun motivo. * * Si el punto recae dentro del area usable pero fuera del viewport (que es de proporcion * fija), se considera que la posicion es limite. * * @param screenX Coordenada X de un punto en pantalla * @param screenY Coordenada Y de un punto en pantalla *//* w w w .j a v a 2 s . c o m*/ private Vector2 translate(int screenX, int screenY) { float offsetX = 0.5f * ((float) Gdx.graphics.getWidth() - (float) vp.getScreenWidth()); float offsetY = 0.5f * ((float) Gdx.graphics.getHeight() - (float) vp.getScreenHeight()); int x = (int) (screenX - offsetX); int y = (int) ((Gdx.graphics.getHeight() - screenY) - offsetY); x = MathUtils.clamp(x, 0, vp.getScreenWidth()); y = MathUtils.clamp(y, 0, vp.getScreenHeight()); float ratioX = (vp.getWorldWidth() / (float) vp.getScreenWidth()); float ratioY = (vp.getWorldHeight() / (float) vp.getScreenHeight()); x = (int) (ratioX * x); y = (int) (ratioY * y); return new Vector2(x, y); }
From source file:com.jmolina.orb.var.Utils.java
License:Open Source License
/** * Calcula la normal a un vector/*from www . ja v a 2 s . c o m*/ * * @param vector Vector * @return Vector normal */ public static Vector2 normal(Vector2 vector) { Vector2 normal = new Vector2(vector.y, -vector.x); normal.nor(); return normal; }
From source file:com.jmolina.orb.widgets.game.Arrow.java
License:Open Source License
/** * Fija el punto de inicio y fin de la flecha * * @param start Punto de inicio en pixeles * @param end Punto de fin en pixeles/*from www. j av a2 s .c om*/ */ public void set(Vector2 start, Vector2 end) { Vector2 direction; float angle, distance; base.setPosition(start.x - 0.5f * base.getWidth(), start.y - 0.5f * base.getHeight()); arrowhead.setPosition(end.x - 0.5f * arrowhead.getWidth(), end.y - 0.5f * arrowhead.getHeight()); direction = new Vector2(end.x - start.x, end.y - start.y); angle = MathUtils.radiansToDegrees * MathUtils.atan2(direction.y, direction.x); distance = (float) Math.sqrt(direction.x * direction.x + direction.y * direction.y); arrowhead.setRotation(angle); line.setRotation(angle); line.setScaleX(distance / line.getWidth()); line.setPosition(0.5f * (base.getX() + arrowhead.getX()), 0.5f * (base.getY() + arrowhead.getY())); }
From source file:com.jmstudios.pointandhit.GameScreen.java
License:Open Source License
public GameScreen(final OneShotGame game) { this.game = game; this.scale = game.scale; batch = new SpriteBatch(); shapeRenderer = new ShapeRenderer(); scoreFont = new BitmapFont(Gdx.files.internal("fonts/deja_vu_sans_large.fnt")); scoreFont.setColor(Color.WHITE); scoreFont.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear); scoreFont.setScale(scale);//from w w w. j a v a 2 s. c om heartTex = new Texture(Gdx.files.internal("heart.png")); screenSize = new Vector2(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); setupMenus(); // Set up multiplexers gameRunningMultiplexer = new InputMultiplexer(); gameRunningMultiplexer.addProcessor(gameRunningStage); gameRunningMultiplexer.addProcessor(this); gamePausedMultiplexer = new InputMultiplexer(); gamePausedMultiplexer.addProcessor(pauseStage); gamePausedMultiplexer.addProcessor(this); gameOverMultiplexer = new InputMultiplexer(); gameOverMultiplexer.addProcessor(gameOverStage); gameOverMultiplexer.addProcessor(this); }
From source file:com.jmstudios.pointandhit.MainMenuScreen.java
License:Open Source License
public MainMenuScreen(final OneShotGame game) { this.game = game; this.stage = new Stage(); this.scale = game.scale; this.table = new Table(); this.buttonsTable = new Table(); table.setFillParent(true);/*www . jav a2 s .com*/ //buttonsTable.setDebug(true); stage.addActor(table); float padding = 40 * scale; Vector2 screenSize = new Vector2(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); BitmapFont titleFont = new BitmapFont(Gdx.files.internal("fonts/deja_vu_sans_large.fnt")); titleFont.setScale(scale); Label.LabelStyle titleLabelStyle = new Label.LabelStyle(titleFont, Color.WHITE); titleText = new Label("Point & Hit", titleLabelStyle); titleText.setWrap(true); titleText.setWidth(screenSize.x - padding * 2); titleText.setAlignment(Align.center); // Set up buttons Texture buttonsTex = game.buttons; Texture bigPlayButton = new Texture(Gdx.files.internal("buttons/play_button.png")); TextureRegion playTex = new TextureRegion(bigPlayButton), optionsTex = new TextureRegion(buttonsTex, 0, 256, 256, 256), tutorialTex = new TextureRegion(buttonsTex, 768, 0, 256, 256), exitTex = new TextureRegion(buttonsTex, 256, 256, 256, 256); TextureRegionDrawable playDrawable = new TextureRegionDrawable(playTex), optionsDrawable = new TextureRegionDrawable(optionsTex), tutorialDrawable = new TextureRegionDrawable(tutorialTex), exitDrawable = new TextureRegionDrawable(exitTex); playButton = new ImageButton(playDrawable); optionsButton = new ImageButton(optionsDrawable); tutorialButton = new ImageButton(tutorialDrawable); exitButton = new ImageButton(exitDrawable); // Set up buttonsTable buttonsTable.defaults().pad(padding); buttonsTable.add(playButton).colspan(3).center().padBottom(2.5f * padding) .width(scale * playButton.getWidth()).height(scale * playButton.getHeight()); buttonsTable.row(); buttonsTable.add(tutorialButton).width(scale * tutorialButton.getWidth()) .height(scale * tutorialButton.getHeight()); buttonsTable.add(optionsButton).width(scale * optionsButton.getWidth()) .height(scale * optionsButton.getHeight()); // Title table.defaults().pad(padding); table.add(titleText).width(screenSize.x - padding * 2).center(); table.row(); table.add(buttonsTable).center(); // Listeners tutorialButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { game.setScreen(new TutorialScreen(game, false)); } }); playButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { if (game.preferences.getBoolean("tutorial", false)) { game.setScreen(game.getGameScreen()); } else { game.setScreen(new TutorialScreen(game, false)); } } }); optionsButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { game.setScreen(new OptionsScreen(game)); } }); exitButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { game.setScreen(new CreditsScreen(game)); } }); }
From source file:com.jmstudios.pointandhit.NoCompassScreen.java
License:Open Source License
@Override public void show() { stage = new Stage(); table = new Table(); float padding = 50 * scale; BitmapFont font = new BitmapFont(Gdx.files.internal("fonts/deja_vu_sans_medium.fnt")); Vector2 screenSize = new Vector2(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); font.setScale(scale);/* w w w .j ava2 s.c om*/ Label.LabelStyle labelStyle = new Label.LabelStyle(font, Color.WHITE); messageLabel = new Label(text, labelStyle); messageLabel.setWrap(true); messageLabel.setWidth(screenSize.x - padding * 2); messageLabel.setAlignment(Align.center); table.setFillParent(true); table.defaults().pad(padding); table.add(messageLabel).width(screenSize.x - padding * 2); stage.addActor(table); }
From source file:com.jmstudios.pointandhit.OptionsScreen.java
License:Open Source License
public OptionsScreen(final OneShotGame game) { this.game = game; this.scale = game.scale; Vector2 screenSize = new Vector2(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); // Font/* ww w . j av a 2 s. co m*/ textFont = new BitmapFont(Gdx.files.internal("fonts/deja_vu_sans_medium.fnt")); textFont.setScale(scale); BitmapFont titleFont = new BitmapFont(Gdx.files.internal("fonts/deja_vu_sans_large.fnt")); titleFont.setScale(scale); // Checkbox style Texture checkBoxes = new Texture(Gdx.files.internal("buttons/radiobutton.png")); TextureRegionDrawable checkBoxUnchecked = new TextureRegionDrawable( new TextureRegion(checkBoxes, 0, 0, 64, 64)); TextureRegionDrawable checkBoxChecked = new TextureRegionDrawable( new TextureRegion(checkBoxes, 64, 0, 64, 64)); checkBoxStyle = new CheckBox.CheckBoxStyle(checkBoxUnchecked, checkBoxChecked, textFont, Color.WHITE); CheckBox verySensitive = newRadioButton("Very sensitive"), sensitive = newRadioButton("Sensitive"), normal = newRadioButton("Normal"), forgiving = newRadioButton("Forgiving"), veryForgiving = newRadioButton("Very forgiving"), invertControls = newRadioButton("Invert the controls"); sensitivityGroup = new ButtonGroup<CheckBox>(verySensitive, sensitive, normal, forgiving, veryForgiving, invertControls); int startSetting = game.preferences.getInteger("sensitivity", 2); sensitivityGroup.uncheckAll(); sensitivityGroup.getButtons().get(startSetting).setChecked(true); float padding = 20 * scale; // Title Table titleTable = new Table(); titleTable.align(Align.topLeft); Pixmap backgroundPixmap = new Pixmap(1, 1, Format.RGBA8888); backgroundPixmap.setColor(new Color(0.9f, 0.35f, 0.1f, 1)); backgroundPixmap.fill(); titleTable.setBackground(new TextureRegionDrawable(new TextureRegion(new Texture(backgroundPixmap)))); Label.LabelStyle titleLabelStyle = new Label.LabelStyle(titleFont, Color.WHITE); Label titleLabel = new Label("Control sensitivity", titleLabelStyle); titleLabel.setWrap(true); titleLabel.setWidth(screenSize.x - padding * 2); titleLabel.setAlignment(Align.center); titleTable.add(titleLabel).align(Align.topLeft).pad(2 * padding).width(screenSize.x - padding * 2); // Checkboxes optionsTable = new Table(); optionsTable.align(Align.topLeft); optionsTable.defaults().align(Align.topLeft).pad(padding).padBottom(0).padLeft(2 * padding); optionsTable.row(); optionsTable.add(verySensitive); optionsTable.row(); optionsTable.add(sensitive); optionsTable.row(); optionsTable.add(normal); optionsTable.row(); optionsTable.add(forgiving); optionsTable.row(); optionsTable.add(veryForgiving); optionsTable.row(); optionsTable.add(invertControls); optionsTable.addListener(new ClickListener() { public void clicked(InputEvent event, float x, float y) { int newSensitivity = sensitivityGroup.getCheckedIndex(); if (newSensitivity == -1) newSensitivity = 2; game.preferences.putInteger("sensitivity", newSensitivity); game.preferences.flush(); } }); mainTable = new Table(); mainTable.setFillParent(true); mainTable.align(Align.top); mainTable.add(titleTable).pad(0).padBottom(padding * 4).fill(10, 1).align(Align.topLeft); mainTable.row(); mainTable.add(optionsTable).align(Align.left); mainStage = new Stage(); mainStage.addActor(mainTable); // Input inputMultiplexer = new InputMultiplexer(); inputMultiplexer.addProcessor(mainStage); inputMultiplexer.addProcessor(this); }
From source file:com.jmstudios.pointandhit.ShootAnimation.java
License:Open Source License
public void update() { if (shooting) { shootingTimeLeft -= Gdx.graphics.getDeltaTime(); currentRadius = minRadius// w ww. j a va 2 s . c o m + (int) ((float) (maxRadius - minRadius) * Math.pow((shootingTimeLeft / shootingDuration), 2)); int centerX = width / 2, centerY = height / 2; currentX = targetX + (int) ((float) (centerX - targetX) * Math.pow((shootingTimeLeft / shootingDuration), 2)); currentY = targetY + (int) ((float) (centerY - targetY) * Math.pow((shootingTimeLeft / shootingDuration), 2)); } else if (active) { scoreTimeLeft -= Gdx.graphics.getDeltaTime(); } if (shootingTimeLeft <= 0 && shooting && active) { shooting = false; int extraScore = targetManager.hit(new Vector2(targetX, targetY)); if (extraScore != 0) { int index = extraScore - (extraScore > 3 ? 2 : 1); currentScoreTexture = scoreTextures[index]; scoreTimeLeft = scoreDuration; active = true; } else { active = false; } } if (scoreTimeLeft <= 0 && !shooting && active) { active = false; } }
From source file:com.jmstudios.pointandhit.TargetManager.java
License:Open Source License
private Vector2 randomSpawnLocation() { int x = randomGenerator.nextInt(higherX - lowerX) + lowerX; int y = randomGenerator.nextInt(higherY - lowerY) + lowerY; return new Vector2(x, y); }
From source file:com.jmstudios.pointandhit.TutorialScreen.java
License:Open Source License
public TutorialScreen(final OneShotGame game, boolean automatic) { this.game = game; this.automatic = automatic; this.scale = game.scale; batch = new SpriteBatch(); shapeRenderer = new ShapeRenderer(); screenSize = new Vector2(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); textFont = new BitmapFont(Gdx.files.internal("fonts/deja_vu_sans_medium.fnt")); textFont.setScale(scale);/*from www.j a va 2 s.com*/ infoLabelStyle = new Label.LabelStyle(textFont, Color.WHITE); tapToLabelStyle = new Label.LabelStyle(textFont, Color.LIGHT_GRAY); // Step 1 float padding = 50 * scale; step1Stage = new Stage(); step1Table = new Table(); step1Table.setFillParent(true); step1Table.align(Align.bottomLeft); step1TiltInfo = new Label(tiltInfo, infoLabelStyle); step1TiltInfo.setWrap(true); step1TiltInfo.setWidth(screenSize.x - padding * 2); step1TiltInfo.setAlignment(Align.center); step1TapInfo = new Label(tapInfo, infoLabelStyle); step1TapInfo.setWrap(true); step1TapInfo.setWidth(screenSize.x - padding * 2); step1TapInfo.setAlignment(Align.center); step1TapToContinue = new Label(tapToContinue, tapToLabelStyle); step1TapToContinue.setWrap(true); step1TapToContinue.setWidth(screenSize.x - padding * 2); step1TapToContinue.setAlignment(Align.center); step1Table.defaults().pad(padding); step1Table.add(step1TiltInfo).width(screenSize.x - padding * 2); step1Table.row(); step1Table.add(step1TapInfo).width(screenSize.x - padding * 2); step1Table.row(); step1Table.add(step1TapToContinue).width(screenSize.x - padding * 2); step1Stage.addActor(step1Table); // Step 2 step2Stage = new Stage(); step2Table = new Table(); step2Table.setFillParent(true); step2Table.align(Align.bottomLeft); step2ObjectiveInfo = new Label(objectiveInfo, infoLabelStyle); step2ObjectiveInfo.setWrap(true); step2ObjectiveInfo.setWidth(screenSize.x - padding * 2); step2ObjectiveInfo.setAlignment(Align.center); step2ShootToContinue = new Label(shootToContinueInfo, tapToLabelStyle); step2ShootToContinue.setWrap(true); step2ShootToContinue.setWidth(screenSize.x - padding * 2); step2ShootToContinue.setAlignment(Align.center); step2Table.defaults().pad(padding); step2Table.add(step2ObjectiveInfo).width(screenSize.x - padding * 2); step2Table.row(); step2Table.add(step2ShootToContinue).width(screenSize.x - padding * 2); step2Stage.addActor(step2Table); // Done doneStage = new Stage(); doneTable = new Table(); doneTable.setFillParent(true); doneTable.align(Align.left); doneEndMessage = new Label(endMessage, infoLabelStyle); doneEndMessage.setWrap(true); doneEndMessage.setWidth(screenSize.x - padding * 2); doneEndMessage.setAlignment(Align.center); if (automatic) { tapToPlay = "Tap to finish..."; } doneTapToInfo = new Label(tapToPlay, tapToLabelStyle); doneTapToInfo.setWrap(true); doneTapToInfo.setWidth(screenSize.x - padding * 2); doneTapToInfo.setAlignment(Align.center); doneTable.defaults().pad(padding); doneTable.add(doneEndMessage).width(screenSize.x - padding * 2); doneTable.row(); doneTable.add(doneTapToInfo).width(screenSize.x - padding * 2); doneStage.addActor(doneTable); }