Created
August 2, 2013 23:35
-
-
Save jordanorelli/6144297 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import java.awt.AWTException; | |
import java.awt.Robot; | |
Robot robot; | |
float b, x; | |
float tspeed; | |
PVector middle; | |
boolean left, right, backward, forward; | |
boolean SOOPASPEED; | |
int fullspeed = 6; | |
int regspeed = 1; | |
PVector pos = new PVector(500, 300); | |
//float traction = ; //0 to 1. Affects momentum | |
//float inertia = ; //0 to 1. Affects acceleration | |
//float dspeed = ; //Any number. Affects box x&y += ? speed | |
float turnsns = 5; //turning sensitivity, lower#=higher sensitivity | |
void setup() { | |
size(displayWidth, displayHeight, P2D); | |
textAlign(LEFT, TOP); | |
textSize(30); | |
strokeWeight(3); | |
noCursor(); | |
smooth(); | |
fill(255); | |
rectMode(CENTER); | |
middle = new PVector(width/2, height/2); | |
try { | |
robot = new Robot(); | |
} | |
catch (AWTException e) { | |
e.printStackTrace(); | |
} | |
} | |
void draw() { | |
PVector dir = PVector.sub(mx(), middle); | |
float magnitude = dir.mag(); | |
background(255); | |
fill(0); | |
String info = "Degrees: " + int(degrees(dir.heading())) + "\nMagnitude: " + int(magnitude); | |
text(info, 5, 5); | |
translate(middle.x, middle.y); | |
line(0, 0, dir.x, dir.y); | |
robot.mouseMove(int(middle.x), int(middle.y)); | |
tspeed = (int(degrees(dir.heading()))==180)?-(magnitude)/100:((int(degrees(dir.heading()))==0)&&(mouseX!=displayWidth/2))?(magnitude)/100:0; | |
text("Speed:"+tspeed, 100, 100); | |
text(height, 200, 200); | |
pushMatrix(); | |
translate(pos.x, pos.y); | |
rotate(b); | |
rect(0, 0, 50, 90); | |
b+=tspeed/turnsns; | |
popMatrix(); | |
//x = (x >=width/2)? -width/2: x+1; | |
if (left) { | |
if (SOOPASPEED) { pos.x -= fullspeed; } | |
else { pos.x -= regspeed; } | |
} | |
if (right) { | |
if (SOOPASPEED) { pos.x += fullspeed; } | |
else { pos.x += regspeed; } | |
} | |
if (backward) { | |
if (SOOPASPEED) { pos.y += fullspeed; } | |
else { pos.y += regspeed; } | |
} | |
if (forward) { | |
if (SOOPASPEED) { pos.y -= fullspeed; } | |
else { pos.y -= regspeed; } | |
} | |
if (pos.x>width){pos.x=0; } | |
if (pos.x<0){pos.x=width; } | |
if (pos.y>height){pos.y=0;} | |
if (pos.y<0){pos.y=height;} | |
} | |
PVector mx() { | |
return new PVector(mouseX>width/2+100?width/2+100:mouseX<width/2-100?width/2-100:mouseX, displayHeight/2); | |
} | |
boolean sketchFullScreen() { | |
return true; | |
} | |
void keyPressed() { | |
if (key == 'a' || key == 'A') { left = true; } | |
if (key == 'd' || key == 'D') { right = true; } | |
if (key == 's' || key == 'S') { backward = true; } | |
if (key == 'w' || key == 'W') { forward = true; } | |
if(key == CODED) { | |
if(keyCode == SHIFT) { SOOPASPEED = true; } | |
} | |
} | |
void keyReleased() { | |
if (key == 'a' || key == 'A') { left = false; } | |
if (key == 'd' || key == 'D') { right = false; } | |
if (key == 's' || key == 'S') { backward = false; } | |
if (key == 'w' || key == 'W') { forward = false; } | |
if(key == CODED) { | |
if(keyCode == SHIFT) { SOOPASPEED = false; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment