Created
January 30, 2025 16:04
-
-
Save STCollier/c24e2845f9b684a293ec1597799d73e0 to your computer and use it in GitHub Desktop.
Flappy Bird in OpenGL & C (2456 bytes). SPACE to flap
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
#import<glad/glad.h> | |
#import<GLFW/glfw3.h> | |
#define d(a,p,x,y,w,h)glBindVertexArray(a);glUniform2f(glGetUniformLocation(p,"x"),w,h);glUniform2f(glGetUniformLocation(p,"y"),x,y);glDrawArrays(4,0,6); | |
a,b,c,d,e,g,s,x,y,z[]={1,1,1,1,1,-1,1,0,-1,1,0,1,1,-1,1,0,-1,-1,0,0,-1,1,0,1};main(){char*v="#version 330 core\nlayout(location=0)in vec2 p;layout(location=1)in vec2 a;uniform vec2 x;uniform vec2 y;out vec2 t;void main(){gl_Position=vec4(p*x+y,0,1);t=a;}\0",*f="#version 330 core\nout vec4 f;in vec2 t;uniform sampler2D i;void main(){f=texture(i,t);}\0";glfwInit();glfwWindowHint(139266,3);glfwWindowHint(139267,3);glfwWindowHint(139272,204801);int i,o=3553,q=34962,u=16,_=6407;GLFWwindow*w=glfwCreateWindow(800,800,"Flappy Bird",0,0);glfwMakeContextCurrent(w);gladLoadGLLoader(glfwGetProcAddress);c=glCreateShader(35633);glShaderSource(c,1,&v,0);glCompileShader(c);d=glCreateShader(35632);glShaderSource(d,1,&f,0);glCompileShader(d);s=glCreateProgram();glAttachShader(s,c);glAttachShader(s,d);glLinkProgram(s);glGenVertexArrays(1,&a);glGenBuffers(1,&b);glBindVertexArray(a);glBindBuffer(q,b);glBufferData(q,96,z,35044);glVertexAttribPointer(0,2,5124,0,u,0);glEnableVertexAttribArray(0);glVertexAttribPointer(1,2,5124,0,u,(void*)8);glEnableVertexAttribArray(1);glBindBuffer(q,0);glBindVertexArray(0);glGenTextures(1,&e);glBindTexture(o,e);glTexParameteri(o,10240,9728);char*k=malloc(3840);memset(k,0,3840);for(i=0;i++<1280;)x=i%u,y=i/u,!x||y<4||x==15||y>74?0:(k[i*3]=0,k[i*3+1]=255,k[i*3+2]=0);glTexImage2D(o,0,_,u,80,0,_,5121,k);glGenerateMipmap(o);glGenTextures(1,&g);glBindTexture(o,g);glTexParameteri(o,10240,9728);char*l=malloc(786);memset(l,0,786);for(i=0;i++<256;)x=i%u,y=i/u,!x||!y||x==15||y==15?0:(l[i*3]=255,l[i*3+1]=255,l[i*3+2]=0);glTexImage2D(o,0,_,u,u,0,_,5121,l);glGenerateMipmap(o);float j,y=0,x=0.6,xx=-0.6,r=0,rr=0,m=0,_1=0.1,_2=0.2,n,dt;for(glClearColor(0.6,0.7,1,1);!glfwWindowShouldClose(w);glfwPollEvents()){j=rand()/3e9;n=glfwGetTime();dt=n-m;m=n;glClear(16384);glUseProgram(s);glBindTexture(o,e);d(a,s,x,-1.75+r,_2,1);d(a,s,x,1.25+r,_2,1);d(a,s,xx,-1.75+rr,_2,1);d(a,s,xx,1.25+rr,_2,1);glBindTexture(o,g);d(a,s,0,y,_1,_1);float p[]={x,-1.75+r,x,1.25+r,xx,-1.75+rr,xx,1.25+rr};for(i=0;i<4;i++)p[i*2]-_2>+_1||p[i*2]+_2<-_1||p[i*2+1]+1<y-_1||p[i*2+1]-1>y+_1?0:glfwSetWindowShouldClose(w,1);(x+=1.5*dt)>1.2?x=-1.2,r=j:0;(xx+=1.5*dt)>1.2?xx=-1.2,rr=j:0;glfwGetKey(w,32)?y+=5*dt:0;y-=1.5*dt;glfwSwapBuffers(w);}printf("Time Alive: %f\n",n);} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment