@Flacko: I did draw the rectangle before drawing the text, but still...
@Dakatt: Now tried it with clearing and redrawing, now got a new problem(see below).
Instead of being drawn white first and when you press the down arrow turn red, the text "Difficulty level:" is directly drawn red from the start when you select puzzle mode. I also don't seem to be able to let my program set selectiontype to 2 to select the difficulty level. Any help?
Code:
#include <allegro.h>
enum game_modes
{
main_menu, game_menu, controls, game_sandbox, game_puzzle
};
// a lot of other variables
game_modes mode;
int quit = 0;
int finished = 0; // variable to check if the game was finished or the user just pressed [ESC]
int cursor = 1;
int newgame = 0;
int turnsleft; //amount of turns left in puzzle mode
int difficulty = 1; // difficulty level: 1=easy, 2=normal, 3=hard, 4=impossible
int selectiontype = 1; // 1=game mode selection, 2=difficulty selection
volatile long speed_counter = 0;
// a lot of other functions
void increment_speed_counter() // this is to maintain consistant update rate across differing PCs
{
speed_counter++; //increment counter
}
void close_button_handler() {
quit=1;
}
int main(void)
{
allegro_init();
install_keyboard();
install_timer(); //installs the timer
LOCK_VARIABLE(speed_counter);
LOCK_FUNCTION(increment_speed_counter);
install_int_ex(increment_speed_counter, BPS_TO_TIMER(12));
LOCK_FUNCTION(close_button_handler);
set_close_button_callback(close_button_handler);
set_color_depth(32);
set_gfx_mode( GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0);
clear_to_color( screen, makecol( 0, 0, 0));
spritesheet = load_bitmap("tiles.bmp",0);
buffer = create_bitmap(150,150);
bufferscreen = create_bitmap(800,600);
while(!key[KEY_ESC] and !quit){
if(speed_counter>0) {
if(mode == main_menu)
{
if(key[KEY_DOWN]) {cursor++; rest(100);}
if(key[KEY_UP]) {cursor--; rest(100);}
if(cursor > 3) cursor = 1;
if(cursor < 1) cursor = 3;
if(cursor == 1)
{
if(key[KEY_SPACE]){
mode = game_menu;
rest(200);
newgame = 1;
}
textout_ex(bufferscreen, font, "New game", SCREEN_W/2, SCREEN_H/2-15, makecol(255, 255, 255), -1);
} else textout_ex(bufferscreen, font, "New game", SCREEN_W/2, SCREEN_H/2-15, makecol(100, 100, 100), -1);
if(cursor == 2){
if(key[KEY_SPACE]){ mode = controls;}
textout_ex(bufferscreen, font, "Controls", SCREEN_W/2, SCREEN_H/2-5, makecol(255, 255, 255), -1);
}else textout_ex(bufferscreen, font, "Controls", SCREEN_W/2, SCREEN_H/2-5, makecol(100, 100, 100), -1);
if(cursor == 3)
{
if(key[KEY_SPACE]){ exit(0);}
textout_ex(bufferscreen, font, "Quit", SCREEN_W/2, SCREEN_H/2+5, makecol(255, 255, 255), -1);
}else textout_ex(bufferscreen, font, "Quit", SCREEN_W/2, SCREEN_H/2+5, makecol(100, 100, 100), -1);
draw_sprite(screen,bufferscreen,0,0);
}
if(mode == game_menu)
{
clear_to_color(bufferscreen,makecol(0,0,0));
if(selectiontype = 1){
if(key[KEY_LEFT]) {cursor--; rest(100);}
if(key[KEY_RIGHT]) {cursor++; rest(100);}
if(cursor > 2) cursor = 1;
if(cursor < 1) cursor = 2;
textout_centre_ex(bufferscreen,font,"Choose game mode:",SCREEN_W/2,SCREEN_H/4, makecol(100,0,0),-1);
} else if(selectiontype = 2){
if(key[KEY_LEFT]) {difficulty--; rest(100);}
if(key[KEY_RIGHT]) {difficulty++; rest(100);}
if(difficulty > 4) difficulty = 1;
if(difficulty < 1) difficulty = 4;
textout_centre_ex(bufferscreen,font,"Choose game mode:",SCREEN_W/2,SCREEN_H/4, makecol(255,255,255),-1);
}
if(key[KEY_R]) mode = main_menu;
if(cursor==1)
{
if(key[KEY_SPACE]) mode = game_sandbox;
textout_centre_ex(bufferscreen,font,"< Sandbox mode >", SCREEN_W/2, SCREEN_H/4+10, makecol(100,100,100),-1);
}
if(cursor==2)
{
if(key[KEY_DOWN]) selectiontype = 2; // It won't react to this!!
if(key[KEY_SPACE]) mode = game_puzzle;
textout_centre_ex(bufferscreen,font,"< Puzzle mode >", SCREEN_W/2, SCREEN_H/4+10, makecol(100,100,100),-1);
if(selectiontype = 1) textout_centre_ex(bufferscreen,font,"Difficulty level:", SCREEN_W/2, SCREEN_H/2, makecol(255,255,255),-1);
if(selectiontype = 2) textout_centre_ex(bufferscreen,font,"Difficulty level:", SCREEN_W/2, SCREEN_H/2, makecol(100,0,0),-1);
switch(difficulty)
{
case 1:
textout_centre_ex(bufferscreen,font,"< Easy >", SCREEN_W/2, SCREEN_H/2+10, makecol(100,100,100),-1);
turnsleft = 40;
break;
case 2:
textout_centre_ex(bufferscreen,font,"< Normal >", SCREEN_W/2, SCREEN_H/2+10, makecol(100,100,100),-1);
turnsleft = 24;
break;
case 3:
textout_centre_ex(bufferscreen,font,"< Hard >", SCREEN_W/2, SCREEN_H/2+10, makecol(100,100,100),-1);
turnsleft = 16;
break;
case 4:
textout_centre_ex(bufferscreen,font,"< IMPOSSIBLE! >", SCREEN_W/2, SCREEN_H/2+10, makecol(100,100,100),-1);
turnsleft = 8;
break;
}
}
draw_sprite(screen,bufferscreen,0,0);
}
if(mode == game_puzzle)
{
if(key[KEY_R]) mode = main_menu;
clear_to_color(screen, makecol(0,0,0));
}
if(mode == game_sandbox)
{
if(key[KEY_R]) mode = main_menu;
if(newgame) {
clear_to_color(screen,makecol(0,0,0));
tilesinit();
tiledraw();
arrayHussle(pBoard,16);
updatescreen();
rest(200);
newgame=0;
}
moveBox();
if(Check_func()) {
showendscreen();
}
}
if(mode == controls)
{
clear_to_color(screen,makecol(0,0,0));
textout_centre_ex(screen,font,"Press arrow keys to move the cursor",SCREEN_W/2,SCREEN_H/2-5,makecol(255,255,255),-1);
textout_centre_ex(screen,font,"Press space to flip a card",SCREEN_W/2,SCREEN_H/2+5,makecol(255,255,255),-1);
textout_centre_ex(screen,font,"Press R to return to the menu",SCREEN_W/2,SCREEN_H-40,makecol(255,255,255),-1);
while(!key[KEY_R]) {}
mode = main_menu;
}
speed_counter--;
}
}
return 0;
}
END_OF_MAIN()
EDIT: solved everything... My mistake was I used = instead of == in my if-statements... VERY big and hard-to-find error
