We are about to switch to a new forum software. Until then we have removed the registration on this forum.
//Flappy Code
passaro a = new passaro();
pilar[] p = new pilar[3];
boolean fim=false;
boolean intro=true;
int score=0;
PImage img;
void setup()
{
size(500, 800);
img = loadImage("background_flappy2.png");
for (int i = 0;i<3;i++)
{
p[i]=new pilar(i);
}
}
void draw()
{
background(img);
image(img,0,0);
if (fim)
{
a.mover();
}
a.fazerPassaro();
if (fim)
{
a.cair();
}
a.checkCollisions();
for (int i = 0;i<3;i++)
{
p[i].fazerPilar();
p[i].checkPosition();
}
fill(0);
stroke(255);
textSize(32);
if (fim)
{
rect(20, 20, 100, 50);
fill(255);
text(score, 30, 58);
}
else
{
rect(150, 100, 200, 50);
rect(150, 200, 200, 50);
fill(255);
if (intro)
{
text("Flappy Code", 155, 140);
//text("Clica para começares", 155, 240);
}
else
{
text("game over", 170, 140);
text("score", 180, 240);
text(score, 280, 240);
}
}
}
class passaro
{
float PassaroPosX;
float PassaroPosY;
float VelocidadeY;
passaro()
{
PassaroPosX = 250;
PassaroPosY = 400;
}
void fazerPassaro()
{
stroke(255);
fill(0);
strokeWeight(2);
ellipse(PassaroPosX, PassaroPosY, 20, 20);
}
void salto()
{
VelocidadeY=-10;
}
void cair()
{
VelocidadeY+=0.4;
}
void mover()
{
PassaroPosY+=VelocidadeY;
for (int i = 0;i<3;i++)
{
p[i].xPos-=3;
}
}
void checkCollisions()
{
if (PassaroPosY>800)
{
fim=false;
}
for (int i = 0;i<3;i++)
{
if ((PassaroPosX<p[i].xPos+10&&PassaroPosX>p[i].xPos-10)&&(PassaroPosY<p[i].opening-100||PassaroPosY>p[i].opening+100))
{
fim=false;
}
}
}
}
class pilar
{
float xPos, opening;
boolean cashed = false;
pilar(int i)
{
xPos = 100+(i*200);
opening = random(600)+100;
}
void fazerPilar()
{
fill(0);
stroke(0);
line(xPos, 0, xPos, opening-100);
line(xPos, opening+100, xPos, 800);
}
void checkPosition()
{
if (xPos<0)
{
xPos+=(200*3);
opening = random(600)+100;
cashed=false;
}
if (xPos<250&&cashed==false)
{
cashed=true;
score++;
}
}
}
void reset()
{
fim=true;
score=0;
a.PassaroPosY=400;
for (int i = 0;i<3;i++)
{
p[i].xPos+=550;
p[i].cashed = false;
}
}
void keyPressed()
{
a.salto();
intro=false;
if (fim==false)
{
reset();
}
}
Comments
pls edit your code
select and press ctrl-k
do you have a question...?
;-)
http://forum.processing.org/two/discussion/3580/flappy-code
That's not a question, so I moved the topic to Share your Work.
but we can't run it since we don't have the image...
please post at www.openprocessing.org
how does the keys work, how is it played?
Thank you!
;-)
Have a look at this take of a flappy code! It comes from: http://forum.processing.org/two/discussion/3580/flappy-code
float p=400,a;int g,s,v=166,w=500,z=200;boolean d,f,t;float[]y={z,w,v};void setup(){size(w,800);strokeWeight(3);textSize(25);}void draw(){clear();if(d&&f){int x=w-frameCount*2%v;if(x==w){y[0]=y[1];y[1]=y[2];y[2]=random(w);};a+=.3;rect(x-v,-5,v,805);rect(x-332,0,0,800);stroke(0);int c=3;for(int i=x;i>x-333;i-=v)line(i,y[c-=1],i,y[c]+z);stroke(255);d=get(100,int(p=max(min(p+a,795),5)))==color(0);if(d&&x==400)s++;ellipse(100,p,20,20);r(0,0,str(s));}else{r(v,300,(f?"gameover":"flappycode"));r(v,w,(f?"score:"+s:"clicktoplay"));}if(mousePressed||keyPressed)c();}void c(){if(!d)s=0;a=-7;d=f=!t;}void r(int x,int y,String s){stroke(255);rect(x,y,z,40);fill(255);text(s,x+30,y+30);fill(0);}
(by me)
DCRaven, after 6 threads and 48 comments, you still don't know how to format code? Or perhaps you just forgot to do it here?
Just in case, take a look at the sticky post: To newcomers in this forum: read attentively these instructions
(If there was a facepalm emoji I would use it here)
PhiLho of course I know how to format code.
Its just that code that is on one line (an in my flappy code) doesn't work well formatted when its in that 800 character block.