import javax.microedition.lcdui.*; import javax.microedition.lcdui.game.*; import java.io.*; import java.util.*; public class Second extends Canvas { public boolean keyLeft; public boolean keyRight; public boolean fr1; public boolean fr2; public Image img1; public Image brick; public Image life; public Image life2; public Image life3; public Sprite Hero; public Sprite Brick; public Sprite Life; public Sprite Life2; public Sprite Life3; public int w,h; public int HeroX,HeroY; public int []transformT; public int rotate; public int ax,ay; public int bx,by; public int lx,ly; public int l2x,l2y; public int l3x,l3y; Random r = new Random(); String s = "Maga, go, go!"; public Second() { setFullScreenMode(true); w=getWidth(); h=getHeight(); try { img1=Image.createImage("/1.png"); brick=Image.createImage("/brick.png"); life=Image.createImage("/life.png"); life2=Image.createImage("/life.png"); life3=Image.createImage("/life.png"); } catch (IOException ex) { ex.printStackTrace(); } Hero=new Sprite(img1,img1.getWidth(),img1.getHeight()); Brick=new Sprite(brick,brick.getWidth(),brick.getHeight()); Life=new Sprite(life,life.getWidth(),life.getHeight()); Life2=new Sprite(life,life.getWidth(),life.getHeight()); Life3=new Sprite(life,life.getWidth(),life.getHeight()); transformT=new int[2]; transformT[0]=Sprite.TRANS_NONE; transformT[1]=Sprite.TRANS_MIRROR; rotate=0; HeroX=w/2-img1.getWidth()/2; HeroY=h-img1.getHeight()-6; bx=20; by=-30; lx=219; ly=2; l2x=196; l3x=173; } public void paint(Graphics g) { OldPosition(); checkKeys(); g.setColor(250,250,250); g.fillRect(0,0,w,h); g.setColor(0,150,0); g.fillRect(0,305,240,320); Life.paint(g); Life.setPosition(lx, ly); Life2.setPosition(l2x, ly); Life3.setPosition(l3x, ly); Brick.paint(g); Brick.setPosition (bx,by); by=by+5; if (by>h) { by=-Brick.getHeight(); bx=r.nextInt(200); } g.drawImage(brick, bx, by, 20); g.drawImage(life, lx, ly, 20); g.drawImage(life2, l2x, ly, 20); g.drawImage(life3, l3x, ly, 20); g.drawString(" "+s, w/2, 0, 17); Hero.setTransform(transformT[rotate]); Hero.setPosition (HeroX,HeroY); Hero.paint(g); if (fr1) { g.setColor(0,0,0); g.drawRect(HeroX-10,HeroY-10,60,20); g.drawString("Эхехе",HeroX-10,HeroY-10,20); } if (fr2) { g.setColor(0,0,0); g.drawRect(HeroX-10,HeroY-10,60,20); g.drawString("Хехехе",HeroX-10,HeroY-10,20); } if (Hero.collidesWith(Brick, true)); { g.setColor(0,0,0); s = "GAME OVER"; by=-Brick.getHeight(); bx=r.nextInt(200); } fr1=false; fr2=false; repaint(); } private void checkKeys() { if (keyRight) { fr1=true; HeroX=HeroX+4; rotate=0; } if (keyLeft) { fr2=true; HeroX=HeroX-4; rotate=1; } } public void OldPosition() { ax=HeroX; ay=HeroY; } protected void keyPressed(int key) { int ga = getGameAction(key); switch (ga) { case LEFT: keyLeft=true; break; case RIGHT: keyRight=true; break; } } protected void keyReleased(int key) { int ga = getGameAction(key); switch (ga) { case LEFT: keyLeft=false; break; case RIGHT: keyRight=false; break; } } }