Skip to content

Instantly share code, notes, and snippets.

@darkwave
Created January 20, 2017 23:14
Show Gist options
  • Save darkwave/af62789d5670eebb8c40c919500ec756 to your computer and use it in GitHub Desktop.
Save darkwave/af62789d5670eebb8c40c919500ec756 to your computer and use it in GitHub Desktop.
Global Game Jam 2017
Element player;
ArrayList<Element> elements = new ArrayList();
void setup() {
size(900, 600, P3D);
noStroke();
rectMode(CENTER);
player = new Player();
elements.add(player);
ortho();
for (int i = 0; i < 200; i++) {
elements.add(new Element(random(-10000, 10000), random(-10000, 10000), 0));
}
}
void draw() {
background(0);
lights();
for (Element e : elements) {
e.update();
}
camera(player.position.x, player.position.y + 100, player.position.z + 500, player.position.x + 0.01, player.position.y, player.position.z,0, 1, 0);
for (Element e : elements) {
e.display();
}
}
boolean[] keys = new boolean[4];
void keyPressed() {
if (keyCode == LEFT)
keys[0] = true;
else if (keyCode == UP)
keys[1] = true;
else if (keyCode == RIGHT)
keys[2] = true;
else if (keyCode == DOWN)
keys[3] = true;
}
void keyReleased() {
if (keyCode == LEFT)
keys[0] = false;
else if (keyCode == UP)
keys[1] = false;
else if (keyCode == RIGHT)
keys[2] = false;
else if (keyCode == DOWN)
keys[3] = false;
}
class Player extends Element {
Player() {
super(0, 0, 0);
}
void update() {
if (keys[0])
position.x -= 10;
if (keys[1])
position.y -= 10;
if (keys[2])
position.x += 10;
if (keys[3])
position.y += 10;
}
}
class Element {
PVector position;
float w = 20;
float h = 20;
Element(float x, float y, float z) {
position = new PVector(x, y, z);
}
void update() {
}
void display() {
pushMatrix();
translate(position.x, position.y, position.z);
box(100);
popMatrix();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment