Ayuda en j2me
Saludos cordiales estimados amigos, tengo un pequeño problema
Estoy haciendo un juego donde un sprite se desplaza por todo la pantalla definida pero tambien existe el segundo Sprite , el echo es, un vez que se choque entre dos sprite debe aparecer un mensaje (por ejemplo: “EL significado de Blearning es Blended Learning, trducido a español es Aprendizaje Combinado” por un intervalo de 5 segundos) y el sprite 2 debe cambiar de posición nueve veces, haci mismo los mensajes deben aparecer en cada colision.
Agradesco desde ya su ayuda
Son dos .java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package batallafinal;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class batallafinal extends MIDlet implements CommandListener {
private WCanvas canvas;
public void startApp() {
if (canvas == null) {
canvas = new WCanvas(Display.getDisplay(this));
Command exitCommand = new Command("Salir", Command.EXIT, 0);
canvas.addCommand(exitCommand);
canvas.setCommandListener(this);
}
// Start up the canvas
canvas.start();
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {
canvas.stop();
}
public void commandAction(Command c, Displayable s) {
if (c.getCommandType() == Command.EXIT) {
destroyApp(true);
notifyDestroyed();
}
}
}
Y
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package batallafinal;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import java.util.*;
import java.io.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
public class WCanvas extends GameCanvas implements Runnable {
private Display display;
private boolean sleeping;
private long frameDelay;
private int inputDelay;
private LayerManager layers;
private int xView, yView;
private int xball, yball;
private TiledLayer backgroundLayer;
private TiledLayer barrierLayer;
private int waterDelay, waterTile;
private Sprite personSprite;
private Sprite ballSprite;
private Player musicPlayer;
private Alert keys;
private String[] sms;
private int nchoques=0;
public WCanvas(Display d) {
super(true);
display = d;
// Set the frame rate (30 fps)
frameDelay = 33;
// Clear the input delay
inputDelay = 0;
}
public void start() {
// Set the canvas as the current screen
display.setCurrent(this);
// Create the background and barrier tiled layers
try {
backgroundLayer = new TiledLayer(16, 16, Image.createImage("/Background.png"), 48, 48);
barrierLayer = new TiledLayer(16, 16, Image.createImage("/Barrier.png"), 48, 48);
}
catch (IOException e) {
System.err.println("Falló abriendo imagen");
}
// Preparando la pantalla principal de juego
int[] backgroundMap = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0,
0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0,
0, 2, 2, 2, 2, 5, 15, 15, 15, 15, 15, 15, 6, 2, 2, 0,
0, 2, 2, 2, 2, 7, 10, 1, 1, 1, 1, 1, 16, 2, 2, 0,
0, 2, 2, 2, 2, 2, 14, 1, 1, 1, 1, 1, 16, 2, 2, 0,
0, 2, 2, 2, 2, 2, 7, 10, 1, 1, 1, 1, 16, 2, 2, 0,
0, 2, 2, 2, 2, 2, 2, 14, 1, 1, 1, 1, 16, 2, 2, 0,
0, 2, 2, 2, 2, 2, 2, 14, 1, 9, 10, 1, 16, 2, 2, 0,
0, 2, 2, 5, 15, 6, 2, 14, 1, 11, 12, 1, 16, 2, 2, 0,
0, 2, 2, 14, 1, 16, 2, 7, 13, 13, 13, 13, 8, 2, 2, 0,
0, 2, 2, 7, 13, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0,
0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0,
0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
for (int i = 0; i < backgroundMap.length; i++) {
int column = i % 16;
int row = (i - column) / 16;
backgroundLayer.setCell(column, row, backgroundMap[i]);
}
// Preparando el mapa de las barreras para el sprite
barrierLayer.createAnimatedTile(1);
int[] barrierMap = {
-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, 21, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 22, 1,
1, 18, 0, 5, 5, 5, 5, 8, 0, 0, 8, 0, 0, 0, 20, -1,
1, 18, 0, 0, 0, 0, 0, 0, 0, 16, 8, 0, 0, 0, 20, 1,
-1, 18, 7, 7, 7, 11, 7, 8, 0, 0, 10, 5, 0, 0, 20, -1,
1, 18, 0, 11, 0, 0, 11, 7, 7, 12, 0, 0, 0, 0, 20, -1,
-1, 18, 0, 7, 7, 7, 0, 11, 12, 8, 0, 0, 0, 0, 20, 1,
1, 18, 0, 11, 12, 0, 15, 10, 0, 8, 0, 0, 0, 0, 20, 1,
1, 18, 0, 0, 13, 0, 10, 5, 5, 9, 0, 0, 0, 0, 20, -1,
-1, 18, 7, 10, 5, 9, 0, 0, 0, 0, 0, 0, 0, 0, 20, 1,
-1, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, -1,
1, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 1,
1, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 1,
-1, 23, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 24, -1,
-1, -1, 1, -1, 1, -1, 1, 1, 1, -1, 1, -1, -1, 1, 1, -1
};
for (int i = 0; i < barrierMap.length; i++) {
int column = i % 16;
int row = (i - column) / 16;
barrierLayer.setCell(column, row, barrierMap[i]);
}
// Initialize the animated water delay and tile
waterDelay = 0;
waterTile = 1;
// Initialize the person sprite
try {
personSprite = new Sprite(Image.createImage("/Person.png"), 20, 24);
ballSprite = new Sprite(Image.createImage("/ball.png"));
}
catch (IOException e) {
System.err.println("Falló abriendo imagen!");
}
// Create the layer manager
layers = new LayerManager();
layers.append(ballSprite);
layers.append(personSprite);
layers.append(barrierLayer);
layers.append(backgroundLayer);
xView = (backgroundLayer.getWidth() - getWidth()) / 2;
yView = (backgroundLayer.getHeight() - getHeight()) / 2;
layers.setViewWindow(xView, yView, getWidth(), getHeight());
personSprite.setPosition(xView + (getWidth() - personSprite.getWidth()) / 2,
yView + (getHeight() - personSprite.getHeight()) / 2);
ballSprite.setPosition((getWidth()/2)+10,getHeight()/2);
//xball +(getWidth()-ballSprite.getWidth())/2,
// yball+(getHeight()-ballSprite.getHeight())/2
// Inicializando el audio del juego
try {
InputStream is = getClass().getResourceAsStream("Music.mid");
musicPlayer = Manager.createPlayer(is, "audio/midi");
musicPlayer.prefetch();
musicPlayer.setLoopCount(-1);
musicPlayer.start();
}
catch (IOException ioe) {
}
catch (MediaException me) {
}
// Start the animation thread
sleeping = false;
Thread t = new Thread(this);
t.start();
}
public void stop() {
// Close the music player
musicPlayer.close();
// Stop the animation
sleeping = true;
}
/*private void inisms(){
sms[1]="El famoso Blearning viene de los términos " +
"\nen ingles Blended Learning (aprendizaje combinado)";
sms[2]="Los entornos virtuales de aprendiza (EVAs)" +
" son las aulas virtuales que vemos en Moodle";
sms[3]="Moodle es un sistema de administración " +
"de aprendizaje de sus siglas en ingles LMS";
sms[4]="El Blearning consiste en el aprendizaje," +
" enseñanza y capacitaci{on a través de internet";
sms[5]="En un curso blearning el profesor no ocupa el papel central, " +
"dejando ese espacio a los estudiantes adaptando la metodologìa " +
"de aprender haciendo.";
sms[6]="Moodle es Modular Object Oriented Distance Learning Enviroment" +
" traducido a español es Entorno Modular del Aprendizaje " +
"Dinámico Orientado a Objetos ";
sms[7]="MOODLE vio sus raìces en Universidad de Perth, " +
"de Australia en el año de 2002";
sms[8]="Para entrar al campus virtual sobre la plataforma MOODLE " +
"por lo general le pide Nombre de Usuario y Contraseña";
sms[9]="Moodle es traducido a más de 43 idiomas, en más de 49294" +
" instituciones de 214 paìses del mundo hasta mayo del 2010";
}
*
*/
public void run() {
Graphics g = getGraphics();
// The main game loop
while (!sleeping) {
update();
draw(g);
try {
Thread.sleep(frameDelay);
}
catch (InterruptedException ie) {}
}
}
private void update() {
// Process user input to move the background layer and animate the person
if (++inputDelay > 2) {
int keyState = getKeyStates();
int xMove = 0, yMove = 0;
if ((keyState & LEFT_PRESSED) != 0)
xMove = -12;
else if ((keyState & RIGHT_PRESSED) != 0)
xMove = 12;
if ((keyState & UP_PRESSED) != 0)
yMove = -12;
else if ((keyState & DOWN_PRESSED) != 0)
yMove = 12;
if (xMove != 0 || yMove != 0) {
layers.setViewWindow(xView + xMove, yView + yMove, getWidth(), getHeight());
personSprite.move(xMove, yMove);
personSprite.nextFrame();
}
//MOVE BALL
if(ballSprite.collidesWith(personSprite, true)){
// keys.setString("El amor es bueno");
// display.setCurrent(this.keys);
//keys.setString("El famoso Blearning viene de los términos en ingles Blended Learning (aprendizaje combinado)");
nchoques =nchoques+1;
if(nchoques==1){
ballSprite.setPosition(getWidth()+ 100,getHeight()*2);
} else if(nchoques==2){
ballSprite.setPosition(getWidth(), getHeight()*3);
}else if(nchoques==3){
ballSprite.setPosition(getWidth()-20, getHeight()*2);
} else if(nchoques==4){
ballSprite.setPosition((getWidth()+ 200), getHeight()*2);
}else if (nchoques==5){
ballSprite.setPosition((getWidth()+400),getHeight()*2);
}else if (nchoques==6){
ballSprite.setPosition((getWidth()+400),getHeight()*3);
}else if (nchoques==7){
ballSprite.setPosition(getWidth()+ 100,getHeight()*3);
}else if(nchoques==8){
ballSprite.setPosition(getWidth()+200,getHeight()*2);
}else if (nchoques==9){
ballSprite.setVisible( false);
personSprite.setVisible( false);
}
}
// Check for a collision with the person and the barrier tiled layer
if (personSprite.collidesWith(barrierLayer, true)) {
//cambio de primer cambio de posicion
// Play a collision sound
try {
Manager.playTone(ToneControl.C4 + 12, 100, 100);
}
catch (Exception e) {
}
// Restore the original view window and person sprite positions
layers.setViewWindow(xView, yView, getWidth(), getHeight());
personSprite.move(-xMove, -yMove);
}
else {
// If there is no collision, commit the changes to the view window position
xView += xMove;
yView += yMove;
}
// Update the animated water tiles
if (++waterDelay > 2) {
if (++waterTile > 4)
waterTile = 1;
barrierLayer.setAnimatedTile(-1, waterTile);
waterDelay = 0;
}
// Reset the input delay
inputDelay = 0;
}
}
private void draw(Graphics g) {
// Draw the layers
layers.paint(g, 0, 0);
g.drawRect(getWidth(),10,10,20);
//g.drawString(sms[nchoques],5,getHeight()/2,g.TOP);
// Flush the offscreen graphics buffer
flushGraphics();
}
}
Estoy haciendo un juego donde un sprite se desplaza por todo la pantalla definida pero tambien existe el segundo Sprite , el echo es, un vez que se choque entre dos sprite debe aparecer un mensaje (por ejemplo: “EL significado de Blearning es Blended Learning, trducido a español es Aprendizaje Combinado” por un intervalo de 5 segundos) y el sprite 2 debe cambiar de posición nueve veces, haci mismo los mensajes deben aparecer en cada colision.
Agradesco desde ya su ayuda
Son dos .java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package batallafinal;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class batallafinal extends MIDlet implements CommandListener {
private WCanvas canvas;
public void startApp() {
if (canvas == null) {
canvas = new WCanvas(Display.getDisplay(this));
Command exitCommand = new Command("Salir", Command.EXIT, 0);
canvas.addCommand(exitCommand);
canvas.setCommandListener(this);
}
// Start up the canvas
canvas.start();
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {
canvas.stop();
}
public void commandAction(Command c, Displayable s) {
if (c.getCommandType() == Command.EXIT) {
destroyApp(true);
notifyDestroyed();
}
}
}
Y
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package batallafinal;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import java.util.*;
import java.io.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
public class WCanvas extends GameCanvas implements Runnable {
private Display display;
private boolean sleeping;
private long frameDelay;
private int inputDelay;
private LayerManager layers;
private int xView, yView;
private int xball, yball;
private TiledLayer backgroundLayer;
private TiledLayer barrierLayer;
private int waterDelay, waterTile;
private Sprite personSprite;
private Sprite ballSprite;
private Player musicPlayer;
private Alert keys;
private String[] sms;
private int nchoques=0;
public WCanvas(Display d) {
super(true);
display = d;
// Set the frame rate (30 fps)
frameDelay = 33;
// Clear the input delay
inputDelay = 0;
}
public void start() {
// Set the canvas as the current screen
display.setCurrent(this);
// Create the background and barrier tiled layers
try {
backgroundLayer = new TiledLayer(16, 16, Image.createImage("/Background.png"), 48, 48);
barrierLayer = new TiledLayer(16, 16, Image.createImage("/Barrier.png"), 48, 48);
}
catch (IOException e) {
System.err.println("Falló abriendo imagen");
}
// Preparando la pantalla principal de juego
int[] backgroundMap = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0,
0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0,
0, 2, 2, 2, 2, 5, 15, 15, 15, 15, 15, 15, 6, 2, 2, 0,
0, 2, 2, 2, 2, 7, 10, 1, 1, 1, 1, 1, 16, 2, 2, 0,
0, 2, 2, 2, 2, 2, 14, 1, 1, 1, 1, 1, 16, 2, 2, 0,
0, 2, 2, 2, 2, 2, 7, 10, 1, 1, 1, 1, 16, 2, 2, 0,
0, 2, 2, 2, 2, 2, 2, 14, 1, 1, 1, 1, 16, 2, 2, 0,
0, 2, 2, 2, 2, 2, 2, 14, 1, 9, 10, 1, 16, 2, 2, 0,
0, 2, 2, 5, 15, 6, 2, 14, 1, 11, 12, 1, 16, 2, 2, 0,
0, 2, 2, 14, 1, 16, 2, 7, 13, 13, 13, 13, 8, 2, 2, 0,
0, 2, 2, 7, 13, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0,
0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0,
0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
for (int i = 0; i < backgroundMap.length; i++) {
int column = i % 16;
int row = (i - column) / 16;
backgroundLayer.setCell(column, row, backgroundMap[i]);
}
// Preparando el mapa de las barreras para el sprite
barrierLayer.createAnimatedTile(1);
int[] barrierMap = {
-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, 21, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 22, 1,
1, 18, 0, 5, 5, 5, 5, 8, 0, 0, 8, 0, 0, 0, 20, -1,
1, 18, 0, 0, 0, 0, 0, 0, 0, 16, 8, 0, 0, 0, 20, 1,
-1, 18, 7, 7, 7, 11, 7, 8, 0, 0, 10, 5, 0, 0, 20, -1,
1, 18, 0, 11, 0, 0, 11, 7, 7, 12, 0, 0, 0, 0, 20, -1,
-1, 18, 0, 7, 7, 7, 0, 11, 12, 8, 0, 0, 0, 0, 20, 1,
1, 18, 0, 11, 12, 0, 15, 10, 0, 8, 0, 0, 0, 0, 20, 1,
1, 18, 0, 0, 13, 0, 10, 5, 5, 9, 0, 0, 0, 0, 20, -1,
-1, 18, 7, 10, 5, 9, 0, 0, 0, 0, 0, 0, 0, 0, 20, 1,
-1, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, -1,
1, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 1,
1, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 1,
-1, 23, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 24, -1,
-1, -1, 1, -1, 1, -1, 1, 1, 1, -1, 1, -1, -1, 1, 1, -1
};
for (int i = 0; i < barrierMap.length; i++) {
int column = i % 16;
int row = (i - column) / 16;
barrierLayer.setCell(column, row, barrierMap[i]);
}
// Initialize the animated water delay and tile
waterDelay = 0;
waterTile = 1;
// Initialize the person sprite
try {
personSprite = new Sprite(Image.createImage("/Person.png"), 20, 24);
ballSprite = new Sprite(Image.createImage("/ball.png"));
}
catch (IOException e) {
System.err.println("Falló abriendo imagen!");
}
// Create the layer manager
layers = new LayerManager();
layers.append(ballSprite);
layers.append(personSprite);
layers.append(barrierLayer);
layers.append(backgroundLayer);
xView = (backgroundLayer.getWidth() - getWidth()) / 2;
yView = (backgroundLayer.getHeight() - getHeight()) / 2;
layers.setViewWindow(xView, yView, getWidth(), getHeight());
personSprite.setPosition(xView + (getWidth() - personSprite.getWidth()) / 2,
yView + (getHeight() - personSprite.getHeight()) / 2);
ballSprite.setPosition((getWidth()/2)+10,getHeight()/2);
//xball +(getWidth()-ballSprite.getWidth())/2,
// yball+(getHeight()-ballSprite.getHeight())/2
// Inicializando el audio del juego
try {
InputStream is = getClass().getResourceAsStream("Music.mid");
musicPlayer = Manager.createPlayer(is, "audio/midi");
musicPlayer.prefetch();
musicPlayer.setLoopCount(-1);
musicPlayer.start();
}
catch (IOException ioe) {
}
catch (MediaException me) {
}
// Start the animation thread
sleeping = false;
Thread t = new Thread(this);
t.start();
}
public void stop() {
// Close the music player
musicPlayer.close();
// Stop the animation
sleeping = true;
}
/*private void inisms(){
sms[1]="El famoso Blearning viene de los términos " +
"\nen ingles Blended Learning (aprendizaje combinado)";
sms[2]="Los entornos virtuales de aprendiza (EVAs)" +
" son las aulas virtuales que vemos en Moodle";
sms[3]="Moodle es un sistema de administración " +
"de aprendizaje de sus siglas en ingles LMS";
sms[4]="El Blearning consiste en el aprendizaje," +
" enseñanza y capacitaci{on a través de internet";
sms[5]="En un curso blearning el profesor no ocupa el papel central, " +
"dejando ese espacio a los estudiantes adaptando la metodologìa " +
"de aprender haciendo.";
sms[6]="Moodle es Modular Object Oriented Distance Learning Enviroment" +
" traducido a español es Entorno Modular del Aprendizaje " +
"Dinámico Orientado a Objetos ";
sms[7]="MOODLE vio sus raìces en Universidad de Perth, " +
"de Australia en el año de 2002";
sms[8]="Para entrar al campus virtual sobre la plataforma MOODLE " +
"por lo general le pide Nombre de Usuario y Contraseña";
sms[9]="Moodle es traducido a más de 43 idiomas, en más de 49294" +
" instituciones de 214 paìses del mundo hasta mayo del 2010";
}
*
*/
public void run() {
Graphics g = getGraphics();
// The main game loop
while (!sleeping) {
update();
draw(g);
try {
Thread.sleep(frameDelay);
}
catch (InterruptedException ie) {}
}
}
private void update() {
// Process user input to move the background layer and animate the person
if (++inputDelay > 2) {
int keyState = getKeyStates();
int xMove = 0, yMove = 0;
if ((keyState & LEFT_PRESSED) != 0)
xMove = -12;
else if ((keyState & RIGHT_PRESSED) != 0)
xMove = 12;
if ((keyState & UP_PRESSED) != 0)
yMove = -12;
else if ((keyState & DOWN_PRESSED) != 0)
yMove = 12;
if (xMove != 0 || yMove != 0) {
layers.setViewWindow(xView + xMove, yView + yMove, getWidth(), getHeight());
personSprite.move(xMove, yMove);
personSprite.nextFrame();
}
//MOVE BALL
if(ballSprite.collidesWith(personSprite, true)){
// keys.setString("El amor es bueno");
// display.setCurrent(this.keys);
//keys.setString("El famoso Blearning viene de los términos en ingles Blended Learning (aprendizaje combinado)");
nchoques =nchoques+1;
if(nchoques==1){
ballSprite.setPosition(getWidth()+ 100,getHeight()*2);
} else if(nchoques==2){
ballSprite.setPosition(getWidth(), getHeight()*3);
}else if(nchoques==3){
ballSprite.setPosition(getWidth()-20, getHeight()*2);
} else if(nchoques==4){
ballSprite.setPosition((getWidth()+ 200), getHeight()*2);
}else if (nchoques==5){
ballSprite.setPosition((getWidth()+400),getHeight()*2);
}else if (nchoques==6){
ballSprite.setPosition((getWidth()+400),getHeight()*3);
}else if (nchoques==7){
ballSprite.setPosition(getWidth()+ 100,getHeight()*3);
}else if(nchoques==8){
ballSprite.setPosition(getWidth()+200,getHeight()*2);
}else if (nchoques==9){
ballSprite.setVisible( false);
personSprite.setVisible( false);
}
}
// Check for a collision with the person and the barrier tiled layer
if (personSprite.collidesWith(barrierLayer, true)) {
//cambio de primer cambio de posicion
// Play a collision sound
try {
Manager.playTone(ToneControl.C4 + 12, 100, 100);
}
catch (Exception e) {
}
// Restore the original view window and person sprite positions
layers.setViewWindow(xView, yView, getWidth(), getHeight());
personSprite.move(-xMove, -yMove);
}
else {
// If there is no collision, commit the changes to the view window position
xView += xMove;
yView += yMove;
}
// Update the animated water tiles
if (++waterDelay > 2) {
if (++waterTile > 4)
waterTile = 1;
barrierLayer.setAnimatedTile(-1, waterTile);
waterDelay = 0;
}
// Reset the input delay
inputDelay = 0;
}
}
private void draw(Graphics g) {
// Draw the layers
layers.paint(g, 0, 0);
g.drawRect(getWidth(),10,10,20);
//g.drawString(sms[nchoques],5,getHeight()/2,g.TOP);
// Flush the offscreen graphics buffer
flushGraphics();
}
}