an object calls another object's color
in
Programming Questions
•
2 years ago
I'm going to form the ground units into cars and trucks and sky units to fighters. they are just raw drawings but it didnt go further because two fighters are calling color of the truck (Truckx) goes from X to -X. fighter's color suppose to be light and dark gray and Truckx's color is green.
Car c1;
Car c2;
Carx c3;
Carx c4;
Truck t1;
Truckx t2;
Fly f1;
Fly f2;
void setup(){
size(600,400,P2D);
smooth();
noStroke();
colorMode(RGB);
frameRate(30);
c1=new Car(color(255,0,0),-25,380,10);
c2=new Car(color(0,255,0),-25,380,12);
c3=new Carx(color(0,0,255),425,380,15);
c4=new Carx(color(255,255,0),425,380,18);
t1=new Truck(color(150,100,0),30,375,5);
t2=new Truckx(color(0,131,23),430,375,8);
f1=new Fly(color(200,200,200),-50,30,40);
f2=new Fly(color(100,100,100),-60,30,45);
}
void draw(){
background(152,215,255);
fill(0,0,0);
rect(300,395,620,20);
c1.look();
c1.go();
c2.look();
c2.go();
c3.look();
c3.go();
c4.look();
c4.go();
t1.look();
t1.go();
t2.look();
t2.go();
f1.look();
f1.go();
f2.look();
f2.go();
}
class Car{
color c;
float xpos;
float ypos;
float xspeed;
Car(color tempC, float tempXpos, float tempYpos, float tempXspeed){
c=tempC;
xpos=tempXpos;
ypos=tempYpos;
xspeed=tempXspeed;
}
void look(){
fill(c);
rectMode(CENTER);
rect(xpos,ypos,70,20);
}
void go(){
xpos=xpos+xspeed;
if(xpos>900){
xpos=-25;
}
}
}
class Carx{
color c;
float xpos;
float ypos;
float xspeed;
Carx(color tempC, float tempXpos, float tempYpos, float tempXspeed){
c=tempC;
xpos=tempXpos;
ypos=tempYpos;
xspeed=tempXspeed;
}
void look(){
fill(c);
rectMode(CENTER);
rect(xpos,ypos,70,20);
}
void go(){
xpos=xpos-xspeed;
if(xpos<-300){
xpos=425;
}
}
}
class Truck{
color c;
float xpos;
float ypos;
float xspeed;
Truck(color tempC, float tempXpos, float tempYpos, float tempXspeed){
c=tempC;
xpos=tempXpos;
ypos=tempYpos;
xspeed=tempXspeed;
}
void look(){
fill(c);
rectMode(CENTER);
rect(xpos,ypos,60,30);
}
void go(){
xpos=xpos+xspeed;
if(xpos>800){
xpos=-30;
}
}
}
class Truckx{
color c;
float xpos;
float ypos;
float xspeed;
Truckx(color tempC, float tempXpos, float tempYpos, float tempXspeed){
c=tempC;
xpos=tempXpos;
ypos=tempYpos;
xspeed=tempXspeed;
}
void look(){
fill(c);
rectMode(CENTER);
rect(xpos,ypos,60,30);
}
void go(){
xpos=xpos-xspeed;
if(xpos<-200){
xpos=430;
}
}
}
class Fly{
float c;
float xpos;
float ypos;
float xspeed;
Fly(float tempC, float tempXpos, float tempYpos, float tempXspeed){
c=tempC;
xpos=tempXpos;
ypos=tempYpos;
xspeed=tempXspeed;
}
void look(){
color(200,200,200);
rectMode(CENTER);
rect(xpos,ypos,60,15);
triangle(xpos+30,ypos-7.5,xpos+30,ypos+7.5,xpos+50,ypos);
}
void go(){
xpos=xpos+xspeed;
if(xpos>2000){
xpos=-60;
}
}
}
Car c1;
Car c2;
Carx c3;
Carx c4;
Truck t1;
Truckx t2;
Fly f1;
Fly f2;
void setup(){
size(600,400,P2D);
smooth();
noStroke();
colorMode(RGB);
frameRate(30);
c1=new Car(color(255,0,0),-25,380,10);
c2=new Car(color(0,255,0),-25,380,12);
c3=new Carx(color(0,0,255),425,380,15);
c4=new Carx(color(255,255,0),425,380,18);
t1=new Truck(color(150,100,0),30,375,5);
t2=new Truckx(color(0,131,23),430,375,8);
f1=new Fly(color(200,200,200),-50,30,40);
f2=new Fly(color(100,100,100),-60,30,45);
}
void draw(){
background(152,215,255);
fill(0,0,0);
rect(300,395,620,20);
c1.look();
c1.go();
c2.look();
c2.go();
c3.look();
c3.go();
c4.look();
c4.go();
t1.look();
t1.go();
t2.look();
t2.go();
f1.look();
f1.go();
f2.look();
f2.go();
}
class Car{
color c;
float xpos;
float ypos;
float xspeed;
Car(color tempC, float tempXpos, float tempYpos, float tempXspeed){
c=tempC;
xpos=tempXpos;
ypos=tempYpos;
xspeed=tempXspeed;
}
void look(){
fill(c);
rectMode(CENTER);
rect(xpos,ypos,70,20);
}
void go(){
xpos=xpos+xspeed;
if(xpos>900){
xpos=-25;
}
}
}
class Carx{
color c;
float xpos;
float ypos;
float xspeed;
Carx(color tempC, float tempXpos, float tempYpos, float tempXspeed){
c=tempC;
xpos=tempXpos;
ypos=tempYpos;
xspeed=tempXspeed;
}
void look(){
fill(c);
rectMode(CENTER);
rect(xpos,ypos,70,20);
}
void go(){
xpos=xpos-xspeed;
if(xpos<-300){
xpos=425;
}
}
}
class Truck{
color c;
float xpos;
float ypos;
float xspeed;
Truck(color tempC, float tempXpos, float tempYpos, float tempXspeed){
c=tempC;
xpos=tempXpos;
ypos=tempYpos;
xspeed=tempXspeed;
}
void look(){
fill(c);
rectMode(CENTER);
rect(xpos,ypos,60,30);
}
void go(){
xpos=xpos+xspeed;
if(xpos>800){
xpos=-30;
}
}
}
class Truckx{
color c;
float xpos;
float ypos;
float xspeed;
Truckx(color tempC, float tempXpos, float tempYpos, float tempXspeed){
c=tempC;
xpos=tempXpos;
ypos=tempYpos;
xspeed=tempXspeed;
}
void look(){
fill(c);
rectMode(CENTER);
rect(xpos,ypos,60,30);
}
void go(){
xpos=xpos-xspeed;
if(xpos<-200){
xpos=430;
}
}
}
class Fly{
float c;
float xpos;
float ypos;
float xspeed;
Fly(float tempC, float tempXpos, float tempYpos, float tempXspeed){
c=tempC;
xpos=tempXpos;
ypos=tempYpos;
xspeed=tempXspeed;
}
void look(){
color(200,200,200);
rectMode(CENTER);
rect(xpos,ypos,60,15);
triangle(xpos+30,ypos-7.5,xpos+30,ypos+7.5,xpos+50,ypos);
}
void go(){
xpos=xpos+xspeed;
if(xpos>2000){
xpos=-60;
}
}
}
1