#macro FILE_CONFIG "config.ini"
#macro FILE_SAVE "save.ini"

draw_set_font(font_default);

instance_create_depth(room_width / 2, 0, 0, obj_player);
instance_create_depth(room_width / 2, -sprite_get_height(spr_player) - sprite_get_height(spr_booster), 0, obj_booster);

view_camera[0] = camera_create_view(obj_player.x, obj_player.y, room_width, room_height);
view_enabled = true;
view_set_visible(0, true);
camera_set_view_pos(view_camera[0], obj_player.x - room_width / 2, obj_player.y - room_height / 2);

global.deathLine = 32;
global.deathLineSpeed = 0.175;
global.deathLineDelay = 60;
global.deathLineDistance = 550;

physics_pause_enable(true);

global.laserSize = sprite_get_width(spr_laserH);
laserImageIndex = 0;
laserImageSpeed = 0.2;
laserImageNumber = sprite_get_number(spr_laserH);

enum GAME_STATE {
	MAIN_MENU,
	WAITING,
	PLAYING,
	PAUSE,
	GAME_OVER
}

global.gameState = GAME_STATE.MAIN_MENU;

enum MENU {
	START,
	MUSIC,
	SOUND,
	WINDOW_SIZE,
	EXIT
}

global.menuTexts[MENU.START] = "START";
global.menuTexts[MENU.MUSIC] = "MUSIC";
global.menuTexts[MENU.SOUND] = "SOUND";
global.menuTexts[MENU.WINDOW_SIZE] = "SIZE";
global.menuTexts[MENU.EXIT] = "EXIT";

global.menuSelected = MENU.START;

ini_open(FILE_CONFIG);
global.scale = ini_read_real("SYSTEM", "window_size", 3);
global.maxScale = 4;
global.scale = clamp(global.scale, 0, global.maxScale);
if (global.scale == 0) {
	window_set_fullscreen(true);
} else {
	window_set_size(256 * global.scale, 240 * global.scale);
	alarm[0] = 1;
}

global.music = ini_read_real("SYSTEM", "music", true);
global.sound = ini_read_real("SYSTEM", "sound", true);
ini_close();

ini_open(FILE_SAVE);
global.bestScore = ini_read_real("GAME", "best_score", 0);
ini_close();
global.newScore = false;

global.menuEvents[MENU.START] = startGame;
global.menuEvents[MENU.MUSIC] = changeMusic;
global.menuEvents[MENU.SOUND] = changeSound;
global.menuEvents[MENU.WINDOW_SIZE] = changeWindowSize;
global.menuEvents[MENU.EXIT] = exitFromGame;

menuSelectDelay = 10;
menuSelectTimer = 0;

enemyCreatingTimer = 0;
enemyCreatingDelay = 10
enemyCreatingDelayRandom = 10;

laserCreatingTimer = 0;
laserCreatingDelay = 200
laserCreatingDelayRandom = 20;

boosterCreatingTimer = 0;
boosterCreatingDelay = 200
boosterCreatingDelayRandom = 20;

if (global.music) {
	audio_play_sound(snd_mainMenu, 0, false);
}

pressTimer = 0;
pressDelayShow = 60;
pressDelayHide = 30;
pressShowing = true;

enum PAUSE_MENU {
	CONTINUE,
	EXIT
}
global.pauseMenuTexts[PAUSE_MENU.CONTINUE] = "CONTINUE";
global.pauseMenuTexts[PAUSE_MENU.EXIT] = "GO TO MENU";

global.pauseMenuEvents[PAUSE_MENU.CONTINUE] = continueGame;
global.pauseMenuEvents[PAUSE_MENU.EXIT] = goToMenu;

global.noMoved = true;
global.noSplashed = true;

window_set_caption("Blast of 8-bit");