안드로이드 개발 질문/답변
(글 수 45,052)
package com.example.expop2;
import java.util.Random;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Shader.TileMode;
public class Bubble {
public int x, y, rad;
public Bitmap imgBall;
public boolean dead = false;
private int _rad;
private int sx, sy;
private int width, height;
private Bitmap Bubbles[] = new Bitmap[6];
private int imgNum = 0;
private int loop = 0;
private int counter = 0;
private int papnum;
private int ppp;
public Bubble(Context context, int _x, int _y, int _width, int _height){
width = _width;
height = _height;
x = _x;
y = _y;
Random rnd = new Random();
papnum = rnd.nextInt(6);
imgBall = BitmapFactory.decodeResource
(context.getResources(), R.drawable.bpop1+ papnum);
_rad = rnd.nextInt(21)+30;
rad = _rad;
for(int i = 0; i<=3; i++)
Bubbles[i] = Bitmap.createScaledBitmap
(imgBall,_rad*2 + i * 2,_rad * 2 + i * 2,false);
Bubbles[4] = Bubbles[2];
Bubbles[5] = Bubbles[1];
imgBall = Bubbles[0];
int radan;
Random rnda = new Random();
radan = rnda.nextInt(2);
if(radan == 0){
sx=(rnd.nextInt(3)+5);//*k;
sy=-(rnd.nextInt(2)+1)-70;//*k;
}
else
sx=-(rnd.nextInt(3)+5);//*k;
sy=-(rnd.nextInt(2)+1)-70;//*k;
MoveBubble();
}
public void MoveBubble(){
loop ++;
if(loop % 3 ==0){
imgNum++;
if(imgNum > 5) imgNum=0;
imgBall = Bubbles [imgNum];
rad = _rad + (imgNum <=3 ? imgNum : 6 - imgNum) * 2;
}
double vo = 1;
int th = 1;
float dh = 0;
float dl = 0;
float t = 0;
double r = th *Math.PI/180;
while (dh>=0){
dh = (float)(vo*Math.sin(r)*t-1);
dl = (float)(vo*Math.cos(r)*t);
sx+=dl;
sy+=-dh;
t+=1;
x+= sx;
y+= sy*0.2; // 속도
}
if(x<= rad || x >= width - rad){
sx = -sx;
x += sx;
counter ++;
}
if(y<= rad +200|| y>=height - rad){
sy = -sy/2;
y+= sy;
counter++;
}
//if(counter >= 100) dead = true;
}
}
위와같은소스코딩입니다. 물방울이미지가 포물선으로 튀어나와서 밑에 쌓이는걸 구현하려고 합니다.
벽과의 충돌시 이동방향 반대로는 구현을 하였는데 이미지끼리 충돌시 겹치지않고 쌓이도록 구현하고 싶습니다.
어떻게 해야될까요?