Package com.sertaogames.terremoto.component

Source Code of com.sertaogames.terremoto.component.TerremotoComponent

package com.sertaogames.terremoto.component;

import java.util.List;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.sertaogames.cactus2d.Cactus2DApplication;
import com.sertaogames.cactus2d.Component;
import com.sertaogames.cactus2d.GameObject;
import com.sertaogames.cactus2d.components.LabelComponent;
import com.sertaogames.cactus2d.components.PhysicsComponent;

public class TerremotoComponent extends Component {
 
  private float maxTime = 10;
  private float time = maxTime;
  List<GameObject> objetos = null;
  LabelComponent timeLabel = null;
  LabelComponent msgLabel = null;
 
  @Override
  public void init() {
    objetos = gameObject.findAll("Objeto");
    timeLabel = gameObject.getComponent(LabelComponent.class);
    GameObject msg = gameObject.find("Message");
    msgLabel = msg.getComponent(LabelComponent.class);
  }
 
  PhysicsComponent physics = null;
  float accel = 20f;
  int facingDirectionX = 1;
  int facingDirectionY = 1;
  int groundSpeedX = 0;
  int groundSpeedY = 0;
 
  @Override
  public void update() {
   
   
    if(time < 0){
      gameObject.RemoveComponent(this);
      gameObject.AddComponent(new GameControllerComponent());
    } else {
      if(Gdx.input.isKeyPressed(Keys.T)){
        facingDirectionX *= (Math.random()) > 0.5d ? 1 : -1;
        facingDirectionY *= (Math.random()) > 0.5d ? 1 : -1;
        for (GameObject objeto : objetos) {
          physics = objeto.getComponent(PhysicsComponent.class);
          physics.rigidbody.setLinearVelocity(facingDirectionX * accel + groundSpeedX, facingDirectionY * accel + groundSpeedY);
        }
      }
      time -= Cactus2DApplication.deltaTime;
      timeLabel.text = "Time: " + (int)(1 + time) ;
      if(time > maxTime - 5){
        msgLabel.text = "TERREMOOOOOTO!!!";
      } else {
        msgLabel.text = "";
      }
    }
  }
}
TOP

Related Classes of com.sertaogames.terremoto.component.TerremotoComponent

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.