Android Open Source - tetris-android Test Screen






From Project

Back to project page tetris-android.

License

The source code is released under:

MIT License

If you think the Android project tetris-android 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.badlogic.androidgames.framework;
/* www  .  jav a 2  s . c  om*/
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.List;

import android.graphics.Color;
import android.util.Log;

import com.badlogic.androidgames.framework.Graphics.PixmapFormat;
import com.badlogic.androidgames.framework.Input.KeyEvent;
import com.badlogic.androidgames.framework.Input.TouchEvent;

class TestScreen extends Screen {
    long startTime = System.nanoTime();
    int frames;
    Pixmap bob;
    Pixmap bobAlpha;
    Sound sound;
    Music music;
        
    public TestScreen(Game game) {
        super(game);    
        bob = game.getGraphics().newPixmap("bobrgb888.png", PixmapFormat.RGB565);
        bobAlpha = game.getGraphics().newPixmap("bobargb8888.png", PixmapFormat.ARGB4444);
        music = game.getAudio().newMusic("music.ogg");
        music.setLooping(true);
        music.setVolume(0.5f);
        music.play();
        sound = game.getAudio().newSound("music.ogg");
        
        try {
            BufferedReader in = new BufferedReader(new InputStreamReader(game.getFileIO().readAsset("test.txt")));
            String text = in.readLine();
            in.close();
            
            BufferedWriter out = new BufferedWriter(new OutputStreamWriter(game.getFileIO().writeFile("test.txt")));
            out.write("This is a freaking test");
            out.close();
            
            in = new BufferedReader(new InputStreamReader(game.getFileIO().readFile("test.txt")));
            String text2 = in.readLine();
            in.close();
            
            Log.d("MrNom", text + ", " + text2 );
        } catch(Exception ex) {
            ex.printStackTrace();
        }
    }
    
    @Override
    public void update(float deltaTime) {
    }

    @Override
    public void present(float deltaTime) {
        Graphics g = game.getGraphics();
        Input inp = game.getInput();
        g.clear(Color.RED);
        g.drawLine(0,0,320, 480, Color.BLUE);
        g.drawRect(20,20,100,100, Color.GREEN);
        g.drawPixmap(bob, 100, 100);
        g.drawPixmap(bobAlpha, 100, 200);
        g.drawPixmap(bob, 200, 200, 0, 0, 64, 64);
        for(int i=0; i < 2; i++) {
            if(inp.isTouchDown(i)) {
                g.drawPixmap(bob, inp.getTouchX(i), inp.getTouchY(i), 0, 0, 64, 64);
            }
        }
        
        g.drawPixmap(bob, (int)(inp.getAccelX() * 10) + 160 - 16, (int)(inp.getAccelY() * 10) + 240 - 16, 0, 0, 32, 32 );
        
        List<KeyEvent> keyEvents = inp.getKeyEvents();
        int len = keyEvents.size();
        for(int i = 0; i < len; i++) {
            Log.d("MrNom", keyEvents.get(i).toString());
        }
        
        List<TouchEvent> touchEvents = inp.getTouchEvents();
        len = touchEvents.size();
        for(int i = 0; i < len; i++) {
            Log.d("MrNom", touchEvents.get(i).toString());
            if(touchEvents.get(i).type == TouchEvent.TOUCH_UP)
                sound.play(1);
        }
        
        frames++;
        if(System.nanoTime() - startTime > 1000000000l) {
            Log.d("MrNom", "fps: " + frames + ", delta: " + deltaTime);
            frames = 0;
            startTime = System.nanoTime();
        }
    }

    @Override
    public void pause() {
        Log.d("MrNom", "pause");                
    }

    @Override
    public void resume() {
        Log.d("MrNom", "resume");   
    }

    @Override
    public void dispose() {
        Log.d("MrNom", "dispose");
        music.dispose();
    }

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




Java Source Code List

com.badlogic.androidgames.framework.Audio.java
com.badlogic.androidgames.framework.Color.java
com.badlogic.androidgames.framework.DynamicGameObject.java
com.badlogic.androidgames.framework.FileIOInternal.java
com.badlogic.androidgames.framework.FileIO.java
com.badlogic.androidgames.framework.GameObject.java
com.badlogic.androidgames.framework.Game.java
com.badlogic.androidgames.framework.Graphics.java
com.badlogic.androidgames.framework.Input.java
com.badlogic.androidgames.framework.Music.java
com.badlogic.androidgames.framework.Pixmap.java
com.badlogic.androidgames.framework.Pool.java
com.badlogic.androidgames.framework.Screen.java
com.badlogic.androidgames.framework.Sound.java
com.badlogic.androidgames.framework.TestScreen.java
com.badlogic.androidgames.framework.gl.Animation.java
com.badlogic.androidgames.framework.gl.BTMPFont.java
com.badlogic.androidgames.framework.gl.Camera2D.java
com.badlogic.androidgames.framework.gl.Font.java
com.badlogic.androidgames.framework.gl.SpatialHashGrid.java
com.badlogic.androidgames.framework.gl.SpriteBatcher.java
com.badlogic.androidgames.framework.gl.TextureRegion.java
com.badlogic.androidgames.framework.gl.Texture.java
com.badlogic.androidgames.framework.gl.Vertices.java
com.badlogic.androidgames.framework.helper.DebugDraw.java
com.badlogic.androidgames.framework.helper.FPSCounter.java
com.badlogic.androidgames.framework.helper.Logger.java
com.badlogic.androidgames.framework.impl.AccelerometerHandler.java
com.badlogic.androidgames.framework.impl.AndroidAudio.java
com.badlogic.androidgames.framework.impl.AndroidFastRenderView.java
com.badlogic.androidgames.framework.impl.AndroidFileIOInternal.java
com.badlogic.androidgames.framework.impl.AndroidFileIO.java
com.badlogic.androidgames.framework.impl.AndroidGame.java
com.badlogic.androidgames.framework.impl.AndroidGraphics.java
com.badlogic.androidgames.framework.impl.AndroidInput.java
com.badlogic.androidgames.framework.impl.AndroidMusic.java
com.badlogic.androidgames.framework.impl.AndroidPixmap.java
com.badlogic.androidgames.framework.impl.AndroidSound.java
com.badlogic.androidgames.framework.impl.GLGame.java
com.badlogic.androidgames.framework.impl.GLGraphics.java
com.badlogic.androidgames.framework.impl.GLScreen.java
com.badlogic.androidgames.framework.impl.KeyboardHandler.java
com.badlogic.androidgames.framework.impl.MultiTouchHandler.java
com.badlogic.androidgames.framework.impl.SingleTouchHandler.java
com.badlogic.androidgames.framework.impl.TouchHandler.java
com.badlogic.androidgames.framework.math.Circle.java
com.badlogic.androidgames.framework.math.OverlapTester.java
com.badlogic.androidgames.framework.math.Rectangle.java
com.badlogic.androidgames.framework.math.Vector2.java
com.ultimate39.android.games.tetris.Assets.java
com.ultimate39.android.games.tetris.FactoryShape.java
com.ultimate39.android.games.tetris.GameScreen.java
com.ultimate39.android.games.tetris.MainMenuScreen.java
com.ultimate39.android.games.tetris.Settings.java
com.ultimate39.android.games.tetris.Shape.java
com.ultimate39.android.games.tetris.Square.java
com.ultimate39.android.games.tetris.Tetris.java
com.ultimate39.android.games.tetris.World.java