Package com.sertaogames.terremoto.level

Source Code of com.sertaogames.terremoto.level.MenuLevel

package com.sertaogames.terremoto.level;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.sertaogames.cactus2d.Cactus2DApplication;
import com.sertaogames.cactus2d.Cactus2DLevel;
import com.sertaogames.cactus2d.GameObject;
import com.sertaogames.cactus2d.components.AnimationComponent;
import com.sertaogames.cactus2d.components.AudioComponent;
import com.sertaogames.cactus2d.components.ButtonComponent;
import com.sertaogames.cactus2d.components.LevelLoader;
import com.sertaogames.cactus2d.components.SpriteRendererComponent;
import com.sertaogames.terremoto.Utils;
import com.sertaogames.terremoto.component.ToggleButtonComponent;

public class MenuLevel extends Cactus2DLevel {
 
  @Override
  protected void init() {
   
    GameObject go = new GameObject("back");
    Texture texture = Cactus2DApplication.loadTexture("data/textures/allTextures.png", true);
    int width = 600;
    int height = 1024;
    TextureRegion[][] matriz = TextureRegion.split(texture, width, height);
    SpriteRendererComponent sr = new SpriteRendererComponent(texture);
    sr.spriteRegion = matriz[0][0];
    Utils.offsetCorrection(go.transform.getLocalPosition());
   
    go.AddComponent(sr);
    addGameObject(go);
   
    GameObject seismographGO = new GameObject("seismograph");
    texture = Cactus2DApplication.loadTexture("data/textures/gui.png", true);
    width = 512;
    height = 256;
    seismographGO.transform.getPosition().set(300 - width/2, 1024 - height * 1.2f);
    Utils.offsetCorrection(seismographGO.transform.getLocalPosition());
    TextureRegion[][] matriz3 = TextureRegion.split(texture, width, height);
    sr = new SpriteRendererComponent(null,matriz3[2][0]);
    seismographGO.AddComponent(sr);
    addGameObject(seismographGO);
   
    GameObject animatedGO = new GameObject("anim");
    AnimationComponent anim = new AnimationComponent();
    Texture tx  = new Texture(Gdx.files.internal("data/textures/sismoAnim.png"));
    int[] frames = { 0, 1, 2, 3, 4, 5, 6, 7};
    anim.addAnimation("anim", tx, 384, 192, frames, 5, false);
   
    anim.play("anim");
   
    animatedGO.AddComponent(anim);
    animatedGO.AddComponent(new SpriteRendererComponent(null));
    animatedGO.transform.getPosition().add(width/2 - 370/2, height/2 - 215/2);
    seismographGO.addGameObject(animatedGO);
   
    GameObject titleGO = new GameObject("title");
    titleGO.transform.getPosition().add(width/2 - 384/2, height/2 - 128/2);
    width = 384;
    height = 128;
    TextureRegion[][] matriz2 = TextureRegion.split(texture, 384, 128);
     sr = new SpriteRendererComponent(null,matriz2[6][0]);
     titleGO.AddComponent(sr);
    seismographGO.addGameObject(titleGO);
   
    go = new GameObject("play");
    go.AddComponent(new SpriteRendererComponent(null));
   
    Texture bt = Cactus2DApplication.loadTexture("data/textures/gui.png",true);
    width = 256;
    height = 128;
    TextureRegion[][] tmp = TextureRegion.split(bt, width, height);
    go.transform.getLocalPosition().add(Gdx.graphics.getWidth()/2 - 128 * Cactus2DApplication.invCameraZoom, Gdx.graphics.getHeight()/2 - 64 * Cactus2DApplication.invCameraZoom);
    go.spriteRenderer.gui = true;
    go.AddComponent(new ButtonComponent(tmp[2][0],tmp[2][1]));
    go.AddComponent(new LevelLoader(MainLevel.class));
    go.AddComponent(new AudioComponent("data/sound/click.wav"));
    addGameObject(go);

    go = new GameObject("sound");
    tmp = TextureRegion.split(bt, 128, 128);
    go.AddComponent(new ButtonComponent(tmp[1][4],tmp[1][5]));
    go.AddComponent(new SpriteRendererComponent(null));
    go.AddComponent(new ToggleButtonComponent(tmp[1][2],tmp[1][3], tmp[1][4],tmp[1][5]));
    addGameObject(go);
   
    Cactus2DApplication.jukeBox.play(0);
  }

}
TOP

Related Classes of com.sertaogames.terremoto.level.MenuLevel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.