PImage heli; PImage backgrd; PImage station; PImage bigheli; //Heli int xpos; int ypos; int speed = 1/2; int direction = 0; //color int c1 ; int c2 ; int c1dir = 40; int c2dir = -40; int start = 3; //Button PButton button; PFont font; boolean fly; void setup(){ framerate(25); heli = loadImage("hilicopter.PNG"); backgrd = loadImage("bkgrd1.PNG"); station = loadImage("station.PNG"); bigheli = loadImage("hilicopterbig.PNG"); //Heli xpos = 160; ypos = 218; //Button button = new PButton("Ready To FLY "); //Calculating button size accordin to text size button.calculateBounds(0, 0, width, height); //Setting the position of the button button.setBounds((width - button.width) / 2, (height - button.height)-30, button.width, button.height); button.initialize(); font = loadFont(); textFont(font); textAlign(CENTER); } void draw(){ switch(start){ case 0: c1 = 255; c2 = 255; c1dir = 0; c2dir = 0; background(0); image(station,145,231); helicopter(); softkey("Engine On"); image(backgrd,0,0); break; case 1: background(0); image(station,145,231); helicopter(); image(backgrd,0,0); //Boundaries if ( xpos <= 0 || xpos+24 >= width){ direction*= -1; } ypos = ypos + speed; xpos = xpos + direction; break; case 3: background(255); image(bigheli,0,0); button.draw(); if (fly) { start = 0; } } } void helicopter(){ image(heli,xpos,ypos); noStroke(); fill(c1); rect(xpos+5,ypos+12,10,1); fill(c2); rect(xpos+18,ypos+12,10,1); //Color varying c1 = c1 + c1dir; c2 = c2 + c2dir; if( c1 < 0 || c1 > 255){ c1dir*= -1; } if (c2 < 0 || c2 > 255) { c2dir *= -1; } } void keyPressed(){ if (keyCode == UP){ speed = speed -1; } else if (keyCode == DOWN){ speed = speed + 1; } else if (keyCode == LEFT){ direction = direction - 1; } else if (keyCode == RIGHT){ direction = direction + 1; } button.keyPressed(); } void softkeyPressed(String label){ if (label.equals("Engine On")){ start = 1; c1 = 0; c2 = 255; c1dir= 40; c2dir= -40; } } void keyReleased() { button.keyReleased(); } void libraryEvent(Object library, int event, Object data) { if (library == button) { //// if the button sent a library event, it was pressed! fly = !fly; } }