Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Aufgabe 1
- //Balloon Klasse
- class Balloon{
- //Attribute
- float x,y;
- float w,h;
- //Konstruktor
- Balloon(float x, float y, float w, float h){
- this.x = x;
- this.y = y;
- this.w = w;
- this.h = h;
- }
- void move(float velocity){
- y+=velocity;
- }
- boolean visible(){
- //Ausserhalb vom oberen Rand
- if(y+h<0) return false;
- return true;
- }
- void display(){
- move(-3); //bewegt Ballon 3 pixeln nach oben
- ellipse(x+w/2,y+h/2,w,h);
- }
- }
- //Aufgabe 2: 20 ballons spawnen
- Balloon[] balloons = new Balloon[20];
- void setup(){
- size(400,300);
- //Ballons initiieren
- for (int i=0; i<balloons.length;i++)
- balloons[i]=new Balloon((int) random(0,width),height,10,15);
- }
- void draw(){
- background(0);
- for (int i=0; i<balloons.length;i++)
- balloons[i].display();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement