//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; }
// Gameplay Screen Initialization logic void InitAtticScreen(void) { ResetPlayer(); // Reset Screen variables monsterHover = false; monsterCheck = -1; msgState = 0; msgCounter = 0; lettersCounter = 0; for (int i = 0; i < 256; i++) msgBuffer[i] = '\0'; framesCounter = 0; finishScreen = 0; background = LoadTexture("resources/textures/background_attic.png"); // Initialize doors doorRight.position = (Vector2) { 1074, 140 }; doorRight.facing = 2; doorRight.locked = true; doorRight.frameRec =(Rectangle) {((doors.width/3)*doorRight.facing), doors.height/2, doors.width/3, doors.height/2}; doorRight.bound = (Rectangle) { doorRight.position.x, doorRight.position.y, doors.width/3, doors.height/2}; doorRight.selected = false; // Monster init: lamp lamp.position = (Vector2){ 50, 316 }; lamp.texture = LoadTexture("resources/textures/monster_lamp_left.png"); lamp.currentFrame = 0; lamp.framesCounter = 0; lamp.numFrames = 4; lamp.bounds = (Rectangle){ lamp.position.x + 20, lamp.position.y, 90, 380 }; lamp.frameRec = (Rectangle) { 0, 0, lamp.texture.width/lamp.numFrames, lamp.texture.height }; lamp.selected = false; lamp.active = false; lamp.spooky = false; // Monster init: arc arc.position = (Vector2){ 760, 430 }; arc.texture = LoadTexture("resources/textures/monster_arc.png"); arc.currentFrame = 0; arc.framesCounter = 0; arc.numFrames = 4; arc.bounds = (Rectangle){ arc.position.x + 44, arc.position.y + 70, 220, 120 }; arc.frameRec = (Rectangle) { 0, 0, arc.texture.width/arc.numFrames, arc.texture.height }; arc.selected = false; arc.active = false; arc.spooky = true; }
//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; } }
// Gameplay Screen Initialization logic void InitLivingroomScreen(void) { ResetPlayer(); // Reset Screen variables monsterHover = false; monsterCheck = -1; msgState = 0; msgCounter = 0; lettersCounter = 0; for (int i = 0; i < 256; i++) msgBuffer[i] = '\0'; framesCounter = 0; finishScreen = 0; background = LoadTexture("resources/textures/background_livingroom.png"); // Initialize doors doorLeft.position = (Vector2) { -45, 140}; doorLeft.facing = 0; doorLeft.locked = true; doorLeft.frameRec =(Rectangle) {((doors.width/3)*doorLeft.facing), doors.height/2, doors.width/3, doors.height/2}; doorLeft.bound = (Rectangle) { doorLeft.position.x, doorLeft.position.y, doors.width/3, doors.height/2}; doorLeft.selected = false; doorCenter.position = (Vector2) { 830, 108 }; doorCenter.facing = 1; doorCenter.locked = true; doorCenter.frameRec =(Rectangle) {((doors.width/3)*doorCenter.facing), doors.height/2, doors.width/3, doors.height/2}; doorCenter.bound = (Rectangle) { doorCenter.position.x, doorCenter.position.y, doors.width/3, doors.height/2}; doorCenter.selected = false; // Monster init: lamp candle.position = (Vector2){ 154, 256 }; candle.texture = LoadTexture("resources/textures/monster_candle.png"); candle.currentFrame = 0; candle.framesCounter = 0; candle.numFrames = 4; candle.bounds = (Rectangle){ candle.position.x + 90, candle.position.y + 30, 185, 340 }; candle.frameRec = (Rectangle) { 0, 0, candle.texture.width/candle.numFrames, candle.texture.height }; candle.selected = false; candle.active = false; candle.spooky = false; // Monster init: arc picture.position = (Vector2){ 504, 164 }; picture.texture = LoadTexture("resources/textures/monster_picture.png"); picture.currentFrame = 0; picture.framesCounter = 0; picture.numFrames = 4; picture.bounds = (Rectangle){ picture.position.x + 44, picture.position.y, 174, 264 }; picture.frameRec = (Rectangle) { 0, 0, picture.texture.width/picture.numFrames, picture.texture.height }; picture.selected = false; picture.active = false; picture.spooky = true; // Monster init: phone phone.position = (Vector2){ 1054, 404 }; phone.texture = LoadTexture("resources/textures/monster_phone.png"); phone.currentFrame = 0; phone.framesCounter = 0; phone.numFrames = 4; phone.bounds = (Rectangle){ phone.position.x + 64, phone.position.y +120, 100, 160 }; phone.frameRec = (Rectangle) { 0, 0, phone.texture.width/phone.numFrames, phone.texture.height }; phone.selected = false; phone.active = false; phone.spooky = true; }
// Gameplay Screen Initialization logic void InitAisle01Screen(void) { ResetPlayer(); // Reset Screen variables monsterHover = false; monsterCheck = -1; msgState = 0; msgCounter = 0; lettersCounter = 0; for (int i = 0; i < 256; i++) msgBuffer[i] = '\0'; framesCounter = 0; finishScreen = 0; background = LoadTexture("resources/textures/background_aisle01.png"); scroll = player.position.x - 200; // Initialize doors doorLeft.position = (Vector2) { -30, 135 }; doorLeft.facing = 0; doorLeft.locked = true; doorLeft.frameRec =(Rectangle) {((doors.width/3)*doorLeft.facing), doors.height/2, doors.width/3, doors.height/2}; doorLeft.bound = (Rectangle) { doorLeft.position.x, doorLeft.position.y, doors.width/3, doors.height/2}; doorLeft.selected = false; doorCenter.position = (Vector2) { 1115, 104 }; doorCenter.facing = 1; doorCenter.locked = true; doorCenter.frameRec =(Rectangle) {((doors.width/3)*doorCenter.facing), doors.height/2, doors.width/3, doors.height/2}; doorCenter.bound = (Rectangle) { doorCenter.position.x, doorCenter.position.y, doors.width/3, doors.height/2}; doorCenter.selected = false; doorRight.position = (Vector2) { 1710, 140 }; doorRight.facing = 2; doorRight.locked = true; doorRight.frameRec =(Rectangle) {((doors.width/3)*doorRight.facing), doors.height/2, doors.width/3, doors.height/2}; doorRight.bound = (Rectangle) { doorRight.position.x, doorRight.position.y, doors.width/3, doors.height/2}; // Monster init: lamp lamp.position = (Vector2){ 187, 256 }; lamp.texture = LoadTexture("resources/textures/monster_lamp_left.png"); lamp.currentFrame = 0; lamp.framesCounter = 0; lamp.numFrames = 4; lamp.bounds = (Rectangle){ lamp.position.x + 20, lamp.position.y, 90, 380 }; lamp.frameRec = (Rectangle) { 0, 0, lamp.texture.width/lamp.numFrames, lamp.texture.height }; lamp.selected = false; lamp.active = false; lamp.spooky = true; // Monster init: arc picture.position = (Vector2){ 637, 178 }; picture.texture = LoadTexture("resources/textures/monster_picture.png"); picture.currentFrame = 0; picture.framesCounter = 0; picture.numFrames = 4; picture.bounds = (Rectangle){ picture.position.x + 44, picture.position.y, 174, 256 }; picture.frameRec = (Rectangle) { 0, 0, picture.texture.width/picture.numFrames, picture.texture.height }; picture.selected = false; picture.active = false; picture.spooky = false; }
//main int main() { int letra; OpcaoBackground(letra); //primitive variables int NUM_ENEMYRED = 10; //quantidade de inimigos vermelhos int NUM_ENEMYBLUE = 10; //quantidade de inimigos azuis int NUM_BOSS = 5; int text_color = 255; //variavel para cor (animacao inicial de jogo - efeito relampago) int text_boss = 255; //variavel para cor de texto boss int FPS = 60; //frames per second bool done = false; bool redraw = true; enum KEYS {UP, DOWN, LEFT, RIGHT, Q, W, E, R}; bool keys[8] = {false, false, false, false, false, false, false, false}; //object variables struct Player player; struct Enemy_red enemyred[NUM_ENEMYRED]; struct Enemy_blue enemyblue[NUM_ENEMYBLUE]; struct Boss boss[NUM_BOSS]; struct Shoot shootQ; struct Shoot shootW; struct Shoot shootE; struct Obstacle obstacle; struct SpriteScientist scientist; struct Sprite background; struct Sprite background1; struct Sprite background2; struct Sprite background3; struct Sprite background4; struct Sprite background5; struct Sprite background6; struct Sprite enemyred_sprite; //allegro variables ALLEGRO_DISPLAY *display; ALLEGRO_EVENT_QUEUE *event_queue = NULL; ALLEGRO_TIMER *timer = NULL; ALLEGRO_FONT *title_font = NULL; ALLEGRO_FONT *medium_font = NULL; //////////////////////////////////////////////////////////////////////// //verificacoes de erro if(!al_init()) return -1; //caso de erro ao inicializar allegro display = al_create_display(WIDTH,HEIGHT); //criar display if(!display) return -1; //se der merda //Allegro Module Init al_init_primitives_addon(); al_init_font_addon(); if (!al_init_ttf_addon()) { printf("Falha ao inicializar addon allegro_ttf.\n"); return -1; } al_install_keyboard(); if(!al_init_image_addon()) { printf("Falha ao inicializar image addon"); return -1; } event_queue = al_create_event_queue(); timer = al_create_timer(1.0 / FPS); medium_font = al_load_font("fonts/EHSMB.TTF", 50, 0); if (!medium_font) { al_destroy_display(display); printf("Falha ao carregar fonte.\n"); return -1; } title_font = al_load_font("fonts/French Electric Techno.ttf", 200, 0); if (!title_font) { al_destroy_display(display); printf("Falha ao carregar fonte.\n"); return -1; } int b; //Inicializacao de objetos InitPlayer(player, &text_color); //funcao que "inicia" player InitScientist(scientist); if (!scientist.bitmap) { al_destroy_display(display); printf("Falha ao carregar sprite scientist.\n"); return -1; } InitEnemyRed(enemyred, &NUM_ENEMYRED); //funcao que inicia enemyred InitEnemyBlue(enemyblue, &NUM_ENEMYBLUE); //funcao que inicia enemyblue InitShootQ(shootQ); //funcao que inicializa disparo 1 (capacitor) if(!shootQ.bitmap) { al_destroy_display(display); printf("Falha ao carregar sprite shootQ.\n"); return -1; } InitShootW(shootW); //funcao que inicializa disparo 2 (indutor) if(!shootW.bitmap) { al_destroy_display(display); printf("Falha ao carregar sprite shootW.\n"); return -1; } InitShootE(shootE); //funcao que inicializa habilidade de escudo (shield / resistor) if(!shootE.bitmap) { al_destroy_display(display); printf("Falha ao carregar sprite shield.\n"); return -1; } InitObstacle(obstacle); //funcao que inicializa obstaculos InitBoss(boss, &NUM_BOSS); //funcao que inicializa chefes (bosses) InitBackground(background, letra); //funcao que inicializa sprite de background InitBackground1(background1, letra); //funcao que inicializa sprite de background1 alternativo InitBackground2(background2, letra); //funcao que inicializa sprite de background2 alternativo InitBackground3(background3, letra); //funcao que inicializa sprite de background3 alternativo InitBackground4(background4, letra); //funcao que inicializa sprite de background4 alternativo InitBackground5(background5, letra); //funcao que inicializa sprite de background4 alternativo InitBackground6(background6, letra); //funcao que inicializa sprite de background4 alternativo InitEnemyredSprite(enemyred_sprite); // funcao que inicializa sprite de inimigo vermelho al_register_event_source(event_queue, al_get_keyboard_event_source()); al_register_event_source(event_queue, al_get_display_event_source(display)); al_register_event_source(event_queue, al_get_timer_event_source(timer)); al_start_timer(timer); while (!done) { ALLEGRO_EVENT ev; al_wait_for_event(event_queue, &ev); //se clicar para fechar a janela if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { done = true; } //evento do timer (vai entrar nesse else if sempre, a nao ser que feche a janela) else if(ev.type == ALLEGRO_EVENT_TIMER) { redraw = true; if(keys[RIGHT] && !player.moving) { player.velx = player.speed; player.moving = true; } if(keys[LEFT] && !player.moving) { player.velx = player.speed; player.moving = true; } ChangeColor(&text_color, player, boss, &NUM_BOSS, &text_boss); PlayerJump(player, &keys[UP]); PlayerRight(player, &keys[RIGHT], scientist); PlayerLeft(player, &keys[LEFT]); //updates UpdateShootQ(shootQ, player); UpdateShootW(shootW, player); UpdateShootE(shootE, player); UpdateEnemyRed(enemyred, &NUM_ENEMYRED, player, shootQ); UpdateEnemyBlue(enemyblue, &NUM_ENEMYBLUE, player, shootW); UpdateObstacle(obstacle, medium_font, player); UpdateBoss(boss, &NUM_BOSS, &text_boss, player, enemyred, &NUM_ENEMYRED, enemyblue, &NUM_ENEMYBLUE); //colisoes ShootQColisionEnemyRed(shootQ,enemyred, &NUM_ENEMYRED, player); ShootWColisionEnemyBlue(shootW, enemyblue, &NUM_ENEMYBLUE, player); ShootColisionBoss(shootW, shootQ, boss, &NUM_BOSS, player); PlayerColisionEnemyBlue(player, enemyblue, &NUM_ENEMYBLUE); PlayerColisionEnemyRed(player, enemyred, &NUM_ENEMYRED); PlayerColisionObstacle(player,obstacle); PlayerColisionBoss(player, boss, &NUM_BOSS); ResetPlayer(player, enemyred, &NUM_ENEMYRED, enemyblue, &NUM_ENEMYBLUE, obstacle, boss, &NUM_BOSS, &text_color); } else if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { switch(ev.keyboard.keycode) { case ALLEGRO_KEY_ESCAPE: done = true; break; case ALLEGRO_KEY_UP: keys[UP] = true; break; case ALLEGRO_KEY_RIGHT: keys[RIGHT] = true; break; case ALLEGRO_KEY_LEFT: keys[LEFT] = true; break; case ALLEGRO_KEY_Q: keys[Q] = true; FireShootQ(shootQ, player); break; case ALLEGRO_KEY_W: keys[W] = true; FireShootW(shootW, player); break; case ALLEGRO_KEY_E: keys[E] = true; FireShootE(shootE, player); break; case ALLEGRO_KEY_R: keys[R] = true; break; } } else if(ev.type == ALLEGRO_EVENT_KEY_UP) { switch(ev.keyboard.keycode) { case ALLEGRO_KEY_UP: keys[UP] = false; break; case ALLEGRO_KEY_RIGHT: keys[RIGHT] = false; player.moving = false; break; case ALLEGRO_KEY_LEFT: keys[LEFT] = false; player.moving = false; break; case ALLEGRO_KEY_Q: keys[Q] = false; break; case ALLEGRO_KEY_W: keys[W] = false; break; case ALLEGRO_KEY_E: keys[E] = false; break; case ALLEGRO_KEY_R: keys[R] = false; break; } } if(redraw && al_is_event_queue_empty(event_queue)) { redraw = false; //desenhar objetos DrawBackground(background, letra); DrawBackground1(background1, letra); DrawBackground2(background2, letra); DrawBackground3(background3, letra); DrawBackground4(background4, letra); DrawBackground5(background5, letra); DrawBackground6(background6, letra); DrawText(title_font, medium_font, player, boss, &NUM_BOSS, &text_color, &text_boss); DrawShootQ(shootQ); DrawShootW(shootW); DrawShootE(shootE, player); DrawEnemyRed(enemyred, &NUM_ENEMYRED, player, enemyred_sprite); DrawEnemyBlue(enemyblue, &NUM_ENEMYBLUE, player); DrawBoss(boss, &NUM_BOSS, player); DrawObstacle(obstacle); DrawScientist(player, scientist, &keys[LEFT], &keys[RIGHT]); al_flip_display(); } } al_destroy_event_queue(event_queue); al_destroy_timer(timer); al_destroy_font(title_font); al_destroy_font(medium_font); al_destroy_display(display); al_destroy_bitmap(scientist.bitmap); al_destroy_bitmap(shootE.bitmap); for(b=0; b<background.frame_max; b++) { al_destroy_bitmap(background.image[b]); } for(b=0; b<background1.frame_max; b++) { al_destroy_bitmap(background1.image[b]); } for(b=0; b<background2.frame_max; b++) { al_destroy_bitmap(background2.image[b]); } for(b=0; b<background3.frame_max; b++) { al_destroy_bitmap(background3.image[b]); } for(b=0; b<background4.frame_max; b++) { al_destroy_bitmap(background4.image[b]); } for(b=0; b<background5.frame_max; b++) { al_destroy_bitmap(background5.image[b]); } for(b=0; b<background6.frame_max; b++) { al_destroy_bitmap(background6.image[b]); } return 0; }//final da MAIN!!
// Gameplay Screen Initialization logic void InitAisle02Screen(void) { ResetPlayer(); // Reset Screen variables monsterHover = false; monsterCheck = -1; msgState = 0; msgCounter = 0; lettersCounter = 0; for (int i = 0; i < 256; i++) msgBuffer[i] = '\0'; framesCounter = 0; finishScreen = 0; background = LoadTexture("resources/textures/background_aisle02.png"); scroll = player.position.x - 200; // Initialize doors doorLeft.position = (Vector2) { -10, 136 }; doorLeft.facing = 0; doorLeft.locked = true; doorLeft.frameRec =(Rectangle) {((doors.width/3)*doorLeft.facing), doors.height/2, doors.width/3, doors.height/2}; doorLeft.bound = (Rectangle) { doorLeft.position.x, doorLeft.position.y, doors.width/3, doors.height/2}; doorLeft.selected = false; // Monster init: lamp lamp.position = (Vector2){ 1520, 300 }; lamp.texture = LoadTexture("resources/textures/monster_lamp_right.png"); lamp.currentFrame = 0; lamp.framesCounter = 0; lamp.numFrames = 4; lamp.bounds = (Rectangle){ lamp.position.x + 200, lamp.position.y, 90, 380 }; lamp.frameRec = (Rectangle) { 0, 0, lamp.texture.width/lamp.numFrames, lamp.texture.height }; lamp.selected = false; lamp.active = false; lamp.spooky = true; // Monster init: chair chair.position = (Vector2){ 1400, 404 }; chair.texture = LoadTexture("resources/textures/monster_chair_right.png"); chair.currentFrame = 0; chair.framesCounter = 0; chair.numFrames = 4; chair.bounds = (Rectangle){ chair.position.x + 50, chair.position.y + 30, 120, 190 }; chair.frameRec = (Rectangle) { 0, 0, chair.texture.width/chair.numFrames, chair.texture.height }; chair.selected = false; chair.active = false; chair.spooky = false; // Monster init: picture picture.position = (Vector2){ 837, 162 }; picture.texture = LoadTexture("resources/textures/monster_picture.png"); picture.currentFrame = 0; picture.framesCounter = 0; picture.numFrames = 4; picture.bounds = (Rectangle){ picture.position.x + 44, picture.position.y, 174, 264 }; picture.frameRec = (Rectangle) { 0, 0, picture.texture.width/picture.numFrames, picture.texture.height }; picture.selected = false; picture.active = false; picture.spooky = true; // Monster init: arc arc.position = (Vector2){ 388, 423 }; arc.texture = LoadTexture("resources/textures/monster_arc.png"); arc.currentFrame = 0; arc.framesCounter = 0; arc.numFrames = 4; arc.bounds = (Rectangle){ arc.position.x + 44, arc.position.y + 70, 220, 120 }; arc.frameRec = (Rectangle) { 0, 0, arc.texture.width/arc.numFrames, arc.texture.height }; arc.selected = false; arc.active = false; arc.spooky = true; }