Вы находитесь на странице: 1из 3

//////////////////////

// VARIABLES PRINCIPALES
//
//------PANTALLA------------:
//
//"Quadrcula-Va" para la serpiente:
int gridStart = 25;
//"Quadrcula-Va" para la serpiente:
int gridSpacing = 15;
//"Quadrcula-Va" para la serpiente:
int gridRows = 40;
//"Quadrcula-Va" para la serpiente:
int gridColumns = 30;

empieza en:
cada cuantos pxels:
cuantas filas:
cuantas columnas:

//color de los elemen


//Ancho de la pantalla (dependiente de lo previo):
int theWidth = gridStart*2+gridSpacing*gridRows;
//Alto de la pantalla (dependiente de lo previo):
int theHeight = gridStart*2+gridSpacing*gridColumns;
//Color de los grficos
color screenColor = color(0,255,0);
//color de fondo
color backgroundColor = color(0);
//
//------JUEGO------------:
//
//Milisegundos de separacin entre cada paso del juego (FPS del juego, o velocidad
)
//esto es lo que ira disminuyendo al aumentar el juego de nivel
int gameSpeed =80;
//
//------SERPIENTE------------:
//
//Dimetro de la cabeza
int headSize =13;
//Dimetro de la cola
int tailSize =9;
//Largo inicial de la cola
int tailLength =5;
//velocidad
int snakeSpeed = gridSpacing;
//
//------COMIDA-----------:
//
//Dimetro del elemento comida
int foodSize = 6;
//Frequencia a la que aparece la comida (en milisegundos)
int foodFrequence =5000;
//Tiempo que est la comida en pantalla (en milisegundos)
//mejor si es menor al nmero anterior
int foodLiveSpan =3500;
//
////// FIN DE VARIABLES PRINCIPALES
//////////////////////////////////////////////////
//creamos los objetos para el juego
snake serp;
//variable para controlar el tiempo:4
int tiempo, tiempoComida;

//para guardar la comida...


ArrayList foodArray = new ArrayList();
//Funcin de inicializacin (SETUP);
void setup(){
//establecemos tamao de pantalla
//size(theWidth,theHeight);
size(650,500);
//smooth para suavizar grficos
//smooth();
serp = new snake(headSize,tailSize,tailLength,snakeSpeed,gridStart, gridStart+
(gridSpacing*gridColumns/2));
fill(screenColor);
stroke(screenColor);
// frameRate(5);
//pintamos el fondo
background(backgroundColor);
serp.update();
drawWalls();
rectMode(CENTER);
}
//Funcin Bucle:
void draw(){
// println(millis()+" --- "+tiempo+"_______"+gameSpeed);
// println(millis()-tiempo > gameSpeed);
//Si hay que hacer otro paso en el juego:
if(millis()-tiempo > gameSpeed){
//pintamos el fondo
background(backgroundColor);
//dibujamos la cuadrcula (para debugging)
//drawGrid();
drawWalls();
//Comida
println(millis()-tiempoComida);
println((millis()-tiempoComida > foodFrequence));
if(millis()-tiempoComida > foodFrequence){
println("menjar!");
foodArray.add(new food(foodSize,foodLiveSpan));
//y tambin pa la comida
tiempoComida = millis();
}
//ms Comida
for(int i=0; i<foodArray.size(); i++){
food f = (food) foodArray.get(i);
f.update();
}
//actualizamos la serpiente
serp.update();

//y al final, guardamos el tiempo de juego para controlar el ritmo:


tiempo = millis();
} //fin del condicional de juego

}
//Teclado:
void keyPressed() {
if (key == CODED) {
if (keyCode == UP) {
serp.setDirection(1);
}
else if (keyCode == DOWN) {
serp.setDirection(2);
}
else if (keyCode == LEFT) {
serp.setDirection(3);
}
else if (keyCode == RIGHT) {
serp.setDirection(4);
}
}
}
void drawGrid(){
stroke(255,0,0,64);
for(int x=gridStart; x <= (gridSpacing*gridRows)+gridStart; x+=gridSpacing){
line(x,0,x,height);
}
for(int y=gridStart; y <= (gridSpacing*gridColumns)+gridStart; y+=gridSpacing)
{
line(0,y,width,y);
}
fill(screenColor);
stroke(screenColor);
}
void drawWalls(){
strokeWeight(5);
// stroke(0,0,255,127);
stroke(0,255,0,127);
line(gridStart/2,0,gridStart/2,height);
line(width-gridStart/2,0,width-gridStart/2,height);
line(0,gridStart/2,width,gridStart/2);
line(0,height-gridStart/2,width,height-gridStart/2);
fill(screenColor);
stroke(screenColor);
strokeWeight(1);
}

Вам также может понравиться