//======================================================================= // Mouse Function //======================================================================= void Mouse(int button, int state, int x, int y) { y = glutGet(GLUT_WINDOW_HEIGHT) - y; if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { Vector dirVector = Vector(x,y) - Vector(WIDTH/2, HEIGHT/2); float dirVectorMag = sqrtf((dirVector.x * dirVector.x) + (dirVector.y * dirVector.y)); Vector normalizedDir = dirVector/dirVectorMag; Entity *bullet = new Entity(WIDTH/2, HEIGHT/2, normalizedDir, BULLET); bulletsList.AddEntity(bullet); Vector shipUp(0,1); float dotProduct = (dirVector.x * shipUp.x) + (dirVector.y * shipUp.y); float cosAngle = dotProduct / (shipUp.Magnitude() * dirVector.Magnitude()) ; float angle = acos(cosAngle) * 180.f / PI; x > WIDTH/2 ? shipRotation = -angle : shipRotation = angle; } }
//======================================================================= // Random Enemy Location Function //======================================================================= void SpawnEnemies(int) { Vector startlocation = GetRandomPosOffScreen(); int level; (((int)startlocation.x + (int)startlocation.y) % 2) == 0 ? level = 0 : level = 1; Enemy *enemy = new Enemy(startlocation.x, startlocation.y, Vector(), ENEMY, startlocation, level); EnemyList.AddEntity(enemy); glutTimerFunc(1000.0/Difficulty, SpawnEnemies, 0); }