Diferencia entre revisiones de «Ur Conejeros - Proyecto Imagen Escrita 2019 T1»
De Casiopea
Sin resumen de edición |
Sin resumen de edición |
||
Línea 7: | Línea 7: | ||
|Alumnos=Ur Conejeros | |Alumnos=Ur Conejeros | ||
}} | }} | ||
===Demo=== | |||
http://www.openprocessing.org/sketch/714217 | |||
===Código=== | ===Código=== | ||
Revisión actual - 04:12 21 may 2019
Título | Ur Conejeros - Proyecto Imagen Escrita 2019 T1 |
---|---|
Asignatura | Imagen Escrita |
Del Curso | Imagen Escrita 2019 |
Carreras | Formación y Oficio"Formación y Oficio" is not in the list (Arquitectura, Diseño, Magíster, Otra) of allowed values for the "Carreras Relacionadas" property., Interacción y Servicios"Interacción y Servicios" is not in the list (Arquitectura, Diseño, Magíster, Otra) of allowed values for the "Carreras Relacionadas" property., Otra |
Nº | 1 |
Alumno(s) | Ur Conejeros |
Demo
http://www.openprocessing.org/sketch/714217
Código
ArrayList<Integer> x = new ArrayList<Integer>(), y = new ArrayList<Integer>(); //Determina la posición de partida int w = 30, h = 30, bs = 20, dir = 2, applex = 12, appley = 10; int movex = 0; int movey = 0; //Referencias para movimiento int[] dx = {0, 0, 1, -1}, dy = {1, -1, 0, 0}; //Movimientos de la serpiente en los ejes X e Y boolean gameover = false; //Referencia para GAME OVER void setup() { size(600, 600); x.add(5); y.add(5); } void draw() { background(0); for (int i = 0; i < x.size(); i++) { //cuerpo de la serpiente fill(0, 150, 0); //color de la serpiente rect(x.get(i)*bs, y.get(i)*bs, bs, bs); //Forma de la serpiente } if (!gameover) { fill(255, 0, 0); //Color de la fruta rect(applex*bs, appley*bs, bs, bs); //Forma de la fruta if (frameCount%5==0) { x.add(0, x.get(0) + dx[dir]); y.add(0, y.get(0) + dy[dir]); //Incrementa el largo de la serpiente cuando come una fruta if (x.get(0) < 0 || y.get(0) < 0 || x.get(0) >= w || y.get(0) >= h) gameover = true; //Si la serpiente toca las paredes GAME OVER for (int i = 1; i < x.size(); i++) if (x.get(0)==x.get(i) && y.get(0) == y.get(i)) gameover =true; //Si la serpiene se toca a si misma GAME OVER if (x.get(0)==applex && y.get(0)==appley) { applex = (int)random(0, w); //Crea una nueva fruta en otro lugar appley = (int)random(0, h); //Crea una nueva fruta en otro lugar } else { x.remove(x.size()-1); y.remove(y.size()-1);//Para que la serpiente no crezca sobre si misma } } } else { //Que pasa cuando hay GAME OVER fill(255, 0, 0); textAlign(CENTER); textSize(35); text("GAME OVER", width/2, height/2); //Texto de instrucciones fill(255); textAlign(CENTER); textSize(20); text("Presiona Espacio para reinciar", width/2, height/2+30); //Texto de instrucciones if (keyPressed&&key==' ') { x.clear(); y.clear(); x.add(5); y.add(5); gameover = false; //Resetea el juego } } } void keyPressed() { int newdir = key=='s' ? 0 : (key=='w' ? 1 : (key=='d' ? 2 : (key=='a' ? 3 : -1))); //Controles: S= Down, W= Up, D=Right, A=Left if (newdir != -1 && (x.size() <= 1 ||!(x.get(1)==x.get(0)+dx[newdir] && y.get(1)==y.get(0)+dy[newdir]))) dir = newdir; //Para que la serpiente no vuelva sobre si misma }