Android Open Source - googol Character






From Project

Back to project page googol.

License

The source code is released under:

MIT License

If you think the Android project googol 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.martinb.googol.Objects;
// w w  w .j  a  v a  2s. c  o m
import java.util.Comparator;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.martinb.googol.Control.Path;

/**
 * Parent of all objects in actual game, extends Body
 */
@SuppressWarnings("serial")
public class Character extends Body {

  Path path;
  Vector2 tempVector2 = new Vector2();
  float difficulty;
  float depth;
  
  public Character(float x, float y, float w, float h, Texture texture, float difficulty, World world) {
    super(x, y, w, h, texture, world);
    this.difficulty = difficulty;
    this.path = new Path(difficulty);
  }
  
  public Character(Rectangle rect, Texture texture, float difficulty, World world) {
    super(rect, texture, world);
    this.difficulty = difficulty;
    this.path = new Path(difficulty);
  }
  
  public void update(float delta) {
    path.update(delta);
    move(delta);
  }
  
  public void clicked() {
    
  }
  
  float getDepth() {
    return depth;
  }
  
  void move(float delta) {
    setPosition(getPosition(tempVector2).add(path.getVelocity().cpy().scl(delta)));
    
    // If touches line x = 0
    if (x <= 0) {
      setPosition(0, y);
      path.mirrorVelocity(Path.MIRROR_LEFT_TO_RIGHT);
    }
    
    // If touches line x = world.size.x
    if (x + width >= world.size.x) {
      setPosition(world.size.x - width, y);
      path.mirrorVelocity(Path.MIRROR_RIGHT_TO_LEFT);
    }
    
    // If touches line y = 0
    if (y < 0) {
      setPosition(x, 0);
      path.mirrorVelocity(Path.MIRROR_DOWN_TO_UP);
    }
        
    // If touches line y = world.size.y
    if (y + height >= world.size.y) {
      setPosition(x, world.size.y - height);
      path.mirrorVelocity(Path.MIRROR_UP_TO_DOWN);
    }
    
    depth = -y;
  }
}

class CharacterDepthComparator implements Comparator<Character> {

  @Override
  public int compare(Character o1, Character o2) {
    return Float.compare(o1.getDepth(), o2.getDepth());
  }
  
}




Java Source Code List

com.martinb.googol.Googol.java
com.martinb.googol.Control.Assets.java
com.martinb.googol.Control.Input.java
com.martinb.googol.Control.Path.java
com.martinb.googol.Control.Upgrades.java
com.martinb.googol.Objects.Body.java
com.martinb.googol.Objects.Character.java
com.martinb.googol.Objects.Coin.java
com.martinb.googol.Objects.World.java
com.martinb.googol.Screens.MenuScreen.java
com.martinb.googol.Screens.Screen.java
com.martinb.googol.android.AndroidLauncher.java
com.martinb.googol.client.HtmlLauncher.java
com.martinb.googol.desktop.DesktopLauncher.java