//destroys the asteroid, spawning new ones if necessary void AsteroidHit(LIST * a, int fromplayershot) { if(a) { PlaySoundIndex(SND_EXP_ASTEROID); SpawnExplosion(NewListNode(&g_explosion_list, sizeof(EXPLOSION)), &(((ASTEROID *)a->d)->pos), (int)(((ASTEROID *)a->d)->scale) * 8); if(((ASTEROID *)a->d)->scale > 1.0f) { if(fromplayershot) Score(((ASTEROID *)a->d)->scale > 2.0f ? 20 : 50, &(((ASTEROID *)a->d)->pos)); SpawnAsteroid(NewListNode(&g_asteroid_list, sizeof(ASTEROID)), &(((ASTEROID *)a->d)->pos), ((ASTEROID *)a->d)->scale * 0.5f); SpawnAsteroid(NewListNode(&g_asteroid_list, sizeof(ASTEROID)), &(((ASTEROID *)a->d)->pos), ((ASTEROID *)a->d)->scale * 0.5f); } else if(fromplayershot) Score(100, &(((ASTEROID *)a->d)->pos)); RemoveNode(a, &g_asteroid_list); if(!g_asteroid_list && g_ships) g_time_to_reset = RESET_TIME; } }
void Insert(List L, int Value) { if (L -> Head == NULL) { L -> Head = NewListNode(Value); L -> Last = L -> Head; return; } L -> Last -> next = NewListNode(Value); L -> Last = L -> Last -> next; }
List CreateReversedList(int Size) { List L, *P; int i; L = NewListNode(Size); P = L; for (i = 1; i <= Size; ++i) { P -> next = NewListNode(Size - i); P = P -> next; } return L; }
List CreateRandList(int Size) { List L, *P; int i; L = NewListNode(0); P = L; for (i = 1; i <= Size; ++i) { P -> next = NewListNode(rand() % (Size * 4)); P = P -> next; } return L; }
List CreateIdenticalList(int Size) { List L, *P; int i, j; L = NewListNode(0); P = L; for (i = 1; i <= Size; ++i) { P -> next = NewListNode(0); P = P -> next; } return L; }
List CreateEvenList(int Size) { List L, *P; int i; L = NewListNode(0); P = L; for (i = 1; i <= Size; ++i) { P -> next = NewListNode(2 * i); P = P -> next; } return L; }
//initializes or resets the state of the game void NextLevel(void) { int i; PlaySoundIndex(SND_NEWLEVEL); g_level++; InitStarfield(&g_starfield); DeleteEntireList(&g_asteroid_list); DeleteEntireList(&g_alien_list); DeleteEntireList(&g_shot_list); DeleteEntireList(&g_explosion_list); DeleteEntireList(&g_burst_list); DeleteEntireList(&g_powerup_list); i = g_player.powerups; ResetPlayer(&g_player); g_player.powerups = i; for(i = 0; i < (int)(log((double)g_level) + 2.5); i++) SpawnAsteroid(NewListNode(&g_asteroid_list, sizeof(ASTEROID)), NULL, 4.0f); Score((g_level > 100 ? 999 : (g_level - 1) * 10), NULL); //completion bonus g_frame = 0; g_time_to_reset = 0; }
List CreateDupList(int Size) { List L, *P; int i, j; L = NewListNode(0); P = L; for (i = 1; i <= Size; ++i) { for (j = 0; j < i / 2; ++j) { P -> next = NewListNode(i); P = P -> next; } } return L; }
//spawns a text burst void NewBurst(const VECTOR2 * pos, const char * msg, ...) { char buf[1024]; va_list vList; va_start(vList, msg); vsprintf(buf, msg, vList); va_end(vList); SpawnBurst(NewListNode(&g_burst_list, sizeof(BURST)), pos, buf); }
//destroys the powerup without getting it void PowerupHit(LIST * p, int fromplayershot) { if(p) { PlaySoundIndex(SND_EXP_OTHER); SpawnExplosion(NewListNode(&g_explosion_list, sizeof(EXPLOSION)), &(((POWERUP *)p->d)->pos), NUM_EXPLOSION_PARTICLES / 2); if(fromplayershot) Score(666, &(((POWERUP *)p->d)->pos)); RemoveNode(p, &g_powerup_list); } }
//destroys the alien ship void AlienHit(LIST * a, int fromplayershot) { if(a) { PlaySoundIndex(SND_EXP_OTHER); SpawnExplosion(NewListNode(&g_explosion_list, sizeof(EXPLOSION)), &(((ALIEN *)a->d)->pos), (((ALIEN *)a->d)->scale == 2.0f ? NUM_EXPLOSION_PARTICLES / 2 : NUM_EXPLOSION_PARTICLES)); if(fromplayershot) Score((((ALIEN *)a->d)->scale == 2.0f ? 500 : 200), &(((ALIEN *)a->d)->pos)); RemoveNode(a, &g_alien_list); } }
//destroys the player, respawns it void PlayerHit(void) { if(g_player.powerups & PL_POW_SHIELD) { g_player.powerups &= (~PL_POW_SHIELD); g_player.wait_time = PLAYER_SPAWN_WAIT; } else { PlaySoundIndex(SND_EXP_SHIP); SpawnExplosion(NewListNode(&g_explosion_list, sizeof(EXPLOSION)), &g_player.pos, NUM_EXPLOSION_PARTICLES); ResetPlayer(&g_player); if(g_ships && !(--g_ships)) g_hisct_delay = HISCT_DELAY; } }
void InsertInList(struct ListNode *head, int data, int pos) { struct ListNode *newnode; struct ListNode *curNode; int curpos = 0; curNode = head; newnode = NewListNode(data); if(pos == 0) { if(!head) head = newnode; else { newnode->next = head; head = newnode; } } else if(curpos < pos && curNode) { curNode = curNode->next; curpos++; } }
void NewPowerup(void) { PlaySoundIndex(SND_SPAWN_POWERUP); SpawnPowerup(NewListNode(&g_powerup_list, sizeof(POWERUP))); }
//adds an alien to the list of aliens void NewAlien(int big) { PlaySoundIndex(SND_SPAWN_ALIEN); SpawnAlien(NewListNode(&g_alien_list, sizeof(ALIEN)), big); }
//adds a shot to the list of shots void NewShot(const VECTOR2 * pos, const VECTOR2 * vel, float angle, int player_owned) { PlaySoundIndex(SND_SPAWN_SHOT); SpawnShot(NewListNode(&g_shot_list, sizeof(SHOT)), pos, vel, angle, player_owned); }