modify the following project to use a infinite configuration of conways game of life as…
- User
modify the following project to use a infinite configuration of conways game of life as the ground. Use shaders where possible, to optimise rendering. Make living cells act in 3d, applying force to the player.
import java.awt.*;
Input input; Camera cam; Player p; Ground g; Robot r;
void keyPressed() { input.keyPressed(); }
void keyReleased() { input.keyReleased(); }
void mouseMoved() { p.mouseMovedAndDragged(); }
void mouseDragged() { p.mouseMovedAndDragged(); }
void setup() { // Init game fullScreen(P3D); noCursor();
// Init objects input = new Input(); cam = new Camera(); p = new Player(); g = new Ground(); try { r = new Robot(); } catch (AWTException e) { e.printStackTrace(); } }
void draw() { // UPDATE p.update();
// DRAW background(0); cam.draw(); g.draw(); p.draw();
// DRAW GUI hint(DISABLE_DEPTH_TEST); camera(); noLights(); p.drawGui(); hint(ENABLE_DEPTH_TEST); }
class Camera { PVector eye, center, up;
Camera() { eye = new PVector(0, -5, 10); center = new PVector(0, 0, 0); up = new PVector(0, 1, 0); perspective(PI/3.0, 16.0 / 9.0, 5, 1000); }
void draw() { camera(eye.x, eye.y, eye.z, center.x, center.y, center.z, up.x, up.y, up.z); } }
class Ground { PVector pos; PShape ground; PImage tex; float w, h, d;
GameOfLife gameOfLife; PImage gofTexture;
Ground(GameOfLife gol) { w = 1000; // Increased size for a larger ground d = 1000; pos = new PVector(0, 0, 0); gameOfLife = gol; gofTexture = gameOfLife.getGridTexture();
code// Create a large ground plane ground = createShape(); ground.beginShape(QUADS); ground.texture(gofTexture); ground.normal(0, 1, 0); ground.vertex(-w * 0.5, 0, -d * 0.5, 0, 0); ground.vertex(w * 0.5, 0, -d * 0.5, 1, 0); ground.vertex(w * 0.5, 0, d * 0.5, 1, 1); ground.vertex(-w * 0.5, 0, d * 0.5, 0, 1); ground.endShape();}
void update() { gameOfLife.update(); gofTexture = gameOfLife.getGridTexture(); ground.setTexture(gofTexture); }
void draw() { pushMatrix(); translate(pos.x, pos.y, pos.z); textureWrap(REPEAT); shader(gameOfLifeShader); shape(ground); resetShader(); popMatrix(); } }
class Input { // Keys int[] keys = new int[9];
void keyPressed() { if (key == 'a' || key == 'A') { keys[0] = 1; } else if (key == 'd' || key == 'D') { keys[1] = 1; } else if (key == 'w' || key == 'W') { keys[2] = 1; } else if (key == 's' || key == 'S') { keys[3] = 1; } else if (key == ' ') { keys[4] = 1; } }
- Assistant