错误:断言失败allegro5 \ addons \ font \ text.c第77行表达式字体

问题描述 投票:1回答:1

有没有人知道我怎么能解决这个错误,我有正确的ttf文件,所以我不明白为什么我在调试时得到这个错误这里是我的所有代码下面我真的不知道从哪里开始这个问题

#include <iostream>
#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 "Galaxy Quest Source\\globals.h"
#include "Galaxy Quest Source\\buttons.h"
#include "Galaxy Quest Source\\screenState.h"
#include "Galaxy Quest Source\\nebulaBig.h"
#include "Galaxy Quest Source\\tutorialShoot.h"
#include "Galaxy Quest Source\\player.h"
#include "Galaxy Quest Source\\bullets.h"
#include "Galaxy Quest Source\\bulletEnemy.h"
#include "Galaxy Quest Source\\cometBig.h"
#include "Galaxy Quest Source\\cometSmall.h"
#include "Galaxy Quest Source\\healthup.h"
#include "Galaxy Quest Source\\enemyShipNormal.h"
#include "Galaxy Quest Source\\backgroundAnim.h"

int main(int argc, char **argv) {

    /*SHELL VARIABLES*/
    unsigned short addonCheck = 0;
    unsigned long animCounter = 0;

    bool running = false;
    bool rendering = false;

    int gameFPS = 0;
    int frames = 0;
    float gameTime = 0;
    int seconds = 0;
    int minutes = 0;
    int framesElapsed = 0;

    NebulaBig nebulaBigC;
    TutorialShoot tutorialShootC;

    Buttons *bPlay = new Buttons();
    Buttons *bHelp = new Buttons();
    Buttons *bOptn = new Buttons();
    Buttons *bBack = new Buttons();
    Buttons *bExit = new Buttons();
    Buttons *bMenu = new Buttons();
    Buttons *bExit2 = new Buttons();
    Buttons *bVolumeP = new Buttons();
    Buttons *bVolumeM = new Buttons();
    Buttons *bDifficultyP = new Buttons();
    Buttons *bDifficultyM = new Buttons();

    Bullet bullets[20];
    //BulletEnemy bulletEnemy[20];

    CometBig cometsBig[20];
    CometSmall cometsSmall[20];
    HealthUp healthUp[1];

    EnemyShip enemyShip[1];

    Player ship;

    GameBackground bgStars;
    GameBackground bgNebulas;

    /*INITIALIZE ALLEGRO 5*/
    al_init();
    if (!al_init()) {
        al_show_native_message_box(0, "ERROR", "Failed to initialize Allegro 5!", "Press OK to terminate.", 0, ALLEGRO_MESSAGEBOX_ERROR);
        return -1;
    }

    /*ALLEGRO VARIABLES*/
    ALLEGRO_DISPLAY *display = 0;
    ALLEGRO_EVENT_QUEUE *eventQueue = 0;
    ALLEGRO_TIMER *timer = 0;
    ALLEGRO_BITMAP *mouseBMP;
    ALLEGRO_FONT *mainFont, *smallFont, *titleFont, *bigFont;
    ALLEGRO_BITMAP *player, *playerDamaged, *playerLeft, *playerRight, *playerShield, *enemyNormal;
    ALLEGRO_BITMAP *cometBigBMP, *cometSmallBMP, *livesIconRotated;
    ALLEGRO_BITMAP *bulletPlayer, *bulletEnemyBMP;
    ALLEGRO_BITMAP *nebulaBig, *nebulaSmall, *nebulaVerySmall;
    ALLEGRO_BITMAP *gameScreenFast, *gameScreenNebulas, *livesIcon;
    ALLEGRO_BITMAP *tutorialShoot;
    ALLEGRO_SAMPLE *introSound;
    ALLEGRO_SAMPLE *bulletSound, *explosionSound, *healthdownSound, *healthupSound;

    /*CREATE DISPLAY*/
    al_set_new_display_flags(ALLEGRO_FULLSCREEN);
    display = al_create_display(screenW, screenH);
    if (!display) {
        al_show_native_message_box(0, "ERROR", "Failed to initialize the display!", "Press OK to terminate.", 0, ALLEGRO_MESSAGEBOX_ERROR);
        return -1;
    }

    al_hide_mouse_cursor(display);

    /*INSTALL ADDONS*/
    al_init_font_addon(); addonCheck++;
    al_init_ttf_addon(); addonCheck++;
    al_init_primitives_addon(); addonCheck++;
    al_init_image_addon(); addonCheck++;
    al_install_keyboard(); addonCheck++;
    al_install_mouse(); addonCheck++;
    al_install_audio(); addonCheck++;
    al_init_acodec_addon(); addonCheck++;
    if (addonCheck != 8) {
        al_show_native_message_box(0, "ERROR", "Failed to load Allegro addons!", "Press OK to terminate.", 0, ALLEGRO_MESSAGEBOX_ERROR);
        return -1;
    }

    /*FILE LOADING*/

    //LOADING SCREEN
    bigFont = al_load_font("HOOG0555.ttf", 55, 0);
    al_clear_to_color(al_map_rgb(0, 0, 0));
    al_draw_text(bigFont, al_map_rgb(255, 255, 255), screenW / 2.5, screenH / 2, 0, "LOADING.");
    al_flip_display();

    //LOADING IMAGES
    titleFont = al_load_font("HOOG0555.ttf", 125, 0);
    mainFont = al_load_font("HOOG0555.ttf", 35, 0);
    smallFont = al_load_font("HOOG0555.ttf", 15, 0);

    ALLEGRO_PATH *imagesP = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
    al_append_path_component(imagesP, "images");
    al_change_directory(al_path_cstr(imagesP, '/'));
    al_destroy_path(imagesP);

    mouseBMP = al_load_bitmap("mouse.png");

    player = al_load_bitmap("player.png");
    playerDamaged = al_load_bitmap("playerDamaged.png");
    playerLeft = al_load_bitmap("playerLeft.png");
    playerRight = al_load_bitmap("playerRight.png");
    playerShield = al_load_bitmap("shield.png");

    enemyNormal = al_load_bitmap("enemyShip.png");

    cometBigBMP = al_load_bitmap("meteorBig.png");
    cometSmallBMP = al_load_bitmap("meteorSmall.png");

    bulletPlayer = al_load_bitmap("laserGreen.png");
    bulletEnemyBMP = al_load_bitmap("laserRed.png");

    nebulaBig = al_load_bitmap("nebulaBig.png");
    nebulaSmall = al_load_bitmap("nebulaSmall.png");
    nebulaVerySmall = al_load_bitmap("nebulaVerySmall.png");

    gameScreenFast = al_load_bitmap("movingBGlines.png");
    al_convert_mask_to_alpha(gameScreenFast, al_map_rgb(35, 10, 55));
    gameScreenNebulas = al_load_bitmap("movingBGnebulas.png");
    al_convert_mask_to_alpha(gameScreenNebulas, al_map_rgb(35, 10, 55));
    livesIcon = al_load_bitmap("life.png");
    livesIconRotated = al_load_bitmap("life180.png");

    tutorialShoot = al_load_bitmap("tutorialShoot.png");

    al_draw_text(bigFont, al_map_rgb(255, 255, 255), screenW / 2.5, screenH / 2, 0, "LOADING..");
    al_flip_display();

    //LOADING SOUNDS
    al_reserve_samples(5);

    ALLEGRO_PATH *soundsP = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
    al_append_path_component(soundsP, "sounds");
    al_change_directory(al_path_cstr(soundsP, '/'));
    al_destroy_path(soundsP);

    introSound = al_load_sample("introSound.wav");

    bulletSound = al_load_sample("bulletSound.wav");
    explosionSound = al_load_sample("explosionSound.wav");
    healthdownSound = al_load_sample("healthdownSound.wav");
    healthupSound = al_load_sample("healthupSound.wav");

    al_draw_text(bigFont, al_map_rgb(255, 255, 255), screenW / 2.5, screenH / 2, 0, "LOADING...");
    al_flip_display();

start:
    bPlay->setHover(false);
    objectCount = 0;
    shieldTimer = 5;
    enemyFireTimer = 0;

    /*FADE-IN COUNTERS*/
    counter255r = 35;
    counter255g = 10;
    counter255b = 55;
    counter185r = 35;
    counter185g = 10;
    counter185b = 55;
    counterHelp185r = 35;
    counterHelp185g = 10;
    counterHelp185b = 55;
    counterHelp255r = 35;
    counterHelp255g = 10;
    counterHelp255b = 55;

    /*GAME OBJECT INITIALIZATION*/
    nebulaBigC.init(nebulaBig);
    tutorialShootC.init(tutorialShoot);

    bPlay->init(screenW / 2, screenH / 2 + 100, 65, 18, bigFont);
    bHelp->init(screenW / 2, screenH / 2 + 140, 65, 18, bigFont);
    bOptn->init(screenW / 2, screenH / 2 + 180, 65, 18, bigFont);
    bBack->init(screenW / 2, screenH - 80, 65, 18, bigFont);
    bExit->init(screenW / 2, screenH / 2 + 220, 65, 18, bigFont);
    bMenu->init(screenW / 2, screenH / 2 + 40, 65, 18, bigFont);
    bExit2->init(screenW / 2, screenH / 2 + 80, 65, 18, bigFont);
    bVolumeP->init(screenW / 2 + 90, screenH / 3, 18, 18, bigFont);
    bVolumeM->init(screenW / 2 - 90, screenH / 3, 18, 18, bigFont);
    bDifficultyP->init(screenW / 2 + 100, screenH / 3 + 175, 18, 18, bigFont);
    bDifficultyM->init(screenW / 2 - 100, screenH / 3 + 175, 18, 18, bigFont);

    initBullet(bullets, bulletPlayer, bulletSound, explosionSound);
    bulletEnemy->init(bulletEnemy, bulletEnemyBMP, bulletSound, explosionSound, healthdownSound);

    initCometBig(cometsBig, cometBigBMP, healthdownSound);
    initCometSmall(cometsSmall, cometSmallBMP, healthdownSound);
    healthUp->init(healthUp, livesIconRotated, healthupSound);

    enemyShip->init(enemyShip, enemyNormal, explosionSound);

    ship.init(player, playerLeft, playerRight, playerDamaged, playerShield, livesIcon);

    bgStars.init(gameScreenFast, 6, 1);
    bgNebulas.init(gameScreenNebulas, 2, 2);

    /*EQ, TIMER AND REGISTER SOURCES*/
    eventQueue = al_create_event_queue();
    timer = al_create_timer(1.0 / 120);

    al_register_event_source(eventQueue, al_get_timer_event_source(timer));
    al_register_event_source(eventQueue, al_get_display_event_source(display));
    al_register_event_source(eventQueue, al_get_mouse_event_source());
    al_register_event_source(eventQueue, al_get_keyboard_event_source());

    /*FINAL PREPERATIONS, START TIMER*/
    running = true;
    ScreenStateC *screenStateC = new ScreenStateC();
    screenStateC->setToState(1);

    srand(time(NULL));

    al_start_timer(timer);
    gameTime = al_current_time();
    al_play_sample(introSound, volume, ALLEGRO_AUDIO_PAN_NONE, 1.0, ALLEGRO_PLAYMODE_ONCE, 0);

    while (running) {
        if (screenState[TITLESCREEN] && !screenState[GAMESCREEN]) {
            ALLEGRO_EVENT titleEvent;
            al_wait_for_event(eventQueue, &titleEvent);

            if (titleEvent.type == ALLEGRO_EVENT_MOUSE_AXES) {
                mouseX = titleEvent.mouse.x;
                mouseY = titleEvent.mouse.y;
            }

            if (titleEvent.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) {
                if (!screenState[HELPSCREEN] && !screenState[OPTIONSCREEN] && !screenState[GAMESCREEN]) {
                    if (bPlay->getHover()) {
                        if (titleEvent.mouse.button & 1) {
                            screenStateC->setToState(2);
                        }
                    }
                    if (bHelp->getHover()) {
                        if (titleEvent.mouse.button & 1) {
                            screenStateC->setToState(3);
                        }
                    }
                    if (bOptn->getHover()) {
                        if (titleEvent.mouse.button & 1) {
                            screenStateC->setToState(4);
                        }
                    }
                    if (bExit->getHover()) {
                        if (titleEvent.mouse.button & 1) {
                            screenState[TITLESCREEN] = false;
                            running = false;
                        }
                    }
                }
                else if (screenState[HELPSCREEN]) {
                    if (bBack->getHover() & 1) {
                        screenStateC->setToState(1);
                    }
                }
                else if (screenState[OPTIONSCREEN]) {
                    if (bBack->getHover() & 1) {
                        screenStateC->setToState(1);
                    }
                    if (bVolumeP->getHover() & 1) {
                        if (volume == 0.0) {
                            volume = 0.2;
                        }
                        else if (volume == 0.2) {
                            volume = 0.4;
                        }
                        else if (volume == 0.4) {
                            volume = 0.6;
                        }
                        else if (volume == 0.6) {
                            volume = 0.8;
                        }
                        else if (volume == 0.8) {
                            volume = 1.0;
                        }
                    }
                    if (bVolumeM->getHover() & 1) {
                        if (volume == 0.2) {
                            volume = 0.0;
                        }
                        else if (volume == 0.4) {
                            volume = 0.2;
                        }
                        else if (volume == 0.6) {
                            volume = 0.4;
                        }
                        else if (volume == 0.8) {
                            volume = 0.6;
                        }
                        else if (volume == 1.0) {
                            volume = 0.8;
                        }
                    }
                    if (bDifficultyP->getHover() & 1) {
                        if (difficulty[EASY]) {
                            difficulty[EASY] = false;
                            difficulty[NORM] = true;
                            difficulty[HARD] = false;
                        }
                        else if (difficulty[NORM]) {
                            difficulty[EASY] = false;
                            difficulty[NORM] = false;
                            difficulty[HARD] = true;
                        }
                    }
                    if (bDifficultyM->getHover() & 1) {
                        if (difficulty[NORM]) {
                            difficulty[EASY] = true;
                            difficulty[NORM] = false;
                            difficulty[HARD] = false;
                        }
                        else if (difficulty[HARD]) {
                            difficulty[EASY] = false;
                            difficulty[NORM] = true;
                            difficulty[HARD] = false;
                        }
                    }
                }
            }

            if (titleEvent.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
                running = false;
            }

            if (titleEvent.type == ALLEGRO_EVENT_KEY_UP) {
                switch (titleEvent.keyboard.keycode) {
                case ALLEGRO_KEY_F3:
                    if (keys[F3])
                        keys[F3] = false;
                    else if (!keys[F3])
                        keys[F3] = true;
                    break;
                }
            }

            if (titleEvent.type == ALLEGRO_EVENT_TIMER) {
                rendering = true;

                if (screenState[HELPSCREEN]) {
                    tutorialShootC.update();

                    if (tutorialShootC.getFinal()) {
                        if (counterHelp185r < 185)
                            counterHelp185r++;
                        if (counterHelp185g < 185)
                            counterHelp185g++;
                        if (counterHelp185b < 185)
                            counterHelp185b++;

                        if (counterHelp255r < 255)
                            counterHelp255r++;
                        if (counterHelp255g < 255)
                            counterHelp255g++;
                        if (counterHelp255b < 255)
                            counterHelp255b++;
                    }
                }

                if (nebulaBigC.getFinal()) {
                    if (counter185r < 185)
                        counter185r++;
                    if (counter185g < 185)
                        counter185g++;
                    if (counter185b < 185)
                        counter185b++;

                    if (counter255r < 255)
                        counter255r++;
                    if (counter255g < 255)
                        counter255g++;
                    if (counter255b < 255)
                        counter255b++;

                    if (counter255g == 254);
                    bPlay->hoverDetect();
                    bHelp->hoverDetect();
                    bOptn->hoverDetect();
                    bBack->hoverDetect();
                    bExit->hoverDetect();
                    bVolumeP->hoverDetect();
                    bVolumeM->hoverDetect();
                    bDifficultyP->hoverDetect();
                    bDifficultyM->hoverDetect();
                }

                nebulaBigC.update();

                framesElapsed++;
                seconds = framesElapsed / 120;

                if (seconds >= 60) {
                    minutes++;
                    seconds = 0;
                    framesElapsed = 0;
                }

                frames++;
                if (al_current_time() - gameTime >= 1) {
                    gameTime = al_current_time();
                    gameFPS = frames;
                    frames = 0;
                }
            }

            if (rendering && al_is_event_queue_empty(eventQueue)) {
                rendering = false;

                al_clear_to_color(al_map_rgb(35, 10, 55));

                if (!screenState[HELPSCREEN] && !screenState[OPTIONSCREEN]) {
                    nebulaBigC.render();

                    al_draw_text(titleFont, al_map_rgb(counter255r, counter255g, counter255b), screenW / 2 - 30, screenH / 7 + 20, 1, "GALAXY");
                    al_draw_text(titleFont, al_map_rgb(counter255r, counter255g, counter255b), screenW / 2, screenH / 4 + 50, 1, "QUEST");
                    al_draw_text(smallFont, al_map_rgb(counter255r, counter255g, counter255b), screenW / 2, screenH / 1.05, ALLEGRO_ALIGN_CENTRE, author);
                    al_draw_text(smallFont, al_map_rgb(counter255r, counter255g, counter255b), screenW / 1.56, screenH / 3 + 54, 1, version);

                    /*DEBUG MODE*/
                    if (keys[F3]) {
                        al_draw_textf(smallFont, al_map_rgb(0, 255, 0), 5, 5, ALLEGRO_ALIGN_LEFT, "FPS: %i", gameFPS);
                        al_draw_textf(smallFont, al_map_rgb(0, 255, 0), 5, 17, ALLEGRO_ALIGN_LEFT, "Time: %i min, %i sec", minutes, seconds);
                        al_draw_textf(smallFont, al_map_rgb(0, 255, 0), 5, 29, ALLEGRO_ALIGN_LEFT, "Frames: %i", framesElapsed);
                        al_draw_textf(smallFont, al_map_rgb(0, 255, 0), 5, 41, ALLEGRO_ALIGN_LEFT, "Mouse X: %i", mouseX);
                        al_draw_textf(smallFont, al_map_rgb(0, 255, 0), 5, 53, ALLEGRO_ALIGN_LEFT, "Mouse Y: %i", mouseY);
                        al_draw_filled_rectangle(bPlay->getX() - bPlay->getBoundX(), bPlay->getY(), bPlay->getX() + bPlay->getBoundX(), bPlay->getY() + bPlay->getBoundY() * 2, al_map_rgb(0, 255, 20));
                        al_draw_filled_rectangle(bHelp->getX() - bHelp->getBoundX(), bHelp->getY(), bHelp->getX() + bHelp->getBoundX(), bHelp->getY() + bHelp->getBoundY() * 2, al_map_rgb(0, 255, 20));
                        al_draw_filled_rectangle(bOptn->getX() - bOptn->getBoundX(), bOptn->getY(), bOptn->getX() + bOptn->getBoundX(), bOptn->getY() + bOptn->getBoundY() * 2, al_map_rgb(0, 255, 20));
                        al_draw_filled_rectangle(bExit->getX() - bExit->getBoundX(), bExit->getY(), bExit->getX() + bExit->getBoundX(), bExit->getY() + bExit->getBoundY() * 2, al_map_rgb(0, 255, 20));
                    }

                    bPlay->render(1);
                    bHelp->render(2);
                    bOptn->render(3);
                    bExit->render(5);
                }
                else if (screenState[HELPSCREEN] && !screenState[OPTIONSCREEN]) {
                    tutorialShootC.render();

                    al_draw_text(bigFont, al_map_rgb(counterHelp255r, counterHelp255g, counterHelp255b), screenW / 5, 40, 0, "BASICS");
                    al_draw_text(mainFont, al_map_rgb(counterHelp185r, counterHelp185g, counterHelp185b), screenW / 30, screenH / 6, 0, "Galaxy quest is a space invaders type game,");
                    al_draw_text(mainFont, al_map_rgb(counterHelp185r, counterHelp185g, counterHelp185b), screenW / 30, screenH / 6 + 35, 0, "in which the                is to get the highest");
                    al_draw_text(mainFont, al_map_rgb(counterHelp255r, counterHelp255g, counterHelp255b), screenW / 30, screenH / 6 + 35, 0, "                  objective");
                    al_draw_text(mainFont, al_map_rgb(counterHelp185r, counterHelp185g, counterHelp185b), screenW / 30, screenH / 6 + 70, 0, "possible score.           are earned by destroying");
                    al_draw_text(mainFont, al_map_rgb(counterHelp255r, counterHelp255g, counterHelp255b), screenW / 30 + 5, screenH / 6 + 70, 0, "                       Points");
                    al_draw_text(mainFont, al_map_rgb(counterHelp185r, counterHelp185g, counterHelp185b), screenW / 30, screenH / 6 + 105, 0, "comets and enemy space ships.");
                    al_draw_text(mainFont, al_map_rgb(counterHelp185r, counterHelp185g, counterHelp185b), screenW / 30, screenH / 6 + 140, 0, "Enemy commoness scales with difficulty setting.");

                    al_draw_text(bigFont, al_map_rgb(counterHelp255r, counterHelp255g, counterHelp255b), screenW / 5, screenH / 2 - 25, 0, "POWER UPS");
                    al_draw_text(mainFont, al_map_rgb(counterHelp185r, counterHelp185g, counterHelp185b), screenW / 30, screenH / 2 + 70, 0, "During the game you might pick up health power");
                    al_draw_text(mainFont, al_map_rgb(counterHelp185r, counterHelp185g, counterHelp185b), screenW / 30, screenH / 2 + 105, 0, "ups which will replenish your lives. The higher");
                    al_draw_text(mainFont, al_map_rgb(counterHelp185r, counterHelp185g, counterHelp185b), screenW / 30, screenH / 2 + 140, 0, "the difficulty, the rarer the power ups!");

                    /*DEBUG MODE*/
                    if (keys[F3]) {
                        al_draw_textf(smallFont, al_map_rgb(0, 255, 0), 5, 5, ALLEGRO_ALIGN_LEFT, "FPS: %i", gameFPS);
                        al_draw_textf(smallFont, al_map_rgb(0, 255, 0), 5, 17, ALLEGRO_ALIGN_LEFT, "Time: %i min, %i sec", minutes, seconds);
                        al_draw_textf(smallFont, al_map_rgb(0, 255, 0), 5, 29, ALLEGRO_ALIGN_LEFT, "Frames: %i", framesElapsed);
                        al_draw_textf(smallFont, al_map_rgb(0, 255, 0), 5, 41, ALLEGRO_ALIGN_LEFT, "Mouse X: %i", mouseX);
                        al_draw_textf(smallFont, al_map_rgb(0, 255, 0), 5, 53, ALLEGRO_ALIGN_LEFT, "Mouse Y: %i", mouseY);
                        al_draw_filled_rectangle(bBack->getX() - bBack->getBoundX(), bBack->getY(), bBack->getX() + bBack->getBoundX(), bBack->getY() + bBack->getBoundY() * 2, al_map_rgb(0, 255, 20));
                    }

                    bBack->render(4);
                }
                else if (!screenState[HELPSCREEN] && screenState[OPTIONSCREEN]) {
                    /*DEBUG MODE*/
                    if (keys[F3]) {
                        al_draw_textf(smallFont, al_map_rgb(0, 255, 0), 5, 5, ALLEGRO_ALIGN_LEFT, "FPS: %i", gameFPS);
                        al_draw_textf(smallFont, al_map_rgb(0, 255, 0), 5, 17, ALLEGRO_ALIGN_LEFT, "Time: %i min, %i sec", minutes, seconds);
                        al_draw_textf(smallFont, al_map_rgb(0, 255, 0), 5, 29, ALLEGRO_ALIGN_LEFT, "Frames: %i", framesElapsed);
                        al_draw_textf(smallFont, al_map_rgb(0, 255, 0), 5, 41, ALLEGRO_ALIGN_LEFT, "Mouse X: %i", mouseX);
                        al_draw_textf(smallFont, al_map_rgb(0, 255, 0), 5, 53, ALLEGRO_ALIGN_LEFT, "Mouse Y: %i", mouseY);
                        al_draw_filled_rectangle(bBack->getX() - bBack->getBoundX(), bBack->getY(), bBack->getX() + bBack->getBoundX(), bBack->getY() + bBack->getBoundY() * 2, al_map_rgb(0, 255, 20));
                        al_draw_filled_rectangle(bVolumeP->getX() - bVolumeP->getBoundX(), bVolumeP->getY(), bVolumeP->getX() + bVolumeP->getBoundX(), bVolumeP->getY() + bVolumeP->getBoundY() * 2, al_map_rgb(0, 255, 20));
                        al_draw_filled_rectangle(bVolumeM->getX() - bVolumeM->getBoundX(), bVolumeM->getY(), bVolumeM->getX() + bVolumeM->getBoundX(), bVolumeM->getY() + bVolumeM->getBoundY() * 2, al_map_rgb(0, 255, 20));
                        al_draw_filled_rectangle(bDifficultyP->getX() - bDifficultyP->getBoundX(), bDifficultyP->getY(), bDifficultyP->getX() + bDifficultyP->getBoundX(), bDifficultyP->getY() + bDifficultyP->getBoundY() * 2, al_map_rgb(0, 255, 20));
                        al_draw_filled_rectangle(bDifficultyM->getX() - bDifficultyM->getBoundX(), bDifficultyM->getY(), bDifficultyM->getX() + bDifficultyM->getBoundX(), bDifficultyM->getY() + bDifficultyM->getBoundY() * 2, al_map_rgb(0, 255, 20));
                    }

                    al_draw_text(bigFont, al_map_rgb(255, 255, 255), screenW / 2, screenH / 3 - 60, ALLEGRO_ALIGN_CENTRE, "Volume");
                    if (volume == 0.0)
                        al_draw_text(mainFont, al_map_rgb(255, 255, 255), screenW / 2, screenH / 3 + 5, ALLEGRO_ALIGN_CENTRE, "0%");
                    else if (volume == 0.2)
                        al_draw_text(mainFont, al_map_rgb(255, 255, 255), screenW / 2, screenH / 3 + 5, ALLEGRO_ALIGN_CENTRE, "20%");
                    else if (volume == 0.4)
                        al_draw_text(mainFont, al_map_rgb(255, 255, 255), screenW / 2, screenH / 3 + 5, ALLEGRO_ALIGN_CENTRE, "40%");
                    else if (volume == 0.6)
                        al_draw_text(mainFont, al_map_rgb(255, 255, 255), screenW / 2, screenH / 3 + 5, ALLEGRO_ALIGN_CENTRE, "60%");
                    else if (volume == 0.8)
                        al_draw_text(mainFont, al_map_rgb(255, 255, 255), screenW / 2, screenH / 3 + 5, ALLEGRO_ALIGN_CENTRE, "80%");
                    else if (volume == 1.0)
                        al_draw_text(mainFont, al_map_rgb(255, 255, 255), screenW / 2, screenH / 3 + 5, ALLEGRO_ALIGN_CENTRE, "100%");

                    al_draw_text(bigFont, al_map_rgb(255, 255, 255), screenW / 2, (screenH / 3 + 175) - 60, ALLEGRO_ALIGN_CENTRE, "Difficulty");
                    if (difficulty[EASY])
                        al_draw_text(mainFont, al_map_rgb(255, 255, 255), screenW / 2, screenH / 3 + 180, ALLEGRO_ALIGN_CENTRE, "EASY");
                    else if (difficulty[NORM])
                        al_draw_text(mainFont, al_map_rgb(255, 255, 255), screenW / 2, screenH / 3 + 180, ALLEGRO_ALIGN_CENTRE, "NORM");
                    else if (difficulty[HARD])
                        al_draw_text(mainFont, al_map_rgb(255, 255, 255), screenW / 2, screenH / 3 + 180, ALLEGRO_ALIGN_CENTRE, "HARD");

                    bBack->render(4);
                    bVolumeP->render(7);
                    bVolumeM->render(8);
                    bDifficultyP->render(9);
                    bDifficultyM->render(10);
                }

                al_draw_bitmap(mouseBMP, mouseX, mouseY, 0);

                al_flip_display();
                al_clear_to_color(al_map_rgb(0, 0, 0));
            }
        }

        /**********************************************************
        G A M E         L O O P
        **********************************************************/

        if (screenState[GAMESCREEN] && !screenState[TITLESCREEN]) {

            ALLEGRO_EVENT gameEvent;
            al_wait_for_event(eventQueue, &gameEvent);

            if (gameEvent.type == ALLEGRO_EVENT_MOUSE_AXES) {
                mouseX = gameEvent.mouse.x;
                mouseY = gameEvent.mouse.y;
            }

            if (gameEvent.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) {
                if (screenState[MENUSCREEN]) {
                    if (bExit2->getHover()) {
                        if (gameEvent.mouse.button & 1) {
                            screenState[GAMESCREEN] = false;
                            running = false;
                        }
                    }
                    if (bMenu->getHover()) {
                        if (gameEvent.mouse.button & 1) {
                            screenStateC->setToState(1);
                            goto start;
                        }
                    }
                }
            }


                if (counterGame185r > 36) {
                    al_draw_text(mainFont, al_map_rgb(counterGame185r, counterGame185g, counterGame185b), screenW / 2, screenH / 6, 1, "Use WSAD to move");
                    al_draw_text(mainFont, al_map_rgb(counterGame185r, counterGame185g, counterGame185b), screenW / 2, screenH / 5 + 30, 1, "Use SPACE to shoot");
                }

                if (ship.getLives() <= 0) {
                    al_draw_text(titleFont, al_map_rgb(255, 255, 255), screenW / 2, screenH / 2 - 80, 1, "GAME OVER");
                }

                al_draw_filled_rectangle(5, 41, shieldTimer / 10, 59, al_map_rgb(255, 204, 0));
                al_draw_rectangle(5, 41, 1200 / 10, 59, al_map_rgb(255, 255, 255), 2);
                al_draw_textf(smallFont, al_map_rgb(255, 255, 255), 5, 65, 0, "Score: %i", ship.getScore());

                /*DEBUG MODE*/
                if (keys[F3]) {
                    al_draw_textf(smallFont, al_map_rgb(0, 255, 0), 5, 77, ALLEGRO_ALIGN_LEFT, "FPS: %i", gameFPS);
                    al_draw_textf(smallFont, al_map_rgb(0, 255, 0), 5, 89, ALLEGRO_ALIGN_LEFT, "Time: %i min, %i sec", minutes, seconds);
                    al_draw_textf(smallFont, al_map_rgb(0, 255, 0), 5, 101, ALLEGRO_ALIGN_LEFT, "Frames: %i", framesElapsed);
                    al_draw_textf(smallFont, al_map_rgb(0, 255, 0), 5, 113, ALLEGRO_ALIGN_LEFT, "Mouse X: %i", mouseX);
                    al_draw_textf(smallFont, al_map_rgb(0, 255, 0), 5, 125, ALLEGRO_ALIGN_LEFT, "Mouse Y: %i", mouseY);
                    al_draw_textf(smallFont, al_map_rgb(0, 255, 0), 5, 137, ALLEGRO_ALIGN_LEFT, "Objects: %i", objectCount);
                    al_draw_textf(smallFont, al_map_rgb(0, 255, 0), 5, 149, ALLEGRO_ALIGN_LEFT, "Lives: %i", ship.getLives());
                    al_draw_textf(smallFont, al_map_rgb(0, 255, 0), 5, 161, ALLEGRO_ALIGN_LEFT, "Shield: %i", ship.getShield());

                    al_draw_bitmap(mouseBMP, mouseX, mouseY, 0);
                }

                if (screenState[MENUSCREEN]) {
                    /*DEBUG MODE*/
                    if (keys[F3]) {
                        al_draw_filled_rectangle(bExit2->getX() - bExit2->getBoundX(), bExit2->getY(), bExit2->getX() + bExit2->getBoundX(), bExit2->getY() + bExit2->getBoundY() * 2, al_map_rgb(0, 255, 20));
                        al_draw_filled_rectangle(bMenu->getX() - bMenu->getBoundX(), bMenu->getY(), bMenu->getX() + bMenu->getBoundX(), bMenu->getY() + bMenu->getBoundY() * 2, al_map_rgb(0, 255, 20));
                    }

                    if (ship.getLives() > 0)
                        al_draw_text(titleFont, al_map_rgb(255, 255, 255), screenW / 2, screenH / 2 - 80, 1, "PAUSED");
                    else if (ship.getLives() <= 0)
                        al_draw_text(titleFont, al_map_rgb(255, 255, 255), screenW / 2, screenH / 2 - 80, 1, "GAME OVER");

                    bExit2->render(5);
                    bMenu->render(6);

                    al_draw_bitmap(mouseBMP, mouseX, mouseY, 0);
                }

                al_flip_display();
                al_clear_to_color(al_map_rgb(0, 0, 0));
            }
        }
    }

    delete screenStateC;
    delete bPlay;
    delete bHelp;
    delete bOptn;
    delete bBack;
    delete bExit;
    delete bMenu;
    delete bExit2;
    delete bVolumeP;
    delete bVolumeM;
    delete bDifficultyP;
    delete bDifficultyM;

    al_destroy_display(display);
    al_destroy_event_queue(eventQueue);
    al_destroy_timer(timer);
    al_destroy_bitmap(mouseBMP);
    al_destroy_font(mainFont);
    al_destroy_font(smallFont);
    al_destroy_font(titleFont);
    al_destroy_font(bigFont);

    al_destroy_bitmap(player);
    al_destroy_bitmap(playerDamaged);
    al_destroy_bitmap(playerLeft);
    al_destroy_bitmap(playerRight);
    al_destroy_bitmap(playerShield);
    al_destroy_bitmap(bulletPlayer);
    al_destroy_bitmap(nebulaBig);
    al_destroy_bitmap(nebulaSmall);
    al_destroy_bitmap(nebulaVerySmall);
    al_destroy_bitmap(livesIcon);

    al_destroy_sample(bulletSound);
    al_destroy_sample(introSound);

    return 0;
}
c++ allegro5
1个回答
0
投票

你的例子太大而无法破译,但我会给你一些提示。

1)始终初始化变量。

2)在al_init运行之前不要加载资源。这意味着在al_init之前您拥有的所有对象将自动无法加载他们需要的任何资源。同样适用于全局对象,因为它们是在al_init运行之前创建的。

3)如果资源未加载,则可能适用以下其中一项:

A)文件名不正确。

B)当前的工作目录是错误的。

C)不支持您尝试加载的资源格式。

您可以通过尝试资源的绝对路径来消除3A。如果调用成功,您知道您的问题是B),因为程序正在查找文件的错误目录。如果您排除了A并且通过为程序设置正确的工作目录来修复B,并且加载函数返回NULL那么C很可能就是答案。

如果C)是问题,那么有几个选项来解决它。

1)确保您正在使用的allegro版本中内置了对您正在使用的格式的支持。

2)向allegro提交补丁以支持不支持的格式。

© www.soinside.com 2019 - 2024. All rights reserved.