hey everyone,
I have encountered a quite strange error. I have been working on my first little rpg and had never a problem with this function before
but since having made several changes in other positions my args width and height in init_system(int, int) are not defined correctly (having undetermined values) and also have the same address in memory-.-
EDIT: I'm using MS VC++ 2010 and ALLEGRO 5.0.8 for my program.
Here the main file, other files may follow as necessary:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <allegro5/allegro.h>
#include <allegro5/allegro_native_dialog.h>
#include <allegro5\allegro_image.h>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include "GraphicsLibrary.h"
#include "Tile.h"
#include "Player.h"
using namespace std;
#define FPS 60
int init_system(int, int);
void tidy_up();
void drawScene();
void check_key(int);
void proceed_key();
ALLEGRO_DISPLAY *display = NULL;
ALLEGRO_EVENT_QUEUE *event_queue = NULL;
ALLEGRO_TIMER *timer = NULL;
bool keys[ALLEGRO_KEY_MAX];
Tile *currentRegion;
Player *player;
const int SCREEN_WIDTH = 1920;
const int SCREEN_HEIGHT = 1080;
int main(int argc, char *argv[])
{
bool redraw = true;
if (init_system(1920, 1080) == -1){
system("pause");
return -1;
}
while(1){
ALLEGRO_EVENT ev;
al_wait_for_event(event_queue, &ev);
if (ev.type == ALLEGRO_EVENT_TIMER){
redraw = true;
}
else if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE){
break;
}
else if (ev.type == ALLEGRO_EVENT_KEY_DOWN){
check_key(ev.keyboard.keycode);
}
if (redraw && al_is_event_queue_empty(event_queue)){
redraw = false;
drawScene();
al_flip_display();
}
proceed_key();
al_rest(0.01);
}
tidy_up();
}
int init_system(int width, int height){
if(!al_init()) {
fprintf(stderr, "failed to initialize allegro!\n");
return -1;
}
if (!al_install_keyboard()){
fprintf(stderr, "failed to initialize the keyboard!\n");
return -1;
}
if (al_show_native_message_box(display,
"3DPogramming",
"Fullscreen",
"Do you want to launch in fullscreen mode?",
NULL,
ALLEGRO_MESSAGEBOX_YES_NO) == 1)
al_set_new_display_flags(ALLEGRO_FULLSCREEN);
display = al_create_display(width, height);
if(!display) {
fprintf(stderr, "failed to create display!\n");
return -1;
}
event_queue = al_create_event_queue();
if (!event_queue){
fprintf(stderr, "failed to create event queue!\n");
al_destroy_display(display);
return -1;
}
timer = al_create_timer(1.0 / FPS);
if (!timer){
fprintf(stderr, "failed to create timer!\n");
al_destroy_display(display);
al_destroy_event_queue(event_queue);
}
if (!al_init_image_addon()){
fprintf(stderr, "failed to init image addon!\n");
al_destroy_display(display);
al_destroy_event_queue(event_queue);
al_destroy_timer(timer);
}
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_register_event_source(event_queue, al_get_keyboard_event_source());
al_start_timer(timer);
GraphicsLibrary::create();
currentRegion = new CapitalCity();
player = new Player();
return 0;
}
void tidy_up(){
al_destroy_timer(timer);
al_destroy_display(display);
al_destroy_event_queue(event_queue);
al_shutdown_image_addon();
exit(0);
}
void drawScene(){
currentRegion->drawGround(player->getX(), player->getY());
player->draw(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2);
}
void check_key(int kc){
keys[kc] = true;
return;
}
void proceed_key(){
if (keys[ALLEGRO_KEY_ESCAPE]){
keys[ALLEGRO_KEY_ESCAPE] = false;
tidy_up();
}
}