Android Open Source - Phylane Level






From Project

Back to project page Phylane.

License

The source code is released under:

COPYRIGHT 2014 TRISTON JONES

If you think the Android project Phylane listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.lvadt.phylane.model;
/*  w  w  w. j a  va 2 s  .co  m*/
import java.util.Random;

import android.graphics.Point;

public class Level {

    //Types
    //0-Ground
    //1-Ceiling
    //2-Midair
  private enum Objects{
    MOUNTAIN("fly_mountains.png", 0),
        REVERSMOUNTAIN("fly_mountains_reversed.png", 0),
        STORMCLOUD("fly_stormcloud.png", 1);
  
    String filename;
        int type;

    Objects(String file, int t){
      filename = file;
            type = t;
    }
  }
  
  private enum Backgrounds{
    DEFAULT("fly_background.png");
    
    String filename;
    Backgrounds(String file){
      filename = file;
    }
  }
  
  private enum ParallaxEffects{
    DEFAULT("fly_parallax.png");
    
    String filename;
    ParallaxEffects(String file){
      filename = file;
    }
  }

    //All of these values public for rendering, could add getter/setters
  //All of the objects in the level
  public String[] filenames;
  //The position of every object
  public int[] objX, objY;
    //The point at which the level is over
    public int levelFinish;
  //Background image
  public String background;
  public String parallax = null;

    /**
     * Creates a new randomized level
     * @param size the screen size
     * @param minObjects the minimum number of objects in the level
     * @param maxObjects the maximum number of objects in the level
     * @param Difficulty the desired difficulty
     * @param maxHeight the maximum height of an object
     * @return a new random level
     */
  public static Level RandomLevel(Point size, int minObjects, int maxObjects, int Difficulty, int maxHeight){
    Random rand = new Random();
    int numberObj = rand.nextInt((maxObjects - minObjects)+1) + minObjects;
    int values = Objects.values().length;
    int pick, maxDist, minDist;
    
    String[] files = new String[numberObj];
    int[] x = new int[numberObj];
    int[] y = new int[numberObj];
    
    //Generate max distance between each object
    maxDist = 2500 / (Difficulty * 2);
    //Smallest distance
    minDist = 100;
    
    
    //Generate objects
    for(int i = 0; i < numberObj; i++){
      //Get object type
      pick = rand.nextInt(values);
            //Prevent from spawning right in front of plane
            if(i == 0)
                pick = 0;
      files[i] = Objects.values()[pick].filename;

      
      //Get position
      if(i > 0){
        x[i] = rand.nextInt((maxDist+x[i-1]) - (x[i-1]+minDist)) + (x[i-1]+minDist);
      }
      //Generate object height
            switch(Objects.values()[pick].type){
                case 0:
                    y[i] = size.y-rand.nextInt(maxHeight);
                    break;
                case 1:
                    //If it is too close to start
                    y[i] = rand.nextInt(maxHeight);
                    break;
                case 2:
                    y[i] = rand.nextInt(size.y);
                    break;
            }
    }
        //Generate level end, 100 px past last obstacle
        int le = x[numberObj-1]+100;

    Level l = new Level();
    l.filenames = files;
    l.objX = x;
    l.objY = y;
    l.background = Backgrounds.DEFAULT.filename;
    l.parallax = ParallaxEffects.DEFAULT.filename;
        l.levelFinish = le;
    return l;
  }
}




Java Source Code List

com.lvadt.phylane.BuildConfig.java
com.lvadt.phylane.activity.Fly.java
com.lvadt.phylane.activity.HomeScreen.java
com.lvadt.phylane.activity.LevelComplete.java
com.lvadt.phylane.activity.LoadScreen.java
com.lvadt.phylane.activity.MainMenu.java
com.lvadt.phylane.activity.MessagePopup.java
com.lvadt.phylane.activity.Prefs.java
com.lvadt.phylane.activity.Splash.java
com.lvadt.phylane.activity.Store.java
com.lvadt.phylane.activity.Tutorial.java
com.lvadt.phylane.graphics.GLRenderer.java
com.lvadt.phylane.graphics.Sprite.java
com.lvadt.phylane.model.GameObject.java
com.lvadt.phylane.model.Level.java
com.lvadt.phylane.model.LoadingScreens.java
com.lvadt.phylane.model.Objects.java
com.lvadt.phylane.model.Plane.java
com.lvadt.phylane.model.Player.java
com.lvadt.phylane.model.WorldObject.java
com.lvadt.phylane.physics.Physics.java
com.lvadt.phylane.utils.Data.java
com.lvadt.phylane.utils.OnSwipeTouchListener.java
com.lvadt.phylane.utils.Sound.java