diff --git a/ANISHA'S TEAM/Flappy Bird/madalinaFlappyBird/cityscape.jpg b/ANISHA'S TEAM/Flappy Bird/madalinaFlappyBird/cityscape.jpg new file mode 100644 index 0000000..f9a67e2 Binary files /dev/null and b/ANISHA'S TEAM/Flappy Bird/madalinaFlappyBird/cityscape.jpg differ diff --git a/ANISHA'S TEAM/Flappy Bird/madalinaFlappyBird/flappybird/bird.pde b/ANISHA'S TEAM/Flappy Bird/madalinaFlappyBird/flappybird/bird.pde new file mode 100644 index 0000000..6d968a4 --- /dev/null +++ b/ANISHA'S TEAM/Flappy Bird/madalinaFlappyBird/flappybird/bird.pde @@ -0,0 +1,49 @@ +//file for class for bird + +class bird{ + + PVector pos; //make an object of vector class instead of int bc the pos will have direction x&y aka vector + PVector vel; + PVector acc; + float r = 16; //will be used to determine shape of the bird object in "ellipse" + + bird(){ //default constructor + + pos = new PVector( 50, height/2 ); + vel = new PVector( 50, 50 ); + acc = new PVector(); + + } + + void applyForce( PVector force ){ //whenevr key pressed, acceleration is added + + acc.add(force); + + } + + void update(){ //update for every frame how the bird appears + + applyForce(gravity); //bird obj is acted upon by a gravitational force + pos.add(vel); //pos of bird incremented by dist travelled + vel.add(acc); //vel of the bird is incremented by change of speed + vel.limit(4); //max speed the bird can have + acc.mult(0); + + if( pos.y > height ){ //if bird escapes screen + + pos.y = height; //then reset the position and velocity + vel.mult(0); + + } + + } + + void show(){ + + stroke( 0 ); //stroke is the border/outline of the object + fill( 255 ); //col of object + ellipse( pos.x, pos.y, r, r ); //shape of the object + + } + +} diff --git a/ANISHA'S TEAM/Flappy Bird/madalinaFlappyBird/flappybird/flappybird.pde b/ANISHA'S TEAM/Flappy Bird/madalinaFlappyBird/flappybird/flappybird.pde new file mode 100644 index 0000000..9b4f338 --- /dev/null +++ b/ANISHA'S TEAM/Flappy Bird/madalinaFlappyBird/flappybird/flappybird.pde @@ -0,0 +1,76 @@ +PImage cityscape; //declare image object called mountain as bg + +PVector gravity = new PVector( 0, 1 ); +int score = 0; //initialize the score +bird b; +//pipe p; +ArrayList pipes=new ArrayList();//declare an array object of type pipe (for the pipes being generated sequentially in the game) + +void setup(){ + + size(400, 612); + b = new bird(); + pipes.add(new pipe());//add a pipe object to the list of pipes + +} + +void draw(){ + + cityscape = loadImage("cityscape.jpg"); //load dthe image + background(cityscape); + + if( frameCount % 75 == 0 ){ + pipes.add(new pipe()); + } + + if( keyPressed ){ + + PVector up = new PVector( 0, -5 ); //variable for displacement of bird object + b.applyForce(up); //displace object pup by 5 px + + } + + b.show(); + b.update(); + + boolean safe = true; //a true flag variable to indicate if our bird collided with the pipe + + for( int i = pipes.size()-1; i>=0; i-- ){ + pipe p = pipes.get(i); + p.update(); + + if( p.hits(b) )//if the bird collides with the pipe + { + p.show(true); + safe=false; + + }else { + + p.show(false); + + } + + if( p.x < -p.w ){ //if the next x overlaps with the next pipe remove it + pipes.remove(i); + } + + } + + if( safe ) // no collision + { + score++; //increment the score + } + else{ + score -= 50;//decrement the score with a penalty of 50 + } + + + fill(0,0,0); //color of the text displaying the score + textSize(30); //size of the text + textAlign(CENTER); + text(score, width-80, 50); //display the score + score = constrain( score,0,score ); + + + +} diff --git a/ANISHA'S TEAM/Flappy Bird/madalinaFlappyBird/flappybird/pipe.pde b/ANISHA'S TEAM/Flappy Bird/madalinaFlappyBird/flappybird/pipe.pde new file mode 100644 index 0000000..019da0e --- /dev/null +++ b/ANISHA'S TEAM/Flappy Bird/madalinaFlappyBird/flappybird/pipe.pde @@ -0,0 +1,53 @@ + +int wid = 400; + +class pipe{ + + float x; + float top; + float bottom; + float w=40; + + pipe(){ //constructor + + x = wid + w; + top = random( 100, height/2 ); //heihgt of top pipe + bottom = random( 100, height/2 ); //height of bottom pipe + + } + + //check if theres collision of bird w pipe + boolean hits( bird b ){ + + if( (b.pos.x > x) && (b.pos.x <(x+w)) ){ //if bird lies within width of pipe + if( (b.pos.y < (top+b.r)) || (b.pos.y > (height-bottom-b.r)) ){ + //if bird is either below upper pipe or above lower pipe + return true; //collision + } + } + return false; //no collision + } + + void update(){ + x -= 3; + } + + void show( boolean hit ){ + + stroke(0); + strokeWeight(2); + + if(hit){ + fill(0); + } + else{ + fill(255); + } + + rect( x, 0, w, top ); + rect( x, height-bottom, w, bottom ); + + } + + +}