Em que linha dá o problema?
Bom gente eu consegui graças a vcs arruma boa parte so falta o joguin funfa como eu quero
eu so quero transformar o X q ta la em baixo comentado em uma imagem ta tudo ai comentado e talz
comentado roda blz tira os comentario ela da exception e nao roda so queria resolve mais isso
e fim ! Obrigado gente !
import java.io.IOException;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
public class ExampleGameCanvas extends GameCanvas implements Runnable {
private boolean gameOver = false;
private boolean isPlay; // Game Loop runs when isPlay is true
private long delay; // To give thread consistency
private int currentX, currentY; // To hold current position of the 'X'
private int width; // To hold screen width
private int height; // To hold screen height
//private Sprite sprite;// SO TIRA ESSE COMENT
private int pontos = 0;
private int BateL1;
private TextBox textBox1;
private int BateL2;
private int BateS1, BateS2;
// Constructor and initialization
public ExampleGameCanvas() throws Exception{
super( true );
width = getWidth();
height = getHeight();
currentX = 30;
currentY = 170;
delay = 20;
//Image image = Image.createImage("/imagem.png");// SO TIRA ESSE COMENT
// sprite = new Sprite (image,32,32);// SO TIRA ESSE COMENT
}
// Automatically start thread for game loop
public void start() {
isPlay = true;
Thread t = new Thread( this );
t.start();
}
public void stop() {
isPlay = false;
}
// Main Game Loop
public void run() {
Graphics g = getGraphics();
BateL1=getHeight()/4-18;
BateL2=getHeight()/4+100;
BateS1=(getWidth()+6)/4;
BateS2=(getWidth()+6)/4+100;
while ( isPlay == true ) {
input();
drawScreen( g );
try {
Thread.sleep( delay );
}
catch ( InterruptedException ie ) {
}
}
}
// Method to Handle User Inputs
private void input() {
int keyStates = getKeyStates();
// Left
if ((keyStates & LEFT_PRESSED) != 0) {
currentX = Math.max(0, currentX - 1);
// if( currentX == -1 ) currentX = width;
//Verifica se encostou na face lateral 1
if(currentX==BateL2-9)
//verifica se quando encostou na face Lateral o valor de Y esta dentro do quadrado
if(currentY>=BateS1 && currentY<=BateS2)
{
//currentY =BateS1-5;
currentX =BateL2-5;
isPlay = false;
gameOver= true;
}
}
// Right
if ((keyStates & RIGHT_PRESSED) !=0 ) {
currentX = Math.min(width-6, currentX + 1);
//Verifica se encostou na face lateral 1
if(currentX==BateL1)
//verifica se quando encostou na face Lateral o valor de Y esta dentro do quadrado
if(currentY>=BateS1 && currentY<=BateS2)
{
//currentY =BateS1-5;
currentX =BateL1-5;
isPlay = false;
gameOver= true;
}
}
// Up
if ((keyStates & UP_PRESSED) != 0) {
currentY = Math.max(0, currentY - 1);
//verifica se encostou na face inferior do quadrado
if(currentY==(BateS2+5))
//verifica se quando encostou na face superior o valor de X esta dentro do quadrado
if(currentX>=BateL1 && currentX<=BateL2-9)
{
currentY =BateS2+8;
isPlay = false;
gameOver= true;
}
}
// Down
if ( ( keyStates & DOWN_PRESSED ) != 0 ) {
currentY = currentY + 1;
//verifica se encostou na face superior do quadrado
if(currentY==BateS1)
//verifica se quando encostou na face superior o valor de X esta dentro do quadrado
if(currentX>=BateL1 && currentX<=BateL2-9)
{
currentY =BateS1-5;
isPlay = false;
gameOver= true;
}
}
}
// Method to Display Graphics
private void drawScreen(Graphics g) {
String a="";
//cor de fundo do objeto retangulo
g.setColor(0x000000);
g.fillRect(0, 0, getWidth(), getHeight());
//cor de fundo do objeto retangulo menor
g.setColor(0xff0000);
//retangulo menor
g.fillRect( (getWidth()+6)/4, getHeight()/4, 100, 100 );//desenha reta ou contorno do retangulo
//cor do X
g.setColor( 0, 255, 0);
//Desenhando o X
g.drawString("0=0",currentX,currentY,Graphics.TOP|Graphics.LEFT);// KERO Q ISSO SEJA UMA IMAGEM
for(int i=0;i<=160;i++)
{
if(currentX == i && 160 == currentY)
{
pontos++;
if(delay == 20)
{
delay= delay -7;
if(delay == 13)
{
delay= delay -7;
}
}
}
}
g.drawString(" LARGADA ",0,145,Graphics.TOP|Graphics.LEFT);
g.drawLine(-110,160,60,160);
g.drawString(" CHEGADA ",0,160,Graphics.TOP|Graphics.LEFT);
g.drawString("Score:"+pontos,90,250,Graphics.TOP|Graphics.LEFT);
if(gameOver == true)
{
g.drawString("GAME OVER",80,260,Graphics.TOP|Graphics.LEFT);
}
// sprite.setPosition(currentX,currentY); // SO TIRA ESSE COMENT
//sprite.paint(g);// SO TIRA ESSE COMENT
flushGraphics();
}
}
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.Graphics;
public class ExampleGameCanvasMidlet extends MIDlet {
private Display display;
public void startApp(){
//display = Display.getDisplay(this);
//ExampleGameCanvas gameCanvas = new ExampleGameCanvas();
//gameCanvas.start();
//display.setCurrent(gameCanvas);
try {
display = Display.getDisplay(this);
ExampleGameCanvas gameCanvas = new ExampleGameCanvas();
gameCanvas.start();
display.setCurrent(gameCanvas);
} catch (Exception ex) {
System.out.println(ex);
}
}
public Display getDisplay() {
return display;
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
exit();
}
public void exit() {
System.gc();
destroyApp(false);
notifyDestroyed();
}
}
bom gente obrigado passei o dia todo aprendi muito bastante gente me ajudou
obrigado ao thingol ajudo tbm so falta isso ae
obrigado gente ! me ajuda ! hHUAHUshu
la no try la em cima
ela manda uma exception pra mim tendeu dizendo esses erros q eu colokei no post ae
cara so kero por uma imagem nao precisa nem corrigi o codigo so como po acho q funfa
to me matando ahuuahuahuahua
brigadao a atenção cara !