class snake{ //Diámetro de la cabeza int myHeadSize; //Diámetro de la cola int myTailSize; //Largo inicial de la cola int myTailLength; //variables para dirección del bicho int myXDirection = 1; int myYDirection = 0; int mySpeed; int bordes; //int myXOriginalPosition = 100; //int myYOriginalPosition = height/2; PVector myInitialPosition = new PVector(100,height/2); ArrayList myPositions = new ArrayList(); //ArrayList myYPositions = new ArrayList(); boolean dead = false; snake(int _hs, int _ts, int _tl, int _s, int _ipX, int _ipY){ myHeadSize = _hs; myTailSize = _ts; myTailLength = _tl; mySpeed = _s; myInitialPosition.x = _ipX; myInitialPosition.y = _ipY; bordes = _ipX; myPositions.add(myInitialPosition); for(int i=1; i0; i--){ //print("--"+i+"___"); PVector v2 = (PVector) myPositions.get(i); PVector v1 = (PVector) myPositions.get(i-1); v2.x=v1.x; v2.y=v1.y; myPositions.set(i,v2); } //println(""); } void move(){ PVector myPos = (PVector) myPositions.get(0); myPos.x += mySpeed*myXDirection; myPos.y += mySpeed*myYDirection; checkNewPosition(myPos); myPositions.set(0, myPos); } void drawMe(){ PVector myPos = (PVector) myPositions.get(0); ellipse(myPos.x,myPos.y,myHeadSize,myHeadSize); for(int i=1; i width-bordes)die(); if(v.y < bordes || v.y > height-bordes)die(); } void checkNewPosition(PVector _v){ //Comprobar si en la posición hay comida, con lo que habrá que CRECER boolean theresFoodInThisPosition = false; int indexOfFood = -1; for(int i=0; i