Advertisement
Guest User

Untitled

a guest
May 28th, 2015
1,974
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.07 KB | None | 0 0
  1. import controlP5.*;
  2. import processing.serial.*;
  3.  
  4. PImage img;
  5. int iW2, iH2;
  6. int posX, posY;
  7. int velocity, angle;
  8. Serial serial;
  9.  
  10.  
  11. void setup() {
  12.   // tamaño de la ventana
  13.   size(800, 600);
  14.   // carga la imagen en la variable
  15.   img = loadImage("spaceship02.gif");
  16.   iW2 = img.width/2;
  17.   iH2 = img.height/2;
  18.   posX = (width/2)-iW2;
  19.   posY = (height/2)-iH2;
  20.   velocity = -5;
  21.   angle = 0;
  22. }
  23.  
  24. void draw() {
  25.   // limpia la ventana
  26.   background(0);
  27.   posX += velocity * sin(radians(angle));
  28.   if (posX-iW2 < 0) posX = width;
  29.   if (posX-iW2 > width) posX = iW2;
  30.   posY += velocity * cos(radians(angle));
  31.   if (posY-iH2 < 0) posY = height;
  32.   if (posY-iH2 > height) posY = iH2;
  33.   // dibuja la imagen
  34.   pushMatrix();
  35.   translate(posX-iW2, posY-iH2);
  36.   rotate(radians(-angle));
  37.   image(img, -iW2, -iH2);
  38.   popMatrix();
  39. }
  40.  
  41. void keyPressed() {
  42.   if (key == CODED) {
  43.     if (keyCode == UP)
  44.       velocity -= 5;    
  45.     if (keyCode == DOWN)
  46.       velocity += 5;
  47.     if (keyCode == LEFT)
  48.       angle += 5;    
  49.     if (keyCode == RIGHT)
  50.       angle -= 5;
  51.   }    
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement