Experimenting with 3D Shapes
Start of Space Invaders Game
float x;
float r1;
float r2;
float r3;
float r4;
float move;
float y;
int shottime;
int timenow;
int s;
float r;
float g;
float b;
float yshot;
float xshot;
float r1shot;
float r2shot;
float r3shot;
float r4shot;
int lives;
void setup(){
size (600,600);
r=0;
g=0;
b=0;
background(r,g,b);
x=300;
r1 = 30;
r2 = 120;
r3 = 210;
r4 = 300;
move = 1;
y=25;
lives = 3;
}
void draw(){
background(r,g,b);
text("lives", 280, 300);
text(lives, 320,300);
s = second();
if (r1 < 5){
move = 1;
}
if (r1 > 260){
move = -1;
}
r1 += move;
r2 += move;
r3 += move;
r4 += move;
rect(r1, 20,70,20);
rect(r2,20,70,20);
rect(r3,20,70,20);
rect(r4,20,70,20);
playermove();
objectfall();
}
void playermove(){
if (keyPressed == true){
if (keyCode == RIGHT){
x+=10;
}
if (keyCode == LEFT){
x-=10;
}
if (keyCode == UP){
yshot = 550;
xshot = x;
}
}
yshot -= 10;
ellipse(xshot, yshot, 10,10);
ellipse(x,550,30,30);
}
void objectfall(){
if (y>590){
y=25;
shottime = second();
r1shot = r1;
r2shot = r2;
r3shot = r3;
}
ellipse(r1shot,y,10,10);
ellipse(r2shot,y,10,10);
ellipse(r3shot,y,10,10);
ellipse(r4shot,y,10,10);
timenow = s-shottime;
//if (timenow = 4){
y+=5;
if ((y >= 530) && (y <= 570) && (r1shot >= x-20) && (r1shot <=x+20)){
y=25;
lives -=1;
}
if ((y >= 530) && (y <= 570) && (r2shot >= x-20) && (r2shot <=x+20)){
y=25;
lives -=1;
}
if ((y >= 530) && (y <= 570) && (r3shot >= x-20) && (r3shot <=x+20)){
y=25;
lives -=1;
}
if ((y >= 530) && (y <= 570) && (r4shot >= x-20) && (r4shot <=x+20)){
y=25;
lives -=1;
}
}
float r1;
float r2;
float r3;
float r4;
float move;
float y;
int shottime;
int timenow;
int s;
float r;
float g;
float b;
float yshot;
float xshot;
float r1shot;
float r2shot;
float r3shot;
float r4shot;
int lives;
void setup(){
size (600,600);
r=0;
g=0;
b=0;
background(r,g,b);
x=300;
r1 = 30;
r2 = 120;
r3 = 210;
r4 = 300;
move = 1;
y=25;
lives = 3;
}
void draw(){
background(r,g,b);
text("lives", 280, 300);
text(lives, 320,300);
s = second();
if (r1 < 5){
move = 1;
}
if (r1 > 260){
move = -1;
}
r1 += move;
r2 += move;
r3 += move;
r4 += move;
rect(r1, 20,70,20);
rect(r2,20,70,20);
rect(r3,20,70,20);
rect(r4,20,70,20);
playermove();
objectfall();
}
void playermove(){
if (keyPressed == true){
if (keyCode == RIGHT){
x+=10;
}
if (keyCode == LEFT){
x-=10;
}
if (keyCode == UP){
yshot = 550;
xshot = x;
}
}
yshot -= 10;
ellipse(xshot, yshot, 10,10);
ellipse(x,550,30,30);
}
void objectfall(){
if (y>590){
y=25;
shottime = second();
r1shot = r1;
r2shot = r2;
r3shot = r3;
}
ellipse(r1shot,y,10,10);
ellipse(r2shot,y,10,10);
ellipse(r3shot,y,10,10);
ellipse(r4shot,y,10,10);
timenow = s-shottime;
//if (timenow = 4){
y+=5;
if ((y >= 530) && (y <= 570) && (r1shot >= x-20) && (r1shot <=x+20)){
y=25;
lives -=1;
}
if ((y >= 530) && (y <= 570) && (r2shot >= x-20) && (r2shot <=x+20)){
y=25;
lives -=1;
}
if ((y >= 530) && (y <= 570) && (r3shot >= x-20) && (r3shot <=x+20)){
y=25;
lives -=1;
}
if ((y >= 530) && (y <= 570) && (r4shot >= x-20) && (r4shot <=x+20)){
y=25;
lives -=1;
}
}