/* Copyright (c) Mark J. Kilgard, 1997, 1998. */ /* This program is freely distributable without licensing fees and is provided without guarantee or warrantee expressed or implied. This program is -not- in the public domain. */ #include #include #include #include #include /* Some files do not define M_PI... */ #ifndef M_PI #define M_PI 3.14159265358979323846 #endif void initWindow(void); float angle = 0.0; int left, right; int leftTime, rightTime; int thrust, thrustTime; int joyThrust = 0, joyLeft = 0, joyRight = 0; float x = 20, y = 20, xv, yv, v; int shield = 0, joyShield = 0, cursor = 1; int lastTime; int paused = 0; int resuming = 1; int originalWindow = 0, currentWindow; typedef struct { int inuse; float x; float y; float v; float xv; float yv; int expire; } Bullet; #define MAX_BULLETS 10 Bullet bullet[MAX_BULLETS]; int allocBullet(void) { int i; for (i=0; i bullet[i].expire) { bullet[i].inuse = 0; continue; } x = bullet[i].x + bullet[i].xv * delta; y = bullet[i].y + bullet[i].yv * delta; x = x / 40.0; bullet[i].x = (x - floor(x))*40.0; y = y / 40.0; bullet[i].y = (y - floor(y))*40.0; } } } void shotBullet(void) { int entry; entry = allocBullet(); if (entry >= 0) { initBullet(entry, glutGet(GLUT_ELAPSED_TIME)); } } void drawBullets(void) { int i; glBegin(GL_POINTS); glColor3f(1.0, 0.0, 1.0); for (i=0; i 300) { right = 1; rightTime = glutGet(GLUT_ELAPSED_TIME); joyRight = 1; } else { /* joyRight helps avoid "joystick in neutral" from continually stopping rotation. */ if (joyRight) { right = 0; joyRight = 0; } } } void initWindow(void) { glutIgnoreKeyRepeat(1); glutDisplayFunc(display); glutVisibilityFunc(visible); glutKeyboardFunc(key); glutKeyboardUpFunc(keyup); glutSpecialFunc(special); glutSpecialUpFunc(specialup); glutJoystickFunc(joystick, 100); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, 40, 0, 40, 0, 40); glMatrixMode(GL_MODELVIEW); glPointSize(3.0); currentWindow = glutGetWindow(); } int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); if (argc > 1 && !strcmp(argv[1], "-fullscreen")) { glutGameModeString("640x480:16@60"); glutEnterGameMode(); } else { originalWindow = glutCreateWindow("asteroids"); } initWindow(); glutMainLoop(); return 0; /* ANSI C requires main to return int. */ }