CHM & PDF Programming Manuals

Comments 3 Standard

I know these have come in handy for me over the years. Right click and save link as.

Advertisements

PLEX Update

Leave a comment Standard

Okay, so my blitting is working again but it’s not working up to my standards. Yes, it removes the character from the screen but its re-loading a much larger piece of the board then I want it to. I’m still working on getting it to exactly where I want it (a small bounding box around the player’s last position on the board) but I need to get other work done as well.

Now that the character is moving around again without leaving a trail behind, I’ve switched it over to using a local x and y value. What this does is calculate the character’s position on the screen based on the maximum blocks in the window. So you could be looking at a 5 x 5 block of squares around position 50, 50 but instead of drawing the character off the screen like it was before, block 50, 50 is in the center of the screen and the character orients itself around the top upper left corner as the 0, 0 coordinate. I’ve done this by modding the character’s global x and y value by the maximum visible blocks on the board.

Now the next thing I’ll be working on is getting blocks from other parts of the board to re-draw themselves and to finish re-positioning the character after it has moved off of the current frame of blocks. I’m including some pictures below to help explain what I’ve been doing.

Blitting Problems

Visible Blocks

Experimental Gameplay

Leave a comment Standard

My friend sent me this link. Looks interesting! http://experimentalgameplay.com/

Allegro Tutorial: Alternative Text Input (not using Allegro GUI)

Comments 4 Standard

Okay, I didn’t program this, I actually got it from a friend. I’m not sure who wrote it (my friend didn’t) but he said it was freeware.

#include allegro.h
#include winalleg.h
#include string
using namespace std;

#define WHITE makecol(255, 255, 255)

void init();
void deinit();

int main()
{
   // typical Allegro initialization
   allegro_init();
   install_keyboard();
   set_gfx_mode(GFX_AUTODETECT, 320, 240, 0, 0);

   // all variables are here
   BITMAP* buffer = create_bitmap(320, 240); // initialize the double buffer
   string  edittext;                         // an empty string for editting
   string::iterator iter = edittext.begin(); // string iterator
   int     caret  = 0;                       // tracks the text caret
   bool    insert = true;                    // true if text should be inserted

   // the game loop
   do
   {
      while(keypressed())
      {
         int  newkey   = readkey();
         char ASCII    = newkey & 0xff;
         char scancode = newkey >> 8;

         // a character key was pressed; add it to the string
         if(ASCII >= 32 && ASCII <= 126)
         {
            // add the new char, inserting or replacing as need be
            if(insert || iter == edittext.end())
               iter = edittext.insert(iter, ASCII);
            else
               edittext.replace(caret, 1, 1, ASCII);

            // increment both the caret and the iterator
            caret++;
            iter++;
         }
         // some other, "special" key was pressed; handle it here
         else
            switch(scancode)
            {
               case KEY_DEL:
                  if(iter != edittext.end()) iter = edittext.erase(iter);
               break;

               case KEY_BACKSPACE:
                  if(iter != edittext.begin())
                  {
                     caret--;
                     iter--;
                     iter = edittext.erase(iter);
                  }
               break;

               case KEY_RIGHT:
                  if(iter != edittext.end())   caret++, iter++;
               break;

               case KEY_LEFT:
                  if(iter != edittext.begin()) caret--, iter--;
               break;

               case KEY_INSERT:
                  insert = !insert;
               break;

               default:

               break;
            }
      }

      // clear screen
      clear(buffer);

      // output the string to the screen
      textout(buffer, font, edittext.c_str(), 0, 10, WHITE);

      // output some stats using Allegro's printf functions
      textprintf(buffer, font,  0, 20, WHITE, "length:   %d", edittext.length());
      textprintf(buffer, font,  0, 30, WHITE, "capacity: %d", edittext.capacity());
      textprintf(buffer, font,  0, 40, WHITE, "empty?:   %d", edittext.empty());
      if(insert)
         textout(buffer, font, "Inserting", 0, 50, WHITE);
      else
         textout(buffer, font, "Replacing", 0, 50, WHITE);

      // draw the caret
      vline(buffer, caret * 8, 8, 18, WHITE);

      // blit to screen
      blit(buffer, screen, 0, 0, 0, 0, 320, 240);

   }while(!key[KEY_ESC]); // end of game loop

   // clean up
   destroy_bitmap(buffer);
   set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);

   return 0;
}
END_OF_MAIN()

void init() {
	int depth, res;
	allegro_init();
	depth = desktop_color_depth();
	if (depth == 0) depth = 32;
	set_color_depth(depth);
	res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
	if (res != 0) {
		allegro_message(allegro_error);
		exit(-1);
	}

	install_timer();
	install_keyboard();
	install_mouse();
	/* add other initializations here */
}

void deinit() {
	clear_keybuf();
	/* add other deinitializations here */
}