5
This commit is contained in:
parent
f491889b36
commit
fa4a7c2968
@ -8,72 +8,57 @@
|
|||||||
* www.mobilab.ru
|
* www.mobilab.ru
|
||||||
*/
|
*/
|
||||||
import com.emos.ui.ESkin;
|
import com.emos.ui.ESkin;
|
||||||
|
import com.emos.ui.EWindow;
|
||||||
import com.emos.ui.StringEncoder;
|
import com.emos.ui.StringEncoder;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
import javax.microedition.lcdui.*;
|
import javax.microedition.lcdui.*;
|
||||||
|
|
||||||
public class About extends Canvas {
|
public class About extends EWindow {
|
||||||
|
|
||||||
private final String path = "about.ru";
|
private final String path = "/res/about.ru";
|
||||||
private Font def, fnt;
|
private Font def;
|
||||||
private int fontHeight, defHeight;
|
private int defHeight;
|
||||||
private String str; //текст
|
private String str; //текст
|
||||||
private int w, h; //размеры
|
|
||||||
|
|
||||||
private int mh; //Размер ограничивающего прямоугольника;
|
private int mh, y0; //Положение верхнего края текста
|
||||||
private int y0; //Положение верхнего края текста
|
|
||||||
private int dy; //Шаг при прокрутке текста
|
private int dy; //Шаг при прокрутке текста
|
||||||
private int textheight; //Общая высота текста
|
private int textheight; //Общая высота текста
|
||||||
private Vector strLines;
|
private Vector strLines;
|
||||||
|
|
||||||
public About() {
|
public About(String about) {
|
||||||
setFullScreenMode(true);
|
super(about);
|
||||||
w = getWidth();
|
|
||||||
h = getHeight();
|
|
||||||
str = getText(path);
|
str = getText(path);
|
||||||
fnt = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD, Font.SIZE_SMALL);
|
|
||||||
def = Font.getDefaultFont();
|
def = Font.getDefaultFont();
|
||||||
fontHeight = fnt.getHeight()+2;
|
|
||||||
dy = defHeight = def.getHeight()+2;
|
dy = defHeight = def.getHeight()+2;
|
||||||
//
|
mh = super.hh - 1;
|
||||||
//15;
|
|
||||||
mh = h - fontHeight - 1;
|
|
||||||
SetTextPar();
|
SetTextPar();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void paint(Graphics g) {
|
public void paint(Graphics g, int w, int h) {
|
||||||
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);
|
|
||||||
g.setFont(def);
|
g.setFont(def);
|
||||||
g.setClip(0, fontHeight+1, w, mh);
|
g.setColor(ESkin.wBack);
|
||||||
int y1 = y0;
|
int y1 = y0;
|
||||||
for (int i = 0; i < strLines.size(); i++) {
|
for (int i = 0; i < strLines.size(); i++) {
|
||||||
if ((y1 + defHeight) > 0) {
|
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) {
|
||||||
int ga = getGameAction(key);
|
if(state!=RELEASED) {
|
||||||
if(ga==UP) MoveUp();
|
int ga = getGameAction(key);
|
||||||
else if(ga==DOWN) MoveDown();
|
if(ga==UP) MoveUp();
|
||||||
else if(ga==LEFT) PageUp();
|
else if(ga==DOWN) MoveDown();
|
||||||
else if(ga==RIGHT) PageDown();
|
else if(ga==LEFT) PageUp();
|
||||||
else if(ga==FIRE || key==-6 || key==-7)
|
else if(ga==RIGHT) PageDown();
|
||||||
Main.midlet.dsp.setCurrent(Main.midlet.mn);
|
else if(ga==FIRE || key==-6 || key==-7)
|
||||||
repaint();
|
Main.midlet.dsp.setCurrent(Main.midlet.mn);
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void pointerPressed(int x, int y) {
|
protected void pointerPressed(int x, int y) {
|
||||||
@ -147,6 +132,7 @@ public class About extends Canvas {
|
|||||||
StringBuffer strBuff = new StringBuffer();
|
StringBuffer strBuff = new StringBuffer();
|
||||||
int ch = 0;
|
int ch = 0;
|
||||||
try {
|
try {
|
||||||
|
dis.read(); dis.read();
|
||||||
while ((ch = dis.read()) != -1) {
|
while ((ch = dis.read()) != -1) {
|
||||||
strBuff.append(StringEncoder.decodeCharCP1251((byte)ch));
|
strBuff.append(StringEncoder.decodeCharCP1251((byte)ch));
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,24 @@
|
|||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Random;
|
||||||
import javax.microedition.midlet.*;
|
import javax.microedition.midlet.*;
|
||||||
import javax.microedition.lcdui.*;
|
import javax.microedition.lcdui.*;
|
||||||
|
import javax.microedition.media.*;
|
||||||
|
|
||||||
public class Main extends MIDlet {
|
public class Main extends MIDlet implements PlayerListener {
|
||||||
|
|
||||||
public Display dsp;
|
public Display dsp;
|
||||||
public static Main midlet;
|
public static Main midlet;
|
||||||
public Menu mn;
|
public Menu mn;
|
||||||
|
public static boolean music = false;
|
||||||
|
private int currentmusic;
|
||||||
|
private Random rnd;
|
||||||
|
private Player plr;
|
||||||
|
|
||||||
public Main() {
|
public Main() {
|
||||||
dsp = Display.getDisplay(Main.this);
|
dsp = Display.getDisplay(Main.this);
|
||||||
midlet = Main.this;
|
midlet = Main.this;
|
||||||
|
rnd = new Random();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startApp() {
|
public void startApp() {
|
||||||
@ -22,7 +29,48 @@ public class Main extends MIDlet {
|
|||||||
public void pauseApp() {
|
public void pauseApp() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroyApp(boolean unconditional) {
|
public void destroyApp(boolean un) {
|
||||||
notifyDestroyed();
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ public class Menu extends EWindow {
|
|||||||
m1 = new String[] {
|
m1 = new String[] {
|
||||||
"Начать",
|
"Начать",
|
||||||
"Об игре",
|
"Об игре",
|
||||||
|
"Музыка ",
|
||||||
"Выход",
|
"Выход",
|
||||||
};
|
};
|
||||||
rnd = new Random();
|
rnd = new Random();
|
||||||
@ -46,12 +47,16 @@ public class Menu extends EWindow {
|
|||||||
for (int i = 0;i<m1.length;i++) {
|
for (int i = 0;i<m1.length;i++) {
|
||||||
if (i==cu) continue;
|
if (i==cu) continue;
|
||||||
g.setColor(ESkin.wBack2);
|
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.setColor(ESkin.wBack);
|
||||||
g.fillRoundRect(5, hc, w-10, fh, 15, 15);
|
g.fillRoundRect(5, hc, w-10, fh, 15, 15);
|
||||||
g.setColor(ESkin.wTitle);
|
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;
|
if(yy<0) yy+=2;
|
||||||
else if(yy>0) yy-=2;
|
else if(yy>0) yy-=2;
|
||||||
if(yy>1 || yy<-1) redraw();
|
if(yy>1 || yy<-1) redraw();
|
||||||
@ -69,8 +74,9 @@ public class Menu extends EWindow {
|
|||||||
|
|
||||||
private void getM1Code(int nfct) {
|
private void getM1Code(int nfct) {
|
||||||
if(nfct==0) Main.midlet.dsp.setCurrent(ray);
|
if(nfct==0) Main.midlet.dsp.setCurrent(ray);
|
||||||
else if(nfct==1) Main.midlet.dsp.setCurrent(new About());
|
else if(nfct==1) Main.midlet.dsp.setCurrent(new About(m1[nfct]));
|
||||||
else if(nfct==2) Main.midlet.destroyApp(true);
|
else if(nfct==2) Main.midlet.changeSoundState(!Main.music);
|
||||||
|
else if(nfct==3) Main.midlet.destroyApp(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void pointerPressed(int x, int y) {
|
protected void pointerPressed(int x, int y) {
|
||||||
|
@ -38,12 +38,12 @@ public class RayCanvas extends Canvas {// implements Runnable {
|
|||||||
dirX = -1;
|
dirX = -1;
|
||||||
lastTime = 0;
|
lastTime = 0;
|
||||||
dirY = planeX = 0;
|
dirY = planeX = 0;
|
||||||
planeY = 0.66;
|
planeY = 0.56;
|
||||||
gluk = 1;
|
gluk = 1;
|
||||||
|
|
||||||
keyb = new Keyboard();
|
keyb = new Keyboard();
|
||||||
try {
|
try {
|
||||||
pr = Image.createImage("/2.png");
|
pr = Image.createImage("/res/2.png");
|
||||||
} catch (IOException ex) {}
|
} catch (IOException ex) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,53 +115,4 @@ public class ESkin {
|
|||||||
hsb = RGBtoHSV(qr, qg, qb, hsb);
|
hsb = RGBtoHSV(qr, qg, qb, hsb);
|
||||||
return hsb[c];
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Before Width: | Height: | Size: 105 B After Width: | Height: | Size: 105 B |
@ -1,4 +1,4 @@
|
|||||||
RayCanvas
|
«њRayCanvas
|
||||||
|
|
||||||
Цель игры - пройти лабиринт. Цвета стен, лабиринт и эффекты генерируются случайно.
|
Цель игры - пройти лабиринт. Цвета стен, лабиринт и эффекты генерируются случайно.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user