iMackshun

DecalObject.java

Jun 24th, 2016
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.99 KB | None | 0 0
  1. package com.imackshun.games.pokemonfg.objects;
  2.  
  3. import com.badlogic.gdx.graphics.GL20;
  4. import com.badlogic.gdx.graphics.Texture;
  5. import com.badlogic.gdx.graphics.g2d.TextureRegion;
  6. import com.badlogic.gdx.graphics.g3d.decals.Decal;
  7. import com.badlogic.gdx.graphics.g3d.decals.DecalBatch;
  8. import com.badlogic.gdx.math.Vector3;
  9.  
  10. public class DecalObject {
  11.     //Object Properties
  12.     private String WhichObject;
  13.     // Object Location
  14.     public Vector3 Position;
  15.     public Decal ObjectDecal;
  16.     private Texture WhichTexture;
  17.     public double DistanceFromPlayer;
  18.     private double DistanceX;
  19.     private double DistanceZ;
  20.     //Constructor
  21.     public DecalObject(float X, float Y, float Z, float Width, float Height, String WhichObject, CustomCamera Camera3D){
  22.         this.Position = new Vector3(X, Y, Z);
  23.         if(WhichObject.equals("Tree")){
  24.             WhichTexture = new Texture("Textures/TreeTexture.png");
  25.             ObjectDecal = Decal.newDecal(Width, Height, new TextureRegion(WhichTexture));
  26.             ObjectDecal.setBlending(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
  27.         }
  28.         if(WhichObject.equals("Flower")){
  29.             WhichTexture = new Texture("Textures/FlowerTexture.png");
  30.             ObjectDecal = Decal.newDecal(Width, Height, new TextureRegion(WhichTexture));
  31.             ObjectDecal.setBlending(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
  32.         }
  33.         if(WhichObject.equals("Grass")){
  34.             WhichTexture = new Texture("Textures/GrassTexture.png");
  35.             ObjectDecal = Decal.newDecal(Width, Height, new TextureRegion(WhichTexture));
  36.             ObjectDecal.setBlending(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
  37.         }
  38.         ObjectDecal.translateX(X);
  39.         ObjectDecal.translateY(Y);
  40.         ObjectDecal.translateZ(Z);
  41.         ObjectDecal.lookAt(Camera3D.Camera.position, Camera3D.Camera.up);
  42.     }
  43.     public void Draw(DecalBatch batch){
  44.         batch.add(ObjectDecal);
  45.     }
  46.     public void CalculateDistance(Player player){
  47.         DistanceX = Math.pow(Position.x - player.Position.x, 2);
  48.         DistanceZ = Math.pow(-Position.z - player.Position.z, 2);
  49.         DistanceFromPlayer = Math.sqrt(DistanceX + DistanceZ);
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment