cppgameprogramming.com

It is currently Mon Sep 06, 2010 9:01 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Text clearing problem
PostPosted: Fri Jul 30, 2010 2:08 pm 
Offline
Code Master

Joined: Sat Jul 03, 2010 9:28 am
Posts: 110
Location: Belgium
What do I have to do to make the text dissapear? I tried rectfill, but that just drew a rectangle behind the text. The reason I'm asking this is because I'm making a menu where you can choose the difficulty level by hitting the left and the right arrows. Clearing the screen and redrawing everything isn't an option, I have to clear just a little bit of text.

_________________
- Addicted Memory programmer XD - made a port to TI-83+/TI-84+ and planning nds version


Top
 Profile  
 
 Post subject: Re: Text clearing problem
PostPosted: Fri Jul 30, 2010 2:15 pm 
Offline
Moderator
User avatar

Joined: Wed Feb 25, 2009 3:00 am
Posts: 498
Location: Argentina
o.O?
Maybe you drew the rect before the text?
What does your code look like?

_________________
Image


Top
 Profile  
 
 Post subject: Re: Text clearing problem
PostPosted: Fri Jul 30, 2010 4:05 pm 
Offline
Moderator
User avatar

Joined: Tue Aug 19, 2008 2:34 pm
Posts: 102
Why is clearing and redrawing not an option?


Top
 Profile  
 
 Post subject: Re: Text clearing problem
PostPosted: Fri Jul 30, 2010 8:07 pm 
Offline
Code Master

Joined: Sat Jul 03, 2010 9:28 am
Posts: 110
Location: Belgium
@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 :oops: :oops: :oops:

_________________
- Addicted Memory programmer XD - made a port to TI-83+/TI-84+ and planning nds version


Top
 Profile  
 
 Post subject: Re: Text clearing problem
PostPosted: Sat Jul 31, 2010 5:52 pm 
Offline
Code Master
User avatar

Joined: Fri Apr 17, 2009 12:50 am
Posts: 166
Location: United States
lol good to see the game_modes enumeration I showed you, I don't see where you set mode to main_menu in the beginning, but if it's working for you then I guess there's no problem here, nice job.
edit: yeah, I just ran it and can definitely see the resemblance with pongX's menu :P too bad they don't have easy text functions in SDL like in Allegro or I'd still use this method as well.

_________________
http://www.youtube.com/user/Donutslayer7

I turned 848 lines of code into 14.
Oh and another 24 into 4 just now.


Top
 Profile  
 
 Post subject: Re: Text clearing problem
PostPosted: Sat Jul 31, 2010 6:16 pm 
Offline
Code Master

Joined: Sat Jul 03, 2010 9:28 am
Posts: 110
Location: Belgium
Quote:
lol good to see the game_modes enumeration I showed you, I don't see where you set mode to main_menu in the beginning, but if it's working for you then I guess there's no problem here, nice job.

It's working because main_menu is the first element of game_modes. Therefore main_menu is the same as 0. As mode isn't set to any value it will automatically 0 so there is your main_menu.

_________________
- Addicted Memory programmer XD - made a port to TI-83+/TI-84+ and planning nds version


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group