功能实现:绘制出子弹模型,按左右键可以调整在水平方向的位置。窗口中有一蓝色正方形在窗口内移动,按空格键进行射击,子弹沿y轴方向射出,如击中正方形,则正方形变为红色。
#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
#include<iostream>
#include<fstream>
#include <iostream>
#include <string>
#include<math.h>
#include <time.h>
#include <windows.h>
using namespace std;
float bullet[5][2]={
{250,30},{245,20},{245,0},{255,0},{255,20}};
float bullet2[5][2]={
{bullet[0][0],0},{bullet[1][0],-10},{bullet[2][0],-30},{bullet[3][0],-30},{bullet[4][0],-10}};
float zheng[4][2] ={
{100,200},{160,200},{160,140},{100,140}};
bool can_move=true;
bool shoot =false;
int c=0;//用于控制正方形的颜色
int xstep=7;
int ystep=7;
float color[2][3]={
{0.0,0.0,1.0},{1.0,0.0,0.0}};
void myinit()
{
glClearColor(1.0f,1.0f,1.0f,1.0f);
glMatrixMode(GL_PROJECTION);
glLoadIde