xxxxxxxxxx
/* COLLISION DETAILS:
1. The player shakes
2. The color of the player becomes opaque
3. The enemy changes color
*/
ArrayList<Car> carList = new ArrayList<Car>();
boolean left,right,up,down; // Keys
boolean shakyShaky; // sacudida
Player player;
void setup() {
size(550, 300);
left=right=up=down=false;
shakyShaky=false;
player=new Player();
for(int i=0;i<7;i++) {
carList.add(new Car((float)random(width,750), i*50 ));
}
}
void draw() {
background(#333333); // #122425 #FFD87F // E8C574
// ++++++SKETCH BORDER++++++++
//noFill();
//stroke(#E8C574);
//strokeWeight(2);
fill(#122425); // #7D8788
rect(0,0,width,height);
//#FBA100
// +++++++PLAYER MOVEMENT+++++++
if (left==true) {
player.moveLeft();
}
if (right==true) {
player.moveRight();
}
if (up==true) {
player.moveUp();
}
if (down==true) {
player.moveDown();
}
// ++++++COLLISION DETECTION++++++++
shakyShaky=false;
for(int i=0;i<carList.size();i++){
boolean hayCollision = player.collisionDetection(carList.get(i).xpos,
carList.get(i).ypos, carList.get(i).ancho , carList.get(i).alto);
if(hayCollision){
carList.get(i).touchedCar();
shakyShaky=true;
}
carList.get(i).moveLeft();
carList.get(i).display();
}
player.display(shakyShaky);
}
void keyPressed(){
//if (keyPressed) { //For Processing add this line
if (key == CODED) {
if (keyCode == LEFT) {
left=true;
}
if (keyCode == RIGHT) {
right=true;
}
if (keyCode == UP) {
up=true;
}
if (keyCode == DOWN) {
down=true;
}
}
//}
}
void keyReleased(){
if (key == CODED) {
if (keyCode == LEFT) {
left=false;
}
if (keyCode == RIGHT) {
right=false;
}
if (keyCode == UP) {
up=false;
}
if (keyCode == DOWN) {
down=false;
}
}
}