2015年4月16日 星期四

week8 廖彥豪

今天是期中考前的一週
但我們今天就要考試ㄖ
應該是不難吧哈哈
去年考過了說 ....

第一節課
對ㄖ
在剛上課時玩了一個小遊戲
好啦 就是一個罐子飛來飛去而已 ㄎㄎ
再來就是一個方便我們複習的東西ㄖ
這個是我們光線的複習用具
其實只要調整旁邊的數值就可以發現它的變化了
再來還有一個
這個就是我們的貼圖功能ㄖ
看一下紅色的數值
就可以看到他的改變
我們圖中左上方的貼圖是不是變得很不一樣了阿哈哈

這就是期中考開始前的複習囉

好ㄖ 考完ㄖ
應該是100分吧哈哈

第二節課
我們要做和上課一開始很像的遊戲
所以我們開始吧ㄎㄎ
因為只有聲音跟藍藍的背景
我貼這樣
音樂檔要放在freeglut>>>bin資料夾裡面
這樣聲音才會出來
不然會一直燈燈燈燈燈燈(((MSN?
程式碼如下
#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("hello");

    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) potY=-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("hello");

    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("Shot.wav", NULL, SND_ASYNC);
            printf("You got it!\n");
        }
    }
}
void keyboard(unsigned char key,int x, int y)
{
    exit(0);
}
void display()
{
    potX+=0.01;
    if(potX>1.1) potY=-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("hello");
    glutFullScreen();
    glutDisplayFunc(display);
    glutIdleFunc(display);
    glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);
    glutMainLoop();
}

然後今天的課就開開心心的結束囉~~~

沒有留言:

張貼留言