Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // initialize variables
- // We can do this in the main code as well but since these (global)
- // variables are only used in this state I've placed it here.
- int distance;
- int dotX;
- int dotY;
- int stepSize = 5;
- float xpos;
- float ypos;
- float drag = 30.0;
- void beginState3() {
- // set dot coordinates in the middle of the screen
- dotX = width/2;
- dotY = height/2;
- movie2.play();
- }
- void updateState3(){
- // --------------------------------------------
- // Do something with input
- // --------------------------------------------
- if (keyPressed){
- if (key == '1') {currentState = 1;}
- if (key == '2') {currentState = 2;}
- if (key == CODED) {
- if(keyCode == UP) {dotY = dotY - stepSize;}
- if(keyCode == DOWN) {dotY = dotY + stepSize;}
- if(keyCode == LEFT) {dotX = dotX - stepSize;}
- if(keyCode == RIGHT) {dotX = dotX + stepSize;}
- }
- }
- // keep dotX and dotY within screen
- if(dotX < 0) {dotX = width;}
- if(dotX > width) {dotX = 0;}
- if(dotY < 0) {dotY = height;}
- if(dotY > height) {dotY = 0;}
- // --------------------------------------------
- // Do something with output
- // --------------------------------------------
- distance = dotY - 500;
- println (distance);
- background(0,0,255);
- textSize(32);
- text("State: " + currentState + " Active!", 10, 30);
- text("Press 1,2 to switch to other state", 10, 70);
- text("Press up,down,left,right arrow keys ", 10, 110);
- noStroke();
- fill(255,255,0);
- ellipse(dotX, dotY, 20, 20);
- ellipse(400, 500, 60, 60);
- }
- void movieEvent(Movie m) {
- m.read();
- }
- void endState3() {
- movie2.stop();
- }
Advertisement
RAW Paste Data
Copied
Advertisement