This commit is contained in:
Victor 2018-11-15 00:01:03 +02:00
parent f491889b36
commit fa4a7c2968
12 changed files with 91 additions and 100 deletions

View File

@ -8,64 +8,48 @@
* 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);
g.drawString(strLines.elementAt(i).toString(), 1, 3 + y1, Graphics.LEFT | Graphics.TOP);
}
y1 = y1 + defHeight;
if (y1 > mh) {
break;
y1 += defHeight;
if (y1 > mh) break;
}
}
g.setClip(0, 0, w, h);
}
protected void keyPressed(int key) {
public void keyEvent(int key, byte state) {
if(state!=RELEASED) {
int ga = getGameAction(key);
if(ga==UP) MoveUp();
else if(ga==DOWN) MoveDown();
@ -73,7 +57,8 @@ public class About extends Canvas {
else if(ga==RIGHT) PageDown();
else if(ga==FIRE || key==-6 || key==-7)
Main.midlet.dsp.setCurrent(Main.midlet.mn);
repaint();
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));
}

View File

@ -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();
}
}
}

View File

@ -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;i<m1.length;i++) {
if (i==cu) continue;
g.setColor(ESkin.wBack2);
g.drawString(m1[i], w/2, d+i*fh, Graphics.HCENTER| Graphics.TOP);
String nn = m1[i];
if (i==2) nn += Main.music ? "вкл" : "выкл";
g.drawString(nn, w/2, d+i*fh, Graphics.HCENTER| Graphics.TOP);
}
g.setColor(ESkin.wBack);
g.fillRoundRect(5, hc, w-10, fh, 15, 15);
g.setColor(ESkin.wTitle);
g.drawString(m1[cu], w/2, d+cu*fh, Graphics.HCENTER| Graphics.TOP);
String nn = m1[cu];
if (cu==2) nn += Main.music ? "вкл" : "выкл";
g.drawString(nn, w/2, d+cu*fh, Graphics.HCENTER| Graphics.TOP);
if(yy<0) yy+=2;
else if(yy>0) 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) {

View File

@ -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) {}
}

View File

@ -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; i<hgt; i++) {
r=r1 + (((i - hgt) + 1) * (r2 - r1)) / (hgt - yn - 1) + (r2 - r1);
g=g1 + (((i - hgt) + 1) * (g2 - g1)) / (hgt - yn - 1) + (g2 - g1);
b=b1 + (((i - hgt) + 1) * (b2 - b1)) / (hgt - yn - 1) + (b2 - b1);
gr.setColor (r,g,b);
gr.drawLine (xn,i,wdh-1,i);
}
}
public static void drawHGradient (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=xn; i<wdh; i++) {
r=r1+(((i-wdh)+1)*(r2-r1))/(wdh-xn-1)+(r2-r1);
g=g1+(((i-wdh)+1)*(g2-g1))/(wdh-xn-1)+(g2-g1);
b=b1+(((i-wdh)+1)*(b2-b1))/(wdh-xn-1)+(b2-b1);
if(r>255) 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);
}
}

BIN
src/res/0 Normal file

Binary file not shown.

BIN
src/res/1 Normal file

Binary file not shown.

BIN
src/res/2 Normal file

Binary file not shown.

View File

Before

Width:  |  Height:  |  Size: 105 B

After

Width:  |  Height:  |  Size: 105 B

BIN
src/res/3 Normal file

Binary file not shown.

BIN
src/res/4 Normal file

Binary file not shown.

View File

@ -1,4 +1,4 @@
RayCanvas
«њRayCanvas
Цель игры - пройти лабиринт. Цвета стен, лабиринт и эффекты генерируются случайно.