diff --git a/src/About.java b/src/About.java index 452384f..a674186 100644 --- a/src/About.java +++ b/src/About.java @@ -8,72 +8,57 @@ * www.mobilab.ru */ import com.emos.ui.ESkin; +import com.emos.ui.EWindow; import com.emos.ui.StringEncoder; import java.io.DataInputStream; import java.util.Vector; import javax.microedition.lcdui.*; -public class About extends Canvas { +public class About extends EWindow { - private final String path = "about.ru"; - private Font def, fnt; - private int fontHeight, defHeight; + private final String path = "/res/about.ru"; + private Font def; + private int defHeight; private String str; //текст - private int w, h; //размеры - private int mh; //Размер ограничивающего прямоугольника; - private int y0; //Положение верхнего края текста + private int mh, y0; //Положение верхнего края текста private int dy; //Шаг при прокрутке текста private int textheight; //Общая высота текста private Vector strLines; - public About() { - setFullScreenMode(true); - w = getWidth(); - h = getHeight(); + public About(String about) { + super(about); str = getText(path); - fnt = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD, Font.SIZE_SMALL); def = Font.getDefaultFont(); - fontHeight = fnt.getHeight()+2; dy = defHeight = def.getHeight()+2; - // - //15; - mh = h - fontHeight - 1; + mh = super.hh - 1; SetTextPar(); } - protected void paint(Graphics g) { - int hc = h/2; - ESkin.drawVGradient (g, ESkin.wBack, ESkin.wBack2, 0,0, w,hc); - ESkin.drawVGradient (g, ESkin.wBack2, ESkin.wBack, 0,hc,w,h-hc); - ESkin.drawHGradient(g, ESkin.wTitle, ESkin.lBack, 0, 0, w, fontHeight); - g.setFont(fnt); - g.setColor(ESkin.wTitle); - g.drawString("RayCanvas", w/2, 1, 17); + public void paint(Graphics g, int w, int h) { g.setFont(def); - g.setClip(0, fontHeight+1, w, mh); + g.setColor(ESkin.wBack); int y1 = y0; for (int i = 0; i < strLines.size(); i++) { if ((y1 + defHeight) > 0) { - g.drawString(strLines.elementAt(i).toString(), 1, fontHeight + 5 + y1, Graphics.LEFT | Graphics.TOP); - } - y1 = y1 + defHeight; - if (y1 > mh) { - break; + g.drawString(strLines.elementAt(i).toString(), 1, 3 + y1, Graphics.LEFT | Graphics.TOP); } + y1 += defHeight; + if (y1 > mh) break; } - g.setClip(0, 0, w, h); } - - protected void keyPressed(int key) { - int ga = getGameAction(key); - if(ga==UP) MoveUp(); - else if(ga==DOWN) MoveDown(); - else if(ga==LEFT) PageUp(); - else if(ga==RIGHT) PageDown(); - else if(ga==FIRE || key==-6 || key==-7) - Main.midlet.dsp.setCurrent(Main.midlet.mn); - repaint(); + + public void keyEvent(int key, byte state) { + if(state!=RELEASED) { + int ga = getGameAction(key); + if(ga==UP) MoveUp(); + else if(ga==DOWN) MoveDown(); + else if(ga==LEFT) PageUp(); + else if(ga==RIGHT) PageDown(); + else if(ga==FIRE || key==-6 || key==-7) + Main.midlet.dsp.setCurrent(Main.midlet.mn); + redraw(); + } } protected void pointerPressed(int x, int y) { @@ -147,6 +132,7 @@ public class About extends Canvas { StringBuffer strBuff = new StringBuffer(); int ch = 0; try { + dis.read(); dis.read(); while ((ch = dis.read()) != -1) { strBuff.append(StringEncoder.decodeCharCP1251((byte)ch)); } diff --git a/src/Main.java b/src/Main.java index 330665b..c2efae7 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,17 +1,24 @@ +import java.io.InputStream; +import java.util.Random; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; +import javax.microedition.media.*; -public class Main extends MIDlet { +public class Main extends MIDlet implements PlayerListener { public Display dsp; public static Main midlet; public Menu mn; - + public static boolean music = false; + private int currentmusic; + private Random rnd; + private Player plr; public Main() { dsp = Display.getDisplay(Main.this); midlet = Main.this; + rnd = new Random(); } public void startApp() { @@ -22,7 +29,48 @@ public class Main extends MIDlet { public void pauseApp() { } - public void destroyApp(boolean unconditional) { + public void destroyApp(boolean un) { notifyDestroyed(); } + + public void changeSoundState(boolean on) { + music = on; + if(on) yesSound(); + else { + if(plr!=null) { + try { + plr.stop(); + plr.close(); + plr = null; + } catch (MediaException ex) { + ex.printStackTrace(); + } + } + } + } + + private void yesSound() { + try { + int yy; + do yy = Math.abs(rnd.nextInt()%5); + while(currentmusic == yy); + currentmusic = yy; + + InputStream is = getClass().getResourceAsStream("/res/"+String.valueOf(yy)); + is.read(); is.read(); + plr = Manager.createPlayer(is, "audio/midi"); + plr.realize(); + plr.prefetch(); + plr.addPlayerListener(this); + plr.start(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public void playerUpdate (Player player, String event, Object data) { + if (event.equals(PlayerListener.END_OF_MEDIA)) { + if(music) yesSound(); + } + } } diff --git a/src/Menu.java b/src/Menu.java index 3a2774d..061d90b 100644 --- a/src/Menu.java +++ b/src/Menu.java @@ -25,6 +25,7 @@ public class Menu extends EWindow { m1 = new String[] { "Начать", "Об игре", + "Музыка ", "Выход", }; rnd = new Random(); @@ -46,12 +47,16 @@ public class Menu extends EWindow { for (int i = 0;i0) yy-=2; if(yy>1 || yy<-1) redraw(); @@ -69,8 +74,9 @@ public class Menu extends EWindow { private void getM1Code(int nfct) { if(nfct==0) Main.midlet.dsp.setCurrent(ray); - else if(nfct==1) Main.midlet.dsp.setCurrent(new About()); - else if(nfct==2) Main.midlet.destroyApp(true); + else if(nfct==1) Main.midlet.dsp.setCurrent(new About(m1[nfct])); + else if(nfct==2) Main.midlet.changeSoundState(!Main.music); + else if(nfct==3) Main.midlet.destroyApp(true); } protected void pointerPressed(int x, int y) { diff --git a/src/RayCanvas.java b/src/RayCanvas.java index 55280a9..46b2c96 100644 --- a/src/RayCanvas.java +++ b/src/RayCanvas.java @@ -38,12 +38,12 @@ public class RayCanvas extends Canvas {// implements Runnable { dirX = -1; lastTime = 0; dirY = planeX = 0; - planeY = 0.66; + planeY = 0.56; gluk = 1; keyb = new Keyboard(); try { - pr = Image.createImage("/2.png"); + pr = Image.createImage("/res/2.png"); } catch (IOException ex) {} } diff --git a/src/com/emos/ui/ESkin.java b/src/com/emos/ui/ESkin.java index 896393b..a5625ec 100644 --- a/src/com/emos/ui/ESkin.java +++ b/src/com/emos/ui/ESkin.java @@ -115,53 +115,4 @@ public class ESkin { hsb = RGBtoHSV(qr, qg, qb, hsb); return hsb[c]; } - - public static void drawVGradient (Graphics gr, int rgb1, int rgb2, int xn, int yn, int wdh, int hgt) { - int r,g,b; - int r1, r2, g1, g2, b1, b2; - r1=acolor(rgb1, 'r'); r2=acolor(rgb2, 'r'); - g1=acolor(rgb1, 'g'); g2=acolor(rgb2, 'g'); - b1=acolor(rgb1, 'b'); b2=acolor(rgb2, 'b'); - wdh+=xn; - hgt+=yn; - for (int i=yn; i255) r=255; - else if(r<0) r=0; - if(g>255) g=255; - else if(g<0) g=0; - if(b>255) b=255; - else if(b<0) b=0; - gr.setColor (r,g,b); - gr.drawLine (i,yn,i,hgt-1); - } - } - - private static int acolor(int argb, char c) { - int bitmask = 0; - if(c=='b') return (argb & 0xff); - else if(c=='a') bitmask = 24; - else if(c=='r') bitmask = 16; - else if(c=='g') bitmask = 8; - return ((argb >> bitmask) & 0xff); - } } diff --git a/src/res/0 b/src/res/0 new file mode 100644 index 0000000..ff4e22d Binary files /dev/null and b/src/res/0 differ diff --git a/src/res/1 b/src/res/1 new file mode 100644 index 0000000..c297fff Binary files /dev/null and b/src/res/1 differ diff --git a/src/res/2 b/src/res/2 new file mode 100644 index 0000000..6197951 Binary files /dev/null and b/src/res/2 differ diff --git a/src/2.png b/src/res/2.png similarity index 100% rename from src/2.png rename to src/res/2.png diff --git a/src/res/3 b/src/res/3 new file mode 100644 index 0000000..c826504 Binary files /dev/null and b/src/res/3 differ diff --git a/src/res/4 b/src/res/4 new file mode 100644 index 0000000..497eaa7 Binary files /dev/null and b/src/res/4 differ diff --git a/src/about.ru b/src/res/about.ru similarity index 96% rename from src/about.ru rename to src/res/about.ru index b94bdcb..b6fe9bd 100644 --- a/src/about.ru +++ b/src/res/about.ru @@ -1,4 +1,4 @@ -RayCanvas +«њRayCanvas Цель игры - пройти лабиринт. Цвета стен, лабиринт и эффекты генерируются случайно.