-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6593e4d
commit 00b265c
Showing
4 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions
49
ANISHA'S TEAM/Flappy Bird/madalinaFlappyBird/flappybird/bird.pde
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
} | ||
|
||
} |
76 changes: 76 additions & 0 deletions
76
ANISHA'S TEAM/Flappy Bird/madalinaFlappyBird/flappybird/flappybird.pde
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<pipe> pipes=new ArrayList<pipe>();//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 ); | ||
|
||
|
||
|
||
} |
53 changes: 53 additions & 0 deletions
53
ANISHA'S TEAM/Flappy Bird/madalinaFlappyBird/flappybird/pipe.pde
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ); | ||
|
||
} | ||
|
||
|
||
} |