bueno lo que ma pasa es que yo le do un icono a un jlabel (es un personaje, de un juego, que a sido ovido con las teclas), bueno cuando llamo al metodo donde se le cambia el icono
el icono se pone donde estaba inicialmente el jlabel, como si jamas lo hubiese movido con las teclas y puedo eso me esta jodiendo la vida como lo arreglo
codigo:
//CLASE DONDE SE LLAMA EL METODO SOLO VAYAN A DONDE DICEN LOS //COMENTARIOS
CLASE CON EL METODO CON EL ERROR
HAY OTRA CLASE PERO ESA CLASE SOLO LLAMA AL METODO "TECLADO"
Código Java:
Ver originalpackage killthegamsters.Codigo;
import java.util.Vector;
import javax.swing.ImageIcon;
import killthegamsters.Ventanas.Complementos;
import killthegamsters.Ventanas.Juego;
import static killthegamsters.Ventanas.Juego.Kevin;
public class Protagonista extends Personajes{
Vector<ImageIcon> ima = new Vector<ImageIcon>();
private static int nivel = 0;
//SETTER AND GETTER
public int getNivel() {
return nivel;
}
public void setNivel(int nivel) {
Protagonista.nivel = nivel;
}
//CONSTRUCTOR
public Protagonista(){
}
public static void Hola(){
System.
out.
println("hola baka"); }
//METODOS
public void MoverDerecha(Protagonista prota, Enemigo e,Complementos com,EsperarDisparo es){
if(Juego.Kevin.getX() < 500){
Juego.
Kevin.
setIcon(new javax.
swing.
ImageIcon(getClass
().
getResource("/killthegamsters/Texturas/adi.gif"))); prota.x += 2;
Juego.Kevin.setLocation(x, y);
prota.direccion = true;
}else{
Juego.Kevin.setLocation(3, prota.y);
Juego.Fondo.setIcon(ima.elementAt(nivel));
e.valor(e,es);
prota.valor(prota, com);
Juego.
Rata.
setIcon(new javax.
swing.
ImageIcon(getClass
().
getResource("/killthegamsters/Texturas/paradoi.png"))); prota.setNivel(prota.getNivel() + 1);
}
}
public void Agachar(){ //ERROR
Juego.Kevin.setLocation(x, y);
Juego.
Kevin.
setIcon(new javax.
swing.
ImageIcon(getClass
().
getResource("/killthegamsters/Texturas/AgachadoD.png"))); Juego.Kevin.setLocation(x, y);
}
public void MoverIzquierda(Protagonista prota){
Juego.
Kevin.
setIcon(new javax.
swing.
ImageIcon(getClass
().
getResource("/killthegamsters/Texturas/aii.gif"))); prota.x -= 2;
Juego.Kevin.setLocation(x, y);
prota.direccion = false;
}
public void valor(Protagonista prota, Complementos comple){
prota.
ima.
add( new javax.
swing.
ImageIcon(getClass
().
getResource("/killthegamsters/Texturas/1_1.jpg"))); prota.
ima.
add( new javax.
swing.
ImageIcon(getClass
().
getResource("/killthegamsters/Texturas/2.jpg"))); prota.
ima.
add( new javax.
swing.
ImageIcon(getClass
().
getResource("/killthegamsters/Texturas/3.jpg"))); prota.
ima.
add( new javax.
swing.
ImageIcon(getClass
().
getResource("/killthegamsters/Texturas/4.jpg"))); prota.setDireccion(true);
prota.setNombre(comple.getRNombre());
prota.setPedido(false);
prota.setVida(100);
prota.setX(Juego.Kevin.getX());
prota.setY(Juego.Kevin.getY());
Juego.HP.setValue(prota.getVida());
Juego.vida.setText("HP: "+prota.getVida()+"/100");
Juego.Rango.setText(prota.getNombre()+": Cadete");
}
public void DisparoBien
(Enemigo ene, Protagonista prota,java.
awt.
event.
MouseEvent evt
){ bala.play();
if(prota.getDireccion() && prota.getX() < ene.getX()){
if(ene.getVida() > 0 && prota.getVida() > 0){
if(ene.getVida() > 1){
Daño.play();
Juego.
Rata.
setIcon(new javax.
swing.
ImageIcon(getClass
().
getResource("/killthegamsters/Texturas/sangrei.png"))); ene.setVida(ene.getVida() - 1);
}else{
Daño.play();
Juego.
Rata.
setIcon(new javax.
swing.
ImageIcon(getClass
().
getResource("/killthegamsters/Texturas/si.gif"))); ene.setVida(ene.getVida() - 1);
}
}
}
}
public void Teclado
(Protagonista prota,java.
awt.
event.
KeyEvent evt,Enemigo e,Complementos com, Esperar es,EsperarDisparo espe
){ if(evt.getKeyChar() == 'a'){
prota.MoverIzquierda(prota);
}
if(evt.getKeyChar() == 'd'){
prota.MoverDerecha(prota,e,com,espe);
}
if(evt.getKeyChar() == 'w'){
prota.Salto(prota,es,com);
}
if(evt.getKeyChar() == 's'){
prota.Agachar(); //METODO CON EL ERROR
}
}
public void detenerce
(java.
awt.
event.
KeyEvent evt, Protagonista prota, Esperar es, Complementos com
){ if(evt.getKeyChar() == 'd'){
Kevin.
setIcon(new javax.
swing.
ImageIcon(getClass
().
getResource("/killthegamsters/Texturas/PoliciaD.png"))); }
if(evt.getKeyChar() == 'a'){
Kevin.
setIcon(new javax.
swing.
ImageIcon(getClass
().
getResource("/killthegamsters/Texturas/PoliciaI.png"))); }
if(evt.getKeyChar() == 'w'){
prota.BajarS(prota,es,com);
}
if(evt.getKeyChar()== 's'){
Juego.
Kevin.
setIcon(new javax.
swing.
ImageIcon(getClass
().
getResource("/killthegamsters/Texturas/PoliciaD.png"))); }
}
public void DisparoFail(){
bala.play();
}
public void Salto(Protagonista prota, Esperar es,Complementos com){
if(Juego.Kevin.getY() > 120){
prota.y--;
Juego.Kevin.setLocation(prota.getX(), prota.getY());
}else{
prota.BajarS(prota,es, com );
}
}
public void BajarS(Protagonista prota, Esperar esperar, Complementos com ){
try {
esperar.start();
}
}
}