試寫射擊遊戲,今日目標:讓茶壺可從左往又快速移動!!!
#include <GL/glut.h>
#include <mmsystem.h>
#include <stdio.h>
#include <math.h>
void keyboard(unsigned char, int, int);
void mouse(int, int, int, int);
void display(void);
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutCreateWindow("02160295");
glutFullScreen();
glutDisplayFunc(display);
glutIdleFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMainLoop();
}
float potX=-1,potY=0;
void display()
{
potX+=0.01;
glClearColor(0.5,0.5,1,0);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glTranslatef(potX, potY, 0);
glutSolidTeapot(0.05);
glPopMatrix();
glFlush();
if(potX>1)
{
potX=-1;
potY+=0.1;
if(potY>1) potY=-1;
}
}
void keyboard(unsigned char key, int x, int y)
{
if(key==27)
exit(0);
}
void mouse(int button, int state, int x, int y)
{
if(state==GLUT_DOWN)
{
PlaySound("Shot.wav", NULL, SND_ASYNC);
puts("!!!");
float mouseX = 2*x/1280.0-1, mouseY = 2*y/1024-1;
if(fabs(mouseX - potX)<0.1 && fabs(mouseY - potY)<0.1)
{
PlaySound("Femaleha.wav",NULL,SND_ASYNC);
printf("K.O!");
}
}
}
沒有留言:
張貼留言