This site requires JavaScript, please enable it in your browser!
Greenfoot back
MichZent
MichZent wrote ...

2013/1/20

hi, i hava a problem with mi game , im doing wreck it ralph but a i have problems with my code, could someone help me?

MichZent MichZent

2013/1/20

#
import greenfoot.*; public class felix extends Actor { int indiceX=0; int indiceY=0; coordenada plano= new coordenada; public boolean posible(int incrementox, int incrementoy) { if( indiceX+incrementox>=0 && indiceX+incrementox<5 && indiceY+incrementoy>=0 && indiceY+incrementoy<3) return true; else return false; } public void salta(int direccion) {coordenada posicion; posicion=new coordenada(); posicion= plano; if (posicion.x != plano.x) { posicion.x+= direccion; } int distancia; if (direccion>0) { distancia=plano.x-posicion.x;} else { distancia=(plano.x+posicion.x);} int altura=distancia/2; boolean flag=false; if (posicion.y<altura) {posicion.y--;} if (flag== true) {if (posicion.y>plano .y) {posicion.y++;} } if (posicion.y==altura) {flag=true;} setLocation (posicion.x,posicion.y); } public felix() { coordenada token= new coordenada(); token.x=115; token.y=304; plano=token; token.x=196; token.y=304; plano=token; token.x=299; token.y=304; plano=token; token.x=399; token.y=304; plano=token; token.x=476; token.y=304; plano=token; token.x=115; token.y=486; plano=token; token.x=196; token.y=486; plano=token; token.x=299; token.y=486; plano=token; token.x=399; token.y=486; plano=token; token.x=476; token.y=486; plano=token; token.x=115; token.y=606; plano=token; token.x=196; token.y=606; plano=token; token.x=299; token.y=606; plano=token; token.x=399; token.y=606; plano=token; token.x=476; token.y=606; plano=token; } public void act() { if(Greenfoot.isKeyDown("left")==true) { if(posible(-1,0)==true) { salta(-1); } } if(Greenfoot.isKeyDown("right")==true) { if(posible(+1,0)==true) { salta(1); }} } }
danpost danpost

2013/1/20

#
In your constructor, you need to create a new coodinata object on each element. public felix() { coordenada token=new coordenada(); token.x=115; token.y=304; plano=token; token=new coordenada(); token.x=196; token.y=304; plano=token; token=new coordenada(); token.x=299; token.y=304; plano=token; token=new coordenada(); token.x=399; token.y=304; plano=token; token=new coordenada(); token.x=476; token.y=304; plano=token; token=new coordenada(); token.x=115; token.y=486; plano=token; token=new coordenada(); token.x=196; token.y=486; plano=token; token=new coordenada(); token.x=299; token.y=486; plano=token; token=new coordenada(); token.x=399; token.y=486; plano=token; token=new coordenada(); token.x=476; token.y=486; plano=token; token=new coordenada(); token.x=115; token.y=606; plano=token; token=new coordenada(); token.x=196; token.y=606; plano=token; token=new coordenada(); token.x=299; token.y=606; plano=token; token=new coordenada(); token.x=399; token.y=606; plano=token; token=new coordenada(); token.x=476; token.y=606; plano=token; }
MichZent MichZent

2013/1/20

#
thank you very much :)
You need to login to post a reply.