2015年4月16日 星期四

week08 02160765龔郁如


剛開始先看看這些程式能做什麼


開始今天第一個實做程式
剛開始我們先加音效進去,
然後有加了一個可以開全銀幕的程式碼,
然後還可以案esc鍵結束


程式碼:
#include <GL/glut.h>
#include <mmsystem.h>
#include <stdio.h>
void mouse(int button, int state, int x, int y)
{
    if(state==GLUT_DOWN){
        PlaySound("Shot.wav", NULL, SND_ASYNC);
        printf("Shot!\n");
    }
}
void keyboard(unsigned char key, int x, int y)
{
    exit(0);
}
void display()
{
    glClearColor(0.5, 0.5, 1, 0);
    glClear(GL_COLOR_BUFFER_BIT);
    glFlush();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutCreateWindow("02160765:))");

    glutFullScreen();

    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);
    glutMainLoop();
}
接下來加入茶壺出現

程式碼:
#include <GL/glut.h>
#include <mmsystem.h>
#include <stdio.h>
void mouse(int button, int state, int x, int y)
{
    if(state==GLUT_DOWN){
        PlaySound("Shot.wav", NULL, SND_ASYNC);
        printf("Shot!\n");
    }
}
void keyboard(unsigned char key, int x, int y)
{
    exit(0);
}
float potX=-1, potY=0;
void display()
{
    potX+=0.01;
    if(potX>1.1) potX=-1.1;
    glClearColor(0.5, 0.5, 1, 0);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
        glTranslatef(potX, potY,0);
        glutSolidTeapot(0.05);
    glPopMatrix();
    glFlush();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutCreateWindow("02160765:))");

    glutFullScreen();
    glutDisplayFunc(display);
    glutIdleFunc(display);
    glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);
    glutMainLoop();
}



接下來又多加了打中物體的笑聲

程式碼:

#include <GL/glut.h>
#include <mmsystem.h>
#include <stdio.h>
#include <math.h>
float potX=-1, potY=0;
void mouse(int button, int state, int x, int y)
{
    if(state==GLUT_DOWN){
        PlaySound("Shot.wav", NULL, SND_ASYNC);
        printf("Shot!\n");

            float mouseX = 2*x/1280.0 -1, mouseY = 2*y/1024.0 -1;
            if( fabs(mouseX - potX) <0.1 && fabs(mouseY-potY)<0.1){
                PlaySound("Hahaha.wav",NULL,SND_ASYNC);
                printf("YA!You got it!\n");
            }
    }
}
void keyboard(unsigned char key, int x, int y)
{
    exit(0);
}
void display()
{
    potX+=0.01;
    if(potX>1.1) potX=-1.1;
    glClearColor(0.5, 0.5, 1, 0);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
        glTranslatef(potX, potY,0);
        glutSolidTeapot(0.05);
    glPopMatrix();
    glFlush();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutCreateWindow("02160765:))");
    glutFullScreen();
    glutDisplayFunc(display);
    glutIdleFunc(display);
    glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);
    glutMainLoop();
}





沒有留言:

張貼留言