Page MenuHomec4science

Game.pde
No OneTemporary

File Metadata

Created
Wed, May 15, 23:45

Game.pde

import java.text.DecimalFormat;
Mover mover;
Cylinder cyl;
PImage img;
PShape globe;
float depth = 2000;
float plate_w=1000;
float plate_t=plate_w/20;
float x_coord;
float y_coord;
float mX;
float mY;
float rz;
float rx;
float cameraHeight;
float speed=10;
float radius=plate_t*4/5;
DecimalFormat f = new DecimalFormat("#0.0");
float variable=0;
boolean shiftMod=false;
ArrayList<PVector> cyls=new ArrayList<PVector>();
float xOnPlane;
float yOnPlane;
void settings() {
size(displayWidth, displayHeight, P3D);
//size(1000, 1000, P3D);
x_coord=width/2;
y_coord=height/2;
}
void setup() {
mover = new Mover(plate_w);
cyl=new Cylinder();
noStroke();
img = loadImage("earth.jpg");
globe = createShape(SPHERE, radius);
globe.setStroke(false);
globe.setTexture(img);
}
void draw() {
directionalLight(50, 100, 125, 0, 1, 0);
ambientLight(102, 102, 102);
pointLight(150, 150, 150, 0, -200, 0);
background(200);
if (!shiftMod) {
mover.update();
mover.checkEdges();
mover.checkCylinderCollision(cyls, radius);
rz = map(x_coord, 0, width, -PI/3, PI/3);
rx = map(y_coord, 0, height, -PI/3, PI/3);
cameraHeight=400;
} else {
rz=0;
rx=-PI/2;
cameraHeight=0;
}
pushMatrix();
camera(0, -cameraHeight, depth, 0, 0, 0, 0, 1, 0);
rotateZ(rz);
rotateX(rx);
shininess(100);
box(plate_w, plate_t, plate_w);
if (shiftMod) {
float wMappedX=2*plate_w;
float wMappedY=1.1*plate_w;
xOnPlane=map(mouseX, 0, width, -wMappedX, wMappedX);
yOnPlane=map(mouseY, 0, height, -wMappedY, wMappedY);
cyl.draw(xOnPlane, yOnPlane, -(plate_t/2), PI/2);
}
for (PVector pv : cyls) {
cyl.draw(pv.x, pv.y, -(plate_t/2), PI/2);
}
translate(mover.getX(), -(plate_t/2+radius), mover.getY());
fill(255, 100, 100);
rotateX(mover.getRotX());
//rotateY(mover.getRotY());
rotateZ(mover.getRotZ());
shape(globe);
popMatrix();
fill(0);
textSize(15);
text("Rotation X : "+f.format(rx/Math.PI*180)+"° Rotation Z : "+f.format(rz/Math.PI*180)+"° speed: "+f.format(speed/10), 5, 15);
if (shiftMod) {
textSize(50);
text("[EDIT MOD ON]", 50, 500);
}
fill(255);
}
void mouseWheel(MouseEvent event) {
float e = event.getCount();
if (e<0) {
speed-=speed<=2?0:1;
} else {
speed+=speed>=15?0:1;
}
}
void mouseDragged() {
if (!shiftMod) {
float d=-(mX-mouseX)*speed/10;
x_coord=x_coord+d<=0?0:x_coord+d>=width?width:x_coord+d;
mX=mouseX;
d=(mY-mouseY)*speed/10;
y_coord=y_coord+d<=0?0:y_coord+d>=height?height:y_coord+d;
mY=mouseY;
}
}
void mousePressed() {
mX=mouseX;
mY=mouseY;
if (shiftMod && -plate_w/2<xOnPlane && xOnPlane<plate_w/2 && -plate_w/2<yOnPlane && yOnPlane<plate_w/2) {
cyls.add(new PVector(xOnPlane, yOnPlane));
}
}
void keyPressed() {
if (key == CODED) {
if (keyCode == UP) {
variable -= 50;
} else if (keyCode == DOWN) {
variable += 50;
}
}
if (keyCode == SHIFT) {
shiftMod=true;
}
}
void keyReleased() {
if (keyCode == SHIFT) {
shiftMod=false;
}
}

Event Timeline