public ObsBall(int x, int y, int Rad, int sideDiff, int type) { this.x = x; this.y = y; this.rad = Rad; this.sideDiff = sideDiff; this.type = type; // hero 위치에 이만큼을 더해서, 그 범위 내에서는 장애물 생성 안되게 막으려고 offsetFromHero = Rad * 25; // 속도 조절 speed[0] = MainActivity.unitSpeed * 4; speed[1] = (int) (MainActivity.unitSpeed * 8); speed[2] = (int) (MainActivity.unitSpeed * 12); idx_speed = 0; // vx 정하기. vx = speed[idx_speed]; vy = speed[idx_speed]; if (Rnd.nextInt(1) == 0) vx *= -1; if (Rnd.nextInt(1) == 0) vy *= -1; // inCirclePnt = new Paint(); inCirclePnt.setAntiAlias(true); if (type == TYPE_OBSTACLE) { // 장애물 볼 red[0] = 135; green[0] = 206; blue[0] = 235; red[1] = 28; green[1] = 160; blue[1] = 217; red[2] = 16; green[2] = 94; blue[2] = 126; inCirclePnt.setColor(Color.rgb(red[idx_color], green[idx_color], blue[idx_color])); } else if (type == TYPE_ENERGY) { // 노란색 볼 inCirclePnt.setColor(Color.rgb(243, 218, 150)); } else if (type == ICE_OBSTACLE) { // 얼음 볼 inCirclePnt.setColor(Color.WHITE); } outCirclePnt = new Paint(); outCirclePnt.setAntiAlias(true); outCirclePnt.setColor(Color.BLACK); outCirclePnt.setStyle(Paint.Style.STROKE); outCirclePnt.setStrokeWidth(rad / 5); }
private void initPaint() { mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(Color.rgb(255, 127, 0)); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(12); }
private void drawBackGroudImageOnGivenCanvas(Canvas canvas) { canvas.drawBitmap(dataHolder.getBackgroundImage(), 0, 0, null); dataHolder.getLightPaint().setColor(Color.rgb(0x83, 0x83, 0x83)); dataHolder.getDarkPaint().setColor(Color.rgb(0x3b, 0x3b, 0x3b)); final int cellSize = dataHolder.getCellSize(); final int sizeY = dataHolder.getGameEngine().getGameField().getSizeY(); final int sizeX = dataHolder.getGameEngine().getGameField().getSizeX(); for (int i = 1; i < sizeX; i++) { canvas.drawLine( i * cellSize - 1, 0, i * cellSize - 1, sizeY * cellSize, dataHolder.getLightPaint()); canvas.drawLine(i * cellSize, 0, i * cellSize, sizeY * cellSize, dataHolder.getDarkPaint()); } for (int i = 1; i < sizeY; i++) { canvas.drawLine(0, i * cellSize, sizeX * cellSize, i * cellSize, dataHolder.getDarkPaint()); canvas.drawLine( 0, i * cellSize + 1, sizeX * cellSize, i * cellSize + 1, dataHolder.getLightPaint()); } }
{ listeners = new ArrayList<>(); seriesRegistry = new ArrayList<>(); renderers = new HashMap<>(); borderPaint = new Paint(); borderPaint.setColor(Color.rgb(150, 150, 150)); borderPaint.setStyle(Paint.Style.STROKE); borderPaint.setStrokeWidth(1.0f); borderPaint.setAntiAlias(true); backgroundPaint = new Paint(); backgroundPaint.setColor(Color.DKGRAY); backgroundPaint.setStyle(Paint.Style.FILL); }
// 새로운 볼 생성 static Ball Create(int x, int y, int Rad) { Random Rnd = new Random(); Ball NewBall = new Ball(); NewBall.x = x; NewBall.y = y; NewBall.rad = Rad; do { NewBall.dx = Rnd.nextInt(11) - 5; NewBall.dy = Rnd.nextInt(11) - 5; } while (NewBall.dx == 0 || NewBall.dy == 0); NewBall.count = 0; NewBall.color = Color.rgb(Rnd.nextInt(256), Rnd.nextInt(256), Rnd.nextInt(256)); return NewBall; }
public static Bitmap blurBmp(Bitmap bmp, int Blur) { int pixels[] = new int[bmp.getWidth() * bmp.getHeight()]; int pixelsRawSource[] = new int[bmp.getWidth() * bmp.getHeight() * 3]; int pixelsRawNew[] = new int[bmp.getWidth() * bmp.getHeight() * 3]; bmp.getPixels(pixels, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight()); for (int k = 1; k <= Blur; k++) { for (int i = 0; i < pixels.length; i++) { pixelsRawSource[i * 3 + 0] = Color.red(pixels[i]); pixelsRawSource[i * 3 + 1] = Color.green(pixels[i]); pixelsRawSource[i * 3 + 2] = Color.blue(pixels[i]); } int CurrentPixel = bmp.getWidth() * 3 + 3; for (int i = 0; i < bmp.getHeight() - 3; i++) { for (int j = 0; j < bmp.getWidth() * 3; j++) { CurrentPixel += 1; int sumColor = 0; sumColor = pixelsRawSource[CurrentPixel - bmp.getWidth() * 3]; sumColor = sumColor + pixelsRawSource[CurrentPixel - 3]; sumColor = sumColor + pixelsRawSource[CurrentPixel + 3]; sumColor = sumColor + pixelsRawSource[CurrentPixel + bmp.getWidth() * 3]; pixelsRawNew[CurrentPixel] = Math.round(sumColor / 4); } } for (int i = 0; i < pixels.length; i++) { pixels[i] = Color.rgb(pixelsRawNew[i * 3 + 0], pixelsRawNew[i * 3 + 1], pixelsRawNew[i * 3 + 2]); } } Bitmap bmpReturn = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), Config.ARGB_8888); bmpReturn.setPixels(pixels, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight()); return bmpReturn; }
// 충돌(장애물끼리 혹은 장애물 + 에너지볼)시 불러서 방향을 바꿔준다. 가속도도 약간 더해준다. // TYPE_OBSTACLE 일 때만 불려야 된다. public void afterCrashed(int type) { // 부딪혔을 때 중복으로 체크되서(불린 변수를 뒀음 -> 저에게 물어봐주세요) if (!isStateChagedByCrash) { // 방향 변경 vx *= -1; vy *= -1; if (type == 0 /*장애물 끼리 충돌이라면*/ && idx_color < 2) { // 색 변경 idx_color++; inCirclePnt.setColor(Color.rgb(red[idx_color], green[idx_color], blue[idx_color])); // 속도 상승 idx_speed++; vx = speed[idx_speed]; vx = speed[idx_speed]; } // 모든 상태 변화에 대해서 . 최초 충돌 시에만 적용 되기 위해서. isStateChagedByCrash = true; } }
/** Updates DisplacementMap and path for current coordinates. */ public void update() { setUpdateNeeded(false); if (newWidth == map.getWidth() && newHeight == map.getHeight() && targetX == oldTargetX && targetY == oldTargetY) { return; } oldTargetX = targetX; oldTargetY = targetY; if (newWidth != map.getWidth() || newHeight != map.getHeight()) { map.setWidth(newWidth); map.setHeight(newHeight); } final double W = node.getLayoutBounds().getWidth(); final double H = node.getLayoutBounds().getHeight(); // target point F for folded corner final double xF = Math.min(targetX, W - 1); final double yF = Math.min(targetY, H - 1); final Point2D F = new Point2D(xF, yF); // corner point O final double xO = W; final double yO = H; // distance between them final double FO = Math.hypot(xF - xO, yF - yO); final double AF = FO / 2; final double AC = Math.min(AF * 0.5, 200); // radius of the fold as seen along the l2 line final double R = AC / Math.PI * 1.5; final double BC = R; final double flat_R = AC; // Gradient for the line from target point to corner point final double K = (yO - yF) / (xO - xF); // angle of a line l1 final double ANGLE = Math.atan(1 / K); // point A (on line l1 - the mirror line of target and corner points) final double xA = (xO + xF) / 2; final double yA = (yO + yF) / 2; // end points of line l1 final double bottomX = xA - (H - yA) * K; final double bottomY = H; final double rightX = W; final double rightY = yA - (W - xA) / K; final Point2D RL1 = new Point2D(rightX, rightY); final Point2D BL1 = new Point2D(bottomX, bottomY); // point C (on line l2 - the line when distortion begins) final double kC = AC / AF; final double xC = xA - (xA - xF) * kC; final double yC = yA - (yA - yF) * kC; final Point2D C = new Point2D(xC, yC); final Point2D RL2 = new Point2D(W, yC - (W - xC) / K); final Point2D BL2 = new Point2D(xC - (H - yC) * K, H); // point B (on line l3 - the line where distortion ends) final double kB = BC / AC; final double xB = xC + (xA - xC) * kB; final double yB = yC + (yA - yC) * kB; // Bottom ellipse calculations final Point2D BP1 = calcIntersection(F, BL1, BL2, C); final Point2D BP3 = BL2; final Point2D BP2 = middle(BP1, BP3, 0.5); final Point2D BP4 = new Point2D(xB + BP2.getX() - xC, yB + BP2.getY() - yC); final double bE_x1 = hypot(BP2, BP3); final double bE_y2 = -hypot(BP2, BP4); final double bE_yc = -hypot(BP2, BL1); final double bE_y0 = bE_y2 * bE_y2 / (2 * bE_y2 - bE_yc); final double bE_b = bE_y0 - bE_y2; final double bE_a = Math.sqrt(-bE_x1 * bE_x1 / bE_y0 * bE_b * bE_b / bE_yc); // Right ellipse calculations final Point2D RP1 = calcIntersection(F, RL1, RL2, C); final Point2D RP3 = RL2; final Point2D RP2 = middle(RP1, RP3, 0.5); final Point2D RP4 = new Point2D(xB + RP2.getX() - xC, yB + RP2.getY() - yC); final double rE_x1 = hypot(RP2, RP3); final double rE_y2 = -hypot(RP2, RP4); final double rE_yc = -hypot(RP2, RL1); final double rE_y0 = rE_y2 * rE_y2 / (2 * rE_y2 - rE_yc); final double rE_b = rE_y0 - rE_y2; final double rE_a = Math.sqrt(-rE_x1 * rE_x1 / rE_y0 * rE_b * rE_b / rE_yc); p.setFill( new LinearGradient( xF, yF, xO, yO, false, CycleMethod.NO_CYCLE, new Stop(0, pathColor), new Stop((xC - xF) / (xO - xF), bendStartColor), new Stop((xB - xF) / (xO - xF), bendEndColor))); p.getElements() .setAll( new MoveTo(BP4.getX(), BP4.getY()), ArcToBuilder.create() .XAxisRotation(Math.toDegrees(-ANGLE)) .radiusX(bE_a) .radiusY(bE_b) .x(BP1.getX()) .y(BP1.getY()) .build(), new LineTo(xF, yF), new LineTo(RP1.getX(), RP1.getY()), ArcToBuilder.create() .XAxisRotation(Math.toDegrees(-ANGLE)) .radiusX(rE_a) .radiusY(rE_b) .x(RP4.getX()) .y(RP4.getY()) .build(), new ClosePath()); if (shadow != null) { double level0 = (xB - xF) / (xO - xF) - R / FO * 0.5; double level1 = (xB - xF) / (xO - xF) + (0.3 + (200 - AC) / 200) * R / FO; shadow.setFill( new LinearGradient( xF, yF, xO, yO, false, CycleMethod.NO_CYCLE, new Stop(level0, Color.rgb(0, 0, 0, 0.7)), new Stop(level0 * 0.3 + level1 * 0.7, Color.rgb(0, 0, 0, 0.25)), new Stop(level1, Color.rgb(0, 0, 0, 0.0)), new Stop(1, Color.rgb(0, 0, 0, 0)))); shadow .getElements() .setAll( new MoveTo(RP3.getX(), RP3.getY()), ArcToBuilder.create() .XAxisRotation(Math.toDegrees(-ANGLE)) .radiusX(rE_a) .radiusY(rE_b) .x(RP4.getX()) .y(RP4.getY()) .sweepFlag(true) .build(), new LineTo(BP4.getX(), BP4.getY()), ArcToBuilder.create() .XAxisRotation(Math.toDegrees(-ANGLE)) .radiusX(bE_a) .radiusY(bE_b) .x(BP3.getX()) .y(BP3.getY()) .sweepFlag(true) .build(), new LineTo(xO, yO), new ClosePath()); } if (clip != null) { final Point2D RL3 = new Point2D(W, yB - (W - xB) / K); final Point2D BL3 = new Point2D(xB - (H - yB) * K, H); clip.getElements() .setAll( new MoveTo(0, 0), RL3.getY() > 0 ? new LineTo(W, 0) : new LineTo(0, 0), RL3.getY() >= 0 ? new LineTo(RL3.getX(), RL3.getY()) : new LineTo(xB - (0 - yB) * K, 0), BL3.getX() >= 0 ? new LineTo(BL3.getX(), BL3.getY()) : new LineTo(0, yB - (0 - xB) / K), BL3.getX() > 0 ? new LineTo(0, H) : new LineTo(0, 0), new ClosePath()); } final double K2 = -K; final double C2 = BP3.getX() - K2 * H; final double K3 = -K; final double C3 = xB - K3 * yB; final double STEP = Math.max(0.1, R / (buffer.length - 1)); final double HYPOT = Math.hypot(1, K); final double yR = 1.5 * R; double x_1 = 0, y_1 = 0, cur_len = 0; for (double len = 0; len <= R; len += STEP) { final int index = (int) Math.round(len / STEP); final double angle = Math.asin(len / R); final double y = yR * Math.cos(angle); if (len > 0) { cur_len += Math.hypot(y - y_1, len - x_1); } buffer[index][0] = (float) angle; buffer[index][1] = (float) (cur_len * flat_R); x_1 = len; y_1 = y; } double total_len = cur_len; for (double len = 0; len <= R; len += STEP) { final int index = (int) Math.round(len / STEP); final double flat_len = buffer[index][1] / total_len; final double delta_len = flat_len - len; final double xs = delta_len / HYPOT; final double ys = K * delta_len / HYPOT; buffer[index][0] = (float) (xs / W); buffer[index][1] = (float) (ys / H); } for (int y = 0; y < map.getHeight(); y++) { final double lx2 = K2 * (y + 0.5) + C2; final double lx3 = K3 * (y + 0.5) + C3; for (int x = 0; x < map.getWidth(); x++) { if (x + 0.5 < lx2) { map.setSamples(x, y, 0, 0); } else if (x + 0.5 >= lx3 - 1) { map.setSamples(x, y, 1, 0); } else { final double len = Math.abs((x + 0.5) - K2 * (y + 0.5) - C2) / HYPOT; final int index = (int) Math.round(len / STEP); map.setSamples(x, y, buffer[index][0], buffer[index][1]); } } } }
// 회복 됨 public void dePoisoned() { inCirclePnt.setColor(Color.rgb(243, 218, 150)); type = TYPE_ENERGY; }
private int getDarkerShade(int color) { return Color.rgb( (int) (SHADE_FACTOR * Color.red(color)), (int) (SHADE_FACTOR * Color.green(color)), (int) (SHADE_FACTOR * Color.blue(color))); }
public int makeColor(int r, int g, int b) { color = Color.rgb(r, g, b); return color; }