I'm developing a game and it's only generating an image on the screen randomly. I would like to implement 3 different images, which through a random
would appear automatically on the screen, and that each image would have a value.
Example:
imagem1 = 1;
imagem2 = 2;
Imagine the game fruit ninja !! Mine is similar, except that in the place of fruits mine is just falling 1 image of 1 square. I would like to add more images and do not know how to create. For example, that they were 3 squares; a yellow, a green and a blue, I want to show them repeatedly on the screen like the fruit ninja. Randomly he calls an image and presents it on the screen. My code so far, I wanted to create a method that would do this but I do not know how !!
public class Inimigo extends Retangulo{
private static Bitmap bmp;
public Inimigo(int x, int y, Resources res){
super(x, y, 40, 40);
if(bmp==null){
//instancio a imagem do resource
bmp = BitmapFactory.decodeResource(res, R.drawable.amarelo);
//redimensiona a imagem
bmp = Bitmap.createScaledBitmap(bmp, 40, 40, true);
}
}
public void mexe(int height,int width){
if (getY()<height){
setY(getY()+5);
}
else{
int x = (int)(Math.random()*(width-25));
setX(x); setY(-25);
}
}
public void draw(Canvas canvas, Paint paint){
canvas.drawBitmap(bmp, getX(), getY(), paint);
}
}