DEADSOFTWARE

License project under GNU GPL 3.
[LongFlight.git] / src / code / kalter / longflight / space / Star.java
1 package code.kalter.longflight.space;
3 import code.kalter.longflight.Color;
4 import java.util.Random;
5 import javax.microedition.lcdui.Graphics;
7 /**
8 * Звёзды...
9 *
10 * @author KalterFive
11 */
12 class Star {
14 private final int screenH;
15 private final int COUNT;
16 private final int[] positionX;
17 private final int[] positionY;
18 private final int[] color;
20 public Star(int screenW, int screenH) {
21 this.screenH = screenH;
22 Random random = new Random();
23 COUNT = (screenH + screenW) / 3;
24 positionX = new int[COUNT];
25 positionY = new int[COUNT];
26 color = new int[COUNT];
27 for (int i = 0; i < COUNT; i++) {
28 positionX[i] = random.nextInt(screenH);
29 positionY[i] = random.nextInt(screenW);
30 int a = random.nextInt(256);
31 color[i] = Color.maskRGB(a, a, a);
32 }
33 }
35 public void paint(Graphics graphics) {
36 for (int i = 0; i < COUNT; i++) {
37 graphics.setColor(color[i]);
38 graphics.fillRect(positionX[i], positionY[i], 1, 1);
39 }
40 }
42 public void upd() {
43 for (int i = 0; i < COUNT; i++) {
44 if ((positionY[i] += ((color[i] & 0x0000FF) / 50)) > screenH) {
45 positionY[i] = 0;
46 }
47 }
48 }
49 }