Esempio n. 1
0
  private void updatePhysics() {
    // Update
    // float deltaTime = Gdx.graphics.getRawDeltaTime();
    float deltaTime = 1 / 60f;
    // System.out.println(deltaTime);
    tweenManager.update(deltaTime); // Setting delta time
    world.step(deltaTime, 10, 10);

    Vector2 planetPos = planetModel.getPosition().sub(planetModelOrigin);
    planetSprite.setPosition(planetPos.x, planetPos.y);
    planetSprite.setOrigin(planetModelOrigin.x, planetModelOrigin.y);
    planetSprite.setRotation(planetModel.getAngle() * MathUtils.radiansToDegrees);

    Vector2 planetCorePos = planetCoreModel.getPosition().sub(planetCoreModelOrigin);
    planetCoreSprite.setPosition(planetCorePos.x, planetCorePos.y);
    planetCoreSprite.setOrigin(planetCoreModelOrigin.x, planetCoreModelOrigin.y);
    planetCoreSprite.setRotation(planetCoreModel.getAngle() * MathUtils.radiansToDegrees);

    for (int i = 0; i < MAX_BALLS; i++) {
      Vector2 ballPos = ballModels[i].getPosition();
      ballSprites[i].setPosition(
          ballPos.x - ballSprites[i].getWidth() / 2, ballPos.y - ballSprites[i].getHeight() / 2);
      ballSprites[i].setRotation(ballModels[i].getAngle() * MathUtils.radiansToDegrees);
    }
  }
Esempio n. 2
0
  @Override
  public void create() {
    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();

    camera = new OrthographicCamera(1, h / w);
    batch = new SpriteBatch();

    texture = new Texture(Gdx.files.internal("data/libgdx.png"));
    texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);

    texture_nave = new Texture(Gdx.files.internal("data/nave.png"));

    sprite_nave = new Sprite(texture_nave, 128, 64);
    sprite_nave.setPosition(-0.5f, -0.5f);
    sprite_nave.setSize(0.5f, 0.5f);

    TextureRegion region = new TextureRegion(texture, 0, 0, 512, 275);

    sprite = new Sprite(region);
    sprite2 = new Sprite(region);

    sprite.setSize(0.9f, 0.9f * sprite.getHeight() / sprite.getWidth());
    sprite.setOrigin(sprite.getWidth() / 2, sprite.getHeight() / 2);
    sprite.setPosition(-sprite.getWidth() / 2, -sprite.getHeight() / 2);
    sprite.setPosition(0, 0);
    sprite.setRotation(25);
  }
  public MainMenuScreen(MissileCommand game) {
    this.game = game;

    guiCam =
        new OrthographicCamera(
            com.intel.libgdxmissilecommand.common.Assets.screenWidth,
            com.intel.libgdxmissilecommand.common.Assets.screenHeight);
    guiCam.position.set(
        com.intel.libgdxmissilecommand.common.Assets.screenWidth / 2,
        com.intel.libgdxmissilecommand.common.Assets.screenHeight / 2,
        0);

    startButton = new Sprite(com.intel.libgdxmissilecommand.common.Assets.startButtonTextureRegion);
    startButton.setPosition(
        com.intel.libgdxmissilecommand.common.Assets.screenWidth / 2 - startButton.getWidth() / 2,
        startButton.getHeight() * 2.5f);

    creditsButton =
        new Sprite(com.intel.libgdxmissilecommand.common.Assets.creditsButtonTextureRegion);
    creditsButton.setPosition(
        com.intel.libgdxmissilecommand.common.Assets.screenWidth / 2 - creditsButton.getWidth() / 2,
        creditsButton.getHeight());

    touchPoint = new Vector3();
  }
Esempio n. 4
0
 public void draw(Batch batch) {
   if (type == enemyNORMAL) {
     enemySprite.setPosition(enemyRec.x - 2.5f, enemyRec.y - 3);
   } else {
     enemySprite.setPosition(enemyRec.x - 5, enemyRec.y - 8);
   }
   enemySprite.draw(batch);
 }
Esempio n. 5
0
  public Fly(float x, float y, int fly_type, int slot_number) { // set static data of fly(x, y, ect)
    xCoord = x;
    yCoord = y;
    fly_size = fly_type;
    slotNumber = slot_number;

    switch (fly_type) {
      case 1: // small fly
        texture = new Texture(Gdx.files.internal("data/medium_fly.png"));
        texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);

        TextureRegion region = new TextureRegion(texture, 0, 0, 212, 143);

        fly_sprite = new Sprite(region);
        fly_sprite.setSize(.0745f, .06155f);
        fly_sprite.setOrigin(fly_sprite.getWidth() / 2, fly_sprite.getHeight() / 2);
        fly_sprite.setPosition(x, y);
        break;
      case 2: // small fly
        texture = new Texture(Gdx.files.internal("data/medium_fly.png"));
        texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);

        region = new TextureRegion(texture, 0, 0, 212, 143);

        fly_sprite = new Sprite(region);
        fly_sprite.setSize(.0745f, .06155f);
        fly_sprite.setOrigin(fly_sprite.getWidth() / 2, fly_sprite.getHeight() / 2);
        fly_sprite.setPosition(x, y);
        break;
      case 3: // medium fly
        texture = new Texture(Gdx.files.internal("data/medium_fly.png"));
        texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);

        region = new TextureRegion(texture, 0, 0, 212, 143);

        fly_sprite = new Sprite(region);
        fly_sprite.setSize(.115f, .097f);
        fly_sprite.setOrigin(fly_sprite.getWidth() / 2, fly_sprite.getHeight() / 2);
        fly_sprite.setPosition(x, y);
        break;
      case 4: // large fly
        texture = new Texture(Gdx.files.internal("data/medium_fly.png"));
        texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);

        region = new TextureRegion(texture, 0, 0, 212, 143);

        fly_sprite = new Sprite(region);
        fly_sprite.setSize(.155f, .135f);
        fly_sprite.setOrigin(fly_sprite.getWidth() / 2, fly_sprite.getHeight() / 2);
        fly_sprite.setPosition(x, y);
        break;

      default:
        break;
    }
  }
Esempio n. 6
0
  @Override
  public void render(float delta) {
    Gdx.gl.glClearColor(0.39f, 0.58f, 0.92f, 1.0f);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    // Update deltaTime & animationTime
    deltaTime = Gdx.graphics.getDeltaTime();
    animationTime += Gdx.graphics.getDeltaTime();

    // Store Spritesheet to sprite
    sprite = new Sprite(animation.getKeyFrame(animationTime, true));
    sprite.setPosition(xPosition, 0);
    sprite.setScale(1.8f);

    // Set camera to batch and undate camera
    batch.setProjectionMatrix(camera.combined);
    camera.update();

    tiledMapRenderer.setView(camera);
    tiledMapRenderer.render(background);
    tiledMapRenderer.render(foreground);

    // Display on Screen
    batch.begin();
    sprite.draw(batch);
    batch.end();

    // update xPosition
    xPosition = xPosition + (speed * deltaTime);

    HUDBatch.begin();
    font1.draw(HUDBatch, "SCORE:100", 100, 450);
    HUDBatch.end();
  }
Esempio n. 7
0
  public void draw(SpriteBatch sb) {
    if (mCogs_ReallyBig.size() > 0) {
      mCogs_ReallyBig.get(0).setCenterX(121);
      mCogs_ReallyBig.get(0).setCenterY(156);
      mCogs_ReallyBig.get(0).draw(sb);
    }

    if (mCogs_Big.size() > 0) {
      mCogs_Big.get(0).setCenterX(326);
      mCogs_Big.get(0).setCenterY(112);
      mCogs_Big.get(0).draw(sb);
    }

    if (mCogs_Medium.size() > 0) {
      mCogs_Medium.get(0).setCenterX(498);
      mCogs_Medium.get(0).setCenterY(95);
      mCogs_Medium.get(0).draw(sb);
    }

    if (mCogs_Small.size() > 0) {
      mCogs_Small.get(0).setCenterX(633);
      mCogs_Small.get(0).setCenterY(83);
      mCogs_Small.get(0).draw(sb);
    }

    if (mCogs_Tiny.size() > 0) {
      mCogs_Tiny.get(0).setCenterX(732);
      mCogs_Tiny.get(0).setCenterY(69);
      mCogs_Tiny.get(0).draw(sb);
    }

    mSprite.setPosition(0, 0);
    mSprite.draw(sb);
  }
  @Override
  public void create() {

    GeneralStorage.load();
    MenuStorage.load();
    SplashStorage.load();
    MenuStorage.load();
    PauseStorage.load();
    RunningStorage.load();
    GameOverStorage.load();

    GeneralStorage.estado = GeneralStorage.state.splash;
    MenuStorage.HelpTouched = false;
    // Init the particle effect
    particle1 = new ParticleEffect();
    particleLeft = new ParticleEffect();
    particleRight = new ParticleEffect();
    // load the particle, first parameter is path and name file when is the particle,
    // second one the fold when is the particle image.
    particle1.load(Gdx.files.internal("efectos/vuelo2"), Gdx.files.internal("efectos"));
    particleLeft.load(Gdx.files.internal("efectos/efLateral3"), Gdx.files.internal("efectos"));
    particleRight.load(Gdx.files.internal("efectos/efLateral3"), Gdx.files.internal("efectos"));
    // Sprites of button of the menu screen to music, sound and button help

    spHelp = new Sprite(GeneralStorage.imgBTHelp);
    spHelp.setSize(GeneralStorage.w / 10, GeneralStorage.w / 10);
    spHelp.setPosition(
        GeneralStorage.w - GeneralStorage.w / 4 - spHelp.getWidth() / 2, GeneralStorage.h / 4);

    // storage the background color
    colorFondo = MenuStorage.spBackGroundGame.getColor();
    // Time to splash screen.
    timer = 100;
  }
  public static void wyswietlBitmape(Sprite sprite, int x, int y) {

    PrzechowalniaAssets.spriteBatch.begin();
    sprite.setPosition(x, y);
    sprite.draw(PrzechowalniaAssets.spriteBatch);
    PrzechowalniaAssets.spriteBatch.end();
  }
Esempio n. 10
0
  @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();
  }
Esempio n. 11
0
  private void createSprites() {

    // background
    backgroundTexture = new Texture(Gdx.files.internal("data/cr/map1bg.png"));
    backgroundTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    backgroundSprite = new Sprite(backgroundTexture);
    backgroundSprite.setSize(WIDTH_WORLD, HEIGHT_WORLD);
    backgroundSprite.setPosition(-WIDTH_WORLD / 2f, 0);

    // planet
    planetTexture = new Texture(Gdx.files.internal("data/cr/planet_terrain.png"));
    planetTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    planetSprite = new Sprite(planetTexture);
    planetSprite.setSize(
        PLANET_WIDTH, PLANET_WIDTH * planetSprite.getHeight() / planetSprite.getWidth());

    // planet core
    planetCoreTexture = new Texture(Gdx.files.internal("data/cr/planet_core.png"));
    planetCoreTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    planetCoreSprite = new Sprite(planetCoreTexture);
    planetCoreSprite.setSize(
        PLANET_CORE_WIDTH,
        PLANET_CORE_WIDTH * planetCoreSprite.getHeight() / planetCoreSprite.getWidth());

    // balls
    ballTexture = new Texture(Gdx.files.internal("data/gfx/ball.png"));
    ballTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);

    ballSprites = new Sprite[MAX_BALLS];
    for (int i = 0; i < MAX_BALLS; i++) {
      ballSprites[i] = new Sprite(ballTexture);
      ballSprites[i].setSize(BALL_RADIUS * 2, BALL_RADIUS * 2);
      ballSprites[i].setOrigin(BALL_RADIUS, BALL_RADIUS);
    }
  }
Esempio n. 12
0
  public void render(float delta) {
    Gdx.gl.glClearColor(0, 0, 0.2f, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    // tell the camera to update its matrices.
    camera.update(
        car.body.getPosition().x * PIXELS_PER_METER, car.body.getPosition().y * PIXELS_PER_METER);

    spriteBatch.setProjectionMatrix(camera.getCombined());

    if (Gdx.input.isKeyPressed(Input.Keys.UP) || Gdx.input.isTouched()) {
      car.setAccelerate(Car.ACC_ACCELERATE);
    } else if (Gdx.input.isKeyPressed(Input.Keys.DOWN)) {
      car.setAccelerate(Car.ACC_BRAKE);
    } else {
      car.setAccelerate(Car.ACC_NONE);
    }

    if (Gdx.input.isKeyPressed(Input.Keys.LEFT) || Gdx.input.getAccelerometerY() < -2.5) {
      car.setSteer(Car.STEER_HARD_LEFT);
    } else if (Gdx.input.getAccelerometerY() < -1) {
      car.setSteer(Car.STEER_LEFT);
    } else if (Gdx.input.isKeyPressed(Input.Keys.RIGHT) || Gdx.input.getAccelerometerY() > 2.5) {
      car.setSteer(Car.STEER_HARD_RIGHT);
    } else if (Gdx.input.getAccelerometerY() > 1) {
      car.setSteer(Car.STEER_RIGHT);
    } else {
      car.setSteer(Car.STEER_NONE);
    }

    car.update(Gdx.app.getGraphics().getDeltaTime());

    /**
     * Have box2d update the positions and velocities (and etc) of all tracked objects. The second
     * and third argument specify the number of iterations of velocity and position tests to perform
     * -- higher is more accurate but is also slower.
     */
    world.step(Gdx.app.getGraphics().getDeltaTime(), 3, 3);

    world.clearForces();

    // draw the sprites
    spriteBatch.begin();

    playerSprite.setPosition(
        PIXELS_PER_METER * car.body.getPosition().x - playerTexture.getRegionWidth() / 2,
        PIXELS_PER_METER * car.body.getPosition().y - playerTexture.getRegionHeight() / 2);
    playerSprite.setRotation((MathUtils.radiansToDegrees * car.body.getAngle()));

    playerSprite.setFlip(false, true);
    playerSprite.setScale(0.3f);

    playerSprite.draw(spriteBatch);

    spriteBatch.end();

    /** Draw this last, so we can see the collision boundaries on top of the sprites and map. */
    debugRenderer.render(
        world, camera.getCombined().scale(PIXELS_PER_METER, PIXELS_PER_METER, PIXELS_PER_METER));
  }
Esempio n. 13
0
  /** @param path */
  public LoadTexture(String path) {
    array_Texs.add(new Texture(path));
    array_Texs.get(BACKGROUND).setFilter(TextureFilter.Linear, TextureFilter.Linear);
    array_Texs.add(new Texture(Gdx.files.internal("data/arrow-down.png")));
    array_Texs.add(new Texture(Gdx.files.internal("data/arrow-up.png")));
    array_Texs.add(new Texture(Gdx.files.internal("data/menu.png")));

    for (int i = 0; i < array_Texs.size(); i++) {
      array_TexRegions.add(
          new TextureRegion(
              array_Texs.get(i),
              0,
              0,
              array_Texs.get(i).getWidth(),
              array_Texs.get(i).getHeight()));
      array_Sprites.add(new Sprite(array_TexRegions.get(i)));
    }

    // 背景画像設定
    Sprite sprite = array_Sprites.get(BACKGROUND);
    sprite.setSize(sprite.getRegionWidth(), sprite.getRegionHeight());
    sprite.setOrigin(sprite.getWidth() / 2, sprite.getHeight() / 2);
    sprite.setPosition(-sprite.getWidth() / 2, -sprite.getHeight() / 2);
    array_Sprites.set(BACKGROUND, sprite);
  }
Esempio n. 14
0
  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();
  }
Esempio n. 15
0
  public void setUp() {

    BodyDef bodyDef = new BodyDef();
    bodyDef.position.set(x + width / 2, y + height / 2);
    bodyDef.type = BodyDef.BodyType.KinematicBody;

    PolygonShape shape = new PolygonShape();
    shape.setAsBox(width / 2, height / 2);

    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = shape;

    body = world.createBody(bodyDef);
    body.createFixture(fixtureDef);
    body.setUserData(Constants.robotNinjaID);

    body.setLinearVelocity(Constants.standardVelocity);

    sprite = new Sprite(texture);
    sprite.setSize(width, height);
    sprite.setOrigin(width / 2, height / 2);
    sprite.flip(false, flipy);
    sprite.setPosition(x, y);

    dead = false;
  }
  @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();
  }
Esempio n. 17
0
 public void update() {
   if (body.getUserData() == Constants.robotNinjaID) {
     body.setLinearVelocity(Constants.standardVelocity.x, 0);
   }
   sprite.setPosition(
       body.getPosition().x - sprite.getWidth() / 2,
       body.getPosition().y - sprite.getHeight() / 2);
 }
Esempio n. 18
0
 public GameMap() {
   for (int x = 0; x < width; x++) {
     for (int y = 0; y < height; y++) {
       Sprite cell = new Sprite(TextureManager.instance().loadTexture("cell.png"));
       cell.setPosition(x * 16, y * 16);
       cells.add(cell);
     }
   }
 }
Esempio n. 19
0
 public void victory() {
   victory.setPosition(
       -victory.getWidth() / 2 + Gdx.graphics.getWidth() / 2,
       -victory.getHeight() / 2 + 50 * HW4.SCALE + Gdx.graphics.getHeight() / 2);
   gameEnd.begin();
   victory.draw(gameEnd);
   gameEnd.end();
   if (rs.getStage() == null) stage.addActor(rs);
 }
Esempio n. 20
0
  public Health(ShooterGame g) {

    lifeManager = new LifeManager(3);

    game = g;
    lifeManager.setGame(game);

    backBarTexture = new Texture(Gdx.files.internal("hud/health/backbar2.png"));
    backBarDangerTexture = new Texture(Gdx.files.internal("hud/health/backbar-danger.png"));
    backBarSprite = new Sprite(backBarTexture);
    backBarWarningSprite = new Sprite(backBarTexture);

    healthBarTexture = new Texture(Gdx.files.internal("hud/health/healthbar.png"));
    healthBarSprite = new Sprite(healthBarTexture);

    setHealthBarSprite(healthBarSprite);

    topLeftWingTexture = new Texture(Gdx.files.internal("hud/health/topleftwing.png"));
    topLeftWingSprite = new Sprite(topLeftWingTexture);

    bottomLeftWingTexture = new Texture(Gdx.files.internal("hud/life/bottomleftwing.png"));
    bottomLeftWingSprite = new Sprite(bottomLeftWingTexture);

    // Initial Positions
    backBarSprite.setPosition(50, 688);
    healthBarSprite.setPosition(50, 688);
    topLeftWingSprite.setPosition(10, 670);
    bottomLeftWingSprite.setPosition(64, 640);

    // Set up animated health bar when health goes below 20
    animationFrames = new TextureRegion[DANGER_HEALTH_FRAMES];

    TextureRegion[][] tmpFrames = TextureRegion.split(backBarDangerTexture, 454, 15);

    int index = 0;
    for (int i = 0; i < 2; i++) {
      for (int j = 0; j < 11; j++) {
        animationFrames[index++] = tmpFrames[i][j];
      }
    }

    backbarAnimation = new Animation(1f / 22f, animationFrames);
    backbarAnimation.setPlayMode(Animation.PlayMode.LOOP);
  }
 public InteractButton(float x, float y) {
   this.x = x;
   this.y = y;
   width = 64;
   height = 40;
   sprite = new Sprite(new Texture(Gdx.files.internal("sprites/placeables/usebutton.png")));
   sprite.setSize(64, 40);
   sprite.setPosition(x, y);
   hitBox = new Rectangle(x, y, width, height);
 }
Esempio n. 22
0
  public void update(float dt, OrthographicCamera cam) {
    stage.act(dt);
    if (Core.persistentAssets.update() && !assetsLoaded) {

      GameSave.save();

      assetsLoaded = true;

      layout = new Table(Core.persistentAssets.get("skins/uiskin.json", Skin.class));
      layout.setFillParent(true);
      layout.center().bottom();

      pressBtn =
          new Label(
              "Press any key to continue",
              Core.persistentAssets.get("skins/uiskin.json", Skin.class));

      layout.add(pressBtn).padBottom(40);

      layout.debug();

      stage.addActor(layout);

      stage.addListener(
          new InputListener() {
            public boolean keyUp(InputEvent event, int keycode) {
              gsm.setState(GameStateManager.MENU);
              return false;
            }

            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
              return true;
            }

            public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
              gsm.setState(GameStateManager.MENU);
            }
          });
    }

    if (Core.persistentAssets.isLoaded("images/main-menu/background.jpg")) {
      if (!bgLoaded) {
        bgLoaded = true;
        bg =
            new Sprite(Core.persistentAssets.get("images/main-menu/background.jpg", Texture.class));
        float[] size =
            ImageUtils.minimalStretch(bg.getWidth(), bg.getHeight(), Core.WIDTH, Core.HEIGHT);

        bg.setSize(size[0], size[1]);
        bg.setPosition(size[2], size[3]);
      }
      bgOpacity += bgOpacityModifier * dt;
      bgOpacity = bgOpacity > 1 ? 1 : bgOpacity;
    }
  }
Esempio n. 23
0
  public GameState(TitleState title) {
    this.title = title;
    this.title.reset();
    prefs = Gdx.app.getPreferences("highscore");
    adsController = MainGame.adsController;
    restartButton = new RestartButton(MainGame.WIDTH / 2 - 78, MainGame.HEIGHT / 2 - 100);
    menuButton = new MenuButton(MainGame.WIDTH / 2 - 125, MainGame.HEIGHT / 2);
    unpauseButton = new UnpauseButton(MainGame.WIDTH / 2 - 78, MainGame.HEIGHT / 2 + 100);
    highScore = prefs.getInteger("highscore", 0);

    gameOverOverlay = new Sprite(new Texture(Gdx.files.internal("gui/gameoverlay.png")));
    gameOverOverlay.setPosition(0, MainGame.HEIGHT / 2 - (gameOverOverlay.getHeight() / 2));

    backGroundFade = new Sprite(new Texture(Gdx.files.internal("gui/bgfade.png")));
    backGroundFade.setPosition(0, 0);
    backGroundFade.setSize(MainGame.WIDTH, MainGame.HEIGHT);
    backGroundFade.setAlpha(0.6f);

    grid = new Grid(15, 15, 390, 390, prefs);

    parameter.size = 20;
    parameter.shadowColor = new Color(0, 0, 0, 1f);
    parameter.shadowOffsetX = 1;
    parameter.shadowOffsetY = 1;
    score = grid.getScore();
    scoreFont = generator.generateFont(parameter);
    highscoreFont = generator.generateFont(parameter);
    redCounter = new Sprite(new Texture(Gdx.files.internal("gui/score/scorecounter.png")));
    redCounter.setSize(144, 26.4f);
    redCounter.setPosition(18, MainGame.HEIGHT - redCounter.getHeight() - 260);

    blueCounter = new Sprite(new Texture(Gdx.files.internal("gui/score/highscorecounter.png")));
    blueCounter.setSize(144, 26.4f);
    blueCounter.setPosition(
        MainGame.WIDTH - blueCounter.getWidth() - 18,
        MainGame.HEIGHT - blueCounter.getHeight() - 260);

    scoreFont.setColor(Color.WHITE);
    scoreFont.setFixedWidthGlyphs("0123456789");
    highscoreFont.setFixedWidthGlyphs("0123456789");
    grid.setPaused(false);
  }
Esempio n. 24
0
  @Override
  public void create() {
    batch = new SpriteBatch();
    img = new Texture("scale.png");
    sprite = new Sprite(img);
    sprite.setPosition(
        Gdx.graphics.getWidth() / 2 - sprite.getWidth() / 2,
        Gdx.graphics.getHeight() / 2 - sprite.getHeight() / 2);

    Gdx.input.setInputProcessor(this);
  }
Esempio n. 25
0
  @Override
  public void draw(SpriteBatch batch, float parentAlpha) {
    super.draw(batch, parentAlpha);

    Vector2 worldPos = getPosition();

    sprite.setPosition(worldPos.x - (sprite.getWidth() / 2), worldPos.y - sprite.getHeight() / 2);

    sprite.setRotation(getRotation());

    sprite.draw(batch);
  }
Esempio n. 26
0
 public Spike(float x, float y, float speed, float _size) {
   float rot = (float) (Math.random() * 360);
   _drot = (float) (Math.random() - 0.5) * 200;
   _x = x;
   _y = y;
   _dy = speed;
   _sprite = new Sprite(Resources.spike);
   _sprite.setSize(_size, _size);
   _sprite.setOrigin(_size / 2, _size / 2);
   _sprite.setPosition(_x - _size / 2, _y - _size / 2);
   // _sprite.rotate(rot);
 }
Esempio n. 27
0
  @Override
  public void render(SpriteBatch batch) {

    if (!alive) {
      return;
    }

    if (left_throttle) {
      flame.setPosition(x - width / 2, y - height);
      flame.setOrigin(width / 2, height);
      flame.setRotation(rotation);
      flame.draw(batch);
    }
    if (right_throttle) {
      flame.setPosition(x, y - height);
      flame.setOrigin(0, height);
      flame.setRotation(rotation);
      flame.draw(batch);
    }
    sprite.draw(batch);
  }
  public void initDialogBG() {

    dialogBGPath = "menu/save-score-popup/bg.png";

    // Dialog
    Texture dialogTexture = game.assetManager.getTexture(dialogBGPath);
    dialogSprite = new Sprite(dialogTexture);

    dialogSprite.setSize(536, 286);
    dialogSprite.setPosition(
        (stage.getWidth() / 2) - (dialogSprite.getWidth() / 2),
        (stage.getHeight() / 2) - (dialogSprite.getHeight() / 2));
  }
Esempio n. 29
0
  @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();
  }
Esempio n. 30
0
  public void renderLoading(float delta) {
    Gdx.gl.glClearColor(0, 0, 0, wrapper.getF());
    stateTime += delta;
    Sprite frameSprite = new Sprite(loadingAnim().getKeyFrame(stateTime, true));
    loadingBatch.begin();
    frameSprite.setColor(wrapper.getF(), wrapper.getF(), wrapper.getF(), wrapper.getF());

    //        frameSprite.setSize(Gdx.graphics.getHeight(), Gdx.graphics.getHeight()*ratio);
    frameSprite.setPosition(
        (Gdx.graphics.getWidth() / 2) - (frameSprite.getWidth() / 2),
        (Gdx.graphics.getHeight() / 2) - (frameSprite.getHeight() / 2));
    frameSprite.draw(loadingBatch, wrapper.getF());
    loadingBatch.end();
  }