Android Open Source - NotATop Classic Game






From Project

Back to project page NotATop.

License

The source code is released under:

GNU General Public License

If you think the Android project NotATop 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.gg.game;
/*  w  w  w  .j  a  va 2s  .co  m*/
import java.util.ArrayList;
import javax.microedition.khronos.opengles.GL10;
import android.view.MotionEvent;
import android.widget.Toast;
import com.gg.module.*;
import com.gg.top.BasicTop;
import com.gg.top.DrawTop;
import com.gg.util.*;
import com.gg.view.R;

/* ?????????????????????????????????? */
public class ClassicGame extends GameFrame implements Runnable { // ????????????????????????????

  /* 3D???????????? */
  private GL10 gl; // ??3D???????????gl????
  private int coneTextureId; // ??????????????
  private int cylinderTextureId; // ????????????????
  private int circleTextureId; // ??????????????
  private int pauseTextureId; // ?????????????????

  /* ????????????????? */
  private long startTime; // ????????????????????????????????????????
  private long endTime; // ??startTime???
  private long touchStart; // ??????startTime??????????????????????????????ACTION_MOVE??????????????
  private boolean responseFlag; // ?????????????????????
  private Point firstPoint; // ?????????????????????????????????????????????????
  private Point secondPoint; // ??????????????????

  /* ????????????? */
  private Thread thread; // ??????????????
  private int state; // ?????????????
  private double duration; // ??????????????
  private double score; // ???????????????????????????????????????????????????????????????????????
  private DrawTop drawTop; // 3D???????
  private Circle logicCircle; // ????????????????????????????????????????????????????????????????????????
  private DrawBackground drawPause; // ???????????????

  /* ???????????? */
  private boolean collideFlag; // ?????????????????????????????????????Activity??????
  private boolean crackFlag; // ???????????Crack???????

  /* ?????????? */
  private boolean difficultyFlag; // ????????????????????????????????????????
  
  public ClassicGame(GL10 gl, int coneTextureId, int cylinderTextureId,
      int circleTextureId, int pauseTextureId) { // ?????????3D???

    this.gl = gl;
    this.coneTextureId = coneTextureId;
    this.cylinderTextureId = cylinderTextureId;
    this.circleTextureId = circleTextureId;
    this.pauseTextureId = pauseTextureId;

    state = PREPARE; // ?????????????
    init(); // ??????????????????????????????????
  }

  @Override
  public void init() {
    // TODO Auto-generated method stub
    
    drawTop = new DrawTop(coneTextureId, cylinderTextureId, circleTextureId);// ????????????????????????????
    logicCircle = new Circle(drawTop.getBasicPoint().x, 
        drawTop.getBasicPoint().y, drawTop.getRadius()); // ???????????????????????

    drawPause = new DrawBackground(pauseTextureId); // ?????????????????????????????

    firstPoint = new Point(0f, 0f, 0f); // ?????????????????????????????????????
    secondPoint = new Point(0f, 0f, 0f); // ????????????????
  }

  @Override
  public void start() {
    // TODO Auto-generated method stub
    
    state = RUN; // ??????????RUN??????
    drawTop.setState(RUN); // ???????????RUN??????

    duration = 0; // ?????????????
    score = 0; // ??????????????

    thread = new Thread(this); // ?????????????????????
    thread.start(); // ??????????????
  }

  public void run() {
    // TODO Auto-generated method stub
    
    while (true) { // ?????????????????????????????????????????????????????????????
      long start = System.currentTimeMillis(); // ?????????????????????

      logic(); // ????????????

      long end = System.currentTimeMillis(); // ???????????????????

      try {
        if (end - start < Constant.INTERVAL) { // ?????????????????????????
          thread.sleep(Constant.INTERVAL - (end - start)); // ?????????????????????????????????????????
        }
      } catch (Exception e) { // ???sleep?????????????
        e.printStackTrace();
      }
    }
  }

  @Override
  public void onTouch(MotionEvent e) {
    // TODO Auto-generated method stub
    
    switch (e.getAction()) {
    case MotionEvent.ACTION_DOWN:
      if (state == RUN) {
        responseFlag = false;
      } else if (state == PAUSE) {
        double x = Constant.convertX(e.getX());
        double y = Constant.convertY(e.getY());
        
        if(x>-0.8 && x<-0.2 && y>0.-6 && y<0.0){
          resume();
        }else if(x<0.8 && x>0.2 && y>0.-6 && y<0.0){
          end();
        }
      }
      break;
    case MotionEvent.ACTION_MOVE:
      if (state == RUN) {
        if (responseFlag == false) {
          if (isInLogicCircle(Constant.convertX(e.getX()),
              Constant.convertY(e.getY()))) {
            startTime = System.currentTimeMillis();

            touchStart = System.currentTimeMillis();

            firstPoint.x = Constant.convertX(e.getX());
            firstPoint.y = Constant.convertY(e.getY());

            responseFlag = true;
          }
        } else {
          endTime = System.currentTimeMillis();

          if (crackFlag == true) {
            endTime = 0;
          }

          if (endTime - startTime > 90) {
            return;
          }

          if (System.currentTimeMillis() - touchStart > Constant.INTERVAL) {
            if (isInLogicCircle(Constant.convertX(e.getX()),
                Constant.convertY(e.getY()))) {
              secondPoint.x = Constant.convertX(e.getX());
              secondPoint.y = Constant.convertY(e.getY());

              responseTouch(firstPoint, secondPoint);
              // System.out.println("response");

              touchStart = System.currentTimeMillis();
              firstPoint.x = Constant.convertX(e.getX());
              firstPoint.y = Constant.convertY(e.getY());
            }

          }
        }
      }

      break;
    case MotionEvent.ACTION_UP:
      if (state == RUN) {
        firstPoint.x = 0;
        firstPoint.y = 0;
        secondPoint.x = 0;
        secondPoint.y = 0;

        responseFlag = false;
      }

      break;
    }
  }

  @Override
  public void logic() {
    // TODO Auto-generated method stub

    if (state == RUN) {
      drawTop.logic();

      updateLogicCircle();

      duration += (double) Constant.INTERVAL / 1000;
      score += (double) Constant.INTERVAL / 1000 * drawTop.getAxleAngle()
          * 10 + duration * 120 / 1000;// ???????????????????????

      if ((int) duration % 30 == 29) {
        difficultyFlag = true;
        drawTop.setAutoAngleAccelerate(drawTop.getAutoAngleAccelerate() * 1.005f);
      }

    } else if (state == PAUSE) {

    }

    if (drawTop.getAxleAngle() > drawTop.getDEAD_AXLE_ANGLE()) {
      end();
    }

    if (logicCircle.getCenter().x - logicCircle.getRadius() <= -Constant.LOGIC_WIDTH / 2) { // ??????
      drawTop.getBasicPoint().x += 0.1f; // ????????????????0.05?????????????0.1????????
      drawTop.setxMoveSpeed(-drawTop.getxMoveSpeed() * 1 / 2); // ???????????
      drawTop.setAngleSpeed(drawTop.getAngleSpeed() * 9 / 10); // ????????
      collideFlag = true; // ???????????????????????
    } else if (logicCircle.getCenter().x + logicCircle.getRadius() >= Constant.LOGIC_WIDTH / 2) { // ??????
      drawTop.getBasicPoint().x -= 0.1f;
      drawTop.setxMoveSpeed(-drawTop.getxMoveSpeed() * 1 / 2);
      drawTop.setAngleSpeed(drawTop.getAngleSpeed() * 9 / 10);
      collideFlag = true;
    }

    if (logicCircle.getCenter().y + logicCircle.getRadius() >= Constant.LOGIC_HEIGHT / 2) { // ??????
      drawTop.getBasicPoint().y -= 0.1f;
      drawTop.setyMoveSpeed(-drawTop.getyMoveSpeed() * 1 / 2);
      drawTop.setAngleSpeed(drawTop.getAngleSpeed() * 9 / 10);
      collideFlag = true;
    } else if (logicCircle.getCenter().y - logicCircle.getRadius() <= -Constant.LOGIC_HEIGHT / 2) { // ??????
      drawTop.getBasicPoint().y += 0.1f;
      drawTop.setyMoveSpeed(-drawTop.getyMoveSpeed() * 1 / 2);
      drawTop.setAngleSpeed(drawTop.getAngleSpeed() * 9 / 10);
      collideFlag = true;
    }

  }

  @Override
  public void draw(GL10 gl) {
    // TODO Auto-generated method stub
    if (state == RUN) {
      drawTop.drawSelf(gl);
    } else if (state == PAUSE) {
      drawPause.drawSelf(gl);
    }
  }

  @Override
  public void pause() {
    // TODO Auto-generated method stub

    state = PAUSE;
  }

  @Override
  public void resume() {
    // TODO Auto-generated method stub

    state = RUN;
  }

  @Override
  public void end() {
    // TODO Auto-generated method stub

    try {
      Thread.sleep(500);
    } catch (Exception e) {
      e.printStackTrace();
    }

    state = END;
    drawTop.setState(END);

  }

  @Override
  public void save() {
    // TODO Auto-generated method stub

  }

  @Override
  public void load() {
    // TODO Auto-generated method stub

  }

  public DrawTop getDrawTop() {
    return drawTop;
  }

  public int getState() {
    return state;
  }

  public void setState(int state) {
    this.state = state;
  }

  public void updateLogicCircle() {
    logicCircle.getCenter().x = drawTop.getBasicPoint().x + 3
        * drawTop.getRadius()
        * (float) Math.sin(drawTop.getAxleAngle() * Math.PI / 180)
        * (float) Math.cos(drawTop.getAxleAngleCount() * Math.PI / 180);
    logicCircle.getCenter().y = drawTop.getBasicPoint().y + 3
        * drawTop.getRadius()
        * (float) Math.sin(drawTop.getAxleAngle() * Math.PI / 180)
        * (float) Math.sin(drawTop.getAxleAngleCount() * Math.PI / 180);
    logicCircle.setRadius(drawTop.getRadius());

  }

  public boolean isInLogicCircle(float x, float y) {
    float distance = (float) Math.sqrt((x - logicCircle.getCenter().x)
        * (x - logicCircle.getCenter().x)
        + (y - logicCircle.getCenter().y)
        * (y - logicCircle.getCenter().y));
    if (distance < logicCircle.getRadius() * 1.2
        && distance > logicCircle.getRadius() / 3) {
      return true;
    } else {
      return false;
    }

  }

  public void responseTouch(Point firstPoint, Point secondPoint) {

    Line touchLine = new Line(firstPoint, secondPoint);
    Line axleLine = new Line(drawTop.getBasicPoint(),
        logicCircle.getCenter());

    float angleSpeedOffset = 0.7f; // ????????????????????????1.0????????????0.8??????????0.5???????,0.6????,0.7????
    float downAngleSpeedOffset = 0.5f; // ?????????????????????????????????????????

    float xMoveOffset = 0.04f; // ????????x????????????0.06??????,0.04???????????????
    float yMoveOffset = 0.04f; // ????????y????????????
    float xMoveSpeedOffset = 0.0015f; // ??????x??????????????0.001???????????????????????,0.02??????0.0015???????
    float yMoveSpeedOffset = 0.0015f; // ??????y????????????

    switch (touchLine.getDirection().getDirection()) { // ????????????????
    case Direction.UP_RIGHT: // ??????????????????
      if (touchLine.directionCircle(logicCircle).getDirection() == Direction.DOWN) { // ??????????????????????
        angleSpeedOffset = -angleSpeedOffset; // ????????
        xMoveSpeedOffset = -xMoveSpeedOffset; // ???????
        yMoveSpeedOffset = yMoveSpeedOffset; // ???????
        xMoveOffset = -xMoveOffset; // ??????????????????????
        yMoveOffset = yMoveOffset; // ??????????????????????
        if (axleLine.getDirection().getDirection() == Direction.UP_LEFT) { // ??????????????????
          downAngleSpeedOffset = -downAngleSpeedOffset; // ????????????????????
        } else if (axleLine.getDirection().getDirection() == Direction.DOWN_RIGHT) { // ??????????????????
          downAngleSpeedOffset = downAngleSpeedOffset; // ????????????????????????
        }
      } else if (touchLine.directionCircle(logicCircle).getDirection() == Direction.UP) {
        angleSpeedOffset = angleSpeedOffset;
        xMoveSpeedOffset = xMoveSpeedOffset;
        yMoveSpeedOffset = -yMoveSpeedOffset;
        xMoveOffset = xMoveOffset;
        yMoveOffset = -yMoveOffset;
        if (axleLine.getDirection().getDirection() == Direction.DOWN_RIGHT) {
          downAngleSpeedOffset = -downAngleSpeedOffset;
        } else if (axleLine.getDirection().getDirection() == Direction.UP_LEFT) {
          downAngleSpeedOffset = downAngleSpeedOffset;
        }
      }
      break;
    case Direction.DOWN_RIGHT:
      if (touchLine.directionCircle(logicCircle).getDirection() == Direction.DOWN) {
        angleSpeedOffset = -angleSpeedOffset;
        xMoveSpeedOffset = xMoveSpeedOffset;
        yMoveSpeedOffset = yMoveSpeedOffset;
        xMoveOffset = xMoveOffset;
        yMoveOffset = yMoveOffset;
        if (axleLine.getDirection().getDirection() == Direction.UP_RIGHT) {
          downAngleSpeedOffset = -downAngleSpeedOffset;
        } else if (axleLine.getDirection().getDirection() == Direction.DOWN_LEFT) {
          downAngleSpeedOffset = downAngleSpeedOffset;
        }
      } else if (touchLine.directionCircle(logicCircle).getDirection() == Direction.UP) {
        angleSpeedOffset = angleSpeedOffset;
        xMoveSpeedOffset = -xMoveSpeedOffset;
        yMoveSpeedOffset = -yMoveSpeedOffset;
        xMoveOffset = -xMoveOffset;
        yMoveOffset = -yMoveOffset;
        if (axleLine.getDirection().getDirection() == Direction.DOWN_LEFT) {
          downAngleSpeedOffset = -downAngleSpeedOffset;
        } else if (axleLine.getDirection().getDirection() == Direction.UP_RIGHT) {
          downAngleSpeedOffset = downAngleSpeedOffset;
        }
      }
      break;
    case Direction.UP_LEFT:
      if (touchLine.directionCircle(logicCircle).getDirection() == Direction.DOWN) {
        angleSpeedOffset = angleSpeedOffset;
        xMoveSpeedOffset = xMoveSpeedOffset;
        yMoveSpeedOffset = yMoveSpeedOffset;
        xMoveOffset = xMoveOffset;
        yMoveOffset = yMoveOffset;
        if (axleLine.getDirection().getDirection() == Direction.UP_RIGHT) {
          downAngleSpeedOffset = -downAngleSpeedOffset;
        } else if (axleLine.getDirection().getDirection() == Direction.DOWN_LEFT) {
          downAngleSpeedOffset = downAngleSpeedOffset;
        }
      } else if (touchLine.directionCircle(logicCircle).getDirection() == Direction.UP) {
        angleSpeedOffset = -angleSpeedOffset;
        xMoveSpeedOffset = -xMoveSpeedOffset;
        yMoveSpeedOffset = -yMoveSpeedOffset;
        xMoveOffset = -xMoveOffset;
        yMoveOffset = -yMoveOffset;
        if (axleLine.getDirection().getDirection() == Direction.DOWN_LEFT) {
          downAngleSpeedOffset = -downAngleSpeedOffset;
        } else if (axleLine.getDirection().getDirection() == Direction.UP_RIGHT) {
          downAngleSpeedOffset = downAngleSpeedOffset;
        }
      }
      break;
    case Direction.DOWN_LEFT:
      if (touchLine.directionCircle(logicCircle).getDirection() == Direction.DOWN) {
        angleSpeedOffset = angleSpeedOffset;
        xMoveSpeedOffset = -xMoveSpeedOffset;
        yMoveSpeedOffset = yMoveSpeedOffset;
        xMoveOffset = -xMoveOffset;
        yMoveOffset = yMoveOffset;
        if (axleLine.getDirection().getDirection() == Direction.UP_LEFT) {
          downAngleSpeedOffset = -downAngleSpeedOffset;
        } else if (axleLine.getDirection().getDirection() == Direction.DOWN_RIGHT) {
          downAngleSpeedOffset = downAngleSpeedOffset;
        }
      } else if (touchLine.directionCircle(logicCircle).getDirection() == Direction.UP) {
        angleSpeedOffset = -angleSpeedOffset;
        xMoveSpeedOffset = xMoveSpeedOffset;
        yMoveSpeedOffset = -yMoveSpeedOffset;
        xMoveOffset = xMoveOffset;
        yMoveOffset = -yMoveOffset;
        if (axleLine.getDirection().getDirection() == Direction.DOWN_RIGHT) {
          downAngleSpeedOffset = -downAngleSpeedOffset;
        } else if (axleLine.getDirection().getDirection() == Direction.UP_LEFT) {
          downAngleSpeedOffset = downAngleSpeedOffset;
        }
      }
      break;
    }

    if (drawTop.getAngleSpeed() + angleSpeedOffset < BasicTop.MAX_ANGLE_SPEED) { // ???????????????????????
      drawTop.setAngleSpeed(drawTop.getAngleSpeed() + angleSpeedOffset);
    }

    if (drawTop.getAngleSpeed() + downAngleSpeedOffset < BasicTop.MAX_ANGLE_SPEED) {
      drawTop.setAngleSpeed(drawTop.getAngleSpeed()
          + downAngleSpeedOffset);
    }

    if (Math.abs(drawTop.getxMoveSpeed() + xMoveSpeedOffset) < BasicTop.X_MAX_MOVE_SPEED) {
      drawTop.setxMoveSpeed(drawTop.getxMoveSpeed() + xMoveSpeedOffset);
    }

    if (Math.abs(drawTop.getyMoveSpeed() + yMoveSpeedOffset) < BasicTop.Y_MAX_MOVE_SPEED) {
      drawTop.setyMoveSpeed(drawTop.getyMoveSpeed() + yMoveSpeedOffset);
    }

    if (drawTop.getBasicPoint().x + xMoveOffset > -Constant.LOGIC_WIDTH / 2
        && drawTop.getBasicPoint().x + xMoveOffset < Constant.LOGIC_WIDTH / 2) {
      drawTop.setBasicPoint(new Point(drawTop.getBasicPoint().x
          + xMoveOffset, drawTop.getBasicPoint().y));
    }

    if (drawTop.getBasicPoint().y + yMoveOffset > -Constant.LOGIC_HEIGHT / 2
        && drawTop.getBasicPoint().y + yMoveOffset < Constant.LOGIC_HEIGHT / 2) {
      drawTop.setBasicPoint(new Point(drawTop.getBasicPoint().x, drawTop
          .getBasicPoint().y + yMoveOffset));
    }

  }

  public double getDuration() {
    return duration;
  }

  public void setDuration(double duration) {
    this.duration = duration;
  }

  public double getScore() {
    return score;
  }

  public void setScore(double score) {
    this.score = score;
  }

  public boolean isCollideFlag() {
    return collideFlag;
  }

  public void setCollideFlag(boolean collideFlag) {
    this.collideFlag = collideFlag;
  }

  public boolean isDifficultyFlag() {
    return difficultyFlag;
  }

  public void setDifficultyFlag(boolean difficultFlag) {
    this.difficultyFlag = difficultFlag;
  }

  public boolean isCrackFlag() {
    return crackFlag;
  }

  public void setCrackFlag(boolean crackFlag) {
    this.crackFlag = crackFlag;
  }

}




Java Source Code List

com.gg.game.ClassicGame.java
com.gg.game.ClassicGame.java
com.gg.game.GameFrame.java
com.gg.game.GameFrame.java
com.gg.game.TimeGame.java
com.gg.game.TimeGame.java
com.gg.module.DrawBackground.java
com.gg.module.DrawBackground.java
com.gg.module.DrawScore.java
com.gg.module.DrawScore.java
com.gg.module.DrawTrack.java
com.gg.module.DrawTrack.java
com.gg.module.SelectControl.java
com.gg.module.SelectControl.java
com.gg.module.SoundControl.java
com.gg.module.SoundControl.java
com.gg.module.VoiceControl.java
com.gg.module.VoiceControl.java
com.gg.top.BasicTop.java
com.gg.top.BasicTop.java
com.gg.top.DrawCircle.java
com.gg.top.DrawCircle.java
com.gg.top.DrawCone.java
com.gg.top.DrawCone.java
com.gg.top.DrawCylinder.java
com.gg.top.DrawCylinder.java
com.gg.top.DrawTop.java
com.gg.top.DrawTop.java
com.gg.util.Circle.java
com.gg.util.Circle.java
com.gg.util.Constant.java
com.gg.util.Constant.java
com.gg.util.DateUtil.java
com.gg.util.DateUtil.java
com.gg.util.Direction.java
com.gg.util.Direction.java
com.gg.util.Line.java
com.gg.util.Line.java
com.gg.util.Point.java
com.gg.util.Point.java
com.gg.util.TextureRect.java
com.gg.util.TextureRect.java
com.gg.util.TrackPoint.java
com.gg.util.TrackPoint.java
com.gg.util.Track.java
com.gg.util.Track.java
com.gg.util.Utils.java
com.gg.util.Utils.java
com.gg.view.ClassicGameSurfaceView.java
com.gg.view.ClassicGameSurfaceView.java
com.gg.view.EndSurfaceView.java
com.gg.view.EndSurfaceView.java
com.gg.view.FirstTimeSurfaceView.java
com.gg.view.FirstTimeSurfaceView.java
com.gg.view.GameModeSurfaceView.java
com.gg.view.GameModeSurfaceView.java
com.gg.view.HelpSurfaceView.java
com.gg.view.HelpSurfaceView.java
com.gg.view.MainActivity.java
com.gg.view.MainActivity.java
com.gg.view.MainMenuSurfaceView.java
com.gg.view.MainMenuSurfaceView.java
com.gg.view.ScoreSurfaceView.java
com.gg.view.ScoreSurfaceView.java
com.gg.view.SelectSurfaceView.java
com.gg.view.SelectSurfaceView.java
com.gg.view.SurfaceViewFactory.java
com.gg.view.SurfaceViewFactory.java
com.gg.view.TimeGameSurfaceView.java
com.gg.view.TimeGameSurfaceView.java
com.gg.view.WelcomeSurfaceView.java
com.gg.view.WelcomeSurfaceView.java