Advertisement
Guest User

Untitled

a guest
Nov 20th, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. final color THMLightBlue = #40ffed;
  2. final color THMGreen = color(128, 186, 36);
  3. //Balloon Klasse
  4. class Balloon{
  5.   //Attribute
  6.   float x,y;
  7.   float w,h;
  8.   float vy;
  9.   color c;
  10.   //Konstruktor
  11.   Balloon(float x, float y, float w, float h){
  12.     this.x = x;
  13.     this.y = y;
  14.     this.w = w;
  15.     this.h = h;
  16.     vy = random(-4,-1);
  17.     c = color((int)random(0,255),
  18.     (int) random(0,255),
  19.     (int)random(0,255), 200);  
  20.   }
  21.   void move(){
  22.     y+=vy;
  23.   }
  24.   boolean visible(){
  25.     //Ausserhalb vom oberen Rand
  26.     if(y+h<0) return false;
  27.     return true;
  28.   }
  29.   void display(){
  30.     if(!visible()) y = height;
  31.     noStroke();
  32.     fill(c);
  33.     ellipse(x+w/2,y+h/2,w,h);
  34.   }
  35.   void puff(){
  36.      y = height;
  37.   }
  38. }
  39. //Vogelklasse
  40. class Bird{
  41.   //Attribute
  42.   float x,y;
  43.   float w,h;
  44.   float vx;
  45.   color c;
  46.   Bird(float x, float y, float w, float h){
  47.     this.x = x;
  48.     this.y = y;
  49.     this.w = w;
  50.     this.h = h;    
  51.     vx = 0;
  52.     c = THMGreen;
  53.   }
  54.  void move(){
  55.       x+=vx;
  56.   }
  57.  void display(){
  58.     noStroke();
  59.     fill(c);
  60.     if (visible()){
  61.       triangle(x,y+h/2,x+w,y,x+w,y+h);
  62.     } else
  63.       stop();
  64.   }
  65.  void stop(){
  66.    vx = 0;
  67.  }
  68.  void start(){
  69.    vx = -5;
  70.  }
  71.  void spawn(){
  72.    x = width;
  73.    y = mouseY;
  74.    start();
  75.  }
  76.  boolean visible(){
  77.     //Ausserhalb vom oberen Rand
  78.     if(x+w<0) return false;
  79.     return true;
  80.   }
  81.  boolean intersects(Balloon b){
  82.    if (x<b.x+w && x+w>b.x && y<b.y+b.h && y+h>b.y ) return true;
  83.    return false;
  84.  }
  85. }
  86.  
  87. Balloon[] balloons = new Balloon[20];
  88. Bird bird;
  89. void setup(){
  90.   size(400,300);
  91.   //Ballons initiieren
  92.   float w;
  93.   for (int i=0; i<balloons.length;i++){
  94.     w = random(10,50);
  95.     balloons[i]=new Balloon((int) random(0,width/2),height,20,30);
  96.   }
  97.   bird = new Bird(width, 0, 30,20);
  98. }
  99. void draw(){
  100.   bird.move();
  101.   background(255);
  102.   for (int i=0; i<balloons.length;i++){
  103.     balloons[i].move();  
  104.     balloons[i].display();
  105.     if (bird.intersects(balloons[i]))
  106.       balloons[i].puff();
  107.   }
  108.   bird.display();
  109.  
  110. }
  111.  
  112. void mouseReleased(){
  113.   bird.spawn();
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement