Last active
April 2, 2016 22:35
-
-
Save SLOLNE/056686ec5696109819f0f7eabf4437aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Libraries | |
//same as the other code expept instead of | |
//using buttons it uses arrow keys (wasd for player 1 and rightleftupdown for layer two) on the coputer keyboard | |
//import processing.serial.*; | |
//import cc.arduino.*; | |
//Calling Arduino Ports | |
//Arduino arduino; | |
//int RightPin1 = 2; | |
//int DownPin1 = 3; | |
//int LeftPin1 = 4; | |
//int UpPin1 = 5; | |
//int RightPin2 = 6; | |
//int DownPin2 = 7; | |
//int LeftPin2 = 8; | |
//int UpPin2 = 9; | |
// Proceesing ints and floats | |
int directionX1 = 2, directionY1 = 0, directionX2 = -2, directionY2 = 0; | |
float x1=500, y1=500, x2=1420, y2=500, speed=3.5; | |
void setup() | |
{ | |
size(1920, 1080); | |
background(0); | |
smooth(); | |
noStroke(); | |
//arduino = new Arduino(this, "COM3", 9600); // Will have to change for MAC users | |
//arduino.pinMode(RightPin1, Arduino.INPUT); | |
//arduino.pinMode(DownPin1, Arduino.INPUT); | |
//arduino.pinMode(LeftPin1, Arduino.INPUT); | |
//arduino.pinMode(UpPin1, Arduino.INPUT); | |
//arduino.pinMode(RightPin2, Arduino.INPUT); | |
//arduino.pinMode(DownPin2, Arduino.INPUT); | |
//arduino.pinMode(LeftPin2, Arduino.INPUT); | |
//arduino.pinMode(UpPin2, Arduino.INPUT); | |
} | |
// | |
void draw() { | |
//giving the elipeses momentum | |
x1 = x1+speed*directionX1; | |
y1 = y1+speed*directionY1; | |
x2 = x2+speed*directionX2; | |
y2 = y2+speed*directionY2; | |
//Checking boundries | |
if ((x1>width) || (x1<0)) | |
{ | |
directionX1=-directionX1; | |
} | |
if ((y1>height) || (y1<0)) | |
{ | |
directionY1=-directionY1; | |
} | |
if ((x2>width) || (x2<0)) | |
{ | |
directionX2=-directionX2; | |
} | |
if ((y2>height) || (y2<0)) | |
{ | |
directionY2=-directionY2; | |
} | |
fill(0, 255, 0); | |
ellipse(x1, y1, 100, 75); | |
fill(255, 0, 0); | |
ellipse(x2, y2, 100, 75); | |
} | |
void keyPressed() | |
{ | |
if (key == CODED) | |
{ | |
if (keyCode == LEFT) | |
{ | |
//if (directionX>0) { | |
directionX1=-1; | |
directionY1=0; | |
//} | |
} else if (keyCode == RIGHT) | |
{ | |
//if (directionX<0) { | |
directionX1=1; | |
directionY1=0; | |
//} | |
} else if (keyCode == UP) | |
{ | |
//if (directionY<0) { | |
directionY1=-1; | |
directionX1=0; | |
//} | |
} else if (keyCode == DOWN) | |
{ | |
//if (directionY<0) { | |
directionY1=1; | |
directionX1=0; | |
//} | |
} | |
} | |
} | |
// ========================================================= |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment