NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

/*
Opengl-yilan-oyunu v0.01 OpenGL kütüphanesi ile yazılmış basit bir yılan oyunu.
Copyright (C) 2004 Engin KUZU

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

//http://www.gnu.org/copyleft/gpl.html
//Turkce cevirisi: http://www.belgeler.org/howto/gpl_copy.html

#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <unistd.h>

unsigned int hiz=0,basla=0,bekleme,indis=15;
float r11=0,r12=0,r13=1,r21=0,r22=0,r23=1,r31=0,r32=0,r33=1,r41=0.5,r42=0.5,r43=0.9;
int i,hata;
int dizi[200][2]={5,5,0,5,-5,5,-10,5,-10,0,-10,-5,-15,-5,-20,-5,-20,0,-25,0,-30,0,-30,5,-30,10,-35,10,-40,10,0,0};
int siradaki[2],yemek[2]={20,20},salla[2],xa=5,ya=0;

void animasyon()
{
float x=-1,y=1,r1=0.01,r2=0,r3=0,p1=0,p2=0,p3=0;
glPointSize(4.0);
while(1)
{
if(x>1 && y<-1)
{ break; glFlush(); usleep(800000); }
if(x>1)
{ x=-1; y=y-0.01; glFlush(); usleep(4000); }
x=x+0.01;
p1+=r1; p2+=r2; p3+=r3;
if(p1>1)
{ p1=0; r1=0; r2=0.02; }
if(p2>1)
{ p2=0; r2=0; r3=0.02; }
if(p3>1)
{ p3=0; r3=0; r1=0.01; }
glColor3f(p1,p2,p3);
glBegin(GL_POINTS);
glVertex2f(x,y);
glEnd();
}
}

void ana()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(r11,r12,r13);
glBegin(GL_POLYGON);
glVertex2f(-0.4,0.2);
glVertex2f(-0.2,0.2);
glVertex2f(-0.2,0.1);
glVertex2f(-0.4,0.1);
glEnd();
glColor3f(r21,r22,r23);
glBegin(GL_POLYGON);
glVertex2f(-0.1,0.2);
glVertex2f(0.1,0.2);
glVertex2f(0.1,0.1);
glVertex2f(-0.1,0.1);
glEnd();
glColor3f(r31,r32,r33);
glBegin(GL_POLYGON);
glVertex2f(0.4,0.2);
glVertex2f(0.2,0.2);
glVertex2f(0.2,0.1);
glVertex2f(0.4,0.1);
glEnd();
glColor3f(r41,r42,r43);
glBegin(GL_POLYGON);
glVertex2f(-0.1,-0.1);
glVertex2f(0.1,-0.1);
glVertex2f(0.1,-0.2);
glVertex2f(-0.1,-0.2);
glEnd();

char t1[]="Lutfen Oyun Hizini Seciniz:";
char t2[]="YAVAS";
char t3[]="ORTA";
char t4[]="HIZLI";
char t5[]="BASLA";
char t6[]="P : DURDUR ESC : CIKIS";
glColor3f (1.0F, 1.0F, 1.0F);
glRasterPos2f (-0.25, 0.40);
for (i = 0; i < strlen (t1); i++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, t1[i]);
glRasterPos2f (-0.35, 0.15);
for (i = 0; i < strlen (t2); i++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, t2[i]);
glRasterPos2f (-0.05, 0.15);
for (i = 0; i < strlen (t3); i++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, t3[i]);
glRasterPos2f ( 0.25, 0.15);
for (i = 0; i < strlen (t4); i++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, t4[i]);
glRasterPos2f (-0.05,-0.15);
for (i = 0; i < strlen (t5); i++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, t5[i]);
glRasterPos2f (-0.20,-0.65);
for (i = 0; i < strlen (t6); i++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, t6[i]);
glFlush();
}

void tuslar(unsigned char tus,int xx,int yy)
{
static int x=1,y=0,p=0;
//printf("%dn",tus);

if(tus==27)
exit(0);
if(tus==112)
{ if(basla==2) {basla=1;} else {basla=2;} }

else if(tus==52 && x!=1) { xa=-5; x=-1; ya=0; y=0; }
else if(tus==53 && y!=1) { ya=-5; y=-1; xa=0; x=0; }
else if(tus==54 && x!=-1) { xa=5; x=1; ya=0; y=0; }
else if(tus==56 && y!=-1) { ya=5; y=1; xa=0; x=0; }
}

void ciz(int tus,int durum,int xx,int yy)
{
float x=(xx-400)/400.0,y=(yy-400)/400.0;
if(tus==0 && durum==0)
{
if( x>-0.4 && x<-0.2 && y>-0.2 && y<-0.1 )
{ r11=0,r12=1,r13=1,r21=0,r22=0,r23=1,r31=0,r32=0,r33=1,r41=0.5,r42=0.5,r43=0.9; ana(); hiz=1; }
else if( x>-0.1 && x<0.1 && y>-0.2 && y<-0.1 )
{ r11=0,r12=0,r13=1,r21=0,r22=1,r23=1,r31=0,r32=0,r33=1,r41=0.5,r42=0.5,r43=0.9; ana(); hiz=2; }
else if( x>0.2 && x<0.4 && y>-0.2 && y<-0.1 )
{ r11=0,r12=0,r13=1,r21=0,r22=0,r23=1,r31=0,r32=1,r33=1,r41=0.5,r42=0.5,r43=0.9; ana(); hiz=3; }
else if( x>-0.1 && x<0.1 && y>0.1 && y<0.2 )
{ r11=0,r12=0,r13=1,r21=0,r22=0,r23=1,r31=0,r32=0,r33=1,r41=0.9,r42=0.5,r43=0.9; ana();
if(hiz==0)
{
char yaz[]="Secim yapilmamis !!!";
glRasterPos2f (-0.15,-0.35);
for (i = 0; i < strlen (yaz);i++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, yaz[i]);
}
else
{
animasyon();
basla=1;
if(hiz==1) bekleme=400000;
else if(hiz==2) bekleme=200000;
else bekleme=100000; //BEKLEME ZAMANLARI
}
}
}
}

void olum()
{
printf("Olum Gerceklendi...n");
exit(0);
}

void kazandin()
{
printf("Oyunu Kazandin...n");
exit(0);
}

void dongu()
{
if(basla==2)
{ usleep(1000); return; }
if(basla==0)
{
usleep(1000);
}else{

glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,0,1); //KENARLIK RENGI.
glBegin(GL_LINES);
glVertex2f(-0.98,-0.98);
glVertex2f(-0.98,+0.98);
glVertex2f(-0.98,+0.98);
glVertex2f(+0.98,+0.98);
glVertex2f(+0.98,+0.98);
glVertex2f(+0.98,-0.98);
glVertex2f(+0.98,-0.98);
glVertex2f(-0.98,-0.98);
glEnd();

siradaki[0]=dizi[0][0]+xa;
siradaki[1]=dizi[0][1]+ya;
for (i=1;i<indis;i++)
{
if(dizi[i][0]==siradaki[0] && dizi[i][1]==siradaki[1])
{ printf("Kuyruga carptin. "); olum(); }
}
if(siradaki[0]<-95 || siradaki[0]>95 || siradaki[1]<-95 || siradaki[1]>95)
{ printf("Haritadan ciktin. %d %d koduyla son.n",siradaki[0],siradaki[1]); olum(); }

if( siradaki[0]==yemek[0] && siradaki[1]==yemek[1] )
{
indis++;
dizi[indis+1][0]=0; dizi[indis+1][1]=0;
for(i=indis-1;i!=-1;i--)
{ dizi[i+1][0]=dizi[i][0]; dizi[i+1][1]=dizi[i][1]; }
dizi[0][0]=yemek[0]; dizi[0][1]=yemek[1];
if(indis==198)
kazandin();

do{
hata=0;
srand(time(NULL));
salla[0]=((int)((random()-RAND_MAX/2)/(float)(RAND_MAX/2.0)*20)/20.0)*100;
salla[1]=((int)((random()-RAND_MAX/2)/(float)(RAND_MAX/2.0)*20)/20.0)*100;
for(i=0;i<=indis;i++)
{
if( dizi[i][0]==salla[0] && dizi[i][1]==salla[1] )
hata=1;
}
}while(hata==1);

yemek[0]=salla[0]; yemek[1]=salla[1];
printf("Yilan boyu:%dn",indis);
}
else
{
for(i=indis-1;i>=0;i--)
{
dizi[i+1][0]=dizi[i][0];
dizi[i+1][1]=dizi[i][1];
}
dizi[0][0]=siradaki[0]; dizi[0][1]=siradaki[1];
}

glPointSize(14.0);
glColor3f(1,0,0); //YEMEK KIRMIZI RENKTE
glBegin(GL_POINTS);
glVertex2f(yemek[0]/100.0,yemek[1]/100.0);
glEnd();

for(i=0;i<=indis;i++)
{
glColor3f(0,0,1);
glPointSize(14.0);
glBegin(GL_POINTS);
glVertex2f(dizi[i][0]/100.0,dizi[i][1]/100.0);
glEnd();
if(indis>i)
{
glPointSize(7.0); glColor3f(0,1,0); glBegin(GL_POINTS);
glVertex2f((dizi[i][0]+dizi[i+1][0])/200.0,(dizi[i][1]+dizi[i+1][1])/200.0);
glEnd();
}
}

glFlush();
usleep(bekleme);
}
}

int main (int argc, char *argv[])
{
glutInit (&argc, argv);
glutInitWindowSize(800,800);
glutInitWindowPosition(50,50);
glutCreateWindow("YILAN OYUNU TARIH: 9 Ekim 2004 Cumartesi VERSIYON: 0.1");

//glutFullScreen();
glutDisplayFunc(ana);
glutMouseFunc(ciz);
glutIdleFunc(dongu);
glutKeyboardFunc(tuslar);
glutMainLoop();
return(0);
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.