Advertisement
Guest User

Untitled

a guest
Nov 20th, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. //Aufgabe 1
  2. //Balloon Klasse
  3. class Balloon{
  4.   //Attribute
  5.   float x,y;
  6.   float w,h;
  7.   //Konstruktor
  8.   Balloon(float x, float y, float w, float h){
  9.     this.x = x;
  10.     this.y = y;
  11.     this.w = w;
  12.     this.h = h;  
  13.   }
  14.   void move(float velocity){
  15.     y+=velocity;
  16.   }
  17.   boolean visible(){
  18.     //Ausserhalb vom oberen Rand
  19.     if(y+h<0) return false;
  20.     return true;
  21.   }
  22.   void display(){
  23.     move(-3); //bewegt Ballon 3 pixeln nach oben
  24.     ellipse(x+w/2,y+h/2,w,h);
  25.   }  
  26. }
  27. //Aufgabe 2: 20 ballons spawnen
  28. Balloon[] balloons = new Balloon[20];
  29. void setup(){
  30.   size(400,300);
  31.   //Ballons initiieren
  32.   for (int i=0; i<balloons.length;i++)
  33.     balloons[i]=new Balloon((int) random(0,width),height,10,15);
  34. }
  35. void draw(){
  36.   background(0);
  37.   for (int i=0; i<balloons.length;i++)
  38.     balloons[i].display();
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement