Android Open Source - Terry-Coin Coin






From Project

Back to project page Terry-Coin.

License

The source code is released under:

Apache License

If you think the Android project Terry-Coin 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.tcg.terry.entities;
/*  ww  w  . java2 s. c o  m*/
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Rectangle;
import com.tcg.terry.main.Game;
import com.tcg.terry.managers.Timer;

public class Coin {
  
  private Player player;
  long coins;
  private Sprite sprite;
  private Timer t;
  
  private Texture coin = new Texture(Gdx.files.internal("entities/coin.png"));
  
  public Coin(Player player, float x, Timer t) {
    this.player = player;
    this.t = t;
    sprite = new Sprite(coin);
    sprite.setPosition(x, Game.HEIGHT * .5f);    
    sprite.setScale(2);
  }
  
  public void draw(SpriteBatch sb) {
    if(t.isCounting()) sprite.draw(sb);
  }
  
  public void update(float dt) {
    if(t.isCounting()) {  
      if(sprite.getBoundingRectangle().overlaps(player.getBounds())) {
        sprite.setX(MathUtils.random(Game.WIDTH - sprite.getWidth()));
        Game.res.getSound("coin").play();
        coins++;
      }
    }
  }
  
  public long getCoins() { return coins; }
  public String coinString() { return Long.toString(coins); }
  
  public Rectangle getBounds() { return sprite.getBoundingRectangle(); }
  
  public void dispose() {
    coin.dispose();
  }

}




Java Source Code List

com.tcg.terry.MainActivity.java
com.tcg.terry.Main.java
com.tcg.terry.entities.Button.java
com.tcg.terry.entities.Cloud.java
com.tcg.terry.entities.Coin.java
com.tcg.terry.entities.Cursor.java
com.tcg.terry.entities.Flower.java
com.tcg.terry.entities.Ground.java
com.tcg.terry.entities.JumpButton.java
com.tcg.terry.entities.MenuButton.java
com.tcg.terry.entities.Player.java
com.tcg.terry.entities.SprintButton.java
com.tcg.terry.gamestates.ControlsState.java
com.tcg.terry.gamestates.GameOverState.java
com.tcg.terry.gamestates.GameState.java
com.tcg.terry.gamestates.MenuState.java
com.tcg.terry.gamestates.PlayState.java
com.tcg.terry.gamestates.SplashState.java
com.tcg.terry.main.Game.java
com.tcg.terry.managers.Content.java
com.tcg.terry.managers.GameStateManager.java
com.tcg.terry.managers.Timer.java