@Override public boolean touchUp(int x, int y, int pointer, int button) { System.out.println("powered: " + powered.getX() + " " + powered.getY()); System.out.println("gdx: " + gdx.getX() + " " + gdx.getY()); System.out.println(); return true; }
@Override public void render(float delta) { begin1.setColor(color); begin2.setColor(rayColor); mid1.setColor(color); mid2.setColor(rayColor); end1.setColor(color); end2.setColor(rayColor); mid1.setSize(mid1.getWidth(), len); mid2.setSize(mid1.getWidth(), len); begin1.setPosition(positon.x, positon.y); begin2.setPosition(positon.x, positon.y); mid1.setPosition(begin1.getX(), begin1.getY() + begin1.getHeight()); mid2.setPosition(begin1.getX(), begin1.getY() + begin1.getHeight()); end1.setPosition(begin1.getX(), begin1.getY() + begin1.getHeight() + mid1.getHeight()); end2.setPosition(begin1.getX(), begin1.getY() + begin1.getHeight() + mid1.getHeight()); begin1.setOrigin(begin1.getWidth() / 2, 0); begin2.setOrigin(begin1.getWidth() / 2, 0); mid1.setOrigin(mid1.getWidth() / 2, -begin1.getHeight()); mid2.setOrigin(mid2.getWidth() / 2, -begin1.getHeight()); end1.setOrigin(mid1.getWidth() / 2, -begin1.getHeight() - mid1.getHeight()); end2.setOrigin(mid2.getWidth() / 2, -begin1.getHeight() - mid2.getHeight()); begin1.setRotation(degrees); begin2.setRotation(degrees); mid1.setRotation(degrees); mid2.setRotation(degrees); end1.setRotation(degrees); end2.setRotation(degrees); Engine.getSpriteBatch().setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE); begin1.draw(Engine.getSpriteBatch()); begin2.draw(Engine.getSpriteBatch()); mid1.draw(Engine.getSpriteBatch()); mid2.draw(Engine.getSpriteBatch()); end1.draw(Engine.getSpriteBatch()); end2.draw(Engine.getSpriteBatch()); Engine.getSpriteBatch().setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); }
@Override public void create() { final float w = Gdx.graphics.getWidth(); final float h = Gdx.graphics.getHeight(); // create the camera and the SpriteBatch camera = new OrthographicCamera(); camera.setToOrtho(false, w, h); viewport = new FitViewport(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, camera); batch = new SpriteBatch(); img = new Texture(Gdx.files.internal("playerSprite_1.png")); // create a new sprite based on our image sprite = new Sprite(img); sprite.setPosition(ScreenWidth / 2 - playerWidth, ScreenHeight / 2 - playerHeight); tiledMap = new TmxMapLoader().load("ritualsite.tmx"); tiledMapRenderer = new OrthogonalTiledMapRendererWithSprites(tiledMap); tiledMapRenderer.addSprite(sprite); Gdx.input.setInputProcessor(this); targetPos = new Vector2(sprite.getX(), sprite.getY()); // create a sprite batch batch = new SpriteBatch(); direction = new Vector2(); playerDirection = new Vector2(); getCollidingRects(); }
@Override public int getValues(Sprite sprite, int i, float[] floats) { switch (Mode.values()[i]) { case SCALE: floats[0] = sprite.getScaleX(); return 1; case ALPHA: floats[0] = sprite.getColor().a; return 1; case POSITION: floats[0] = sprite.getX(); floats[1] = sprite.getY(); return 2; case ROTATION: floats[0] = sprite.getRotation(); return 1; default: assert false; return -1; } }
public void render() { // the artistic drawing function that draws everything out (such talent) // make the frame ticker thing that actually makes pretty pictures move // in this case you are updating the world you just made // apparently you aren't suppose to update this in the render loop but w/e // also have no idea what 6 & 2 mean so again w/e (sensai plssss) world.step(Gdx.graphics.getDeltaTime(), 6, 2); // move the sprite with the body! sprite.setPosition(body.getPosition().x, body.getPosition().y); // just a limit for when it falls off the screen since there is no ground LOL System.out.println(body.getPosition().y); if (body.getPosition().y < (10)) { body.setAwake(false); } else { body.setAwake(true); } // Again not box2dStuff just cool things I added HandleTouch(); // the Background color // This doesn't look like it does anything? Gdx.gl.glClearColor(1, 1, 1, 1); // clears the background after each fram update // Same with this? Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // this is where the sprite img is rendered and updated etc. batch.begin(); batch.draw(sprite, sprite.getX(), sprite.getY()); batch.end(); }
/** * Returns the position of the Entity. * * @return the position, in Vector2 form */ public Vector2 getOriginPosition() { if (sprite != null) { return new Vector2(sprite.getX() + sprite.getOriginX(), sprite.getY() + sprite.getOriginY()); } else { return new Vector2((edges[0].x + edges[1].x) / 2, (edges[0].y + edges[1].y) / 2); } }
@Override public void render() { camera.update(); // Step the physics simulation forward at a rate of 60hz world.step(1f / 60f, 6, 2); sprite.setPosition( (body.getPosition().x * PIXELS_TO_METERS) - sprite.getWidth() / 2, (body.getPosition().y * PIXELS_TO_METERS) - sprite.getHeight() / 2); sprite.setRotation((float) Math.toDegrees(body2.getAngle())); sprite2.setPosition( (body2.getPosition().x * PIXELS_TO_METERS) - sprite2.getWidth() / 2, (body2.getPosition().y * PIXELS_TO_METERS) - sprite2.getHeight() / 2); sprite2.setRotation((float) Math.toDegrees(body.getAngle())); Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.setProjectionMatrix(camera.combined); batch.begin(); batch.draw( sprite, sprite.getX(), sprite.getY(), sprite.getOriginX(), sprite.getOriginY(), sprite.getWidth(), sprite.getHeight(), sprite.getScaleX(), sprite.getScaleY(), sprite.getRotation()); batch.draw( sprite2, sprite2.getX(), sprite2.getY(), sprite2.getOriginX(), sprite2.getOriginY(), sprite2.getWidth(), sprite2.getHeight(), sprite2.getScaleX(), sprite2.getScaleY(), sprite2.getRotation()); batch.end(); }
public void initCancelButton() { // Cancel Button cancelButtonHelper = new ButtonHelper("menu/save-score-popup/cancel-button.png", 71, 71, 0, 0, 0, 71, game); cancelButton = cancelButtonHelper.getButton(); cancelButton.setPosition( (dialogSprite.getX() + dialogSprite.getWidth() - (cancelButton.getWidth() / 2) - 15), dialogSprite.getY() + dialogSprite.getHeight() - cancelButton.getHeight() + 15); }
public BillGhost(int side) { this.side = side; sprite = new Sprite(Assets.getInstance().billDeadRegion); if (side == 1) sprite.flip(true, false); sprite.setCenterX(BILL_DISTANCE * side); sprite.setCenterY(BILL_HEIGHT); alpha = 0.75f; x = sprite.getX(); y = sprite.getY(); ghostTime = 0; }
@Override public boolean touchDown(int x, int y, int pointer, int button) { Vector3 v = new Vector3(x, y, 0); camera.unproject(v); draggedSprite = null; Sprite[] sprites = new Sprite[] {powered, gdx}; for (Sprite sp : sprites) { if (sp.getX() <= v.x && v.x <= sp.getX() + sp.getWidth() && sp.getY() <= v.y && v.y <= sp.getY() + sp.getHeight()) { draggedSprite = sp; break; } } lastX = x; lastY = y; return true; }
private void updateTargetPosition() { // checkBoundsX(); if ((targetPos.x - sprite.getX() > 1 || targetPos.x - sprite.getX() < -1) && isMovingY == false) { // Gdx.app.log("Target Pos", "Target pos is" + targetPos.toString()); // Gdx.app.log("Sprite is at", "Target pos is" + sprite.getX() + ":" + sprite.getY()); moveToPosition(sprite, targetPos.x, 0); isMovingX = true; } else { isMovingX = false; } if ((targetPos.y - sprite.getY() > 1 || targetPos.y - sprite.getY() < -1) && isMovingX == false) { moveToPosition(sprite, 0, targetPos.y); isMovingY = true; } else { isMovingY = false; } }
@Override public void create() { // creates everything you need LOL batch = new SpriteBatch(); img = new Texture("Alien.png"); sprite = new Sprite(img); // sets the sprite in the middle of the screen sprite.setPosition( Gdx.graphics.getWidth() / 2 - sprite.getWidth() / 2, Gdx.graphics.getHeight() / 2); // This is were the magic happens, this is the "physics world" created where the gravity is set // to 98 // The 'f' makes 98 a float, the true means that it is active, vector 2d just means it takes x y // coor world = new World(new Vector2(0, -98f), true); // The body is the "object" set in the world, BodyDef makes the world aware of the object // basically so world Senpai notices BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyDef.BodyType.DynamicBody; // using 1 to 1 dimensions, meaning 1 in physics engine is 1px // set the body to the same position as the sprite bodyDef.position.set(sprite.getX(), sprite.getY()); // now create the body in the world! body = world.createBody(bodyDef); // now make the "shape" of the body that you just created shape = new PolygonShape(); // in this example I made a box (you can make circles too and stuff) that surrounds the sprite // aka the hit-box // so make the shape the same dimensions as the sprite image we are using shape.setAsBox(sprite.getWidth() / 2, sprite.getHeight() / 2); // FixtureDef is used to add physical properties to the shape // Ex. density, mass, area etc. fixtureDef = new FixtureDef(); // now assign the FixtureDef to the new shape that we just made fixtureDef.shape = shape; // Adding density using FixtureDef & adding it to the body so again world senpai notices fixtureDef.density = 1f; fixture = body.createFixture(fixtureDef); // the shape can be disposed to reduce clutter that will slow down the game shape.dispose(); }
@Override public void render(Batch batch) { Vector2 newPosition = UtilityMethods.moveCoordinate( new Vector2(sprite.getX(), sprite.getY()), spriteVector.x * Gdx.graphics.getDeltaTime(), spriteVector.y * Gdx.graphics.getDeltaTime()); if (isCellBlocked(newPosition.x, newPosition.y)) return; sprite.setPosition(newPosition.x, newPosition.y); position.x = newPosition.x; position.y = newPosition.y; drawPlayer(batch); }
public void moveToPosition(Sprite sprite, float x, float y) { final float currentX = sprite.getX(); final float currentY = sprite.getY(); // go to x first if (x > currentX && x != 0) { sprite.setX(currentX + (movementSpeed * Gdx.graphics.getDeltaTime())); } else if (x < currentX && x != 0) { sprite.setX(currentX - (movementSpeed * Gdx.graphics.getDeltaTime())); } if (y > currentY && y != 0) { sprite.setY(currentY + movementSpeed * Gdx.graphics.getDeltaTime()); } else if (y < currentY && y != 0) { sprite.setY(currentY - movementSpeed * Gdx.graphics.getDeltaTime()); } }
public void draw(SpriteBatch batch, float parentAlpha) { stateTime += Gdx.graphics.getDeltaTime(); Sprite toRender = currentAnimation.getKeyFrame(stateTime); // -1 to account for the sword below his feet toRender.setPosition(getX(), getY() - 1); toRender.setOrigin( toRender.getX() + toRender.getWidth(), toRender.getY() + toRender.getHeight()); toRender.setRotation(getRotation()); setSize(toRender.getWidth(), toRender.getHeight()); setOrigin(toRender.getOriginX(), toRender.getOriginY()); toRender.draw(batch); if (TheLoveOfRice.DRAW_DEBUG) { drawDebug(batch); } }
@Override public void render(float delta) { Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.begin(); backGroundSprite.draw(batch); batch.draw( backGroundSprite, backGroundSprite.getX(), backGroundSprite.getY(), backGroundSprite.getWidth(), backGroundSprite.getHeight()); batch.end(); stage.act(Gdx.graphics.getDeltaTime()); stage.draw(); if (Gdx.input.isKeyPressed(Input.Keys.BACK)) { game.setScreen(new LoginScreen(game)); } }
@Override public void show() { super.show(); // Set up data retrieval. DataManager.setUpBoardDataRetrieval(THREAD_COUNT); // Set up layout manager LayoutManager.setUpLayouts(kApplication.atlas()); // Set up rendering region_of_interest_ = new ROI(ChessViewScreen.kDrawableRegion); this.chessboard_renderer_ = new ChessRenderer(kApplication.atlas(), kApplication.spriteBatch()); // Set up game tree this.game_path_ = new ArrayDeque<GraphSquare>(); Board temp = new Board(); temp.setFen(kInitialFen); this.game_path_.addFirst( new ChessGraphSquare(new ChessBoardBitBasic(temp), this.chessboard_renderer_)); // Set up UI this.background = kApplication.atlas().createSprite("background"); this.background.setPosition(-kVirtualWidth / 2, -kVirtualHeight / 2); this.disableDrag = false; this.hud = new HUD(background.getX(), background.getY(), kApplication.atlas(), this.textFont); // Set up input handling Gdx.input.setInputProcessor(new DualInputGestureDetector(this)); // Gdx.input.setInputProcessor(this); /* if(Gdx.app.getType() == ApplicationType.Desktop) { } else {; } */ }
private void updateCamera() { direction.set(0.0f, 0.0f); int mouseX = Gdx.input.getX(); int mouseY = Gdx.input.getY(); int width = Gdx.graphics.getWidth(); int height = Gdx.graphics.getHeight(); if (Gdx.input.isKeyPressed(Input.Keys.LEFT) || (Gdx.input.isTouched() && mouseX < width * 0.75f)) { direction.x = -1; } else if (Gdx.input.isKeyPressed(Input.Keys.RIGHT) || (Gdx.input.isTouched() && mouseX > width * 0.75f)) { direction.x = 1; } if (Gdx.input.isKeyPressed(Input.Keys.UP) || (Gdx.input.isTouched() && mouseY < height * 0.75f)) { direction.y = 1; } else if (Gdx.input.isKeyPressed(Input.Keys.DOWN) || (Gdx.input.isTouched() && mouseY > height * 0.75f)) { direction.y = -1; } direction.nor().scl(CAMERA_SPEED * Gdx.graphics.getDeltaTime()); camera.position.x += direction.x; camera.position.y += direction.y; TiledMapTileLayer layer = (TiledMapTileLayer) tiledMap.getLayers().get(0); float cameraMinX = viewport.getWorldWidth() * 0.5f; float cameraMinY = viewport.getWorldHeight() * 0.5f; float cameraMaxX = layer.getWidth() * layer.getTileWidth() + (playerWidth - cameraMinX); float cameraMaxY = layer.getHeight() * layer.getTileHeight() - cameraMinY; camera.position.x = MathUtils.clamp(sprite.getX(), cameraMinX, cameraMaxX); camera.position.y = MathUtils.clamp(sprite.getY(), cameraMinY, cameraMaxY); camera.update(); }
@Override public void render() { // mag+=1; /*if(Gdx.input.isKeyPressed(Input.Keys.LEFT)) sprite.translateX(-2f); if(Gdx.input.isKeyPressed(Input.Keys.RIGHT)) sprite.translateX(2f);*/ long startTime = System.currentTimeMillis(); // long elapsedTime = 0; if (Gdx.input.isButtonPressed(Input.Buttons.LEFT)) { time = System.currentTimeMillis(); /*time%=100000000; time%=100000; time/=3;*/ time %= 10000000; Gdx.app.log("elapsedTime: ", time + ""); if ((time - startTime) > 2000) { sprite.setPosition( Gdx.graphics.getWidth() / 2 - sprite.getWidth() / 2, Gdx.graphics.getHeight() / 2 - sprite.getHeight() / 2); } sprite.translateY(1f); } if (Gdx.input.isButtonPressed(Input.Buttons.RIGHT)) { sprite.translateY(-1f); } startTime = System.currentTimeMillis(); /*sprite.setPosition(Gdx.graphics.getWidth() / 2 - sprite.getWidth() / 2, Gdx.graphics.getHeight() / 2 - sprite.getHeight() / 2);*/ /*if(Gdx.input.isButtonPressed(Input.Keys.LEFT)) sprite.setPosition(Gdx.input.getX(),Gdx.graphics.getHeight() - Gdx.input.getY()); if(movingRight) sprite.translateX(1f);*/ Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.begin(); time = 0; batch.draw(sprite, sprite.getX(), sprite.getY()); batch.end(); }
public void checkBoundsX() { for (Rectangle rect : collideRects) { if (sprite.getBoundingRectangle().overlaps(rect)) { float boundCalc = 0.0f; if (direction.x < 0) { boundCalc = rect.x + rect.getWidth() + 0.01f; } else { boundCalc = rect.x - sprite.getWidth() - 0.01f; } // sprite.setX(boundCalc - .2f); targetPos.x = boundCalc - .2f; direction.x = 0; Gdx.app.log("SpriteOverlap", "Target pos is" + sprite.getX() + ":" + sprite.getY()); } } }
@Override public void create() { batch = new SpriteBatch(); img = new Texture("badlogic.jpg"); // Create two identical sprites slightly offset from each other vertically sprite = new Sprite(img); sprite.setPosition(-sprite.getWidth() / 2, -sprite.getHeight() / 2 + 200); sprite2 = new Sprite(img); sprite2.setPosition(-sprite.getWidth() / 2 + 20, -sprite.getHeight() / 2 + 400); world = new World(new Vector2(0, -1f), true); // Sprite1's Physics body BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyDef.BodyType.DynamicBody; bodyDef.position.set( (sprite.getX() + sprite.getWidth() / 2) / PIXELS_TO_METERS, (sprite.getY() + sprite.getHeight() / 2) / PIXELS_TO_METERS); body = world.createBody(bodyDef); // Sprite2's physics body BodyDef bodyDef2 = new BodyDef(); bodyDef2.type = BodyDef.BodyType.DynamicBody; bodyDef2.position.set( (sprite2.getX() + sprite2.getWidth() / 2) / PIXELS_TO_METERS, (sprite2.getY() + sprite2.getHeight() / 2) / PIXELS_TO_METERS); body2 = world.createBody(bodyDef2); // Both bodies have identical shape PolygonShape shape = new PolygonShape(); shape.setAsBox( sprite.getWidth() / 2 / PIXELS_TO_METERS, sprite.getHeight() / 2 / PIXELS_TO_METERS); // Sprite1 FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = shape; fixtureDef.density = 0.1f; fixtureDef.restitution = 0.5f; // Sprite2 FixtureDef fixtureDef2 = new FixtureDef(); fixtureDef2.shape = shape; fixtureDef2.density = 0.1f; fixtureDef2.restitution = 0.5f; body.createFixture(fixtureDef); body2.createFixture(fixtureDef2); shape.dispose(); // Now the physics body of the bottom edge of the screen BodyDef bodyDef3 = new BodyDef(); bodyDef3.type = BodyDef.BodyType.StaticBody; float w = Gdx.graphics.getWidth() / PIXELS_TO_METERS; float h = Gdx.graphics.getHeight() / PIXELS_TO_METERS; bodyDef3.position.set(0, 0); FixtureDef fixtureDef3 = new FixtureDef(); EdgeShape edgeShape = new EdgeShape(); edgeShape.set(-w / 2, -h / 2, w / 2, -h / 2); fixtureDef3.shape = edgeShape; bodyEdgeScreen = world.createBody(bodyDef3); bodyEdgeScreen.createFixture(fixtureDef3); edgeShape.dispose(); camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); /*world.setContactListener(new ContactListener() { @Override public void beginContact(Contact contact) { // Check to see if the collision is between the second sprite and the bottom of the screen // If so apply a random amount of upward force to both objects... just because if((contact.getFixtureA().getBody() == bodyEdgeScreen && contact.getFixtureB().getBody() == body2) || (contact.getFixtureA().getBody() == body2 && contact.getFixtureB().getBody() == bodyEdgeScreen)) { body.applyForceToCenter(0,MathUtils.random(20,50),true); body2.applyForceToCenter(0, MathUtils.random(20,50), true); } } @Override public void endContact(Contact contact) { } @Override public void preSolve(Contact contact, Manifold oldManifold) { } @Override public void postSolve(Contact contact, ContactImpulse impulse) { } });*/ }
public float getX() { return sprite.getX(); }
public void scoreCounter(SpriteBatch sb) { if (score < 10) { scoreFont.draw(sb, String.valueOf(score), redCounter.getX() + 2, redCounter.getY() + 20); } else if (score >= 10 && score < 100) { int secondNumber = score % 10; int newAmount = score - secondNumber; newAmount /= 10; int firstNumber = newAmount; scoreFont.draw( sb, String.valueOf(firstNumber), redCounter.getX() + 2, redCounter.getY() + 20); scoreFont.draw( sb, String.valueOf(secondNumber), redCounter.getX() + 25, redCounter.getY() + 20); } else if (score >= 100 && score < 1000) { int thirdNumber = score % 10; int newAmount = score - thirdNumber; newAmount /= 10; int secondNumber = newAmount % 10; newAmount /= 10; int firstNumber = newAmount; scoreFont.draw( sb, String.valueOf(firstNumber), redCounter.getX() + 2, redCounter.getY() + 20); scoreFont.draw( sb, String.valueOf(secondNumber), redCounter.getX() + 27, redCounter.getY() + 20); scoreFont.draw( sb, String.valueOf(thirdNumber), redCounter.getX() + 51, redCounter.getY() + 20); } else if (score >= 1000 && score < 10000) { int fourthNumber = score % 10; int newAmount = score - fourthNumber; newAmount /= 10; int thirdNumber = newAmount % 10; newAmount /= 10; int secondNumber = newAmount % 10; newAmount /= 10; int firstNumber = newAmount; scoreFont.draw( sb, String.valueOf(firstNumber), redCounter.getX() + 2, redCounter.getY() + 20); scoreFont.draw( sb, String.valueOf(secondNumber), redCounter.getX() + 27, redCounter.getY() + 20); scoreFont.draw( sb, String.valueOf(thirdNumber), redCounter.getX() + 51, redCounter.getY() + 20); scoreFont.draw( sb, String.valueOf(fourthNumber), redCounter.getX() + 75, redCounter.getY() + 20); } else if (score >= 10000 && score < 100000) { int fifthNumber = score % 10; int newAmount = score - fifthNumber; newAmount /= 10; int fourthNumber = newAmount % 10; newAmount /= 10; int thirdNumber = newAmount % 10; newAmount /= 10; int secondNumber = newAmount % 10; newAmount /= 10; int firstNumber = newAmount; scoreFont.draw( sb, String.valueOf(firstNumber), redCounter.getX() + 2, redCounter.getY() + 20); scoreFont.draw( sb, String.valueOf(secondNumber), redCounter.getX() + 27, redCounter.getY() + 20); scoreFont.draw( sb, String.valueOf(thirdNumber), redCounter.getX() + 51, redCounter.getY() + 20); scoreFont.draw( sb, String.valueOf(fourthNumber), redCounter.getX() + 75, redCounter.getY() + 20); scoreFont.draw( sb, String.valueOf(fifthNumber), redCounter.getX() + 99, redCounter.getY() + 20); } else if (score >= 100000 && score < 1000000) { int sixthNumber = score % 10; int newAmount = score - sixthNumber; newAmount /= 10; int fifthNumber = newAmount % 10; newAmount /= 10; int fourthNumber = newAmount % 10; newAmount /= 10; int thirdNumber = newAmount % 10; newAmount /= 10; int secondNumber = newAmount % 10; newAmount /= 10; int firstNumber = newAmount; scoreFont.draw( sb, String.valueOf(firstNumber), redCounter.getX() + 2, redCounter.getY() + 20); scoreFont.draw( sb, String.valueOf(secondNumber), redCounter.getX() + 27, redCounter.getY() + 20); scoreFont.draw( sb, String.valueOf(thirdNumber), redCounter.getX() + 51, redCounter.getY() + 20); scoreFont.draw( sb, String.valueOf(fourthNumber), redCounter.getX() + 75, redCounter.getY() + 20); scoreFont.draw( sb, String.valueOf(fifthNumber), redCounter.getX() + 99, redCounter.getY() + 20); scoreFont.draw( sb, String.valueOf(sixthNumber), redCounter.getX() + 123, redCounter.getY() + 20); } }
public void highScoreCounter(SpriteBatch sb) { if (highScore < 10) { highscoreFont.draw( sb, String.valueOf(highScore), blueCounter.getX() + blueCounter.getWidth() - 19, blueCounter.getY() + 20); } else if (highScore >= 10 && highScore < 100) { int secondNumber = highScore % 10; int newAmount = highScore - secondNumber; newAmount /= 10; int firstNumber = newAmount; highscoreFont.draw( sb, String.valueOf(secondNumber), blueCounter.getX() + blueCounter.getWidth() - 19, blueCounter.getY() + 20); highscoreFont.draw( sb, String.valueOf(firstNumber), blueCounter.getX() + blueCounter.getWidth() - 45, blueCounter.getY() + 20); } else if (highScore >= 100 && highScore < 1000) { int thirdNumber = highScore % 10; int newAmount = highScore - thirdNumber; newAmount /= 10; int secondNumber = newAmount % 10; newAmount /= 10; int firstNumber = newAmount; highscoreFont.draw( sb, String.valueOf(thirdNumber), blueCounter.getX() + blueCounter.getWidth() - 19, blueCounter.getY() + 20); highscoreFont.draw( sb, String.valueOf(secondNumber), blueCounter.getX() + blueCounter.getWidth() - 45, blueCounter.getY() + 20); highscoreFont.draw( sb, String.valueOf(firstNumber), blueCounter.getX() + blueCounter.getWidth() - 70, blueCounter.getY() + 20); } else if (highScore >= 1000 && highScore < 10000) { int fourthNumber = highScore % 10; int newAmount = highScore - fourthNumber; newAmount /= 10; int thirdNumber = newAmount % 10; newAmount /= 10; int secondNumber = newAmount % 10; newAmount /= 10; int firstNumber = newAmount; highscoreFont.draw( sb, String.valueOf(fourthNumber), blueCounter.getX() + blueCounter.getWidth() - 19, blueCounter.getY() + 20); highscoreFont.draw( sb, String.valueOf(thirdNumber), blueCounter.getX() + blueCounter.getWidth() - 45, blueCounter.getY() + 20); highscoreFont.draw( sb, String.valueOf(secondNumber), blueCounter.getX() + blueCounter.getWidth() - 70, blueCounter.getY() + 20); highscoreFont.draw( sb, String.valueOf(firstNumber), blueCounter.getX() + blueCounter.getWidth() - 95, blueCounter.getY() + 20); } else if (highScore >= 10000 && highScore < 100000) { int fifthNumber = highScore % 10; int newAmount = highScore - fifthNumber; newAmount /= 10; int fourthNumber = newAmount % 10; newAmount /= 10; int thirdNumber = newAmount % 10; newAmount /= 10; int secondNumber = newAmount % 10; newAmount /= 10; int firstNumber = newAmount; highscoreFont.draw( sb, String.valueOf(fifthNumber), blueCounter.getX() + blueCounter.getWidth() - 19, blueCounter.getY() + 20); highscoreFont.draw( sb, String.valueOf(fourthNumber), blueCounter.getX() + blueCounter.getWidth() - 45, blueCounter.getY() + 20); highscoreFont.draw( sb, String.valueOf(thirdNumber), blueCounter.getX() + blueCounter.getWidth() - 70, blueCounter.getY() + 20); highscoreFont.draw( sb, String.valueOf(secondNumber), blueCounter.getX() + blueCounter.getWidth() - 95, blueCounter.getY() + 20); highscoreFont.draw( sb, String.valueOf(firstNumber), blueCounter.getX() + blueCounter.getWidth() - 120, blueCounter.getY() + 20); } else if (highScore >= 100000 && highScore < 1000000) { int sixthNumber = highScore % 10; int newAmount = highScore - sixthNumber; newAmount /= 10; int fifthNumber = newAmount % 10; newAmount /= 10; int fourthNumber = newAmount % 10; newAmount /= 10; int thirdNumber = newAmount % 10; newAmount /= 10; int secondNumber = newAmount % 10; newAmount /= 10; int firstNumber = newAmount; highscoreFont.draw( sb, String.valueOf(sixthNumber), blueCounter.getX() + blueCounter.getWidth() - 19, blueCounter.getY() + 20); highscoreFont.draw( sb, String.valueOf(fifthNumber), blueCounter.getX() + blueCounter.getWidth() - 45, blueCounter.getY() + 20); highscoreFont.draw( sb, String.valueOf(fourthNumber), blueCounter.getX() + blueCounter.getWidth() - 70, blueCounter.getY() + 20); highscoreFont.draw( sb, String.valueOf(thirdNumber), blueCounter.getX() + blueCounter.getWidth() - 95, blueCounter.getY() + 20); highscoreFont.draw( sb, String.valueOf(secondNumber), blueCounter.getX() + blueCounter.getWidth() - 120, blueCounter.getY() + 20); highscoreFont.draw( sb, String.valueOf(firstNumber), blueCounter.getX() + blueCounter.getWidth() - 145, blueCounter.getY() + 20); } }
public BoundingBox(Sprite image, float offset) { this(new Vector2(image.getX(), image.getY()), image.getWidth(), image.getHeight(), offset); }
public float getCenterX() { return sprite.getX() + getScaledWidth() / 2; }
public boolean touchInside(int x, int y) { return (x > mSprite.getX() && x < mSprite.getX() + mSprite.getWidth()) && (y > mSprite.getY() && y < mSprite.getY() + mSprite.getHeight()); }
@Override public void resize(int width, int height) { PPuX = width / 10; System.out.println("width = " + width); System.out.println("height = " + height); PPuY = height / 10; world = new World(new Vector2(0, -9.8f), false); renderer = new Box2DDebugRenderer(); camera = new OrthographicCamera(width, height); debugMatrix = new Matrix4(camera.combined); Circle.setBounds( Circle.getX() * PPuX, Circle.getY() * PPuY, Circle.getWidth() * PPuX, Circle.getHeight() * PPuY); Circle.setOrigin(Circle.getWidth() / 2, Circle.getHeight() / 2); BodyDef circleDef = new BodyDef(); circleDef.type = BodyType.DynamicBody; // To allign the Circle sprite with box 2d circleDef.position.set( convertToBox(Circle.getX() + Circle.getWidth() / 2), convertToBox(Circle.getY() + Circle.getHeight() / 2)); circleBody = world.createBody(circleDef); // box2d builds around 0,0 you can see -X and -Y, this makes sure that you only see X,Y debugMatrix.translate(-camera.viewportWidth / 2, -camera.viewportHeight / 2, 0); // scale the debug matrix by the scaling so everything looks normal debugMatrix.scale(BOX_TO_WORLD, BOX_TO_WORLD, 0); circleShape = new CircleShape(); circleShape.setRadius(convertToBox(Circle.getWidth() / 2)); FixtureDef circleFixture = new FixtureDef(); circleFixture.shape = circleShape; circleFixture.density = 0.4f; circleFixture.friction = 0.2f; circleFixture.restitution = 1f; circleBody.createFixture(circleFixture); circleBody.setUserData(Circle); // create ground BodyDef groundDef = new BodyDef(); groundDef.position.set(convertToBox(camera.viewportWidth / 2), 0); Body groundBody = world.createBody(groundDef); PolygonShape groundBox = new PolygonShape(); groundBox.setAsBox(convertToBox(camera.viewportWidth / 2), 0); groundBody.createFixture(groundBox, 0); BodyDef def = new BodyDef(); def.type = BodyType.DynamicBody; def.position.set(0, 0); Body box = world.createBody(def); PolygonShape poly = new PolygonShape(); poly.setAsBox(0.1f, 0.2f); playerPhysicsFixture = box.createFixture(poly, 1); poly.dispose(); CircleShape circle = new CircleShape(); circle.setRadius(0.1f); circle.setPosition(new Vector2(0, -0.2f)); playerSensorFixture = box.createFixture(circle, 0); circle.dispose(); box.setBullet(true); player = box; player.setTransform(1.0f, 2.0f, 0); player.setFixedRotation(true); }