DEADSOFTWARE

Initial commit.
[LongFlight.git] / src / code / kalter / longflight / screen / Loading.java
1 package code.kalter.longflight.screen;
3 import code.kalter.longflight.Loader;
4 import code.kalter.longflight.LongFlight;
5 import code.kalter.longflight.Quote;
6 import code.kalter.longflight.Sprite;
7 import code.kalter.longflight.StringReader;
8 import java.io.IOException;
9 import java.io.InputStream;
10 import java.util.Random;
11 import javax.microedition.lcdui.Image;
13 /**
14 * Фейковая загрузка
15 *
16 * @author KalterFive
17 */
18 public class Loading extends Screen {
20 private static final long SLEEP = 8000;
22 private final int COUNT; // of quots
23 private final Quote[] quote;
25 private final Sprite loading;
26 private int quoteID;
28 private long lastTime;
30 public Loading() throws IOException {
31 final InputStream file = getClass().getResourceAsStream("/quote.txt");
32 final StringReader reader = new StringReader(file);
33 COUNT = reader.nextInt();
34 quote = new Quote[COUNT];
35 for (int i = 0; i < COUNT; i++) {
36 String q = reader.nextString(); // quote
37 String a = reader.nextString(); // author
38 quote[i] = new Quote(q, a);
39 }
40 reader.close();
42 Loader loader = Loader.getInstance();
44 // loading
45 Image loadingImage = loader.getImage("/gfx/loading/loading.png");
46 int loadingX = screenW - loadingImage.getWidth();
47 int loadingY = 15;
48 loading = new Sprite(loadingImage, loadingX, loadingY);
49 }
51 // override
52 public void start() {
53 lastTime = System.currentTimeMillis();
54 quoteID = new Random().nextInt(COUNT);
55 super.start();
56 }
58 // override
59 public void run() {
60 while (getGameLoop()) {
61 fps.process();
62 update();
63 paint();
64 LongFlight.link.sleep(20);
65 fps.max();
66 }
67 LongFlight.link.setScreen(LongFlight.GAME);
68 }
70 private void update() {
71 if (System.currentTimeMillis() - lastTime > SLEEP) {
72 stop();
73 }
74 }
76 private void paint() {
77 // gfx
78 graphics.setColor(0x002C40);
79 graphics.fillRect(0, 0, screenW, screenH);
80 graphics.setColor(0x004C6F);
81 graphics.fillRect(0, 22, screenW, 2);
82 loading.paint(graphics);
84 // quote
85 String quoteText = quote[quoteID].getQuote();
86 int quoteX = 10;
87 int quoteY = 30;
88 int quoteHeight = screenW - 10;
89 font.paint(graphics, quoteText, quoteX, quoteY, quoteHeight);
91 // author
92 String author = quote[quoteID].getAuthor();
93 int authorX = 10;
94 int authorY = 18 + quoteY + font.getHeight(quoteText, quoteHeight);
95 int authorHeight = screenW - 10;
96 font.paint(graphics, author, authorX, authorY, authorHeight);
97 flushGraphics();
98 }
99 }