import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import br.com.alurajumper.br.graficos.Tela;
import br.com.alurajumper.br.jumper.R;
/*
Created by Lucas on 12/12/2017.
*/
public class Game extends SurfaceView implements Runnable{
private final Tela tela;
private boolean isRunning = true;
private Passaro passaro;
private final SurfaceHolder holder = getHolder();
public Game(Context context) {
super(context);
tela = new Tela(context);
}
private Bitmap background;
@Override
public void run() {
while(isRunning){
if(!holder.getSurface().isValid()) continue;
Canvas canvas = holder.lockCanvas();
//Desenho dos componentes do jogo
canvas.drawBitmap(background,0,0,null);
passaro.desenhaNo(canvas);
passaro.cai();
holder.unlockCanvasAndPost(canvas);
}
}
public void pause(){
this.isRunning = false;
}
public void inicia() {
this.isRunning = true;
}
public void incializaElementos(){
this.passaro = new Passaro();
Bitmap back = BitmapFactory.decodeResource(getResources(), R.drawable.background);
background = Bitmap.createScaledBitmap(back,back.getWidth(),tela.getAltura(),false);
}
}