J2ME

J2ME - Netbook - Ordinateurs portables

Marsh Posté le 12-12-2011 à 23:34:02    

salut tt le monde j'ai realisee le code suivant d'un jeu Biang en J2ME et je voudrai ajouter une image d'une balle mais je sais pas comment. povez vous m'aider SVP ??
 
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.*;
 
public class Bing extends MIDlet
{
private Display _display;  
private Moteur _moteur;  
private TimerBalle _timerBalle;  
private Timer _timer;  
 
public Bing()
{
 
_moteur = new Moteur();
_timerBalle = new TimerBalle(_moteur);
_timer = new Timer();
_display = Display.getDisplay(this);
}
 
protected void destroyApp(boolean unconditional)
{
_timer.cancel(); // arret du timer
}
protected void startApp()
{
_display.setCurrent(_moteur);
_timer.schedule(_timerBalle, 1, 20);  
}
 
protected void pauseApp(){}
}
 
class TimerBalle extends TimerTask
{
private Moteur _moteur;
TimerBalle(Moteur moteur)
{
_moteur = moteur;
}
public void run()
{
_moteur.TestAndMove();
}
}
class Moteur extends Canvas
{
private int _height, _recH, _x, _speedX, _zoneH;
private int _width, _recW, _y, _speedY, _zoneW;
private int _barrePosX, _barrePosY, _barreH, _barreW;
private String _dirBarre = "";  
private boolean _painting = false;
private boolean _perdu = false;
public Moteur()
{
_height = getHeight();  
_width = getWidth();  
_recW = 2;  
_recH = 2;  
_speedX = -1;  
_speedY = -1;  
_x = 50;  
_y = 60;  
_zoneW = _width;  
_zoneH = _height - 11;  
_barrePosX = 60;  
_barrePosY = _zoneH - 4;  
_barreH = 3;  
_barreW = 10;  
}
 
public void TestAndMove()
{
 
if (_painting) return;
 
if (_x >= _zoneW - 1 || _x <= 1) _speedX = -_speedX;
if (_y <= 1) _speedY = -_speedY;
 
if (_y >= _zoneH - 1) _perdu = true;
 
if (_y >= _barrePosY && _x >= _barrePosX && _x <= _barrePosX + _barreW)
_speedY = -_speedY;
 
_x += _speedX;
_y += _speedY;
 
repaint();
}
 
private void scrollBarre()
{
if (_dirBarre == "LEFT" ) _barrePosX -= 2;
else if (_dirBarre == "RIGHT" ) _barrePosX += 2;
}
protected void paint(Graphics g)
{
_painting = true;
scrollBarre();
 
g.setColor(255, 255, 255);
g.fillRect(0,0,_width,_height);
 
g.setColor(0,0,0);
g.drawRect(0,0,_zoneW-1,_zoneH-1);
if (!_perdu) // si le jeu continue
{
g.fillRect(_x, _y, _recW, _recH);
 
g.fillRect(_barrePosX, _barrePosY, _barreW, _barreH);
}
else  
{
g.drawString("Perdu ! Gros Nul !", 7, 35, 0);
}
_painting = false;
}
protected void keyPressed(int keyCode)
{
if (keyCode==Canvas.KEY_NUM4)  
{
_dirBarre="LEFT";
}
if (keyCode==Canvas.KEY_NUM6)  
{
_dirBarre="RIGHT";
}
}
 
protected void keyReleased(int keyCode)
{
if (keyCode==Canvas.KEY_NUM4 || keyCode==Canvas.KEY_NUM6)
{
_dirBarre = "";
}
}
}

Reply

Marsh Posté le 12-12-2011 à 23:34:02   

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed