Hi all,
I'm just working on a little Allegro 5 puzzle game for a bit of fun and practise between jobs.
Anyway, I have a bit of an optimization issue. It's a board based game where you have an 8x8 board with each square having a value of 0-3 representing what is on the square, this info is saved in an array.
So I want the squares to be highlighted when the mouse is positioned over them. I've done this by adding a function that whenever the mouse is moved, checks to see it it is now over a different square, and if it is, draws a bitmap over the square which highlights it. However, the function currently redraws the entire board every time it draws the highlight sprite since the screen goes black, just drawing the highlighter sprite if I don't call my redraw function.
Can anyone suggest a way that I can either just redraw the square the mouse is over rather than the whole board or store the board (made up of 64 bitmaps drawn to the screen) as a new bitmap and just draw that to the screen as 1 bitmap each time the funciton is called rather than each of the 64 bitmaps individually?
Here is my code for this function:
if(ev.type == ALLEGRO_EVENT_MOUSE_AXES && ev.mouse.x < 500 && ev.mouse.y < 500)
{
mousex = ev.mouse.x/50;
mousey = ev.mouse.y/50;
currmousepos[0] = mousey*50;
currmousepos[1] = mousex*50;
if(currmousepos[0] != lastmousepos[0] || currmousepos[1] != lastmousepos[1])
{
printscore();
redraw();
al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE);
al_draw_bitmap(highlight,mousex*50,mousey*50,0);
al_draw_bitmap(pass,500,300,0);
al_flip_display();
}
lastmousepos[0] = currmousepos[0];
lastmousepos[1] = currmousepos[1];
}