Skip to content

Commit

Permalink
Added Anayna's and Vishwa's games
Browse files Browse the repository at this point in the history
  • Loading branch information
subhayu99 committed Sep 2, 2020
1 parent 3e93a67 commit 9cdbe60
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 0 deletions.
63 changes: 63 additions & 0 deletions New Crew (Tanvi)/Vishwa/FlappyBird/FlappyBird.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
Bird b;
int score=0;
int wid=400;
ArrayList<Pipe> pipes=new ArrayList<Pipe>();
PImage mountain;
PVector gravity = new PVector(0,0.5);

void setup(){

size(400,800);
b = new Bird();
pipes.add(new Pipe());
mountain = loadImage("background.jpg");
}

void draw(){
image(mountain,0,0);

if(frameCount % 75 ==0)
{
pipes.add(new Pipe());
}

if(keyPressed)
{
PVector up = new PVector(0,-5);
b.applyForce(up);
}
b.update();
b.show();
boolean safe = true;
for(int i=pipes.size()-1;i>=0;i--)
{
Pipe p=pipes.get(i);
p.update();

if(p.hits(b))
{
p.show(true);
safe = false;
}
else
{
p.show(false);
}
if(p.x < -p.w)
{
pipes.remove(i);
}

}
if(safe)
{
score++;
}
else{
score-=50;}
fill(16,53,201);
textSize(64);
text(score,width/2,50);

score = constrain(score,0,score);
}
41 changes: 41 additions & 0 deletions New Crew (Tanvi)/Vishwa/FlappyBird/bird.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class Bird
{
PVector pos;
PVector vel;
PVector acc;
float r=16;

Bird(){

pos= new PVector(50,height/2);
vel = new PVector(0,0);
acc=new PVector();
}

void applyForce(PVector force)
{
acc.add(force);
}

void update()
{
applyForce(gravity);
pos.add(vel);
vel.add(acc);
vel.limit(4);
acc.mult(0);

if(pos.y > height)
{
pos.y=height;
vel.mult(0);
}
}

void show(){
stroke(0,0,0);
strokeWeight(2);
fill(224,218,34);
ellipse(pos.x,pos.y,r*2,r*2);
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions New Crew (Tanvi)/Vishwa/FlappyBird/pipe.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
class Pipe{
float x;
float top;
float bottom;
float w= 40;
float pipe_speed=3;

Pipe()
{
x=wid+w;
top = random(100, height/2);
bottom = random(100,height/2);
}
boolean hits(Bird b)
{
if((b.pos.x>x) && (b.pos.x < (x + w)))
{
if((b.pos.y < (top + b.r)) || (b.pos.y > (height - bottom - b.r)))
{
return true;
}
}
return false;
}

void update()
{
x-=pipe_speed;
}

void show(boolean hit)
{
stroke(0,0,0);
strokeWeight(2);
if(hit)
{
fill(217,74,30,127);
}
else
{
fill(65,224,129,127);
}

rect(x,0,w,top);
rect(x,height - bottom,w,bottom);
}
}

0 comments on commit 9cdbe60

Please sign in to comment.