Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final color THMLightBlue = #40ffed;
- final color THMGreen = color(128, 186, 36);
- //Balloon Klasse
- class Balloon{
- //Attribute
- float x,y;
- float w,h;
- float vy;
- color c;
- //Konstruktor
- Balloon(float x, float y, float w, float h){
- this.x = x;
- this.y = y;
- this.w = w;
- this.h = h;
- vy = random(-4,-1);
- c = color((int)random(0,255),
- (int) random(0,255),
- (int)random(0,255), 200);
- }
- void move(){
- y+=vy;
- }
- boolean visible(){
- //Ausserhalb vom oberen Rand
- if(y+h<0) return false;
- return true;
- }
- void display(){
- if(!visible()) y = height;
- noStroke();
- fill(c);
- ellipse(x+w/2,y+h/2,w,h);
- }
- void puff(){
- y = height;
- }
- }
- //Vogelklasse
- class Bird{
- //Attribute
- float x,y;
- float w,h;
- float vx;
- color c;
- Bird(float x, float y, float w, float h){
- this.x = x;
- this.y = y;
- this.w = w;
- this.h = h;
- vx = 0;
- c = THMGreen;
- }
- void move(){
- x+=vx;
- }
- void display(){
- noStroke();
- fill(c);
- if (visible()){
- triangle(x,y+h/2,x+w,y,x+w,y+h);
- } else
- stop();
- }
- void stop(){
- vx = 0;
- }
- void start(){
- vx = -5;
- }
- void spawn(){
- x = width;
- y = mouseY;
- start();
- }
- boolean visible(){
- //Ausserhalb vom oberen Rand
- if(x+w<0) return false;
- return true;
- }
- boolean intersects(Balloon b){
- if (x<b.x+w && x+w>b.x && y<b.y+b.h && y+h>b.y ) return true;
- return false;
- }
- }
- Balloon[] balloons = new Balloon[20];
- Bird bird;
- void setup(){
- size(400,300);
- //Ballons initiieren
- float w;
- for (int i=0; i<balloons.length;i++){
- w = random(10,50);
- balloons[i]=new Balloon((int) random(0,width/2),height,20,30);
- }
- bird = new Bird(width, 0, 30,20);
- }
- void draw(){
- bird.move();
- background(255);
- for (int i=0; i<balloons.length;i++){
- balloons[i].move();
- balloons[i].display();
- if (bird.intersects(balloons[i]))
- balloons[i].puff();
- }
- bird.display();
- }
- void mouseReleased(){
- bird.spawn();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement