add a shader based 3d implementation of conways game of life to the ground, that…
- User
add a shader based 3d implementation of conways game of life to the ground, that interacts with the player, pushing the player up, and sideways. Allow the player object to interact with this infinitely.
class Ground { PVector pos; PShape ground; PImage tex; float w, h, d;
Ground() { w = 50; d = 50; pos = new PVector(0, 0, 0); tex = loadImage("grid.png"); textureMode(NORMAL); //ground = createShape(); ground = createShape(); ground.beginShape(QUADS); ground.texture(tex); ground.vertex(-w * 0.5, 0, -d * 0.5, 0, 0); ground.vertex(w * 0.5, 0, -d * 0.5, 0, w * 0.1); ground.vertex(w * 0.5, 0, d * 0.5, w * 0.1, w * 0.1); ground.vertex(-w * 0.5, 0, d * 0.5, w * 0.1, 0); ground.vertex(-w * 0.5, 0, -d * 0.5, 0, 0); ground.endShape(); }
void update() {} void draw() { pushMatrix(); translate(pos.x, pos.y, pos.z); textureWrap(REPEAT); shape(ground); popMatrix();
} }
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 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; } }
void keyReleased() { if (key == 'a' || key == 'A') { keys[0] = 0; } else if (key == 'd' || key == 'D') { keys[1] = 0; } else if (key == 'w' || key == 'W') { keys[2] = 0; } else if (key == 's' || key == 'S') { keys[3] = 0; } else if (key == ' ') { keys[4] = 0; } }
// Move inputs int getMoveLeft() { return keys[0]; } int getMoveRight() { return keys[1]; } int getMoveForward() { return keys[2]; } int getMoveBackward() { return keys[3]; } int getActionJump() { return keys[4]; } }
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 Player { PShape hand; PImage tex; PVector pos, hVel, hDir, vDir; float yVel, jumpStrength, moveSpeed; float w, h, d; float camMinDist; float gravStrength;
- Assistant