Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Projektas_Ktu.cpp : This file contains the 'main' function. Program execution begins and ends there.
- //
- #include "pch.h"
- #include <iostream>
- #include <stdlib.h>
- #include <allegro5/allegro.h>
- #include <allegro5/allegro_native_dialog.h>
- #include <allegro5/allegro_font.h>
- #include <allegro5/allegro_ttf.h>
- #include <allegro5/allegro_primitives.h>
- #include <allegro5/allegro_image.h>
- #include <allegro5/allegro_audio.h>
- #include <allegro5/allegro_acodec.h>
- #include "objects.h"
- #define width 1600 //Taip daroma, kad negalima butu toliau pakeisti situ verciu
- #define height 900 //Panasiai kaip su const
- //Funkciju prototipai
- void initPlayer(Player *player);
- void moveUp(Player *player);
- void moveDown(Player &player);
- void moveLeft(Player &player);
- void moveRight(Player &player);
- void initBullet(Bullet bullet[], int size);
- void initEnemyBullet(Bullet bullet[], int size);
- void drawBullet(Bullet bullet[], int size);
- void fireBullet(Bullet bullet[], int size, Player &player);
- void updateBullet(Bullet bullet[], int size, Player &player);
- void initEnemy(const char* file_name, Enemy enemy[], int size);
- void drawEnemy(Enemy enemy[], int size, ALLEGRO_BITMAP *picture);
- void updateEnemy(Enemy enemy[], int size, Bullet bullet[], int bulletSize, Player &player);
- void updateScreen(Player &player, int &screenNumb);
- void fireEnemyBullet(Bullet bullet[], int size, Enemy enemy[], int sizeEnemy);
- void writeHighScore(Player &player);
- void delayReload(bool *reload); //AR REIKIA POINTERIO???
- void drawPowerUp(int time, bool notUsed, ALLEGRO_BITMAP *picture);
- void updatePowerUp(Player *player, bool *notUsed);
- int* initHighscore();
- //void drawHighScore(int* a, ALLEGRO_FONT* font);
- //Globalus kintamieji
- enum direction { DOWN, LEFT, RIGHT, UP }; // by default enums are 32bit intigers Down lygus 0, left 1, right 2, up 3
- int dir = DOWN; //??? NAUDIJAMAS I KURIA PUSE SAUTI. AR REIKIA KAD I VISAS GALIMA BUTU???
- int bulletCount = 100; // DABARTINIS KULKU SKAICIUS, NE MAX
- int reloadTime = 60; //Ciklu skaicius
- const int NUM_BULLETS = 100; //Galima ir defininti bet nera skirtumo (taip patogiau)
- const int NUM_BULLETS_ENEMY1 = 150;
- const int NUM_ENEMY = 3; //Stukturu masyvas dydis turi buti pastovus skaicius!!
- const int NUM_ENEMY_1 = 5;
- const char* enemy_tut = "enemyTutorial.txt";
- const char* enemy_lvl_1 = "enemy1_LVL.txt";
- int screenPosition = 0;
- int timeCount = 9000;
- int* p;
- ALLEGRO_SAMPLE* judesys = NULL;
- int main()
- {
- ALLEGRO_DISPLAY* display;
- ALLEGRO_SAMPLE* sample = NULL;
- if (!al_init()) //Cekina ar pasileidzia alegro
- {
- al_show_native_message_box(NULL, NULL, "Error", "Falied to initialize allegro", NULL, NULL);
- return -1;
- }
- display = al_create_display(width, height);
- if (!display) //Patikrina ar susikuria ekrano vaizdas(display)
- {
- al_show_native_message_box(NULL, NULL, "Error", "Falied to initialize the display", NULL, NULL);
- return -1;
- }
- Player player; //Sukuria Player struktura pavadinimu player is objects.h
- Bullet bullet[NUM_BULLETS]; //Same kas su player tik cia Bullet strukturos bullet masyvas kurio dydis yra NUM_BULLETS
- Bullet enemBullet[NUM_BULLETS_ENEMY1];
- Enemy enemy[NUM_ENEMY]; //Nukelti zemiau skirtingiems lvl bus siktingas!!!
- Enemy enemy1[NUM_ENEMY_1];
- bool done = false, active = false, draw = true; //REIKES TAISYTI!!! KAD NAUJU BUTI KELIEMS EKRANAMS
- bool mainMeniu = true, reloadBool = false;
- bool redraw = true, optionsBool = false, highscoreBool = false, redrawOptions = false, redrawHigh = false, powerUpBool = true;
- bool dudeBool = false, redrawDude = false;
- bool instructionBool = false, redrawInstruction = false;
- const float FPS = 60; //GLOBALUS turetu but????
- al_init_image_addon();
- al_init_primitives_addon();
- al_install_keyboard();
- al_init_font_addon();
- al_init_ttf_addon();
- initPlayer(&player);
- initBullet(bullet, NUM_BULLETS);
- initEnemy(enemy_tut, enemy, NUM_ENEMY);
- initEnemy(enemy_lvl_1, enemy1, NUM_ENEMY_1);
- initEnemyBullet(enemBullet, NUM_BULLETS_ENEMY1);
- int arowX = 350, arowY = 350;
- al_install_audio();
- al_init_acodec_addon();
- al_reserve_samples(2);
- sample = al_load_sample("Tema.ogg");
- judesys = al_load_sample("JUDESYS.ogg");
- ALLEGRO_KEYBOARD_STATE keystate;
- //Paleidziami failai
- ALLEGRO_BITMAP* character = al_load_bitmap("bicas60x60.png"); //REIKES GALE ISTRINTI!!!
- ALLEGRO_BITMAP* character_2 = al_load_bitmap("bicas_2_60x60.png");
- ALLEGRO_BITMAP* character_1 = al_load_bitmap("bicas60x60.png");
- ALLEGRO_BITMAP* target = al_load_bitmap("target_50x50.png");
- ALLEGRO_BITMAP* mushroom = al_load_bitmap("mushroom70x70.png");
- ALLEGRO_BITMAP* arrow = al_load_bitmap("arrow110x60.png");
- ALLEGRO_BITMAP* healthPotion = al_load_bitmap("PotionRedBottle30x30.png");
- ALLEGRO_FONT* font = al_load_font("Rastas.ttf", 25, 0);
- ALLEGRO_TIMER* timer = al_create_timer(1.0 / FPS);
- ALLEGRO_EVENT_QUEUE * event_queue = al_create_event_queue();
- al_register_event_source(event_queue, al_get_keyboard_event_source());
- al_register_event_source(event_queue, al_get_timer_event_source(timer));
- al_register_event_source(event_queue, al_get_display_event_source(display));
- ALLEGRO_BITMAP * buttonUP = al_load_bitmap("buttonUP_50x50.png");
- ALLEGRO_BITMAP * buttonDOWN = al_load_bitmap("buttonDOWN_50x50.png");
- ALLEGRO_BITMAP * buttonLEFT = al_load_bitmap("buttonLEFT_50x50.png");
- ALLEGRO_BITMAP * buttonRIGHT = al_load_bitmap("buttonRIGHT_50x50.png");
- ALLEGRO_BITMAP * buttonQ = al_load_bitmap("buttonQ_50x50.png");
- ALLEGRO_BITMAP * buttonR = al_load_bitmap("buttonR_50x50.png");
- ALLEGRO_BITMAP * buttonESC = al_load_bitmap("buttonESC_50x50.png");
- ALLEGRO_BITMAP * buttonSPACEBAR = al_load_bitmap("buttonSPACEBAR_105x50.png");
- ALLEGRO_BITMAP * buttonBACKSPACE = al_load_bitmap("buttonBACKSPACE_105x50.png");
- al_play_sample(sample, 1, 0, 1, ALLEGRO_PLAYMODE_LOOP, NULL);
- al_start_timer(timer);
- while (!done)
- {
- ALLEGRO_EVENT event;
- al_wait_for_event(event_queue, &event);
- al_get_keyboard_state(&keystate);
- p = initHighscore();
- while (mainMeniu)
- {
- ALLEGRO_EVENT event;
- al_wait_for_event(event_queue, &event);
- al_get_keyboard_state(&keystate);
- if (al_key_down(&keystate, ALLEGRO_KEY_ENTER))
- {
- switch (arowY)
- {
- case 350:
- mainMeniu = false;
- break;
- case 450:
- optionsBool = true;
- redrawOptions = true;
- while (optionsBool)
- {
- ALLEGRO_EVENT event;
- al_wait_for_event(event_queue, &event);
- al_get_keyboard_state(&keystate);
- if (al_key_down(&keystate, ALLEGRO_KEY_Q))
- {
- optionsBool = false;
- arowY = 350;
- }
- redrawOptions = true;
- if (redrawOptions && al_is_event_queue_empty(event_queue)) {
- redrawOptions = false;
- al_draw_textf(font, al_map_rgb(255, 255, 255), 500, 50, 0, "Controls");
- al_draw_textf(font, al_map_rgb(0, 191, 255), 500, 100, 0, "Move up ");
- al_draw_bitmap(buttonUP, 900, 100, 0);
- al_draw_textf(font, al_map_rgb(0, 191, 255), 500, 200, 0, "Move down");
- al_draw_bitmap(buttonDOWN, 900, 200, 0);
- al_draw_textf(font, al_map_rgb(0, 191, 255), 500, 300, 0, "Move right ");
- al_draw_bitmap(buttonRIGHT, 900, 300, 0);
- al_draw_textf(font, al_map_rgb(0, 191, 255), 500, 400, 0, "Move left ");
- al_draw_bitmap(buttonLEFT, 900, 400, 0);
- al_draw_textf(font, al_map_rgb(139, 0, 0), 500, 800, 0, "Shoot ");
- al_draw_bitmap(buttonSPACEBAR, 900, 800, 0);
- al_draw_textf(font, al_map_rgb(139, 0, 0), 500, 700, 0, "Reload weapon ");
- al_draw_bitmap(buttonR, 900, 700, 0);
- al_draw_textf(font, al_map_rgb(0, 128, 0), 500, 500, 0, "Back to main menu ");
- al_draw_bitmap(buttonQ, 900, 500, 0);
- al_draw_textf(font, al_map_rgb(0, 128, 0), 500, 600, 0, "Quit the game ");
- al_draw_bitmap(buttonESC, 900, 600, 0);
- al_flip_display();
- al_clear_to_color(al_map_rgb(0, 0, 0));
- }
- }
- break;
- case 550:
- highscoreBool = true;
- redrawHigh = true;
- while (highscoreBool)
- {
- ALLEGRO_EVENT event;
- al_wait_for_event(event_queue, &event);
- al_get_keyboard_state(&keystate);
- if (al_key_down(&keystate, ALLEGRO_KEY_Q))
- {
- highscoreBool = false;
- arowY = 350;
- }
- redrawHigh = true;
- if (redrawHigh && al_is_event_queue_empty(event_queue)) {
- redrawHigh = false;
- //drawHighScore(p, font);
- //al_draw_textf(font, al_map_rgb(0, 0, 255), width / 2, 100, 0, "JJ : 1500 ");
- //al_draw_textf(font, al_map_rgb(0, 0, 255), width / 2, 150, 0, "Kitas plat :500");
- //al_draw_textf(font, al_map_rgb(0, 0, 255), width / 2, 200, 0, "kkk 12");
- //al_draw_textf(font, al_map_rgb(0, 0, 255), width / 2, 400, 0, "%d",p[0]);
- al_flip_display();
- al_clear_to_color(al_map_rgb(0, 0, 0));
- }
- }
- break;
- // code to be executed if n is equal to constant2;
- case 650:
- dudeBool = true;
- redrawDude = true;
- while (dudeBool)
- {
- ALLEGRO_EVENT event;
- al_wait_for_event(event_queue, &event);
- al_get_keyboard_state(&keystate);
- if (al_key_down(&keystate, ALLEGRO_KEY_Q))
- {
- dudeBool = false;
- arowY = 350;
- }
- redrawDude = true;
- if (redrawDude && al_is_event_queue_empty(event_queue)) {
- redrawDude = false;
- al_draw_textf(font, al_map_rgb(0, 191, 255), 500, 200, 0, "1 Zmogeliukas ");
- al_draw_bitmap(character_1, 500, 250, 0);
- al_draw_textf(font, al_map_rgb(0, 191, 255), 500, 600, 0, "2 Zmogeliukas ");
- al_draw_bitmap(character_2, 500, 650, 0);
- al_flip_display();
- al_clear_to_color(al_map_rgb(0, 0, 0));
- al_draw_bitmap(arrow, arowX, arowY, 0);
- }
- if (al_key_down(&keystate, ALLEGRO_KEY_DOWN)) {
- arowY += 400;
- al_rest(0.2);
- }
- if (al_key_down(&keystate, ALLEGRO_KEY_UP)) {
- arowY -= 400;
- al_rest(0.2);
- }
- if (al_key_down(&keystate, ALLEGRO_KEY_ENTER))
- {
- switch (arowY)
- {
- case 250:
- character = al_load_bitmap("bicas60x60.png");
- break;
- case 650:
- character = al_load_bitmap("bicas_2_60x60.png");
- break;
- }
- }
- }
- break;
- case 750:
- instructionBool = true;
- redrawInstruction = true;
- while (instructionBool)
- {
- ALLEGRO_EVENT event;
- al_wait_for_event(event_queue, &event);
- al_get_keyboard_state(&keystate);
- if (al_key_down(&keystate, ALLEGRO_KEY_Q))
- {
- instructionBool = false;
- arowY = 350;
- }
- redrawInstruction = true;
- if (redrawInstruction && al_is_event_queue_empty(event_queue)) {
- redrawInstruction = false;
- al_draw_textf(font, al_map_rgb(0, 191, 255), 300, 300, 0, "Shoot the target");
- al_draw_textf(font, al_map_rgb(0, 191, 255), 300, 350, 0, "Try to hit as many bullets as you can");
- al_draw_textf(font, al_map_rgb(0, 191, 255), 300, 400, 0, "Avoid enemy bullets");
- al_draw_textf(font, al_map_rgb(0, 191, 255), 300, 450, 0, "Complete all levels as possible faster");
- al_draw_textf(font, al_map_rgb(0, 0, 255), 900, 200, 0, " Bullet count is written in bottom left corner");
- al_draw_textf(font, al_map_rgb(0, 0, 255), 900, 250, 0, "Your score is written in bottom at middle");
- al_draw_textf(font, al_map_rgb(0, 0, 255), 900, 300, 0, "Timer is written in Top left corner");
- al_draw_bitmap(character_2, 900, 400, 0);
- al_draw_bitmap(target, 1300, 400, 0);
- al_draw_filled_circle(970, 420, 2, al_map_rgb(255, 0, 0));
- al_draw_filled_circle(1000, 420, 2, al_map_rgb(255, 0, 0));
- al_draw_filled_circle(1030, 420, 2, al_map_rgb(255, 0, 0));
- al_draw_filled_circle(1060, 420, 2, al_map_rgb(255, 0, 0));
- al_draw_filled_circle(1090, 420, 2, al_map_rgb(255, 0, 0));
- al_draw_filled_circle(1120, 420, 2, al_map_rgb(255, 0, 0));
- al_draw_filled_circle(1150, 420, 2, al_map_rgb(255, 0, 0));
- al_draw_filled_circle(1180, 420, 2, al_map_rgb(255, 0, 0));
- al_draw_filled_circle(1210, 420, 2, al_map_rgb(255, 0, 0));
- al_draw_filled_circle(1240, 420, 2, al_map_rgb(255, 0, 0));
- al_draw_filled_circle(1270, 420, 2, al_map_rgb(255, 0, 0));
- al_flip_display();
- al_clear_to_color(al_map_rgb(0, 0, 0));
- }
- }
- break;
- }
- }
- if (al_key_down(&keystate, ALLEGRO_KEY_DOWN)) {
- arowY += 100;
- al_rest(0.2);
- }
- if (al_key_down(&keystate, ALLEGRO_KEY_UP)) {
- arowY -= 100;
- al_rest(0.2);
- }
- redraw = true;
- if (redraw && al_is_event_queue_empty(event_queue)) {
- redraw = false;
- al_draw_textf(font, al_map_rgb(0, 255, 0), 500, 350, 0, "Pres enter to start a game");
- al_draw_textf(font, al_map_rgb(0, 255, 0), 500, 450, 0, "Options");
- al_draw_textf(font, al_map_rgb(0, 255, 0), 500, 550, 0, "Highscore");
- al_draw_textf(font, al_map_rgb(0, 255, 0), 500, 650, 0, "Select character");
- al_draw_textf(font, al_map_rgb(0, 255, 0), 500, 750, 0, "Instructions");
- al_draw_bitmap(arrow, arowX, arowY, 0);
- al_flip_display();
- al_clear_to_color(al_map_rgb(0, 0, 0));
- }
- }
- if (al_key_down(&keystate, ALLEGRO_KEY_ESCAPE)) //Galima rasyti if be {} jei TIK VIENA EILUTE VYKDYMO
- done = true;
- else if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
- done = true;
- else if (event.type == ALLEGRO_EVENT_TIMER)
- {
- updateBullet(bullet, NUM_BULLETS, player);
- updateBullet(enemBullet, NUM_BULLETS_ENEMY1, player);
- delayReload(&reloadBool);
- switch (screenPosition)
- {
- case 0:
- updateEnemy(enemy, NUM_ENEMY, bullet, NUM_BULLETS, player); //Udatina kai nk nepaspausta
- break;
- case 1:
- updateEnemy(enemy1, NUM_ENEMY_1, bullet, NUM_BULLETS, player);
- break;
- default:
- updateEnemy(enemy, NUM_ENEMY, bullet, NUM_BULLETS, player); //Udatina kai nk nepaspausta
- break;
- }
- active = true; //AR naudoju?
- if (al_key_down(&keystate, ALLEGRO_KEY_UP)) //SU SWITCH CASE GALIMA PADARYTI
- moveUp(&player);
- if (al_key_down(&keystate, ALLEGRO_KEY_DOWN))
- moveDown(player);
- if (al_key_down(&keystate, ALLEGRO_KEY_RIGHT))
- moveRight(player);
- if (al_key_down(&keystate, ALLEGRO_KEY_LEFT))
- moveLeft(player);
- if (al_key_down(&keystate, ALLEGRO_KEY_SPACE) && bulletCount > 0) //Tikrina ar space paspausta ir ar kulku yra
- {
- fireBullet(bullet, NUM_BULLETS, player);
- }
- if (al_key_down(&keystate, ALLEGRO_KEY_R)) // PADARYTI KAD LAIKAS PRAEITU
- {
- reloadBool = true;
- }
- else
- {
- active = false; //LYG NENAUDOJU
- }
- draw = true;
- updateBullet(bullet, NUM_BULLETS, player);
- updateBullet(enemBullet, NUM_BULLETS_ENEMY1, player);
- updatePowerUp(&player, &powerUpBool);
- switch (screenPosition)
- {
- case 0:
- updateEnemy(enemy, NUM_ENEMY, bullet, NUM_BULLETS, player); //Udatina kai kazkas paspausta
- break;
- case 1:
- updateEnemy(enemy1, NUM_ENEMY_1, bullet, NUM_BULLETS, player);
- fireEnemyBullet(enemBullet, NUM_BULLETS_ENEMY1, enemy1, NUM_ENEMY_1);
- break;
- default: //AR REIKIA DEFAULTO?????
- updateEnemy(enemy, NUM_ENEMY, bullet, NUM_BULLETS, player); //Udatina kai kazkas paspausta
- break;
- }
- }
- if (draw && al_is_event_queue_empty(event_queue))
- {
- draw = false;
- al_draw_bitmap(character, player.x, player.y, 0);
- switch (screenPosition) //JAUCIU GALIMA PAKEISTI PDARIUS ENYMY MASYVA DIDESNI KAD NEREIKTU SWITCH CASO
- {
- case 0:
- drawEnemy(enemy, NUM_ENEMY, target);
- break;
- case 1:
- drawEnemy(enemy1, NUM_ENEMY_1, mushroom);
- drawBullet(enemBullet, NUM_BULLETS_ENEMY1);
- break;
- default:
- drawEnemy(enemy, NUM_ENEMY, target);
- break;
- }
- drawBullet(bullet, NUM_BULLETS);
- drawPowerUp(timeCount, powerUpBool, healthPotion);
- al_draw_textf(font, al_map_rgb(44, 117, 255), 10, 800, 0, "Bullets: %d", bulletCount); //Kulku skaiciu
- al_draw_textf(font, al_map_rgb(255, 0, 0), 200, 800, 0, "Score: %d", player.score); //Scora
- al_draw_textf(font, al_map_rgb(0, 100, 0), 350, 800, 0, "Lives %d", player.lives); //REIKIAPADARYTI KAD KAI MAZAI GYVYBIU RAUDONETU SPAVLA
- al_draw_textf(font, al_map_rgb(0, 255, 0), 400, 100, 0, "BOOOL %d", reloadBool);
- if (reloadBool)
- al_draw_textf(font, al_map_rgb(0, 255, 0), 10, 850, 0, "RELOADING");
- //al_draw_textf(font, al_map_rgb(255, 117, 255), 400, 800, 0, "Priesu: %d", NUM_ENEMY); //bandom
- //al_draw_textf(font, al_map_rgb(255, 117, 255), 400, 600, 0, "Priesu y: %d", enemy[0].y); //bandom
- //al_draw_textf(font, al_map_rgb(255, 117, 255), 400, 400, 0, "Screen: %d", screenPosition); //bandom
- //--------------------------------------------------------------------//
- timeCount--;
- al_draw_textf(font, al_map_rgb(255, 0, 255), 400, 50, 0, "Time left: %d", (timeCount / 60 + 1)); //bandom
- if (timeCount == 0) {
- writeHighScore(player);
- done = true;
- };
- //--------------------------------------------------------------------//
- al_flip_display();
- al_clear_to_color(al_map_rgb(255, 255, 255));
- updateScreen(player, screenPosition);
- }
- }
- al_destroy_sample(sample);
- al_destroy_sample(judesys);
- al_destroy_display(display);
- al_uninstall_keyboard();
- al_destroy_bitmap(character);
- al_destroy_bitmap(target);
- al_destroy_bitmap(arrow);
- al_destroy_bitmap(healthPotion);
- al_destroy_font(font);
- al_destroy_timer(timer);
- al_destroy_event_queue(event_queue);
- return 0;
- }
- void initPlayer(Player *player)
- {
- //foo->bar is equivalent to(*foo).bar, i.e.it gets the member called bar from the struct that foo points to.
- player->x = 10;
- player->y = 10;
- player->ID = PLAYER;
- player->lives = 100;
- player->speed = 5;
- player->score = 0;
- }
- void initEnemy(const char* file_name, Enemy enemy[], int size) //Padaryt kad is failo
- {
- FILE* file = fopen(file_name, "r");
- int count_enem;
- fscanf(file, "%d", &count_enem);
- int i = 0;
- for (i; i < count_enem; i++)
- {
- fscanf(file, "%d", &enemy[i].x);
- fscanf(file, "%d", &enemy[i].y);
- fscanf(file, "%d", &enemy[i].lives);
- fscanf(file, "%f", &enemy[i].speed);
- fscanf(file, "%d", &enemy[i].alive);
- fscanf(file, "%d", &enemy[i].sizeX);
- fscanf(file, "%d", &enemy[i].sizeY);
- }
- fclose(file);
- }
- void moveUp(Player *player)
- {
- player->y -= player->speed;
- dir = UP; //TAI AR REIKIA TOKIO VISUOSE VOID JUDESIO????
- }
- void moveDown(Player &player)
- {
- player.y += player.speed;
- dir = DOWN;
- }
- void moveLeft(Player &player)
- {
- player.x -= player.speed;
- dir = LEFT;
- }
- void moveRight(Player &player)
- {
- player.x += player.speed;
- dir = RIGHT;
- }
- void initBullet(Bullet bullet[], int size)
- {
- int i = 0;
- for (i; i < size; i++)
- {
- bullet[i].ID = BULLET; //NX reikia???
- bullet[i].speed = 3.5;
- bullet[i].live = false;
- bullet[i].radius = 2;
- }
- }
- void initEnemyBullet(Bullet bullet[], int size)
- {
- int i;
- for ( i = 0; i < size; i++)
- {
- bullet[i].ID = ENEMY;
- bullet[i].speed = 1.5;
- bullet[i].live = false;
- bullet[i].radius = 4;
- }
- }
- void drawBullet(Bullet bullet[], int size)
- {
- int i = 0;
- for (i; i < size; i++)
- {
- if (bullet[i].live)
- {
- al_draw_filled_circle(bullet[i].x, bullet[i].y, bullet[i].radius, al_map_rgb(255, 0, 0));
- }
- }
- }
- void drawEnemy(Enemy enemy[], int size, ALLEGRO_BITMAP *picture) {
- int i = 0;
- for (i = 0; i < size; i++)
- {
- if (enemy[i].alive)
- {
- al_draw_bitmap(picture, enemy[i].x, enemy[i].y, 0);
- }
- }
- }
- void updateEnemy(Enemy enemy[], int size, Bullet bullet[], int bulletSize, Player &player) { //GALIMA SUTRUMPTINTI KAD NECEKINTU TU KUR NERA GYVI PRIESAI (KAI ENEMY.ALIVE=0)
- int i = 0;
- for (i; i < size; i++)
- {
- int j = 0;
- for (j; j < bulletSize; j++)
- {
- if (bullet[j].x > enemy[i].x && bullet[j].x < (enemy[i].x + 5) && bullet[j].y > enemy[i].y && bullet[j].y < (enemy[i].y + enemy[i].sizeY) && enemy[i].alive)
- {
- enemy[i].lives--;
- player.score++;
- bullet[j].live = false;
- bullet[j].x = 0;
- bullet[j].y = 0;
- }
- }
- if (enemy[i].lives <= 0)
- {
- enemy[i].alive = 0;
- }
- }
- }
- void fireBullet(Bullet bullet[], int size, Player &player)
- {
- int i = 0;
- for (i; i < size; i++)
- {
- if (!bullet[i].live)
- {
- --bulletCount;
- bullet[i].x = player.x + 35; //Kad atrodytu lyg is sautuvo saudo
- bullet[i].y = player.y + 20;
- bullet[i].live = true;
- break;
- }
- }
- }
- void fireEnemyBullet(Bullet bullet[], int size, Enemy enemy[], int sizeEnemy) {
- int i;
- for (i = 0; i < size; i++)
- {
- if (!bullet[i].live) {
- int j;
- for (j = 0; j < sizeEnemy; j++)
- {
- if (rand() % 5000 == 0 && enemy[j].alive)
- {
- bullet[i].live = true;
- bullet[i].x = enemy[j].x;
- bullet[i].y = enemy[j].y+35; // CIA REIKIA PAKEISTI KAD IVAIRIEM PRIESAM TIKTU FUMKCIJA!!!
- break;
- }
- }
- }
- }
- }
- void updateBullet(Bullet bullet[], int size, Player &player)
- {
- int i = 0;
- for (i; i < size; i++)
- {
- /*if (bullet[i].x > 1400 && bullet[i].x < 1405 && bullet[i].y >200 && bullet[i].y < 250 ||
- bullet[i].x > 1400 && bullet[i].x < 1450 && bullet[i].y >400 && bullet[i].y < 450 ||
- bullet[i].x > 1400 && bullet[i].x < 1450 && bullet[i].y >600 && bullet[i].y < 650) { //Galima graziau surasytiGAL I NAUJA VOIDA SUDETI?!!
- player.score++; //Geriau nauja voida sukur update playeriui tipo arba bent scorui
- bullet[i].live = false;
- bullet[i].x = 0;
- bullet[i].y = 0;
- }
- */
- if (bullet[i].live)
- {
- if(bullet[i].ID ==1)
- bullet[i].x += bullet[i].speed;
- else if (bullet[i].ID == 2) {
- bullet[i].x -= bullet[i].speed;
- if ((bullet[i].x>=player.x && bullet[i].x + ) && bullet[i].y==player.y) //TAISYTI KAD I VISA KUNA PATAIKYTU
- {
- player.lives--;
- bullet[i].live = false;
- al_play_sample(judesys, 1, 0, 1, ALLEGRO_PLAYMODE_ONCE, NULL);
- }
- }
- if (bullet[i].x > width || bullet[i].x < 0)
- {
- bullet[i].live = false;
- }
- }
- }
- }
- void updateScreen(Player &player, int &screenNumb) { //SU STITH CASU PERDARYT
- if (player.score >= 150)
- {
- screenNumb = 1;
- }
- }
- void writeHighScore(Player &player) {
- //Atidarom faila
- FILE *failas = fopen("high.txt", "r");
- //ziurim ar ji egsistuoja, jei ne exitina
- if (failas == NULL)
- {
- printf("Error opening file!\n");
- exit(1);
- }
- // sukuriam penkiu nariu rezultatu masyva
- int results[5], i;
- //I masyva sudedam narius
- for (i = 0; i < 5; i++)
- {
- fscanf(failas, "%d", &results[i]);
- }
- //Ziurima ar esamas scoras didesnis paskutini buvusi, jei taip tada naujas scoras rasomas i 5 masyvo vieta
- if (player.score > results[4]) {
- results[4] = player.score;
- }
- //TADA REIKIA SURIKIUOI MASYVA results[5] didejimo tvarka
- for (i = 4; i >0; i--)
- {
- if (results[i] > results[i - 1]) {
- int a= results[i - 1];
- results[i - 1] = results[i];
- results[i] = a;
- }
- }
- //
- //uzdarom faila
- fclose(failas);
- //Atidarome rasymui (Taip yra istrinami visi buve elementai)
- failas = fopen("high.txt", "w");
- if (failas == NULL)
- {
- printf("Error opening file!\n");
- exit(1);
- }
- //Surasomi i faila elementai
- for (i = 0; i < 5; i++)
- {
- fprintf(failas, "%d\n", results[i]);
- }
- fclose(failas);
- }
- void delayReload(bool *reload) {
- if (*reload) {
- reloadTime--;
- if (reloadTime == 0) {
- *reload = false;
- bulletCount = NUM_BULLETS;
- reloadTime = 60;
- }
- }
- }
- void drawPowerUp(int time, bool notUsed, ALLEGRO_BITMAP *picture) {
- if (time <8000 && notUsed)
- {
- al_draw_bitmap(picture, 500, 500, 0);
- }
- }
- void updatePowerUp(Player *player, bool *notUsed) {
- if (player->x==500 && player->y ==500) {
- *notUsed = false;
- player->lives += 15;
- }
- }
- int *initHighscore() {
- //Atidarom faila
- FILE* failas = fopen("high.txt", "r");
- //ziurim ar ji egsistuoja, jei ne exitina
- if (failas == NULL)
- {
- printf("Error opening file!\n");
- exit(1);
- }
- // sukuriam penkiu nariu rezultatu masyva
- static int results[5], i;
- //I masyva sudedam narius
- for (i = 0; i < 5; i++)
- {
- fscanf(failas, "%d", &results[i]);
- }
- return results;
- }
- //void drawHighScore(int *a, ALLEGRO_FONT *font){
- //int i, aukstis=0;
- //int *variable;
- //for ( i = 0; i < 5; i++)
- //{
- // variable = a[i];
- // al_draw_textf(font, al_map_rgb(0, 0, 255), width / 2, aukstis, "%d", variable);
- // aukstis += 100;
- //}
- // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
- // Debug program: F5 or Debug > Start Debugging menu
- // Tips for Getting Started:
- // 1. Use the Solution Explorer window to add/manage files
- // 2. Use the Team Explorer window to connect to source control
- // 3. Use the Output window to see build output and other messages
- // 4. Use the Error List window to view errors
- // 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
- // 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement