import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.IOException;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
// definice nové třídy, potomka třídy Canvas
public class Hra extends Canvas {
int viewX = 0;
int viewY = 0,z = 0;
Image zemTrava,zemHlina,hrac,hrac2,kamen,block,bedrock,stone;
Mineria midlet;
String keyValue;
int keyCodeVal;
int posun=0;
Timer timer;
TimerTask task;
private Font aFonl;
int HracPosx=32*3;
int HracPosy=32*5;
Image hracObr;
//int mapaBod[][]={{1,1,1,1,1,1,1},{1,1,1,1,1,1,1},{1,1,1,1,1,1,1},{1,1,1,1,1,1,1},{1,1,1,1,1,1,1},{1,1,1,1,1,1,1},{1,1,1,1,1,1,1},{1,1,1,1,1,1,1}};
//ArrayList<Integer> seznam = new ArrayList<Integer>();
int mapaBod[][][] = new int[100][100][100];
int rozbito[][][] = new int[100][100][100];
int sprit=1;
String tmp;
int crt=0,pressed=0,drag=0,released=0,lastPointerX = -1,lastPointerY = -1,lastPointerX_= -1,lastPointerY_= -1,x=0,y=0,repan=0,widthMax=100,heightMax=100;
Display disp;
public Hra(Mineria midleto) {
try {
// použijeme metodu createImage třídy Image
//errorAlert.setTimeout(3000);
setFullScreenMode(true);
aFonl = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_LARGE);
this.midlet = midleto;
hrac = Image.createImage("/panacek_right.PNG");
hrac2= Image.createImage("/panacek_left.PNG");
block= Image.createImage("/FileGrass.png");
bedrock= Image.createImage("/FileBedrock.png");
stone= Image.createImage("/FileStone.png");
//generace mapy
for(int i=0;i<100;i+=1){
for(int a=0;a<100;a+=1){
for(int p=0;p<100;p+=1){
if(i<6){mapaBod[p][i][a]=0;}
else if(a==6){mapaBod[p][i][a]=1;}
else if(a<20){mapaBod[p][i][a]=2;}
else {mapaBod[p][i][a]=3;}
rozbito[p][i][a]=0;
}
}
}
// odchycení možné výjimky
}
catch(Exception e) {
}
}
int round(float a) {
return (int)(a + 0.5f);
}
public void paint(Graphics g) {
repan = 0;
g.setColor(255, 255, 255);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(0, 0, 0);
int y=0;
//y+=showFont(g, "X:"+lastPointerX+", Y:"+lastPointerY+", [P:"+pressed+"](XV:"+(round((viewX/32)-2)*-1)+",XNR"+viewX+")", 0, 0, aFonl);
//y+=showFont(g, "(XY:"+(round(viewY/32)+5)+")[OB: "+mapaBod[(round((viewX/32)-2)*-1)][(round(viewY/32)+5)]+"]", 0, y, aFonl);
if(sprit==1)
g.drawImage(hrac, HracPosx, HracPosy, g.TOP|g.LEFT);
else
g.drawImage(hrac2, HracPosx, HracPosy, g.TOP|g.LEFT);
//vykreslení mapy
//for(int i=0;i<10;i+=1){
int i=0,a=0,p=0,sizeW=17,sizeH=17,kl=1,jk=0,blockSize=23,fCelk=blockSize*sizeW;
boolean mam=false;
int maxFlor=5,sizeHe=maxFlor*blockSize;
for(p=maxFlor;p>-1;p-=1){
//draw_text(0,30+30*p,string(maxFlor)+", "+string(p));
kl=0;jk=0;
for(i=0;i<sizeW+1;i+=1){
for(a=0;a<kl;a+=1){
if(p==0){
/*
if(mouse_in(x+((fCelk/2)-(((kl-a)*(blockSize))/1)+((kl*blockSize)/2))-78,y+(i*(blockSize/2))-(sizeHe-((p*blockSize))/2),x+((fCelk/2)-(((kl-a)*(blockSize))/1)+((kl*blockSize)/2))-78+blockSize,y+(i*(blockSize/2))-(sizeHe-((p*blockSize))/2)+blockSize) and !mam)
{draw_set_alpha(0.5);mam=true;}
else
{draw_set_alpha(1);}
*/
}
crt=0;
if(p==maxFlor){
g.drawImage(bedrock, ((fCelk/2)-(((kl-a)*(blockSize))/1)+((kl*blockSize)/2))-78, 200+((i*(blockSize/2))/2)-(sizeHe-((p*blockSize))/2), g.TOP|g.LEFT);
}else{
//if(p==0){showFont(g, i+"", ((fCelk/2)-(((kl-a)*(blockSize))/1)+((kl*blockSize)/2))-78, 200+((i*(blockSize/2))/2)-(sizeHe-((p*blockSize))/2), aFonl);}
switch(mapaBod[p][i][a]){ //i,a
case 0:crt=1;break;
case 1:g.drawImage(block, ((fCelk/2)-(((kl-a)*(blockSize))/1)+((kl*blockSize)/2))-78, 200+((i*(blockSize/2))/2)-(sizeHe-((p*blockSize))/2), g.TOP|g.LEFT);break;
case 2:g.drawImage(stone, ((fCelk/2)-(((kl-a)*(blockSize))/1)+((kl*blockSize)/2))-78, 200+((i*(blockSize/2))/2)-(sizeHe-((p*blockSize))/2), g.TOP|g.LEFT);break;
case 255:g.drawImage(bedrock, ((fCelk/2)-(((kl-a)*(blockSize))/1)+((kl*blockSize)/2))-78, 200+((i*(blockSize/2))/2)-(sizeHe-((p*blockSize))/2), g.TOP|g.LEFT);break;
}
}
//draw_rectangle(i*blockSize,(fCelk/2)-(((kl-a)*blockSize)/2),(i*blockSize)+blockSize,((fCelk/2)-(((kl-a)*blockSize)/2))+blockSize,false);
}
if(jk==0){kl+=1;}else{kl-=1;}
if(kl>sizeW/2){jk=1;}
}
}
/*
for(r=0;r<50;r+=1){
for(t=0;t<100;t+=1){
//g.drawImage(kamen, viewX+(t*32), viewY+((r+6)*32), g.TOP|g.LEFT);
//showFont(g, t+","+r, viewX+(t*32), viewY+((r+6)*32), aFonl);
case 0:crt=1;break;
case 1:g.drawImage(zemTrava, viewX+(t*32), viewY+((r)*32), g.TOP|g.LEFT);break;
case 2:g.drawImage(zemHlina, viewX+(t*32), viewY+((r)*32), g.TOP|g.LEFT);break; //zemHlina
case 3:g.drawImage(kamen, viewX+(t*32), viewY+((r)*32), g.TOP|g.LEFT);break;
default:g.drawImage(kamen, viewX+(t*32), viewY+((r)*32), g.TOP|g.LEFT);break;
}
if(crt==1 && pressed==1 && lastPointerX>viewX+(t*32) && lastPointerY>viewY+((r)*32) && lastPointerX<viewX+(t*32)+32 && lastPointerY<viewY+((r)*32)+32){
mapaBod[r][t]=2;
}else if(crt !=1 && rozbito[r][t]>20 && pressed==2 && lastPointerX>viewX+(t*32) && lastPointerY>viewY+((r)*32) && lastPointerX<viewX+(t*32)+32 && lastPointerY<viewY+((r)*32)+32){
mapaBod[r][t]=0;
rozbito[r][t]=0;
//disp.vibrate(800);
repan = 1;
}else if(pressed==2 && lastPointerX>viewX+(t*32) && lastPointerY>viewY+((r)*32) && lastPointerX<viewX+(t*32)+32 && lastPointerY<viewY+((r)*32)+32){
rozbito[r][t]+=1;
repan = 1;
}
}
}
*/
//vykreslení mapy end
if(posun==1){
if(keyCodeVal==-4){
x = round((viewX/32)-2)*-1;
y = round(viewY/32)+5;
z = 0;
//if(mapaBod[x][y][z]==0){
// viewX-=4;
//}
//viewX-=4;
sprit=1;
}
if(keyCodeVal==-3 && HracPosx-2>-1){
viewX+=4;
sprit=2;
}
//if(keyCodeVal==-1 && viewY+1<0){viewY+=1;}
//if(keyCodeVal==-2){viewY-=1;}
repaint();
}
//if(HracPosx>32*4){viewX-=2;}
//viewX=HracPosx+(32*4);
if(pressed==1){
pressed=2;
repan=1;
}
released=0;
drag=0;
if(repan==1){repaint();}
}
public void resetPointer(){
lastPointerX_ = lastPointerX;
lastPointerY_ = lastPointerY;
lastPointerX = -1;
lastPointerY = -1;
released = 0;
}
protected void pointerPressed(int x, int y)
{
lastPointerX = x;
lastPointerY = y;
if(pressed!=2)
pressed=1;
repaint ();
}
protected void pointerReleased(int x, int y)
{
pressed=0;
released = 1;
repaint ();
resetPointer();
repaint ();
}
protected void pointerDragged(int x, int y)
{
//scrollImage(lastPointerX - x, lastPointerY - y);
lastPointerX = x;
lastPointerY = y;
drag=1;
repaint ();
}
private int showFont(Graphics g, String s, int x, int y, Font f) {
g.setFont(f);
g.drawString(s, x, y, Graphics.TOP | Graphics.LEFT);
return f.getHeight();
}
public void keyPressed(int keyCode){
keyValue = getKeyName(keyCode);
keyCodeVal = keyCode;
posun=1;
repaint();
}
public void keyReleased(int keyCode){
posun=0;
repaint();
}
}
tohle je celý kod