1 package code
.kalter
.longflight
.screen
;
3 import code
.kalter
.longflight
.EventListener
;
4 import code
.kalter
.longflight
.Loader
;
5 import code
.kalter
.longflight
.LongFlight
;
6 import code
.kalter
.longflight
.Sprite
;
7 import java
.io
.IOException
;
8 import javax
.microedition
.lcdui
.Image
;
11 * Включение / не включение звука
15 public class EnableSound
extends Screen
{
17 private static final int COUNT
= 2; // of choise
19 private static final int YES
= 0;
20 private static final int NO
= 1;
23 private final Sprite window
;
24 private final Sprite leftSoft
;
25 private final Sprite
[] choise
;
26 private final Sprite
[] selectChoise
;
27 private final Image downPanel
;
29 public EnableSound() throws IOException
{
31 Loader loader
= Loader
.getInstance();
34 Image windowImage
= loader
.getImage("/gfx/enable_sound/window.png");
35 int windowX
= (screenW
- windowImage
.getWidth()) / 2;
36 int windowY
= (screenH
- windowImage
.getHeight()) / 2;
37 window
= new Sprite(windowImage
, windowX
, windowY
);
40 Image leftSoftImage
= loader
.getImage("/gfx/awt/left_soft.png");
42 int leftSoftY
= screenH
- leftSoftImage
.getHeight();
43 leftSoft
= new Sprite(leftSoftImage
, leftSoftX
, leftSoftY
);
44 leftSoft
.addEvent(new EventListener() {
47 return leftSoft
.isEntrySet(getXPressed(), getYPressed());
57 Image choiseCrop
= loader
.getImage("/gfx/enable_sound/choise.png");
58 choise
= new Sprite
[COUNT
];
59 selectChoise
= new Sprite
[COUNT
];
60 for (int i
= 0; i
< COUNT
; i
++) {
62 Image c
= Image
.createImage(choiseCrop
, 0, i
* 22, 102, 22, 0);
63 int choiseX
= (screenW
- 102) / 2;
64 int choiseY
= window
.getY() + 51 + i
* 24;
65 choise
[i
] = new Sprite(c
, choiseX
, choiseY
);
68 Image sc
= Image
.createImage(choiseCrop
, 102, i
* 22, 102, 22, 0);
69 int selectChoiseX
= choise
[i
].getX();
70 int selectChoiseY
= choise
[i
].getY();
71 selectChoise
[i
] = new Sprite(sc
, selectChoiseX
, selectChoiseY
);
75 downPanel
= loader
.getImage("/gfx/awt/down_panel.png");
77 // adding event listener for choise about of "yes"
78 choise
[YES
].addEvent(new EventListener() {
81 return choise
[YES
].isEntrySet(getXPressed(), getYPressed());
89 selectChoise
[YES
].addEvent(choise
[YES
].getEvent(0));
91 // adding event listener for choise about of "no"
92 choise
[NO
].addEvent(new EventListener() {
95 return choise
[NO
].isEntrySet(getXPressed(), getYPressed());
103 selectChoise
[NO
].addEvent(choise
[NO
].getEvent(0));
107 public void start() {
108 setDate(39, screenH
- 9);
113 public void pointerPressed(int x
, int y
) {
114 super.pointerPressed(x
, y
);
115 leftSoft
.exciteEvent();
116 choise
[YES
].exciteEvent();
117 choise
[NO
].exciteEvent();
121 public void keyPressed(int keyCode
) {
122 switch (getGameAction(keyCode
)) {
144 while (getGameLoop()) {
148 LongFlight
.link
.sleep(20);
151 LongFlight
.link
.setScreen(LongFlight
.SPLASH
);
154 private void paint() {
155 space
.paint(graphics
);
156 for (int i
= 0; i
< screenW
; i
+= 128) {
157 graphics
.drawImage(downPanel
, i
, screenH
- 18, 0);
160 leftSoft
.paint(graphics
);
161 window
.paint(graphics
);
162 for (int i
= 0; i
< COUNT
; i
++) {
164 selectChoise
[i
].paint(graphics
);
166 choise
[i
].paint(graphics
);
172 private void update() {
176 private void leftSoftPressed() {
180 private void upPressed() {
181 if (--position
< 0) {
186 private void downPressed() {
187 if (++position
>= COUNT
) {
188 position
= COUNT
- 1;
192 private void firePressed() {
205 choise
[YES
].removeEvent(0);
206 LongFlight
.link
.playMusic();