acb75832a9f038bceb6cde556ea91719a6a981a1
1 package code
.kalter
.longflight
.space
;
3 import code
.kalter
.longflight
.Loader
;
4 import code
.kalter
.longflight
.LongFlight
;
5 import java
.io
.IOException
;
6 import java
.util
.Random
;
7 import javax
.microedition
.lcdui
.Graphics
;
8 import javax
.microedition
.lcdui
.Image
;
11 * Генерация случайных планет
17 private final int screenW
;
18 private final int screenH
;
19 private final int COUNT
= 5;
21 private final Random random
;
22 private final Image
[] planetGraphics
; // все планеты
23 //=======================
24 private long lastTime
; // для засекания времени
25 private long delay
; // задержка для генерации планеты
26 //=======================
27 private int positionX
;
28 private int positionY
;
31 public Planet(int screenW
, int screenH
) throws IOException
{
32 this.screenW
= screenW
;
33 this.screenH
= screenH
;
34 random
= new Random();
35 positionX
= random
.nextInt(screenW
- 60);
37 index
= random
.nextInt(COUNT
);
38 planetGraphics
= new Image
[COUNT
];
39 Loader iml
= Loader
.getInstance();
40 for (int i
= 0; i
< COUNT
; i
++) {
41 planetGraphics
[i
] = iml
.getImage("/gfx/space/planet/" + i
+ ".png");
43 delay
= random
.nextInt(25000) + 10000;
44 lastTime
= System
.currentTimeMillis();
47 public void paint(Graphics graph
) {
48 long delta
= System
.currentTimeMillis() - lastTime
;
52 graph
.drawImage(planetGraphics
[index
], positionX
, positionY
, 0);
56 long delta
= System
.currentTimeMillis() - lastTime
;
60 if (positionY
++ > screenH
) {
65 private void newPlanet() {
66 for (int i
= index
; i
== index
; index
= random
.nextInt(COUNT
));
67 delay
= random
.nextInt(25000) + 10000;
68 lastTime
= System
.currentTimeMillis();
69 positionX
= random
.nextInt(screenW
- 60);
70 positionY
= -planetGraphics
[index
].getHeight();