Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 03-27 01:14:59.567 19696-19696/com.example.sam.matrix D/ViewRootImpl﹕ ViewPostImeInputStage ACTION_DOWN
- 03-27 01:14:59.567 19696-19696/com.example.sam.matrix I/System.out﹕ TOUCHED BOARD X: 206
- 03-27 01:14:59.567 19696-19696/com.example.sam.matrix I/System.out﹕ TOUCHED BOARD Y: 190
- 03-27 01:14:59.567 19696-19696/com.example.sam.matrix I/System.out﹕ POSITION OF off X = 3
- 03-27 01:14:59.567 19696-19696/com.example.sam.matrix I/System.out﹕ POSITION OF off Y = 0
- 03-27 01:14:59.567 19696-19696/com.example.sam.matrix I/System.out﹕ POSITION OF pix X = 165
- 03-27 01:14:59.567 19696-19696/com.example.sam.matrix I/System.out﹕ POSITION OF pix Y = 0
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ _____________CELL TEMP_____________
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ CELL Shape = 6
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ CELL pixX = 165
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ CELL pixY = 0
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ CELL offX = 3
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ CELL offY = 0
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ _____________BEFORE SWAP_____________
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ _____________CELL TOUCH_____________
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ board[col][row] Shape = 6
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ board[col][row] pixX = 165
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ board[col][row] pixY = 0
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ board[col][row] offX = 3
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ board[col][row] offY = 0
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ _____________CELL TOUCH SWAP_____________
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ board[col+horzDelta][row] Shape = 6
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ board[col+horzDelta][row] pixX = 110
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ board[col+horzDelta][row] pixY = 0
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ board[col+horzDelta][row] offX = 2
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ board[col+horzDelta][row] offY = 0
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ _____________AFTER SWAP_____________
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ _____________CELL TOUCH_____________
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ board[col][row] Shape = 6
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ board[col][row] pixX = 110
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ board[col][row] pixY = 0
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ board[col][row] offX = 2
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ board[col][row] offY = 0
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ _____________CELL TOUCH SWAP_____________
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ board[col+horzDelta][row] Shape = 6
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ board[col+horzDelta][row] pixX = 165
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ board[col+horzDelta][row] pixY = 0
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ board[col+horzDelta][row] offX = 3
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ board[col+horzDelta][row] offY = 0
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ ____________ RENDERING ____________
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ _____________CELL RENDER swapped left_____________
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ BOARD Shape = 6
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ BOARD PIX X START = 110
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ BOARD PIX Y START = 0
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ BOARD offX = 2
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ BOARD offY = 0
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ _____________CELL RENDER swapped right_____________
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ BOARD Shape = 6
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ BOARD PIX X START = 165
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ BOARD PIX Y START = 0
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ BOARD offX = 3
- 03-27 01:14:59.817 19696-19717/com.example.sam.matrix I/System.out﹕ BOARD offY = 0
- public class Cell {
- //which shape the cell will consist
- private int shape;
- //offset of where the cell is located by cell number -> need to translate the given coordinates to pixel
- private int pixX, pixY;
- private int offX, offY;
- public Cell(int shape, int pixX, int pixY, int offX, int offY){
- this.shape = shape;
- this.pixX = pixX;
- this.pixY = pixY;
- this.offX = offX;
- this.offY = offY;
- }
- public class Board {
- private int col = 8, row= 1;
- private Cell[][] board;
- public void randomBoard(){
- board = new Cell[col][row];
- //Initialize board with cells
- for (int r = 0 ; r<row; r++){
- for(int c = 0; c< col; c++){
- board[c][r] = new Cell(rand.getRandIntBetween(0,6), translateOffsetToPixel(c,r).getX(), translateOffsetToPixel(c,r).getY(),c,r);
- }
- }
- }
- public void swap( int col, int row, int horzDelta, int vertDelta ){
- Cell temp;
- temp = board[col][row];
- //left swap
- if(horzDelta == -1 || horzDelta == 1){
- board[col][row] = board[col+horzDelta][row];
- board[col+horzDelta][row] =temp;
- }
- }
- public class PlayState extends State{
- private Board board;
- @Override
- public void render(Painter g) {
- // g.setBackground(Color.WHITE);
- g.setColor(Color.rgb(255, 255, 255));
- g.fillRect(0, 0, GameMainActivity.GAME_WIDTH, GameMainActivity.GAME_HEIGHT);
- renderBoard(g);
- }
- public void renderBoard(Painter g) {
- // g.drawImage(Assets.circle50 ,board.getBoard()[0][0].getX(), board.getBoard()[0][0].getY(), board.getBoard()[0][0].getX()+25,board.getBoard()[0][0].getY()+25 );
- for(int r = 0; r<board.getRow(); r++){
- for(int c = 0; c<board.getCol(); c++){
- renderCell(g,c,r);
- }
- }
- }
- public void renderCell( Painter g, int col, int row){
- if(board.getSwapLeft() &&
- col == touchedCell.getOffX() &&
- row == touchedCell.getOffY() &&
- touchedCell.getPixX() != 10 )
- {
- //LEFT SWIPE
- board.swap(col, row, -1,0);
- board.setSwapLeft(false);
- }
- switch(board.getBoard()[col][row].getShape()){
- case(0):
- g.drawImage(Assets.circle50 ,board.getBoard()[col][row].getPixX()+SHIFT_RIGHT, board.getBoard()[col][row].getPixY()+SHIFT_DOWN,
- board.getBoard()[0][0].getPixX()+SHAPE_WIDTH,board.getBoard()[0][0].getPixY()+SHAPE_HEIGHT );
- break;
- case(1):
- g.drawImage(Assets.diamond50 ,board.getBoard()[col][row].getPixX()+SHIFT_RIGHT, board.getBoard()[col][row].getPixY()+SHIFT_DOWN,
- board.getBoard()[0][0].getPixX()+SHAPE_WIDTH,board.getBoard()[0][0].getPixY()+SHAPE_HEIGHT );
- break;
- case(2):
- g.drawImage(Assets.heart50 ,board.getBoard()[col][row].getPixX()+SHIFT_RIGHT, board.getBoard()[col][row].getPixY()+SHIFT_DOWN,
- board.getBoard()[0][0].getPixX()+SHAPE_WIDTH,board.getBoard()[0][0].getPixY()+SHAPE_HEIGHT );
- break;
- case(3):
- g.drawImage(Assets.pentagon50 ,board.getBoard()[col][row].getPixX()+SHIFT_RIGHT, board.getBoard()[col][row].getPixY()+SHIFT_DOWN,
- board.getBoard()[0][0].getPixX()+SHAPE_WIDTH,board.getBoard()[0][0].getPixY()+SHAPE_HEIGHT );
- break;
- @Override
- public boolean onTouch(MotionEvent e, int scaledX, int scaledY) {
- if (e.getAction() == MotionEvent.ACTION_DOWN && board.touchBoard(scaledX, scaledY) ) {
- recentTouchY = scaledY;
- recentTouchX = scaledX;
- System.out.println("TOUCHED BOARD X: "+ scaledX);
- System.out.println("TOUCHED BOARD Y: "+ scaledY);
- board.whichCell(scaledX,scaledY);
- touchedCell = board.whichCellTouched(scaledX,scaledY);
- } else if (e.getAction() == MotionEvent.ACTION_UP) {
- //swipe event
- if (scaledX - recentTouchX < -25) {
- board.setSwapLeft(true);
- }
- /*
- else if (scaledY - recentTouchY > 50) {
- player.duck();
- }
- */
- }
- return true;
- }
- /*
- * GameView:
- * The central class for our game, replaces the Game class
- * GameView will host our game loop, and will have methods to start and exit out of our game
- */
- /*
- * Inherit from SurfaceView to have on activity for the entire program -> have whichever state
- */
- public class GameView extends SurfaceView implements Runnable {
- private Bitmap gameImage;
- private Rect gameImageSrc;
- private Rect gameImageDst;
- private Canvas gameCanvas;
- private Painter graphics;
- private Thread gameThread;
- private volatile boolean running = false;
- private volatile State currentState;
- private InputHandler inputHandler;
- public GameView(Context context, int gameWidth, int gameHeight) {
- super(context);
- gameImage = Bitmap.createBitmap(gameWidth, gameHeight,
- Bitmap.Config.RGB_565);
- gameImageSrc = new Rect(0, 0, gameImage.getWidth(),
- gameImage.getHeight());
- gameImageDst = new Rect();
- gameCanvas = new Canvas(gameImage);
- graphics = new Painter(gameCanvas);
- SurfaceHolder holder = getHolder();
- holder.addCallback(new Callback() {
- @Override
- public void surfaceCreated(SurfaceHolder holder) {
- initInput();
- if (currentState == null) {
- setCurrentState(new LoadState());
- }
- initGame();
- }
- @Override
- public void surfaceChanged(SurfaceHolder holder, int format,
- int width, int height) {
- // TODO Auto-generated method stub
- }
- @Override
- public void surfaceDestroyed(SurfaceHolder holder) {
- pauseGame();
- }
- });
- }
- public void setCurrentState(State newState) {
- System.gc();
- newState.init();
- currentState = newState;
- inputHandler.setCurrentState(currentState);
- }
- private void initInput() {
- if (inputHandler == null) {
- inputHandler = new InputHandler();
- }
- setOnTouchListener(inputHandler);
- }
- private void initGame() {
- running = true;
- gameThread = new Thread(this, "Game Thread");
- gameThread.start();
- }
- private void pauseGame() {
- running = false;
- while (gameThread.isAlive()) {
- try {
- gameThread.join();
- break;
- } catch (InterruptedException e) {
- }
- }
- }
- private void updateAndRender(long delta) {
- currentState.update(delta / 1000f);
- currentState.render(graphics);
- renderGameImage();
- }
- private void renderGameImage() {
- Canvas screen = getHolder().lockCanvas();
- if (screen != null) {
- screen.getClipBounds(gameImageDst);
- screen.drawBitmap(gameImage, gameImageSrc, gameImageDst, null);
- getHolder().unlockCanvasAndPost(screen);
- }
- }
- /*
- * Implementing the Game Loop Thread
- */
- public void run() {
- long updateDurationMillis = 0;
- long sleepDurationMillis = 0;
- while (running) {
- long beforeUpdateRender = System.nanoTime();
- long deltaMillis = sleepDurationMillis + updateDurationMillis;
- updateAndRender(deltaMillis);
- updateDurationMillis = (System.nanoTime() - beforeUpdateRender) / 1000000L;
- sleepDurationMillis = Math.max(2, 17 - updateDurationMillis);
- try {
- Thread.sleep(sleepDurationMillis);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement