1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| public class LabyView extends View{
public LabyView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
private ArrayList<Case> tabLaby = new ArrayList<Case>();
public LabyView(Context view, ArrayList<Case> tablaby) {
super(view);
this.tabLaby = tablaby;
}
public void setLaby(ArrayList<Case> tablaby) {
this.tabLaby = tablaby;
}
@Override
public void onDraw(Canvas canvas) {
int x,y;
Bitmap mur = BitmapFactory.decodeResource(getResources(), R.drawable.mur);
Bitmap arrivee = BitmapFactory.decodeResource(getResources(), R.drawable.arrivee);
Bitmap depart = BitmapFactory.decodeResource(getResources(), R.drawable.depart);
Bitmap perso = BitmapFactory.decodeResource(getResources(), R.drawable.pers_smurf);
int tailleCase = mur.getHeight();
int taillePerso = perso.getHeight();
int centerPero = (tailleCase - taillePerso) / 2;
for(int i=0; i< tabLaby.size(); i++) {
x = (int) tabLaby.get(i).getX();
x*= tabLaby.get(i).getTaille();
y = (int) tabLaby.get(i).getY();
y*= tabLaby.get(i).getTaille();
switch(tabLaby.get(i).getTypeCase()) {
case MUR:
canvas.drawBitmap(mur, x, y,null);
break;
case ARRIVEE:
canvas.drawBitmap(arrivee, x, y,null);
break;
case DEPART:
canvas.drawBitmap(depart, x, y,null);
canvas.drawBitmap(perso, x+centerPero, y+centerPero, null);
break;
}
}
Personnage mBoule = new Personnage();
}
} |
Partager