Random stuff
int numLine = 200;
float [] xLine = new float[numLine];
float [] yLine = new float[numLine];
float [] speed = new float[numLine];
int score = 0;
int health = 1000;
float time = 0;
int bulletCap = 5;
float bulletX[];
float bulletY[];
float fire [];
int b =0;
int x =0;
boolean shooting = false;
PVector playerPos = new PVector(500,500);
boolean gameOn = false;
int rectHeight = 10;
int rectWidth = 20;
float cannon = 0;
int nul = 0;
float bulletS = 1;
int eNum = 5;
float eX [] = new float[eNum];
float eY [] = new float[eNum];
void setup() {
frameRate(60);
noCursor();
size(1500,1000);
bulletX = new float [bulletCap];
bulletY = new float [bulletCap];
fire = new float [bulletCap];
}
void enemy(){
int eS = 20;
strokeWeight(0);
fill(255,255,0);
for(int p = 0; p < eNum; p++){
if(eX[p] == 0 && eY[p] == 0){
eY[p] = random(50 + eS,height);
}
rect(eX[p],eY[p],eS,eS);
for(int i = 0; i < bulletCap; i++){
if(bulletX[i] >= eX[p] - eS && bulletX[i] <= eX[p] + eS && bulletY[i] >= eY[p] - eS && bulletY[i] <= eY[p] + eS){
eX[p] = -1 * eS;
eY[p] = random(50,height);
score++;
}
}
if(eX[p] <= width){
eX[p] += .05;
}
else{
eX[p] = -1 * eS;
eY[p] = random(50,height);
health -= 10;
}
if(playerPos.x + rectWidth/2 >= eX[p]-eS/2 && playerPos.x -rectWidth/2 <= eX[p] + eS/2 && playerPos.y + rectHeight/2 >= eY[p] - eS/2 && playerPos.y - rectHeight/2 <= eY[p] + eS/2){
health--;
}
}
strokeWeight(1);
}
void player(){
rectMode(CENTER);
fill(0,0,255);
health = constrain(health,0,1000);
playerPos.x = abs(mouseX - playerPos.x);
if( playerPos.y >= mouseY){
playerPos.y -= abs(mouseY - playerPos.y);
}
if( playerPos.y <= mouseY){
playerPos.y += abs(mouseY - playerPos.y);
}
if( playerPos.x >= mouseX){
playerPos.x -= abs(mouseX - playerPos.x);
}
if( playerPos.x <= mouseX){
playerPos.x += abs(mouseX - playerPos.x);
}
playerPos.y = constrain(playerPos.y,50 + rectHeight/2,height);
rect(playerPos.x,playerPos.y,rectWidth,rectHeight);
//Hitbox and health
/*if(xLine[x] >= mouseX-rectWidth && xLine[x] <= mouseX+rectWidth && yLine[x] >= mouseY-rectHeight && yLine[x] <= mouseY+rectHeight){
health -= 1000/numLine;
}*/
}
void shoot(){
for(int b = 0; b < bulletCap;b++){
fire[b] = constrain(fire[b],0,bulletCap);
if(fire[b] >= 1){
fill(255,0,0);
strokeWeight(0);
stroke(255,0,0);
ellipse(bulletX[b], bulletY[b],bulletS,bulletS);
strokeWeight(1);
bulletX[b] -= .25;
}
if(fire[b] <= 0){
bulletX[b] = playerPos.x;
bulletY[b] = playerPos.y;
}
if(bulletX[b] <= 0 && mouseY > 50){
fire[b] -= 1;
}
if(cannon >= nul){
fire[b] = 1;
nul++;
}
if(shooting){
cannon += .00015;
}
else{
cannon = 0;
nul = 0;
}
stroke(0,0,0);
}
}
void bar(){
fill(0,0,255);
stroke(0);
rect(width/2,25,width,50);
fill(255);
text(score,10,20);
text(health,100,20);
text("Health",100,40);
text("Score" ,10,40);
rect( width-50, 25,50,30);
fill(0);
text("Quit", width-60,30);
// text(fire[0] ,width-140, 20);
// text(shooting,width-120, 20);
// text(time ,width-60, 20);
//text(backMax,100,height-20);
//text(color1,width-50,height-50);
}
void Gameover(){
background(255);
fill(0);
text("Game over",width/2,height/2);
text("Press the r key to play again",width/2-40,height/2+20);
fill(255);
}
void cursorB(){
fill(255,0,0);
ellipse(mouseX, mouseY, 3,3);
}
void menu(){
background(0);
fill(255);
text("Press q to begin", width/2, height/2);
}
void draw() {
if(!gameOn){
menu();
}
if(gameOn){
background(0,0,0);
stroke(255);
strokeWeight(1);
player();
bar();
if(mouseY < 50){
cursorB();
}
time += 0.013889 ;
for(int x = 0;x < numLine; x++) {
stroke(255);
xLine[x] = xLine[x]+speed[x];
line(xLine[x],yLine[x],xLine[x]+10,yLine[x]);
if(xLine[x] > width) {
xLine[x] = -10;
yLine[x] = random(50,1000);
// score++;
speed[x] = random(5,25);
}
if(speed[x] == 0){
speed[x] = random(5,25);
yLine[x] = random(50,1000);
}
shoot();
enemy();
}
}
if(health <= 0){
Gameover();
}
}
void keyPressed() {
if(key == 'r' && health <= 0){
health = 1000;
score = 0;
time = 0;
gameOn = false;
}
if(key == 'q' && !gameOn){
gameOn = true;
}
}
void mousePressed() {
shooting = true;
if(mouseX >= width - 85 && mouseX <= width - 25 && mouseY >= 10 && mouseY <= 40){
gameOn = false;
}
}
void mouseReleased() {
shooting = false;
}
float [] xLine = new float[numLine];
float [] yLine = new float[numLine];
float [] speed = new float[numLine];
int score = 0;
int health = 1000;
float time = 0;
int bulletCap = 5;
float bulletX[];
float bulletY[];
float fire [];
int b =0;
int x =0;
boolean shooting = false;
PVector playerPos = new PVector(500,500);
boolean gameOn = false;
int rectHeight = 10;
int rectWidth = 20;
float cannon = 0;
int nul = 0;
float bulletS = 1;
int eNum = 5;
float eX [] = new float[eNum];
float eY [] = new float[eNum];
void setup() {
frameRate(60);
noCursor();
size(1500,1000);
bulletX = new float [bulletCap];
bulletY = new float [bulletCap];
fire = new float [bulletCap];
}
void enemy(){
int eS = 20;
strokeWeight(0);
fill(255,255,0);
for(int p = 0; p < eNum; p++){
if(eX[p] == 0 && eY[p] == 0){
eY[p] = random(50 + eS,height);
}
rect(eX[p],eY[p],eS,eS);
for(int i = 0; i < bulletCap; i++){
if(bulletX[i] >= eX[p] - eS && bulletX[i] <= eX[p] + eS && bulletY[i] >= eY[p] - eS && bulletY[i] <= eY[p] + eS){
eX[p] = -1 * eS;
eY[p] = random(50,height);
score++;
}
}
if(eX[p] <= width){
eX[p] += .05;
}
else{
eX[p] = -1 * eS;
eY[p] = random(50,height);
health -= 10;
}
if(playerPos.x + rectWidth/2 >= eX[p]-eS/2 && playerPos.x -rectWidth/2 <= eX[p] + eS/2 && playerPos.y + rectHeight/2 >= eY[p] - eS/2 && playerPos.y - rectHeight/2 <= eY[p] + eS/2){
health--;
}
}
strokeWeight(1);
}
void player(){
rectMode(CENTER);
fill(0,0,255);
health = constrain(health,0,1000);
playerPos.x = abs(mouseX - playerPos.x);
if( playerPos.y >= mouseY){
playerPos.y -= abs(mouseY - playerPos.y);
}
if( playerPos.y <= mouseY){
playerPos.y += abs(mouseY - playerPos.y);
}
if( playerPos.x >= mouseX){
playerPos.x -= abs(mouseX - playerPos.x);
}
if( playerPos.x <= mouseX){
playerPos.x += abs(mouseX - playerPos.x);
}
playerPos.y = constrain(playerPos.y,50 + rectHeight/2,height);
rect(playerPos.x,playerPos.y,rectWidth,rectHeight);
//Hitbox and health
/*if(xLine[x] >= mouseX-rectWidth && xLine[x] <= mouseX+rectWidth && yLine[x] >= mouseY-rectHeight && yLine[x] <= mouseY+rectHeight){
health -= 1000/numLine;
}*/
}
void shoot(){
for(int b = 0; b < bulletCap;b++){
fire[b] = constrain(fire[b],0,bulletCap);
if(fire[b] >= 1){
fill(255,0,0);
strokeWeight(0);
stroke(255,0,0);
ellipse(bulletX[b], bulletY[b],bulletS,bulletS);
strokeWeight(1);
bulletX[b] -= .25;
}
if(fire[b] <= 0){
bulletX[b] = playerPos.x;
bulletY[b] = playerPos.y;
}
if(bulletX[b] <= 0 && mouseY > 50){
fire[b] -= 1;
}
if(cannon >= nul){
fire[b] = 1;
nul++;
}
if(shooting){
cannon += .00015;
}
else{
cannon = 0;
nul = 0;
}
stroke(0,0,0);
}
}
void bar(){
fill(0,0,255);
stroke(0);
rect(width/2,25,width,50);
fill(255);
text(score,10,20);
text(health,100,20);
text("Health",100,40);
text("Score" ,10,40);
rect( width-50, 25,50,30);
fill(0);
text("Quit", width-60,30);
// text(fire[0] ,width-140, 20);
// text(shooting,width-120, 20);
// text(time ,width-60, 20);
//text(backMax,100,height-20);
//text(color1,width-50,height-50);
}
void Gameover(){
background(255);
fill(0);
text("Game over",width/2,height/2);
text("Press the r key to play again",width/2-40,height/2+20);
fill(255);
}
void cursorB(){
fill(255,0,0);
ellipse(mouseX, mouseY, 3,3);
}
void menu(){
background(0);
fill(255);
text("Press q to begin", width/2, height/2);
}
void draw() {
if(!gameOn){
menu();
}
if(gameOn){
background(0,0,0);
stroke(255);
strokeWeight(1);
player();
bar();
if(mouseY < 50){
cursorB();
}
time += 0.013889 ;
for(int x = 0;x < numLine; x++) {
stroke(255);
xLine[x] = xLine[x]+speed[x];
line(xLine[x],yLine[x],xLine[x]+10,yLine[x]);
if(xLine[x] > width) {
xLine[x] = -10;
yLine[x] = random(50,1000);
// score++;
speed[x] = random(5,25);
}
if(speed[x] == 0){
speed[x] = random(5,25);
yLine[x] = random(50,1000);
}
shoot();
enemy();
}
}
if(health <= 0){
Gameover();
}
}
void keyPressed() {
if(key == 'r' && health <= 0){
health = 1000;
score = 0;
time = 0;
gameOn = false;
}
if(key == 'q' && !gameOn){
gameOn = true;
}
}
void mousePressed() {
shooting = true;
if(mouseX >= width - 85 && mouseX <= width - 25 && mouseY >= 10 && mouseY <= 40){
gameOn = false;
}
}
void mouseReleased() {
shooting = false;
}
float x =0;
float y = 0;
float t = -1000;
float x2 = 0;
float y2 =0;
float x3 = 0;
float y3 =0;
float x4 = 0;
float y4 =0;
void setup() {
size(1000,1000);
background(255);
}
void draw() {
translate(width/2, height/2);
x = sin(t/50)*100;
y = -1 * t;
x2 = sin(t/50)*100;
y2 =1 * t;
x3 = -1 * t;
y3 = sin(t/50)*100;
x4 = 1 * t;
y4 =sin(t/50)*100;
t+= 2.0;
strokeWeight(1);
point(x,y);
point(x2,y2);
point(x3,y3);
point(x4,y4);
stroke(0,100,255);
line(x,y,x3,y3);
stroke(255,200,0);
line(x,y,x4,y4);
stroke(255,50,0);
line(x2,y2,x4,y4);
stroke(0,150,0);
line(x2,y2,x3,y3);
stroke(0);
line(0,-500,0,width + width/2);
line(-500,0,height + height/2,0);
// if(x <= 0){
// background(255);
// t=5;
// }
}
float y = 0;
float t = -1000;
float x2 = 0;
float y2 =0;
float x3 = 0;
float y3 =0;
float x4 = 0;
float y4 =0;
void setup() {
size(1000,1000);
background(255);
}
void draw() {
translate(width/2, height/2);
x = sin(t/50)*100;
y = -1 * t;
x2 = sin(t/50)*100;
y2 =1 * t;
x3 = -1 * t;
y3 = sin(t/50)*100;
x4 = 1 * t;
y4 =sin(t/50)*100;
t+= 2.0;
strokeWeight(1);
point(x,y);
point(x2,y2);
point(x3,y3);
point(x4,y4);
stroke(0,100,255);
line(x,y,x3,y3);
stroke(255,200,0);
line(x,y,x4,y4);
stroke(255,50,0);
line(x2,y2,x4,y4);
stroke(0,150,0);
line(x2,y2,x3,y3);
stroke(0);
line(0,-500,0,width + width/2);
line(-500,0,height + height/2,0);
// if(x <= 0){
// background(255);
// t=5;
// }
}
PVector location = new PVector(500,500);
PVector velocity = new PVector(0,0);
PVector accelleration = new PVector(0,1);
PVector jerk = new PVector(0,0);
int size = 20;
float impX[];
float impY[];
float impVX[];
float impVY[];
boolean imp = false;
void setup() {
size(1000,1000);
impX = new float[2];
impY = new float[2];
impVX = new float[2];
impVY = new float[2];
impY[0] = height - size * 2;
impY[1] = height - size * 2;
}
void draw() {
background(20,150,255);
// PVector mouse = new PVector(mouseX,mouseY);
// PVector dir = PVector.sub(mouse,location);
// dir.normalize();
// accelleration = dir;
// dir.mult(0.5);
fill(0,255,50);
rect(0,height - size * 2,width,size * 2);
fill(100,78,200);
stroke(0);
strokeWeight(2);
accelleration.x = constrain(accelleration.x,-5,5);
accelleration.y = constrain(accelleration.y,-10,10);
location.x = constrain(location.x,-1,width - size);
location.y = constrain(location.y,-1,height - size * 2 - size);
velocity.x = constrain(velocity.x,-10,10);
velocity.y = constrain(velocity.y,-20,20);
rect(location.x,location.y,size,size);
location.add(velocity);
velocity.add(accelleration);
accelleration.add(jerk);
// if(location.x > width || location.x < 0){
// velocity.x *= -1;
impact(2);
// }
if(location.y > height || location.y < 0){
//velocity.y *= -1;
}
if(location.y >= height - size * 2 - size){
if( velocity.y > 0){
imp = true;
}
accelleration.y = 0;
velocity.y = 0;
}
if(location.y < height - size * 2 - size){
accelleration.y = 1;
}
// if(!keyPressed){
// velocity.x = 0;
// }
// jerk.x = random(-5,5);
//jerk.y = random(-5,5);
}
void impact(int amount){
if(imp){
fill(100,100,3);
for(int q = 0; q < amount; q++){
if(impVY[q] == 0){
impVY[q] = random(-2,-3);
}
impVY[q]+= 1;
impX[q]= location.x;
rect(impX[q],impY[q],10,10);
impY[q] += impVY[q];
if(impY[q] >= height){
impY[q]=height - size * 2;
imp = false;
}
}
}
}
void keyPressed(){
if(key == 'w'){
velocity.y-= 20;
}
if(key == 's'){
velocity.y += 20;
}
if(key == 'd'){
velocity.x += 20;
}
if(key == 'a'){
velocity.x += -20;
}
}
void keyReleased(){
if(key == 'd'){
velocity.x = 0;
}
if(key == 'a'){
velocity.x = 0;
}
}
PVector velocity = new PVector(0,0);
PVector accelleration = new PVector(0,1);
PVector jerk = new PVector(0,0);
int size = 20;
float impX[];
float impY[];
float impVX[];
float impVY[];
boolean imp = false;
void setup() {
size(1000,1000);
impX = new float[2];
impY = new float[2];
impVX = new float[2];
impVY = new float[2];
impY[0] = height - size * 2;
impY[1] = height - size * 2;
}
void draw() {
background(20,150,255);
// PVector mouse = new PVector(mouseX,mouseY);
// PVector dir = PVector.sub(mouse,location);
// dir.normalize();
// accelleration = dir;
// dir.mult(0.5);
fill(0,255,50);
rect(0,height - size * 2,width,size * 2);
fill(100,78,200);
stroke(0);
strokeWeight(2);
accelleration.x = constrain(accelleration.x,-5,5);
accelleration.y = constrain(accelleration.y,-10,10);
location.x = constrain(location.x,-1,width - size);
location.y = constrain(location.y,-1,height - size * 2 - size);
velocity.x = constrain(velocity.x,-10,10);
velocity.y = constrain(velocity.y,-20,20);
rect(location.x,location.y,size,size);
location.add(velocity);
velocity.add(accelleration);
accelleration.add(jerk);
// if(location.x > width || location.x < 0){
// velocity.x *= -1;
impact(2);
// }
if(location.y > height || location.y < 0){
//velocity.y *= -1;
}
if(location.y >= height - size * 2 - size){
if( velocity.y > 0){
imp = true;
}
accelleration.y = 0;
velocity.y = 0;
}
if(location.y < height - size * 2 - size){
accelleration.y = 1;
}
// if(!keyPressed){
// velocity.x = 0;
// }
// jerk.x = random(-5,5);
//jerk.y = random(-5,5);
}
void impact(int amount){
if(imp){
fill(100,100,3);
for(int q = 0; q < amount; q++){
if(impVY[q] == 0){
impVY[q] = random(-2,-3);
}
impVY[q]+= 1;
impX[q]= location.x;
rect(impX[q],impY[q],10,10);
impY[q] += impVY[q];
if(impY[q] >= height){
impY[q]=height - size * 2;
imp = false;
}
}
}
}
void keyPressed(){
if(key == 'w'){
velocity.y-= 20;
}
if(key == 's'){
velocity.y += 20;
}
if(key == 'd'){
velocity.x += 20;
}
if(key == 'a'){
velocity.x += -20;
}
}
void keyReleased(){
if(key == 'd'){
velocity.x = 0;
}
if(key == 'a'){
velocity.x = 0;
}
}
Platformer
PVector location = new PVector(0,900);
PVector velocity = new PVector(0,0);
PVector accelleration = new PVector(0,-1);
PVector jerk = new PVector(0,0);
PVector pPosition = new PVector(500,750);
int size = 20;
boolean onGround = false;
int rectL = 400;
int rectW= 100000;
int jumpN = 0;
int jumpMax = 3;
PImage Obama;
int eS = 1;
float ePosX = -300;
PVector dPosition = new PVector(pPosition.x,pPosition.y);
PVector dVelocity = new PVector(0,-30);
PVector dAccelleration = new PVector(0,1);
boolean deb = false;
void setup() {
size(1920,1080);
Obama = loadImage("Forest.png");
}
void draw() {
background(Obama);
image(Obama, 0 ,0, width, height);
accelleration.x = constrain(accelleration.x,-5,5);
accelleration.y = constrain(accelleration.y,-10,10);
velocity.x = constrain(velocity.x,-20,20);
velocity.y = constrain(velocity.y,-20,20);
dVelocity.y = constrain(dVelocity.y,-50,50);
player();
location.add(velocity);
velocity.add(accelleration);
accelleration.add(jerk);
world();
if(onGround){
accelleration.y = 0;
velocity.y = 0;
location.y = pPosition.y+size;
jumpN = 0;
deb = true;
}
if(!onGround){
accelleration.y =-1;
}
if(deb){
debris();
}
}
void world(){
enemy();
fill(0,255,50);
rect(location.x - rectW/2,location.y,rectW,rectL);
//
if(location.y <= pPosition.y+size && location.y >= pPosition.y){
onGround = true;
}
else{
onGround = false;
}
for(int c = -10000; c <= 10000; c+= 500){
fill(255,255,255);
ellipse(c + location.x,location.y - 700,150,30);
}
}
void player(){
fill(100,78,200);
stroke(0);
strokeWeight(2);
rect(pPosition.x,pPosition.y,size,size);
}
void enemy(){
fill(255,0,0);
stroke(0);
strokeWeight(2);
if( ePosX >= 500 || ePosX <= -500){
eS *= -1;
}
ePosX += eS;
rect(ePosX + location.x, location.y-50,50,50);
if(pPosition.x >= ePosX + location.x && pPosition.x + size <= ePosX + location.x + 50 && !onGround && pPosition.y + size >= location.y -50){
//eS = 0;
velocity.y *= -1;
}
}
void debris(){
//dVelocity.y += -1;
dVelocity.add(dAccelleration);
dPosition.add(dVelocity);
strokeWeight(0);
fill(170,75,0);
rect(pPosition.x,dPosition.y,10,10);
if(dPosition.y > location.y){
dVelocity.y = -30;
dPosition.y = pPosition.y;
dVelocity.x = random(-10,10);
dPosition.x = pPosition.x;
deb = false;
}
}
void keyPressed(){
if(key == 'w'){
if(jumpN <= jumpMax){
velocity.y = 0;
velocity.y+= 20;
jumpN++;
}
}
if(key == 's'){
velocity.y -= 20;
}
if(key == 'd'){
velocity.x -= 20;
}
if(key == 'a'){
velocity.x += 20;
}
}
void keyReleased(){
if(key == 'd'){
velocity.x = 0;
}
if(key == 'a'){
velocity.x = 0;
}
}
PVector velocity = new PVector(0,0);
PVector accelleration = new PVector(0,-1);
PVector jerk = new PVector(0,0);
PVector pPosition = new PVector(500,750);
int size = 20;
boolean onGround = false;
int rectL = 400;
int rectW= 100000;
int jumpN = 0;
int jumpMax = 3;
PImage Obama;
int eS = 1;
float ePosX = -300;
PVector dPosition = new PVector(pPosition.x,pPosition.y);
PVector dVelocity = new PVector(0,-30);
PVector dAccelleration = new PVector(0,1);
boolean deb = false;
void setup() {
size(1920,1080);
Obama = loadImage("Forest.png");
}
void draw() {
background(Obama);
image(Obama, 0 ,0, width, height);
accelleration.x = constrain(accelleration.x,-5,5);
accelleration.y = constrain(accelleration.y,-10,10);
velocity.x = constrain(velocity.x,-20,20);
velocity.y = constrain(velocity.y,-20,20);
dVelocity.y = constrain(dVelocity.y,-50,50);
player();
location.add(velocity);
velocity.add(accelleration);
accelleration.add(jerk);
world();
if(onGround){
accelleration.y = 0;
velocity.y = 0;
location.y = pPosition.y+size;
jumpN = 0;
deb = true;
}
if(!onGround){
accelleration.y =-1;
}
if(deb){
debris();
}
}
void world(){
enemy();
fill(0,255,50);
rect(location.x - rectW/2,location.y,rectW,rectL);
//
if(location.y <= pPosition.y+size && location.y >= pPosition.y){
onGround = true;
}
else{
onGround = false;
}
for(int c = -10000; c <= 10000; c+= 500){
fill(255,255,255);
ellipse(c + location.x,location.y - 700,150,30);
}
}
void player(){
fill(100,78,200);
stroke(0);
strokeWeight(2);
rect(pPosition.x,pPosition.y,size,size);
}
void enemy(){
fill(255,0,0);
stroke(0);
strokeWeight(2);
if( ePosX >= 500 || ePosX <= -500){
eS *= -1;
}
ePosX += eS;
rect(ePosX + location.x, location.y-50,50,50);
if(pPosition.x >= ePosX + location.x && pPosition.x + size <= ePosX + location.x + 50 && !onGround && pPosition.y + size >= location.y -50){
//eS = 0;
velocity.y *= -1;
}
}
void debris(){
//dVelocity.y += -1;
dVelocity.add(dAccelleration);
dPosition.add(dVelocity);
strokeWeight(0);
fill(170,75,0);
rect(pPosition.x,dPosition.y,10,10);
if(dPosition.y > location.y){
dVelocity.y = -30;
dPosition.y = pPosition.y;
dVelocity.x = random(-10,10);
dPosition.x = pPosition.x;
deb = false;
}
}
void keyPressed(){
if(key == 'w'){
if(jumpN <= jumpMax){
velocity.y = 0;
velocity.y+= 20;
jumpN++;
}
}
if(key == 's'){
velocity.y -= 20;
}
if(key == 'd'){
velocity.x -= 20;
}
if(key == 'a'){
velocity.x += 20;
}
}
void keyReleased(){
if(key == 'd'){
velocity.x = 0;
}
if(key == 'a'){
velocity.x = 0;
}
}
3D Stuff
float x,y,z,angle;
float colourR = random(0,255),colourG = random(0,255),colourB = random(0,255);
float changeR = random(.1,1),changeB = random(.1,1),changeG = random(.1,1);
float eyeX,eyeY,eyeZ,centerX,centerY,centerZ,upX,upY,upZ;
boolean moveBack = false, moveForward = false, moveLeft = false, moveRight = false, moveUp = false, moveDown = false;
int sF = 50;
int sChange = 5;
int movespeed = 50;
void setup(){
size(1000,1000,P3D);
x= width/2;
y = height/2;
z = 0;
sphereDetail(8,8);
eyeX = width/2;
eyeY = height/2;
eyeZ = (height/2.0) / tan(PI*30.0 / 180.0);
centerX = width/2;
centerY = height/2;
centerZ = 0;
upX = 0;
upY = 1;
upZ = 0;
noCursor();
}
void draw(){
background(0);
cameraMove();
translate(x,y,z);
// rotateY(angle / 2);
ambientLight(120, 120, 120, 0, 0, 0);
// rotateX(angle);
//rotateZ(angle);
translate(-width/2,-height/2,0);
colourChange();
rectMode(CENTER);
shape();
if(sF <= 20 || sF >= 200){
sChange *= -1;
}
sF += sChange;
angle -= radians(1);
}
void cameraMove(){
// centerY = mouseY;
// centerX = mouseX;
//centerZ = eyeZ - 800;
camera(eyeX,eyeY,eyeZ,centerX,centerY,centerZ,upX,upY,upZ);
if(moveBack){
eyeZ -= movespeed;
centerZ -= movespeed;
}
if(moveForward){
eyeZ += movespeed;
centerZ += movespeed;
}
if(moveLeft){
eyeX -= movespeed;
centerX -= movespeed;
}
if(moveRight){
eyeX += movespeed;
centerX += movespeed;
}
if(moveUp){
eyeY -=movespeed;
centerY -= movespeed;
}
if(moveDown){
eyeY +=movespeed;
centerY += movespeed;
}
}
void shape(){
for(int c = sF; c >= -sF; c -= sF / 8){
for(int p = sF; p >= -sF ; p -= sF / 8){
for(int u = sF; u >= -sF; u-= sF / 8){
pushMatrix();
translate(c,p,u);
rotateY(angle);
// rotateX(angle);
// rotateZ(angle);
box(50,50,50);
// sphere(50);
popMatrix();
}
}
}
}
void colourChange(){
if(colourB <= 0 || colourB >= 255){
changeB *= -1;
}
if(colourR <= 0 || colourR >= 255){
changeR *= -1;
}
if(colourG <= 0 || colourG >= 255){
changeG *= -1;
}
colourG += changeG;
colourB += changeB;
colourR += changeR;
fill(colourR,colourG,colourB);
//noFill();
stroke(colourR,colourG,colourB);
}
void keyPressed(){
if(key == 'r'){
eyeX = width/2;
eyeY = height/2;
eyeZ = (height/2.0) / tan(PI*30.0 / 180.0);
centerX = width/2;
centerY = height/2;
centerZ = 0;
}
if(key == 'w'){
moveBack = true;
}
if(key == 's'){
moveForward = true;
}
if(key == 'a'){
moveLeft = true;
}
if(key == 'd'){
moveRight = true;
}
if(key == ' '){
moveUp = true;
}
if(key == CODED){
if(keyCode == SHIFT){
moveDown = true;
}
}
}
void keyReleased(){
if(key == 'w'){
moveBack = false;
}
if(key == 's'){
moveForward = false;
}
if(key == 'a'){
moveLeft = false;
}
if(key == 'd'){
moveRight = false;
}
if(key == ' '){
moveUp = false;
}
if(key == CODED){
if(keyCode == SHIFT){
moveDown = false;
}
}
}
float colourR = random(0,255),colourG = random(0,255),colourB = random(0,255);
float changeR = random(.1,1),changeB = random(.1,1),changeG = random(.1,1);
float eyeX,eyeY,eyeZ,centerX,centerY,centerZ,upX,upY,upZ;
boolean moveBack = false, moveForward = false, moveLeft = false, moveRight = false, moveUp = false, moveDown = false;
int sF = 50;
int sChange = 5;
int movespeed = 50;
void setup(){
size(1000,1000,P3D);
x= width/2;
y = height/2;
z = 0;
sphereDetail(8,8);
eyeX = width/2;
eyeY = height/2;
eyeZ = (height/2.0) / tan(PI*30.0 / 180.0);
centerX = width/2;
centerY = height/2;
centerZ = 0;
upX = 0;
upY = 1;
upZ = 0;
noCursor();
}
void draw(){
background(0);
cameraMove();
translate(x,y,z);
// rotateY(angle / 2);
ambientLight(120, 120, 120, 0, 0, 0);
// rotateX(angle);
//rotateZ(angle);
translate(-width/2,-height/2,0);
colourChange();
rectMode(CENTER);
shape();
if(sF <= 20 || sF >= 200){
sChange *= -1;
}
sF += sChange;
angle -= radians(1);
}
void cameraMove(){
// centerY = mouseY;
// centerX = mouseX;
//centerZ = eyeZ - 800;
camera(eyeX,eyeY,eyeZ,centerX,centerY,centerZ,upX,upY,upZ);
if(moveBack){
eyeZ -= movespeed;
centerZ -= movespeed;
}
if(moveForward){
eyeZ += movespeed;
centerZ += movespeed;
}
if(moveLeft){
eyeX -= movespeed;
centerX -= movespeed;
}
if(moveRight){
eyeX += movespeed;
centerX += movespeed;
}
if(moveUp){
eyeY -=movespeed;
centerY -= movespeed;
}
if(moveDown){
eyeY +=movespeed;
centerY += movespeed;
}
}
void shape(){
for(int c = sF; c >= -sF; c -= sF / 8){
for(int p = sF; p >= -sF ; p -= sF / 8){
for(int u = sF; u >= -sF; u-= sF / 8){
pushMatrix();
translate(c,p,u);
rotateY(angle);
// rotateX(angle);
// rotateZ(angle);
box(50,50,50);
// sphere(50);
popMatrix();
}
}
}
}
void colourChange(){
if(colourB <= 0 || colourB >= 255){
changeB *= -1;
}
if(colourR <= 0 || colourR >= 255){
changeR *= -1;
}
if(colourG <= 0 || colourG >= 255){
changeG *= -1;
}
colourG += changeG;
colourB += changeB;
colourR += changeR;
fill(colourR,colourG,colourB);
//noFill();
stroke(colourR,colourG,colourB);
}
void keyPressed(){
if(key == 'r'){
eyeX = width/2;
eyeY = height/2;
eyeZ = (height/2.0) / tan(PI*30.0 / 180.0);
centerX = width/2;
centerY = height/2;
centerZ = 0;
}
if(key == 'w'){
moveBack = true;
}
if(key == 's'){
moveForward = true;
}
if(key == 'a'){
moveLeft = true;
}
if(key == 'd'){
moveRight = true;
}
if(key == ' '){
moveUp = true;
}
if(key == CODED){
if(keyCode == SHIFT){
moveDown = true;
}
}
}
void keyReleased(){
if(key == 'w'){
moveBack = false;
}
if(key == 's'){
moveForward = false;
}
if(key == 'a'){
moveLeft = false;
}
if(key == 'd'){
moveRight = false;
}
if(key == ' '){
moveUp = false;
}
if(key == CODED){
if(keyCode == SHIFT){
moveDown = false;
}
}
}
import java.awt.*;
import java.awt.event.*;
Robot robot;
PImage img;
int bNum = 5000;
int x,y;
float z,angleX,angleY;
float colourR = random(0,255),colourG = random(0,255),colourB = random(0,255);
float changeR = random(.1,1),changeB = random(.1,1),changeG = random(.1,1);
float eyeX,eyeY,eyeZ,centerX,centerY,centerZ,upX,upY,upZ;
boolean moveBack = false, moveForward = false, moveLeft = false, moveRight = false, moveUp = false, moveDown = false, camUp = false, camDown = false, camLeft = false, camRight = false;
PVector[] ballP = new PVector[bNum];
PVector[] ballV = new PVector[bNum];
int movespeed = 50;
float sensitivity = .75;
int gX = 10000, gY = 50, gZ = 10000;
int rN = 5000;
float rX[] = new float[rN];
float rY[] = new float[rN];
float rZ[] = new float[rN];
float rS[] = new float[rN];
void setup(){
//size(1000,1000,P3D);
fullScreen(P3D);
x= width/2;
y = height/2;
z = 0;
sphereDetail(8,8);
eyeX = width/2;
eyeY = height/2;
eyeZ = (height/2.0) / tan(PI*30.0 / 180.0);
centerX = width/2;
centerY = height/2;
centerZ = 0;
upX = 0;
upY = 1;
upZ = 0;
for(int b = 0; b <= bNum - 1; b++){
ballP[b] = new PVector(random(-1000, 1000),random(-250,0),random(-1000, 1000));
ballV[b] = new PVector(random(-100, 100),random(-100,100),random(-100, 100));
}
for(int n = 0; n <= rN -1; n++){
rY[n] = random(-2500,500);
rX[n] = random(-2500,2500);
rZ[n] = random(-2500,2500);
rS[n] = random(10,25);
}
noCursor();
try {
robot = new Robot();
robot.setAutoDelay(0);
}
catch (Exception e) {
e.printStackTrace();
}
}
void draw(){
angleX = constrain(angleX, radians(-75), radians(75));
background(0,140,200);
//pushMatrix();
centerBot();
cameraMove();
crosshair();
translate(eyeX,eyeY,eyeZ);
rotateX(angleX);
rotateY(angleY);
translate(-eyeX,-eyeY,-eyeZ);
//popMatrix();
translate(width/2,height/2,0);
ambientLight(120, 120, 120, 0, 0, 0);
directionalLight(120,120,120,0,1,0);
colourChange();
ground();
rectMode(CENTER);
shape();
}
void cameraMove(){
float cameraZ = ((height/2.0) / tan(PI*60.0/360.0));
perspective(PI/3.0, width/height, cameraZ/10.0, cameraZ*50.0);
camera(eyeX,eyeY,eyeZ,centerX,centerY,centerZ,upX,upY,upZ);
if(moveBack){
eyeZ -= cos(angleY) * movespeed;
centerZ -= cos(angleY) * movespeed;
eyeX += sin(angleY) * movespeed;
centerX += sin(angleY) * movespeed;
}
if(moveForward){
eyeZ += cos(angleY) * movespeed;
centerZ += cos(angleY) * movespeed;
eyeX -= sin(angleY) * movespeed;
centerX -= sin(angleY) * movespeed;
}
if(moveLeft){
eyeX -= cos(angleY) * movespeed;
centerX -= cos(angleY) * movespeed;
eyeZ -= sin(angleY) * movespeed;
centerZ -= sin(angleY) * movespeed;
}
if(moveRight){
eyeX += cos(angleY) * movespeed;
centerX += cos(angleY) * movespeed;
eyeZ += sin(angleY) * movespeed;
centerZ += sin(angleY) * movespeed;
}
if(moveUp){
eyeY -=movespeed;
centerY -= movespeed;
}
if(moveDown){
eyeY +=movespeed;
centerY += movespeed;
}
}
void centerBot(){
if(mouseX >= width/2 + 1){
angleY += radians(sqrt(dist(width/2,height/2,mouseX,mouseY)) * sensitivity);
robot.mouseMove(x,y);
}
if (mouseX <= width/2 - 1){
angleY -= radians(sqrt(dist(width/2,height/2,mouseX,mouseY)) * sensitivity);
robot.mouseMove(x,y);
}
if (mouseY >= height/ 2 + 1){
angleX -= radians(sqrt(dist(width/2,height/2,mouseX,mouseY)) * sensitivity);
robot.mouseMove(x,y);
}
if (mouseY <= height/2 - 1){
angleX +=radians(sqrt(dist(width/2,height/2,mouseX,mouseY)) * sensitivity);
robot.mouseMove(x,y);
}
}
void shape(){
for( int b = 0; b <= bNum - 1; b++){
pushMatrix();
translate(ballP[b].x,ballP[b].y,ballP[b].z);
fill(255,255,0);
sphere(10);
if(ballP[b].x >= gX/2 - 12.5 || ballP[b].x <= -gX/2 + 12.5){
ballV[b].x *= -1;
}
if(ballP[b].y <= -50 * gY - 512.5|| ballP[b].y >= gY + 512.5){
ballV[b].y *= -1;
}
if(ballP[b].z >= gZ/2- 12.5 || ballP[b].z <= -gZ/2 + 12.5 ){
ballV[b].z *= -1;
}
ballP[b].add(ballV[b]);
popMatrix();
}
strokeWeight(5);
stroke(255);
for(int n = 0; n <= rN -1; n++){
rY[n] += rS[n];
line(rX[n],rY[n],rZ[n],rX[n],rY[n]-5,rZ[n]);
if(rY[n] >= 500){
rY[n] = -2500;
rX[n] = random(-5000,5000);
rZ[n] = random(-5000,5000);
}
}
}
void ground(){
fill(255);
pushMatrix();
translate(0,500,0);
box(gX,gY,gZ);
// beginShape();
// endShape();
popMatrix();
}
void crosshair(){
translate(centerX,centerY,centerZ);
stroke(100,255,255);
sphere(5);
translate(-centerX,-centerY,-centerZ);
}
void colourChange(){
if(colourB <= 0 || colourB >= 255){
changeB *= -1;
}
if(colourR <= 0 || colourR >= 255){
changeR *= -1;
}
if(colourG <= 0 || colourG >= 255){
changeG *= -1;
}
colourG += changeG;
colourB += changeB;
colourR += changeR;
fill(colourR,colourG,colourB);
//noFill();
noStroke();
// stroke(colourR,colourG,colourB);
}
void keyPressed(){
if(key == 'r'){
eyeX = width/2;
eyeY = height/2;
eyeZ = (height/2.0) / tan(PI*30.0 / 180.0);
centerX = width/2;
centerY = height/2;
centerZ = 0;
}
if(key == 'w'){
moveBack = true;
}
if(key == 's'){
moveForward = true;
}
if(key == 'a'){
moveLeft = true;
}
if(key == 'd'){
moveRight = true;
}
if(key == ' '){
moveUp = true;
}
if(key == CODED){
if(keyCode == SHIFT){
moveDown = true;
}
}
}
void keyReleased(){
if(key == 'w'){
moveBack = false;
}
if(key == 's'){
moveForward = false;
}
if(key == 'a'){
moveLeft = false;
}
if(key == 'd'){
moveRight = false;
}
if(key == ' '){
moveUp = false;
}
if(key == CODED){
if(keyCode == SHIFT){
moveDown = false;
}
}
}
import java.awt.event.*;
Robot robot;
PImage img;
int bNum = 5000;
int x,y;
float z,angleX,angleY;
float colourR = random(0,255),colourG = random(0,255),colourB = random(0,255);
float changeR = random(.1,1),changeB = random(.1,1),changeG = random(.1,1);
float eyeX,eyeY,eyeZ,centerX,centerY,centerZ,upX,upY,upZ;
boolean moveBack = false, moveForward = false, moveLeft = false, moveRight = false, moveUp = false, moveDown = false, camUp = false, camDown = false, camLeft = false, camRight = false;
PVector[] ballP = new PVector[bNum];
PVector[] ballV = new PVector[bNum];
int movespeed = 50;
float sensitivity = .75;
int gX = 10000, gY = 50, gZ = 10000;
int rN = 5000;
float rX[] = new float[rN];
float rY[] = new float[rN];
float rZ[] = new float[rN];
float rS[] = new float[rN];
void setup(){
//size(1000,1000,P3D);
fullScreen(P3D);
x= width/2;
y = height/2;
z = 0;
sphereDetail(8,8);
eyeX = width/2;
eyeY = height/2;
eyeZ = (height/2.0) / tan(PI*30.0 / 180.0);
centerX = width/2;
centerY = height/2;
centerZ = 0;
upX = 0;
upY = 1;
upZ = 0;
for(int b = 0; b <= bNum - 1; b++){
ballP[b] = new PVector(random(-1000, 1000),random(-250,0),random(-1000, 1000));
ballV[b] = new PVector(random(-100, 100),random(-100,100),random(-100, 100));
}
for(int n = 0; n <= rN -1; n++){
rY[n] = random(-2500,500);
rX[n] = random(-2500,2500);
rZ[n] = random(-2500,2500);
rS[n] = random(10,25);
}
noCursor();
try {
robot = new Robot();
robot.setAutoDelay(0);
}
catch (Exception e) {
e.printStackTrace();
}
}
void draw(){
angleX = constrain(angleX, radians(-75), radians(75));
background(0,140,200);
//pushMatrix();
centerBot();
cameraMove();
crosshair();
translate(eyeX,eyeY,eyeZ);
rotateX(angleX);
rotateY(angleY);
translate(-eyeX,-eyeY,-eyeZ);
//popMatrix();
translate(width/2,height/2,0);
ambientLight(120, 120, 120, 0, 0, 0);
directionalLight(120,120,120,0,1,0);
colourChange();
ground();
rectMode(CENTER);
shape();
}
void cameraMove(){
float cameraZ = ((height/2.0) / tan(PI*60.0/360.0));
perspective(PI/3.0, width/height, cameraZ/10.0, cameraZ*50.0);
camera(eyeX,eyeY,eyeZ,centerX,centerY,centerZ,upX,upY,upZ);
if(moveBack){
eyeZ -= cos(angleY) * movespeed;
centerZ -= cos(angleY) * movespeed;
eyeX += sin(angleY) * movespeed;
centerX += sin(angleY) * movespeed;
}
if(moveForward){
eyeZ += cos(angleY) * movespeed;
centerZ += cos(angleY) * movespeed;
eyeX -= sin(angleY) * movespeed;
centerX -= sin(angleY) * movespeed;
}
if(moveLeft){
eyeX -= cos(angleY) * movespeed;
centerX -= cos(angleY) * movespeed;
eyeZ -= sin(angleY) * movespeed;
centerZ -= sin(angleY) * movespeed;
}
if(moveRight){
eyeX += cos(angleY) * movespeed;
centerX += cos(angleY) * movespeed;
eyeZ += sin(angleY) * movespeed;
centerZ += sin(angleY) * movespeed;
}
if(moveUp){
eyeY -=movespeed;
centerY -= movespeed;
}
if(moveDown){
eyeY +=movespeed;
centerY += movespeed;
}
}
void centerBot(){
if(mouseX >= width/2 + 1){
angleY += radians(sqrt(dist(width/2,height/2,mouseX,mouseY)) * sensitivity);
robot.mouseMove(x,y);
}
if (mouseX <= width/2 - 1){
angleY -= radians(sqrt(dist(width/2,height/2,mouseX,mouseY)) * sensitivity);
robot.mouseMove(x,y);
}
if (mouseY >= height/ 2 + 1){
angleX -= radians(sqrt(dist(width/2,height/2,mouseX,mouseY)) * sensitivity);
robot.mouseMove(x,y);
}
if (mouseY <= height/2 - 1){
angleX +=radians(sqrt(dist(width/2,height/2,mouseX,mouseY)) * sensitivity);
robot.mouseMove(x,y);
}
}
void shape(){
for( int b = 0; b <= bNum - 1; b++){
pushMatrix();
translate(ballP[b].x,ballP[b].y,ballP[b].z);
fill(255,255,0);
sphere(10);
if(ballP[b].x >= gX/2 - 12.5 || ballP[b].x <= -gX/2 + 12.5){
ballV[b].x *= -1;
}
if(ballP[b].y <= -50 * gY - 512.5|| ballP[b].y >= gY + 512.5){
ballV[b].y *= -1;
}
if(ballP[b].z >= gZ/2- 12.5 || ballP[b].z <= -gZ/2 + 12.5 ){
ballV[b].z *= -1;
}
ballP[b].add(ballV[b]);
popMatrix();
}
strokeWeight(5);
stroke(255);
for(int n = 0; n <= rN -1; n++){
rY[n] += rS[n];
line(rX[n],rY[n],rZ[n],rX[n],rY[n]-5,rZ[n]);
if(rY[n] >= 500){
rY[n] = -2500;
rX[n] = random(-5000,5000);
rZ[n] = random(-5000,5000);
}
}
}
void ground(){
fill(255);
pushMatrix();
translate(0,500,0);
box(gX,gY,gZ);
// beginShape();
// endShape();
popMatrix();
}
void crosshair(){
translate(centerX,centerY,centerZ);
stroke(100,255,255);
sphere(5);
translate(-centerX,-centerY,-centerZ);
}
void colourChange(){
if(colourB <= 0 || colourB >= 255){
changeB *= -1;
}
if(colourR <= 0 || colourR >= 255){
changeR *= -1;
}
if(colourG <= 0 || colourG >= 255){
changeG *= -1;
}
colourG += changeG;
colourB += changeB;
colourR += changeR;
fill(colourR,colourG,colourB);
//noFill();
noStroke();
// stroke(colourR,colourG,colourB);
}
void keyPressed(){
if(key == 'r'){
eyeX = width/2;
eyeY = height/2;
eyeZ = (height/2.0) / tan(PI*30.0 / 180.0);
centerX = width/2;
centerY = height/2;
centerZ = 0;
}
if(key == 'w'){
moveBack = true;
}
if(key == 's'){
moveForward = true;
}
if(key == 'a'){
moveLeft = true;
}
if(key == 'd'){
moveRight = true;
}
if(key == ' '){
moveUp = true;
}
if(key == CODED){
if(keyCode == SHIFT){
moveDown = true;
}
}
}
void keyReleased(){
if(key == 'w'){
moveBack = false;
}
if(key == 's'){
moveForward = false;
}
if(key == 'a'){
moveLeft = false;
}
if(key == 'd'){
moveRight = false;
}
if(key == ' '){
moveUp = false;
}
if(key == CODED){
if(keyCode == SHIFT){
moveDown = false;
}
}
}
Robot stuff
import java.awt.*;
import java.awt.event.*;
int x,y,sS;
boolean on = false;
Robot robot;
void setup() {
fullScreen();
noCursor();
//size(1920, 1080);
x = width/2;
y = height/2;
sS = 0;
try {
robot = new Robot();
robot.setAutoDelay(0);
}
catch (Exception e) {
e.printStackTrace();
}
}
void draw() {
background(255);
fill(0);
rectMode(CENTER);
rect(width/2,height/2,sS,sS);
text(mouseX,50,50);
text(mouseY,100,50);
if(on){
if(mouseX >= width/2 + 1|| mouseX <= width/2 - 1 || mouseY >= height/ 2 + 1 || mouseY <= height/2 - 1){
sS += 1;
robot.mouseMove(x,y);
//delay(1);
}
else if (sS >= 0){
sS --;
}
}
}
void keyPressed(){
if(key == 'r'){
on = true;
}
if(key == 't'){
on = false;
}
}
import java.awt.event.*;
int x,y,sS;
boolean on = false;
Robot robot;
void setup() {
fullScreen();
noCursor();
//size(1920, 1080);
x = width/2;
y = height/2;
sS = 0;
try {
robot = new Robot();
robot.setAutoDelay(0);
}
catch (Exception e) {
e.printStackTrace();
}
}
void draw() {
background(255);
fill(0);
rectMode(CENTER);
rect(width/2,height/2,sS,sS);
text(mouseX,50,50);
text(mouseY,100,50);
if(on){
if(mouseX >= width/2 + 1|| mouseX <= width/2 - 1 || mouseY >= height/ 2 + 1 || mouseY <= height/2 - 1){
sS += 1;
robot.mouseMove(x,y);
//delay(1);
}
else if (sS >= 0){
sS --;
}
}
}
void keyPressed(){
if(key == 'r'){
on = true;
}
if(key == 't'){
on = false;
}
}